1
0
mirror of synced 2026-03-06 19:41:07 +00:00

fix shifting in flip_h().

This commit is contained in:
Eric Smith
2003-03-16 15:27:06 +00:00
parent 689162e415
commit 51bbc58242

View File

@@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* bitblt routines
* $Id: bitblt.c,v 1.16 2003/03/13 00:57:05 eric Exp $
* $Id: bitblt.c,v 1.17 2003/03/16 07:27:06 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@@ -56,6 +56,24 @@ static word_t bit_reverse_word (word_t d)
}
static void reverse_range_of_bytes (uint8_t *b, uint32_t count)
{
uint8_t *b2 = b + count - 1;
while (b < b2)
{
uint8_t t = bit_reverse_byte [*b];
*b = bit_reverse_byte [*b2];
*b2 = t;
b++;
b2--;
}
if (b == b2)
*b = bit_reverse_byte [*b];
}
static word_t *temp_buffer;
static word_t temp_buffer_size;
@@ -627,30 +645,22 @@ Bitmap *bitblt (Bitmap *src_bitmap,
void flip_h (Bitmap *src)
{
word_t *rp; /* row pointer */
word_t *p1; /* work src ptr */
word_t *p2; /* work dest ptr */
int32_t y;
int shift1, shift2;
realloc_temp_buffer ((src->row_words + 1) * sizeof (word_t));
rp = src->bits;
if ((rect_width (& src->rect) & 7) == 0)
{
for (y = src->rect.min.y; y < src->rect.max.y; y++)
{
memcpy (temp_buffer, rp, src->row_words * sizeof (word_t));
p1 = temp_buffer + src->row_words;
p2 = rp;
while (p1 >= temp_buffer)
*(p2++) = bit_reverse_word (*(p1--));
reverse_range_of_bytes ((uint8_t *) rp, rect_width (& src->rect) / 8);
rp += src->row_words;
}
return;
}
realloc_temp_buffer ((src->row_words + 1) * sizeof (word_t));
temp_buffer [0] = 0;
shift1 = rect_width (& src->rect) & (BITS_PER_WORD - 1);
shift2 = BITS_PER_WORD - shift1;
@@ -658,6 +668,8 @@ void flip_h (Bitmap *src)
for (y = src->rect.min.y; y < src->rect.max.y; y++)
{
word_t d1, d2;
word_t *p1; /* work src ptr */
word_t *p2; /* work dest ptr */
memcpy (temp_buffer + 1, rp, src->row_words * sizeof (word_t));
p1 = temp_buffer + src->row_words;
@@ -667,8 +679,10 @@ void flip_h (Bitmap *src)
while (p1 >= temp_buffer)
{
word_t t;
d1 = *(p1--);
*(p2++) = bit_reverse_word ((d1 << shift1) | (d2 >> shift2));
t = (d1 >> shift1) | (d2 << shift2);
*(p2++) = bit_reverse_word (t);
d2 = d1;
}
@@ -676,6 +690,7 @@ void flip_h (Bitmap *src)
}
}
void flip_v (Bitmap *src)
{
word_t *p1, *p2;