Mon, 26 Aug 2002 05:43:49 +0000
fixed 'middle-endian' output from TIFFReadScanline
bitblt.c | file | annotate | diff | revisions | |
bitblt.h | file | annotate | diff | revisions | |
bitblt_test.c | file | annotate | diff | revisions | |
t2p.c | file | annotate | diff | revisions | |
tumble.c | file | annotate | diff | revisions |
1.1 diff -r 20fda1ec5f17 -r bfc6aaa089b0 bitblt.c 1.2 --- a/bitblt.c Sun Aug 25 13:22:42 2002 +0000 1.3 +++ b/bitblt.c Mon Aug 26 05:43:49 2002 +0000 1.4 @@ -1,3 +1,4 @@ 1.5 +#include <assert.h> 1.6 #include <stdio.h> 1.7 #include <stdlib.h> 1.8 #include <string.h> 1.9 @@ -45,6 +46,17 @@ 1.10 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff 1.11 }; 1.12 1.13 + 1.14 +void reverse_bits (u8 *p, int byte_count) 1.15 +{ 1.16 + while (byte_count--) 1.17 + { 1.18 + (*p) = bit_reverse_byte [*p]; 1.19 + p++; 1.20 + } 1.21 +} 1.22 + 1.23 + 1.24 static word_type bit_reverse_word (word_type d) 1.25 { 1.26 return (bit_reverse_byte [d >> 24] | 1.27 @@ -54,8 +66,8 @@ 1.28 } 1.29 1.30 1.31 -static u32 *temp_buffer; 1.32 -static u32 temp_buffer_size; 1.33 +static word_type *temp_buffer; 1.34 +static word_type temp_buffer_size; 1.35 1.36 static void realloc_temp_buffer (u32 size) 1.37 { 1.38 @@ -71,15 +83,41 @@ 1.39 } 1.40 1.41 1.42 -static inline word_type pixel_mask (x) 1.43 +static inline word_type pixel_mask (int x) 1.44 { 1.45 -#ifdef LSB_LEFT 1.46 - return (1 << x); 1.47 +#if defined (MIXED_ENDIAN) /* disgusting hack for mixed-endian */ 1.48 + word_type m; 1.49 + m = 0x80 >> (x & 7); 1.50 + m <<= (x & 24); 1.51 + return (m); 1.52 +#elif defined (LSB_RIGHT) 1.53 + return (1U << ((BITS_PER_WORD - 1) - x)); 1.54 #else 1.55 - return (1 << ((BITS_PER_WORD - 1) - x)); 1.56 + return (1U << x); 1.57 #endif 1.58 }; 1.59 1.60 + 1.61 +/* mask for range of bits left..right, inclusive */ 1.62 +static inline word_type pixel_range_mask (int left, int right) 1.63 +{ 1.64 + word_type m1, m2, val; 1.65 + 1.66 + /* $$$ one of these cases is wrong! */ 1.67 +#if defined (LSB_RIGHT) 1.68 + m1 = (~ 0U) >> left; 1.69 + m2 = (~ 0U) << (BITS_PER_WORD - 1 - right); 1.70 +#else 1.71 + m1 = (~ 0U) << left; 1.72 + m2 = (~ 0U) >> (BITS_PER_WORD - 1 - right); 1.73 +#endif 1.74 + val = m1 & m2; 1.75 + 1.76 + printf ("left %d, right %d, mask %08x\n", left, right, val); 1.77 + return (val); 1.78 +}; 1.79 + 1.80 + 1.81 Bitmap *create_bitmap (Rect *rect) 1.82 { 1.83 Bitmap *bitmap; 1.84 @@ -112,32 +150,40 @@ 1.85 boolean get_pixel (Bitmap *bitmap, Point coord) 1.86 { 1.87 word_type *p; 1.88 + int w,b; 1.89 + 1.90 if ((coord.x < bitmap->rect.min.x) || 1.91 (coord.x >= bitmap->rect.max.x) || 1.92 (coord.y < bitmap->rect.min.y) || 1.93 (coord.y >= bitmap->rect.max.y)) 1.94 return (0); 1.95 - p = bitmap->bits + 1.96 - (coord.y - bitmap->rect.min.y) * bitmap->row_words + 1.97 - (coord.x - bitmap->rect.min.x) / BITS_PER_WORD; 1.98 - return ((*p & pixel_mask (coord.x & (BITS_PER_WORD - 1))) != 0); 1.99 + coord.y -= bitmap->rect.min.y; 1.100 + coord.x -= bitmap->rect.min.x; 1.101 + w = coord.x / BITS_PER_WORD; 1.102 + b = coord.x & (BITS_PER_WORD - 1); 1.103 + p = bitmap->bits + coord.y * bitmap->row_words + w; 1.104 + return (((*p) & pixel_mask (b)) != 0); 1.105 } 1.106 1.107 void set_pixel (Bitmap *bitmap, Point coord, boolean value) 1.108 { 1.109 word_type *p; 1.110 + int w,b; 1.111 + 1.112 if ((coord.x < bitmap->rect.min.x) || 1.113 (coord.x >= bitmap->rect.max.x) || 1.114 (coord.y < bitmap->rect.min.y) || 1.115 (coord.y >= bitmap->rect.max.y)) 1.116 return; 1.117 - p = bitmap->bits + 1.118 - (coord.y - bitmap->rect.min.y) * bitmap->row_words + 1.119 - (coord.x - bitmap->rect.min.x) / BITS_PER_WORD; 1.120 + coord.y -= bitmap->rect.min.y; 1.121 + coord.x -= bitmap->rect.min.x; 1.122 + w = coord.x / BITS_PER_WORD; 1.123 + b = coord.x & (BITS_PER_WORD - 1); 1.124 + p = bitmap->bits + coord.y * bitmap->row_words + w; 1.125 if (value) 1.126 - *p |= pixel_mask (coord.x & (BITS_PER_WORD - 1)); 1.127 + (*p) |= pixel_mask (b); 1.128 else 1.129 - *p &= ~pixel_mask (coord.x & (BITS_PER_WORD - 1)); 1.130 + (*p) &= ~pixel_mask (b); 1.131 } 1.132 1.133 1.134 @@ -174,36 +220,104 @@ 1.135 } 1.136 1.137 1.138 -#if 0 1.139 static void blt_background (Bitmap *dest_bitmap, 1.140 - Rect *dest_rect) 1.141 + Rect dest_rect) 1.142 { 1.143 - s32 y; 1.144 + u32 y; 1.145 word_type *rp; 1.146 + u32 left_bit, left_word; 1.147 + u32 right_bit, right_word; 1.148 + word_type left_mask, right_mask; 1.149 + s32 word_count; 1.150 1.151 /* This function requires a non-null dest rect */ 1.152 - assert (dest_rect->min.x < dest_rect->max.x); 1.153 - assert (dest_rect->min.y < dest_rect->max.y); 1.154 + assert (dest_rect.min.x < dest_rect.max.x); 1.155 + assert (dest_rect.min.y < dest_rect.max.y); 1.156 1.157 /* and that the rows of the dest rect lie entirely within the dest bitmap */ 1.158 - assert (dest_rect->min.y >= dest_bitmap->rect->min.y); 1.159 - assert (dest_rect->max.y <= dest_bitmap->rect->max.y); 1.160 + assert (dest_rect.min.y >= dest_bitmap->rect.min.y); 1.161 + assert (dest_rect.max.y <= dest_bitmap->rect.max.y); 1.162 1.163 /* clip the x axis of the dest_rect to the bounds of the dest bitmap */ 1.164 - if (dest_rect->min.x < dest_bitmap->rect.min.x) 1.165 - dest_rect->min.x = dest_bitmap->rect.min.x; 1.166 - if (dest_rect->max.x > dest_bitmap->rect.max.x) 1.167 - dest_rect->max.x = dest_bitmap->rect.max.x; 1.168 + if (dest_rect.min.x < dest_bitmap->rect.min.x) 1.169 + dest_rect.min.x = dest_bitmap->rect.min.x; 1.170 + if (dest_rect.max.x > dest_bitmap->rect.max.x) 1.171 + dest_rect.max.x = dest_bitmap->rect.max.x; 1.172 + 1.173 + rp = dest_bitmap->bits + 1.174 + (dest_rect.min.y - dest_bitmap->rect.min.y) * dest_bitmap->row_words + 1.175 + (dest_rect.min.x - dest_bitmap->rect.min.x) / BITS_PER_WORD; 1.176 + 1.177 + left_bit = dest_rect.min.x % BITS_PER_WORD; 1.178 + left_word = dest_rect.min.x / BITS_PER_WORD; 1.179 + 1.180 + right_bit = (dest_rect.max.x - 1) % BITS_PER_WORD; 1.181 + right_word = (dest_rect.max.x - 1) / BITS_PER_WORD; 1.182 + 1.183 + word_count = right_word + 1 - left_word; 1.184 + 1.185 + /* special case if entire horizontal range fits in a single word */ 1.186 + if (word_count == 1) 1.187 + { 1.188 + left_mask = 0; 1.189 + right_mask = ~ pixel_range_mask (left_bit, right_bit); 1.190 + word_count = 0; 1.191 + } 1.192 + else 1.193 + { 1.194 + if (left_bit) 1.195 + { 1.196 + left_mask = ~ pixel_range_mask (left_bit, BITS_PER_WORD - 1); 1.197 + word_count--; 1.198 + } 1.199 1.200 - rp = ???; 1.201 - for (y = 0; y < rect_height (dest_rect); y++) 1.202 + if (right_bit != (BITS_PER_WORD - 1)) 1.203 + { 1.204 + right_mask = ~ pixel_range_mask (0, right_bit); 1.205 + word_count--; 1.206 + } 1.207 + } 1.208 + 1.209 + for (y = 0; y < rect_height (& dest_rect); y++) 1.210 { 1.211 - ???; 1.212 + word_type *wp = rp; 1.213 + 1.214 + /* partial word at left, if any */ 1.215 + if (left_mask) 1.216 + *(wp++) &= left_mask; 1.217 + 1.218 + /* use Duff's Device for the full words */ 1.219 + if (word_count) 1.220 + { 1.221 + s32 i = word_count; 1.222 + switch (i % 8) 1.223 + { 1.224 + while (i > 0) 1.225 + { 1.226 + *(wp++) = 0; 1.227 + case 7: *(wp++) = 0; 1.228 + case 6: *(wp++) = 0; 1.229 + case 5: *(wp++) = 0; 1.230 + case 4: *(wp++) = 0; 1.231 + case 3: *(wp++) = 0; 1.232 + case 2: *(wp++) = 0; 1.233 + case 1: *(wp++) = 0; 1.234 + case 0: i -= 8; 1.235 + } 1.236 + } 1.237 + } 1.238 + 1.239 + /* partial word at right, if any */ 1.240 + if (right_mask) 1.241 + *wp &= right_mask; 1.242 + 1.243 + /* advance to next row */ 1.244 rp += dest_bitmap->row_words; 1.245 } 1.246 } 1.247 1.248 1.249 +#if 0 1.250 static void blt (Bitmap *src_bitmap, 1.251 Rect *src_rect, 1.252 Bitmap *dest_bitmap, 1.253 @@ -253,6 +367,32 @@ 1.254 } 1.255 1.256 1.257 +/* 1.258 + * The destination rectangle is first clipped to the dest bitmap, and 1.259 + * the source rectangle is adjusted in the corresponding manner. 1.260 + * What's left is divided into five sections, any of which may be 1.261 + * null. The portion that actually corresponds to the intersection of 1.262 + * the source rectangle and the source bitmpa is the "middle". The 1.263 + * other four sections will use the background color as the source 1.264 + * operand. 1.265 + * 1.266 + * 1.267 + * y0 -> ------------------------------------------------- 1.268 + * | top | 1.269 + * | | 1.270 + * y1 -> ------------------------------------------------- 1.271 + * | left | middle | right | 1.272 + * | | | | 1.273 + * y2 -> ------------------------------------------------- 1.274 + * | bottom | 1.275 + * | | 1.276 + * y3 -> ------------------------------------------------- 1.277 + * 1.278 + * ^ ^ ^ ^ 1.279 + * | | | | 1.280 + * x0 x1 x2 x3 1.281 + * 1.282 + * */ 1.283 Bitmap *bitblt (Bitmap *src_bitmap, 1.284 Rect *src_rect, 1.285 Bitmap *dest_bitmap, 1.286 @@ -265,6 +405,10 @@ 1.287 u32 drw, drh; /* dest rect width, height - gets adjusted */ 1.288 Point src_point, dest_point; 1.289 1.290 + /* dest coordinates: */ 1.291 + u32 x0, x1, x2, x3; 1.292 + u32 y0, y1, y2, y3; 1.293 + 1.294 { 1.295 sr = * src_rect; 1.296 1.297 @@ -274,7 +418,8 @@ 1.298 if ((srw < 0) || (srh < 0)) 1.299 goto done; /* the source rect is empty! */ 1.300 1.301 - dr.min = * dest_min; 1.302 + dr.min.x = dest_min->x; 1.303 + dr.min.y = dest_min->y; 1.304 dr.max.x = dr.min.x + srw; 1.305 dr.max.y = dr.min.y + srh; 1.306 } 1.307 @@ -291,7 +436,6 @@ 1.308 goto done; /* the dest rect isn't even in the dest bitmap! */ 1.309 1.310 /* crop dest rect to dest bitmap */ 1.311 - 1.312 delta = dest_bitmap->rect.min.x - dr.min.x; 1.313 if (delta > 0) 1.314 { 1.315 @@ -323,17 +467,36 @@ 1.316 drw = rect_width (& dr); 1.317 drh = rect_height (& dh); 1.318 1.319 + x0 = dr.min.x; 1.320 + y0 = dr.min.y; 1.321 + x3 = dr.max.x; 1.322 + y3 = dr.max.y; 1.323 + 1.324 +#if 0 1.325 /* if the source rect min y is >= the source bitmap max y, 1.326 we transfer background color to the entire dest rect */ 1.327 if (sr.min.y >= src->rect.max.y) 1.328 { 1.329 - blt_background (dest_bitmap, & dr); 1.330 + blt_background (dest_bitmap, dr); 1.331 goto done; 1.332 } 1.333 +#endif 1.334 + 1.335 + /* top */ 1.336 + if (y0 != y1) 1.337 + { 1.338 + dr2.min.x = x0; 1.339 + dr2.max.x = x3; 1.340 + dr2.min.y = y0; 1.341 + dr2.max.y = y1; 1.342 + blt_background (dest_bitmap, & dr2); 1.343 + } 1.344 1.345 - /* if the source rect min y is less than the source bitmap min y, 1.346 - we need to transfer some backgound color to the top part of the dest 1.347 - rect */ 1.348 + /* 1.349 + * top: if the source rect min y is less than the source bitmap min y, 1.350 + * we need to transfer some backgound color to the top part of the dest 1.351 + * rect 1.352 + */ 1.353 if (sr.min.y < src->rect.min.y) 1.354 { 1.355 Rect dr2; 1.356 @@ -359,13 +522,43 @@ 1.357 goto done; 1.358 } 1.359 1.360 - /* now blt the available rows of the source rect */ 1.361 + if (y1 != y2) 1.362 + { 1.363 + /* left */ 1.364 + if (x0 != x1) 1.365 + { 1.366 + dr2.min.x = x1; 1.367 + dr2.max.x = x1; 1.368 + dr2.min.y = y1; 1.369 + dr2.max.y = y2 1.370 + blt_background (dest_bitmap, & dr2); 1.371 + } 1.372 + 1.373 + /* middle */ 1.374 + if (x1 != x2) 1.375 + { 1.376 + /* ??? */ 1.377 + } 1.378 1.379 - /* now transfer the background color to any remaining rows of the 1.380 - dest rect */ 1.381 - if (??? ) 1.382 + /* right */ 1.383 + if (x2 != x3) 1.384 + { 1.385 + dr2.min.x = x2; 1.386 + dr2.max.x = x3; 1.387 + dr2.min.y = y1; 1.388 + dr2.max.y = y2 1.389 + blt_background (dest_bitmap, & dr2); 1.390 + } 1.391 + } 1.392 + 1.393 + /* bottom */ 1.394 + if (y2 != y3) 1.395 { 1.396 - blt_background (dest_bitmap, & dr); 1.397 + dr2.min.x = x0; 1.398 + dr2.max.x = x3; 1.399 + dr2.min.y = y2; 1.400 + dr2.max.y = y3; 1.401 + blt_background (dest_bitmap, & dr2); 1.402 } 1.403 1.404 done: 1.405 @@ -390,25 +583,49 @@ 1.406 return (NULL); 1.407 } 1.408 1.409 - for (src_point.y = src_rect->min.y; 1.410 - src_point.y < src_rect->max.y; 1.411 - src_point.y++) 1.412 + if (tfn == TF_SRC) 1.413 { 1.414 - dest_point.y = dest_min->y + src_point.y - src_rect->min.y; 1.415 - 1.416 - for (src_point.x = src_rect->min.x; 1.417 - src_point.x < src_rect->max.x; 1.418 - src_point.x++) 1.419 + for (src_point.y = src_rect->min.y; 1.420 + src_point.y < src_rect->max.y; 1.421 + src_point.y++) 1.422 { 1.423 - boolean a, b, c; 1.424 + dest_point.y = dest_min->y + src_point.y - src_rect->min.y; 1.425 + 1.426 + for (src_point.x = src_rect->min.x; 1.427 + src_point.x < src_rect->max.x; 1.428 + src_point.x++) 1.429 + { 1.430 + boolean a; 1.431 1.432 - dest_point.x = dest_min->x + src_point.x - src_rect->min.x; 1.433 + dest_point.x = dest_min->x + src_point.x - src_rect->min.x; 1.434 1.435 - a = get_pixel (src_bitmap, src_point); 1.436 - b = get_pixel (dest_bitmap, dest_point); 1.437 - c = (tfn & (1 << (a * 2 + b))) != 0; 1.438 + a = get_pixel (src_bitmap, src_point); 1.439 + set_pixel (dest_bitmap, dest_point, a); 1.440 + } 1.441 + } 1.442 + } 1.443 + else 1.444 + { 1.445 + for (src_point.y = src_rect->min.y; 1.446 + src_point.y < src_rect->max.y; 1.447 + src_point.y++) 1.448 + { 1.449 + dest_point.y = dest_min->y + src_point.y - src_rect->min.y; 1.450 + 1.451 + for (src_point.x = src_rect->min.x; 1.452 + src_point.x < src_rect->max.x; 1.453 + src_point.x++) 1.454 + { 1.455 + boolean a, b, c; 1.456 1.457 - set_pixel (dest_bitmap, dest_point, c); 1.458 + dest_point.x = dest_min->x + src_point.x - src_rect->min.x; 1.459 + 1.460 + a = get_pixel (src_bitmap, src_point); 1.461 + b = get_pixel (dest_bitmap, dest_point); 1.462 + c = (tfn & (1 << (a * 2 + b))) != 0; 1.463 + 1.464 + set_pixel (dest_bitmap, dest_point, c); 1.465 + } 1.466 } 1.467 } 1.468 return (dest_bitmap);
2.1 diff -r 20fda1ec5f17 -r bfc6aaa089b0 bitblt.h 2.2 --- a/bitblt.h Sun Aug 25 13:22:42 2002 +0000 2.3 +++ b/bitblt.h Mon Aug 26 05:43:49 2002 +0000 2.4 @@ -20,12 +20,11 @@ 2.5 return (r->max.y - r->min.y); 2.6 } 2.7 2.8 -/* 2.9 - * Despite the following two definitions, there are still some places 2.10 - * in the code that depend on words having 32 bits. 2.11 - */ 2.12 -#define BITS_PER_WORD 32 2.13 + 2.14 typedef u32 word_type; 2.15 +#define BITS_PER_WORD (8 * sizeof (word_type)) 2.16 +#define ALL_ONES (~ 0U) 2.17 + 2.18 2.19 typedef struct Bitmap 2.20 { 2.21 @@ -67,3 +66,6 @@ 2.22 2.23 void rot_90 (Bitmap *src); /* transpose + flip_h */ 2.24 void rot_270 (Bitmap *src); /* transpose + flip_v */ 2.25 + 2.26 + 2.27 +void reverse_bits (u8 *p, int byte_count);
3.1 diff -r 20fda1ec5f17 -r bfc6aaa089b0 bitblt_test.c 3.2 --- a/bitblt_test.c Sun Aug 25 13:22:42 2002 +0000 3.3 +++ b/bitblt_test.c Mon Aug 26 05:43:49 2002 +0000 3.4 @@ -78,16 +78,23 @@ 3.5 print_bitmap (stdout, b); 3.6 printf ("\n"); 3.7 3.8 -#if 0 3.9 - r.upper_left.x = r.upper_left.y = 0; 3.10 - r.lower_right.x = b->width; 3.11 - r.lower_right.y = b->height; 3.12 - p.x = p.y = 0; 3.13 +#if 1 3.14 + r.min.x = r.min.y = 0; 3.15 + r.max.x = b->rect.max.x + 8; 3.16 + r.max.y = b->rect.max.y + 8; 3.17 + 3.18 + b2 = create_bitmap (& r); 3.19 3.20 - b2 = bitblt (b, r, 3.21 - NULL, p, 3.22 - ROT_90, 3.23 - TF_SRC); 3.24 + r.min.x = r.min.y = 0; 3.25 + r.max.x = b->rect.max.x; 3.26 + r.max.y = b->rect.max.y; 3.27 + 3.28 + p.x = -3; 3.29 + p.y = -3; 3.30 + 3.31 + b2 = bitblt (b, & r, 3.32 + b2, & p, 3.33 + TF_SRC, 0); 3.34 if (! b2) 3.35 { 3.36 fprintf (stderr, "bitblt failed\n");
4.1 diff -r 20fda1ec5f17 -r bfc6aaa089b0 t2p.c 4.2 --- a/t2p.c Sun Aug 25 13:22:42 2002 +0000 4.3 +++ b/t2p.c Mon Aug 26 05:43:49 2002 +0000 4.4 @@ -4,7 +4,7 @@ 4.5 * will be compressed using ITU-T T.6 (G4) fax encoding. 4.6 * 4.7 * Main program 4.8 - * $Id: t2p.c,v 1.17 2002/08/25 05:22:42 eric Exp $ 4.9 + * $Id: t2p.c,v 1.18 2002/08/25 21:43:49 eric Exp $ 4.10 * Copyright 2001 Eric Smith <eric@brouhaha.com> 4.11 * 4.12 * This program is free software; you can redistribute it and/or modify 4.13 @@ -26,7 +26,10 @@ 4.14 #include <stdio.h> 4.15 #include <stdlib.h> 4.16 #include <unistd.h> 4.17 + 4.18 #include <tiffio.h> 4.19 +#define TIFF_REVERSE_BITS 4.20 + 4.21 #include <panda/functions.h> 4.22 #include <panda/constants.h> 4.23 4.24 @@ -377,6 +380,11 @@ 4.25 goto fail; 4.26 } 4.27 4.28 +#ifdef TIFF_REVERSE_BITS 4.29 + reverse_bits ((u8 *) bitmap->bits, 4.30 + image_length * bitmap->row_words * sizeof (word_type)); 4.31 +#endif /* TIFF_REVERSE_BITS */ 4.32 + 4.33 if (input_attributes.has_page_size) 4.34 bitmap = resize_bitmap (bitmap, 4.35 x_resolution, 4.36 @@ -415,6 +423,11 @@ 4.37 TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 4.38 TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 4.39 4.40 +#ifdef TIFF_REVERSE_BITS 4.41 + reverse_bits ((u8 *) bitmap->bits, 4.42 + image_length * bitmap->row_words * sizeof (word_type)); 4.43 +#endif /* TIFF_REVERSE_BITS */ 4.44 + 4.45 for (row = 0; row < rect_height (& bitmap->rect); row++) 4.46 if (1 != TIFFWriteScanline (tiff_temp, 4.47 bitmap->bits + row * bitmap->row_words,
5.1 diff -r 20fda1ec5f17 -r bfc6aaa089b0 tumble.c 5.2 --- a/tumble.c Sun Aug 25 13:22:42 2002 +0000 5.3 +++ b/tumble.c Mon Aug 26 05:43:49 2002 +0000 5.4 @@ -4,7 +4,7 @@ 5.5 * will be compressed using ITU-T T.6 (G4) fax encoding. 5.6 * 5.7 * Main program 5.8 - * $Id: tumble.c,v 1.17 2002/08/25 05:22:42 eric Exp $ 5.9 + * $Id: tumble.c,v 1.18 2002/08/25 21:43:49 eric Exp $ 5.10 * Copyright 2001 Eric Smith <eric@brouhaha.com> 5.11 * 5.12 * This program is free software; you can redistribute it and/or modify 5.13 @@ -26,7 +26,10 @@ 5.14 #include <stdio.h> 5.15 #include <stdlib.h> 5.16 #include <unistd.h> 5.17 + 5.18 #include <tiffio.h> 5.19 +#define TIFF_REVERSE_BITS 5.20 + 5.21 #include <panda/functions.h> 5.22 #include <panda/constants.h> 5.23 5.24 @@ -377,6 +380,11 @@ 5.25 goto fail; 5.26 } 5.27 5.28 +#ifdef TIFF_REVERSE_BITS 5.29 + reverse_bits ((u8 *) bitmap->bits, 5.30 + image_length * bitmap->row_words * sizeof (word_type)); 5.31 +#endif /* TIFF_REVERSE_BITS */ 5.32 + 5.33 if (input_attributes.has_page_size) 5.34 bitmap = resize_bitmap (bitmap, 5.35 x_resolution, 5.36 @@ -415,6 +423,11 @@ 5.37 TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 5.38 TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 5.39 5.40 +#ifdef TIFF_REVERSE_BITS 5.41 + reverse_bits ((u8 *) bitmap->bits, 5.42 + image_length * bitmap->row_words * sizeof (word_type)); 5.43 +#endif /* TIFF_REVERSE_BITS */ 5.44 + 5.45 for (row = 0; row < rect_height (& bitmap->rect); row++) 5.46 if (1 != TIFFWriteScanline (tiff_temp, 5.47 bitmap->bits + row * bitmap->row_words,