*** empty log message ***

Tue, 22 Jan 2002 09:42:42 +0000

author
eric
date
Tue, 22 Jan 2002 09:42:42 +0000
changeset 43
b80cb5a4282a
parent 42
9c85a4cd88a3
child 44
0f78374addae

*** empty log message ***

Makefile file | annotate | diff | revisions
TODO file | annotate | diff | revisions
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 --- a/Makefile	Wed Jan 02 16:39:39 2002 +0000
     1.2 +++ b/Makefile	Tue Jan 22 09:42:42 2002 +0000
     1.3 @@ -1,6 +1,6 @@
     1.4  # tiff2pdf: build a PDF file out of one or more TIFF Class F Group 4 files
     1.5  # Makefile
     1.6 -# $Id: Makefile,v 1.7 2001/12/30 23:24:50 eric Exp $
     1.7 +# $Id: Makefile,v 1.8 2002/01/22 01:41:12 eric Exp $
     1.8  # Copyright 2001 Eric Smith <eric@brouhaha.com>
     1.9  #
    1.10  # This program is free software; you can redistribute it and/or modify
    1.11 @@ -34,7 +34,7 @@
    1.12  AUTO_HDRS = parser.tab.h
    1.13  AUTO_MISC = parser.output
    1.14  
    1.15 -tiff2pdf: tiff2pdf.o scanner.o semantics.o parser.tab.o
    1.16 +tiff2pdf: tiff2pdf.o scanner.o semantics.o parser.tab.o bitblt.o
    1.17  
    1.18  bitblt_test: bitblt_test.o bitblt.o
    1.19  
     2.1 --- a/TODO	Wed Jan 02 16:39:39 2002 +0000
     2.2 +++ b/TODO	Tue Jan 22 09:42:42 2002 +0000
     2.3 @@ -1,5 +1,5 @@
     2.4  tiff2pdf TODO list
     2.5 -$Id: TODO,v 1.4 2002/01/02 05:49:42 eric Exp $
     2.6 +$Id: TODO,v 1.5 2002/01/22 01:40:59 eric Exp $
     2.7  
     2.8  No particular order.  Page numbers refer to _Portable Document Format
     2.9  Reference Manual_ by Adobe Systems Incorporated, Addison-Wesley, 1993.
    2.10 @@ -7,6 +7,7 @@
    2.11  -----------------------------------------------------------------------------
    2.12  * bitblt library:
    2.13      * optimize
    2.14 +        * replace inner loops in flip_h and flip_v with Duff's Device
    2.15      * check for endian problems
    2.16  
    2.17  * crop
     3.1 --- a/bitblt.c	Wed Jan 02 16:39:39 2002 +0000
     3.2 +++ b/bitblt.c	Tue Jan 22 09:42:42 2002 +0000
     3.3 @@ -6,7 +6,7 @@
     3.4  #include "bitblt.h"
     3.5  
     3.6  
     3.7 -#define CALC_ROWBYTES(width) (((width) - 1) / 8 + 1)
     3.8 +#define DIV_ROUND_UP(count,pow2) (((count) - 1) / (pow2) + 1)
     3.9  
    3.10  
    3.11  static const u8 bit_reverse_byte [0x100] =
    3.12 @@ -45,8 +45,16 @@
    3.13    0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
    3.14  };
    3.15  
    3.16 +static word_type bit_reverse_word (word_type d)
    3.17 +{
    3.18 +  return (bit_reverse_byte [d >> 24] |
    3.19 +	  (bit_reverse_byte [(d >> 16) & 0xff] << 8) |
    3.20 +	  (bit_reverse_byte [(d >> 8) & 0xff] << 16) |
    3.21 +	  (bit_reverse_byte [d & 0xff] << 24));
    3.22 +}
    3.23  
    3.24 -static u8 *temp_buffer;
    3.25 +
    3.26 +static u32 *temp_buffer;
    3.27  static u32 temp_buffer_size;
    3.28  
    3.29  static void realloc_temp_buffer (u32 size)
    3.30 @@ -63,12 +71,12 @@
    3.31  }
    3.32  
    3.33  
    3.34 -static inline u8 pixel_mask (x)
    3.35 +static inline word_type pixel_mask (x)
    3.36  {
    3.37  #ifdef LSB_LEFT
    3.38    return (1 << x);
    3.39  #else
    3.40 -  return (1 << (7 - x));
    3.41 +  return (1 << ((BITS_PER_WORD - 1) - x));
    3.42  #endif
    3.43  };
    3.44  
    3.45 @@ -85,8 +93,8 @@
    3.46    if (! bitmap)
    3.47      return (NULL);
    3.48    bitmap->rect = * rect;
    3.49 -  bitmap->rowbytes = CALC_ROWBYTES (width);
    3.50 -  bitmap->bits = calloc (height * bitmap->rowbytes, 1);
    3.51 +  bitmap->row_words = DIV_ROUND_UP (width, BITS_PER_WORD);
    3.52 +  bitmap->bits = calloc (1, height * bitmap->row_words * sizeof (word_type));
    3.53    if (! bitmap->bits)
    3.54      {
    3.55        free (bitmap);
    3.56 @@ -103,33 +111,33 @@
    3.57  
    3.58  boolean get_pixel (Bitmap *bitmap, Point coord)
    3.59  {
    3.60 -  u8 *p;
    3.61 +  word_type *p;
    3.62    if ((coord.x < bitmap->rect.min.x) ||
    3.63        (coord.x >= bitmap->rect.max.x) ||
    3.64        (coord.y < bitmap->rect.min.y) ||
    3.65        (coord.y >= bitmap->rect.max.y))
    3.66      return (0);
    3.67    p = bitmap->bits +
    3.68 -    (coord.y - bitmap->rect.min.y) * bitmap->rowbytes +
    3.69 -    (coord.x - bitmap->rect.min.x) / 8;
    3.70 -  return ((*p & pixel_mask (coord.x & 7)) != 0);
    3.71 +    (coord.y - bitmap->rect.min.y) * bitmap->row_words +
    3.72 +    (coord.x - bitmap->rect.min.x) / BITS_PER_WORD;
    3.73 +  return ((*p & pixel_mask (coord.x & (BITS_PER_WORD - 1))) != 0);
    3.74  }
    3.75  
    3.76  void set_pixel (Bitmap *bitmap, Point coord, boolean value)
    3.77  {
    3.78 -  u8 *p;
    3.79 +  word_type *p;
    3.80    if ((coord.x < bitmap->rect.min.x) ||
    3.81        (coord.x >= bitmap->rect.max.x) ||
    3.82        (coord.y < bitmap->rect.min.y) ||
    3.83        (coord.y >= bitmap->rect.max.y))
    3.84      return;
    3.85    p = bitmap->bits +
    3.86 -    (coord.y - bitmap->rect.min.y) * bitmap->rowbytes +
    3.87 -    (coord.x - bitmap->rect.min.x) / 8;
    3.88 +    (coord.y - bitmap->rect.min.y) * bitmap->row_words +
    3.89 +    (coord.x - bitmap->rect.min.x) / BITS_PER_WORD;
    3.90    if (value)
    3.91 -    *p |= pixel_mask (coord.x & 7);
    3.92 +    *p |= pixel_mask (coord.x & (BITS_PER_WORD - 1));
    3.93    else
    3.94 -    *p &= (0xff ^ pixel_mask (coord.x & 7));
    3.95 +    *p &= ~pixel_mask (coord.x & (BITS_PER_WORD - 1));
    3.96  }
    3.97  
    3.98  
    3.99 @@ -166,11 +174,210 @@
   3.100  }
   3.101  
   3.102  
   3.103 +#if 0
   3.104 +static void blt_background (Bitmap *dest_bitmap,
   3.105 +			    Rect *dest_rect)
   3.106 +{
   3.107 +  s32 y;
   3.108 +  word_type *rp;
   3.109 +
   3.110 +  /* This function requires a non-null dest rect */
   3.111 +  assert (dest_rect->min.x < dest_rect->max.x);
   3.112 +  assert (dest_rect->min.y < dest_rect->max.y);
   3.113 + 
   3.114 +  /* and that the rows of the dest rect lie entirely within the dest bitmap */
   3.115 +  assert (dest_rect->min.y >= dest_bitmap->rect->min.y);
   3.116 +  assert (dest_rect->max.y <= dest_bitmap->rect->max.y);
   3.117 +
   3.118 +  /* clip the x axis of the dest_rect to the bounds of the dest bitmap */
   3.119 +  if (dest_rect->min.x < dest_bitmap->rect.min.x)
   3.120 +    dest_rect->min.x = dest_bitmap->rect.min.x;
   3.121 +  if (dest_rect->max.x > dest_bitmap->rect.max.x)
   3.122 +    dest_rect->max.x = dest_bitmap->rect.max.x;
   3.123 +
   3.124 +  rp = ???;
   3.125 +  for (y = 0; y < rect_height (dest_rect); y++)
   3.126 +    {
   3.127 +  ???;
   3.128 +      rp += dest_bitmap->row_words;
   3.129 +    }
   3.130 +}
   3.131 +
   3.132 +
   3.133 +static void blt (Bitmap *src_bitmap,
   3.134 +		 Rect *src_rect,
   3.135 +		 Bitmap *dest_bitmap,
   3.136 +		 Rect *dest_rect)
   3.137 +{
   3.138 +  s32 y;
   3.139 +  word_type *rp;
   3.140 +
   3.141 +  /* This function requires a non-null src rect */
   3.142 +  assert (dest_rect->min.x < dest_rect->max.x);
   3.143 +  assert (dest_rect->min.y < dest_rect->max.y);
   3.144 + 
   3.145 +  /* and a non-null dest rect */
   3.146 +  assert (dest_rect->min.x < dest_rect->max.x);
   3.147 +  assert (dest_rect->min.y < dest_rect->max.y);
   3.148 +
   3.149 +  /* and that the widths and heights of the rects match */
   3.150 +  assert (rect_width (src_rect) == rect_width (dest_rect));
   3.151 +  assert (rect_height (src_rect) == rect_height (dest_rect));
   3.152 + 
   3.153 +  /* and that the rows of the src rect lie entirely within the src bitmap */
   3.154 +  assert (dest_rect->min.y >= dest_bitmap->rect->min.y);
   3.155 +  assert (dest_rect->max.y <= dest_bitmap->rect->max.y);
   3.156 +
   3.157 +  /* and that the rows of the dest rect lie entirely within the dest bitmap */
   3.158 +  assert (dest_rect->min.y >= dest_bitmap->rect->min.y);
   3.159 +  assert (dest_rect->max.y <= dest_bitmap->rect->max.y);
   3.160 +
   3.161 +  /* clip the x axis of the dest_rect to the bounds of the dest bitmap,
   3.162 +     and adjust the src_rect to match */
   3.163 +  if (dest_rect->min.x < dest_bitmap->rect.min.x)
   3.164 +    {
   3.165 +      src_rect->min.x += ???;
   3.166 +      dest_rect->min.x = dest_bitmap->rect.min.x;
   3.167 +    }
   3.168 +  if (dest_rect->max.x > dest_bitmap->rect.max.x)
   3.169 +    {
   3.170 +      dest_rect->max.x = dest_bitmap->rect.max.x;
   3.171 +    }
   3.172 +
   3.173 +  rp = ???;
   3.174 +  for (y = 0; y < rect_height (dest_rect); y++)
   3.175 +    {
   3.176 +  ???;
   3.177 +      rp += dest_bitmap->row_words;
   3.178 +    }
   3.179 +}
   3.180 +
   3.181 +
   3.182  Bitmap *bitblt (Bitmap *src_bitmap,
   3.183  		Rect   *src_rect,
   3.184  		Bitmap *dest_bitmap,
   3.185  		Point  *dest_min,
   3.186 -		int tfn)
   3.187 +		int tfn,
   3.188 +		int background)
   3.189 +{
   3.190 +  Rect sr, dr;     /* src and dest rects, clipped to visible portion of
   3.191 +		      dest rect */
   3.192 +  u32 drw, drh;    /* dest rect width, height - gets adjusted */
   3.193 +  Point src_point, dest_point;
   3.194 +
   3.195 +  {
   3.196 +    sr = * src_rect;
   3.197 +
   3.198 +    u32 srw = rect_width (& sr);
   3.199 +    u32 srh = rect_height (& sr);
   3.200 +
   3.201 +    if ((srw < 0) || (srh < 0))
   3.202 +      goto done;  /* the source rect is empty! */
   3.203 +
   3.204 +    dr.min = * dest_min;
   3.205 +    dr.max.x = dr.min.x + srw;
   3.206 +    dr.max.y = dr.min.y + srh;
   3.207 +  }
   3.208 +
   3.209 +  if (! dest_bitmap)
   3.210 +    {
   3.211 +      dest_bitmap = create_bitmap (& dr);
   3.212 +      if (! dest_bitmap)
   3.213 +	return (NULL);
   3.214 +    }
   3.215 +
   3.216 +  if ((dr.min.x >= dest_bitmap->rect.max.x) ||
   3.217 +      (dr.min.y >= dest_bitmap->rect.max.y))
   3.218 +    goto done;  /* the dest rect isn't even in the dest bitmap! */
   3.219 +
   3.220 +  /* crop dest rect to dest bitmap */
   3.221 +
   3.222 +  delta = dest_bitmap->rect.min.x - dr.min.x;
   3.223 +  if (delta > 0)
   3.224 +    {
   3.225 +      sr.min.x += delta;
   3.226 +      dr.min.x += delta;
   3.227 +    }
   3.228 +
   3.229 +  delta = dest_bitmap->rect.min.y - dr.min.y;
   3.230 +  if (delta > 0)
   3.231 +    {
   3.232 +      sr.min.y += delta;
   3.233 +      dr.min.y += delta;
   3.234 +    }
   3.235 +
   3.236 +  delta = dr.max.x - dest_bitmap->rect.max.x;
   3.237 +  if (delta > 0)
   3.238 +    {
   3.239 +      sr.max.x -= delta;
   3.240 +      dr.max.x -= delta;
   3.241 +    }
   3.242 +
   3.243 +  delta = dr.max.y - dest_bitmap->rect.max.y;
   3.244 +  if (delta > 0)
   3.245 +    {
   3.246 +      sr.max.x -= delta;
   3.247 +      dr.max.x -= delta;
   3.248 +    }
   3.249 +
   3.250 +  drw = rect_width (& dr);
   3.251 +  drh = rect_height (& dh);
   3.252 +
   3.253 +  /* if the source rect min y is >= the source bitmap max y,
   3.254 +     we transfer background color to the entire dest rect */
   3.255 +  if (sr.min.y >= src->rect.max.y)
   3.256 +    {
   3.257 +      blt_background (dest_bitmap, & dr);
   3.258 +      goto done;
   3.259 +    }
   3.260 +
   3.261 +  /* if the source rect min y is less than the source bitmap min y,
   3.262 +     we need to transfer some backgound color to the top part of the dest
   3.263 +     rect */
   3.264 +  if (sr.min.y < src->rect.min.y)
   3.265 +    {
   3.266 +      Rect dr2;
   3.267 +      uint32 bg_height;
   3.268 +
   3.269 +      bg_height = src->rect.min.y - sr.min.y;
   3.270 +      if (bg_height > sh)
   3.271 +	bg_height = sh;
   3.272 +
   3.273 +      dr2 = dr;
   3.274 +      dr2.max.y = dr2.min.y + bg_height;
   3.275 +
   3.276 +      blt_background (dest_bitmap, & dr2);
   3.277 +
   3.278 +      /* now reduce the rect height by the number of lines of background
   3.279 +	 color */
   3.280 +      sr.min.y += bg_height;
   3.281 +      dr.min.y += bg_height;
   3.282 +      sh -= bg_height;
   3.283 +      dh -= bg_height;
   3.284 +
   3.285 +      if (sr.min.y == sr.max.y)
   3.286 +	goto done;
   3.287 +    }
   3.288 +
   3.289 +  /* now blt the available rows of the source rect */
   3.290 +
   3.291 +  /* now transfer the background color to any remaining rows of the
   3.292 +     dest rect */
   3.293 +  if (??? )
   3.294 +    {
   3.295 +      blt_background (dest_bitmap, & dr);
   3.296 +    }
   3.297 +
   3.298 + done:
   3.299 +  return (dest_bitmap);
   3.300 +}
   3.301 +#else
   3.302 +Bitmap *bitblt (Bitmap *src_bitmap,
   3.303 +		Rect   *src_rect,
   3.304 +		Bitmap *dest_bitmap,
   3.305 +		Point  *dest_min,
   3.306 +		int tfn,
   3.307 +		int background)
   3.308  {
   3.309    Point src_point, dest_point;
   3.310  
   3.311 @@ -206,73 +413,77 @@
   3.312      }
   3.313    return (dest_bitmap);
   3.314  }
   3.315 +#endif
   3.316  
   3.317  
   3.318  /* in-place transformations */
   3.319  void flip_h (Bitmap *src)
   3.320  {
   3.321 -  u8 *rp;  /* row pointer */
   3.322 -  u8 *p1;  /* work src ptr */
   3.323 -  u8 *p2;  /* work dest ptr */
   3.324 -  u16 d;
   3.325 +  word_type *rp;  /* row pointer */
   3.326 +  word_type *p1;  /* work src ptr */
   3.327 +  word_type *p2;  /* work dest ptr */
   3.328    s32 y;
   3.329 -  int shift;
   3.330 +  int shift1, shift2;
   3.331  
   3.332 -  realloc_temp_buffer (src->rowbytes + 1);
   3.333 +  realloc_temp_buffer ((src->row_words + 1) * sizeof (word_type));
   3.334  
   3.335    rp = src->bits;
   3.336    if ((rect_width (& src->rect) & 7) == 0)
   3.337      {
   3.338        for (y = src->rect.min.y; y < src->rect.max.y; y++)
   3.339  	{
   3.340 -	  memcpy (temp_buffer, rp, src->rowbytes);
   3.341 -	  p1 = temp_buffer + src->rowbytes - 1;
   3.342 +	  memcpy (temp_buffer, rp, src->row_words * sizeof (word_type));
   3.343 +	  p1 = temp_buffer + src->row_words;
   3.344  	  p2 = rp;
   3.345  
   3.346  	  while (p1 >= temp_buffer)
   3.347 -	    *(p2++) = bit_reverse_byte [*(p1--)];
   3.348 +	    *(p2++) = bit_reverse_word (*(p1--));
   3.349        
   3.350 -	  rp += src->rowbytes;
   3.351 +	  rp += src->row_words;
   3.352  	}
   3.353        return;
   3.354      }
   3.355  
   3.356    temp_buffer [0] = 0;
   3.357 -  shift = 8 - (rect_width (& src->rect) & 7);
   3.358 +  shift1 = rect_width (& src->rect) & (BITS_PER_WORD - 1);
   3.359 +  shift2 = BITS_PER_WORD - shift1;
   3.360  
   3.361    for (y = src->rect.min.y; y < src->rect.max.y; y++)
   3.362      {
   3.363 -      memcpy (temp_buffer + 1, rp, src->rowbytes);
   3.364 -      p1 = temp_buffer + src->rowbytes;
   3.365 +      word_type d1, d2;
   3.366 +
   3.367 +      memcpy (temp_buffer + 1, rp, src->row_words * sizeof (word_type));
   3.368 +      p1 = temp_buffer + src->row_words;
   3.369        p2 = rp;
   3.370  
   3.371 -      d = *(p1--);
   3.372 +      d2 = *(p1--);
   3.373  
   3.374        while (p1 >= temp_buffer)
   3.375  	{
   3.376 -	  d = (d >> 8) | ((*(p1--)) << 8);
   3.377 -	  *(p2++) = bit_reverse_byte [(d >> shift) & 0xff];
   3.378 +	  d1 = *(p1--);
   3.379 +	  *(p2++) = bit_reverse_word ((d1 << shift1) | (d2 >> shift2));
   3.380 +	  d2 = d1;
   3.381  	}      
   3.382  
   3.383 -      rp += src->rowbytes;
   3.384 +      rp += src->row_words;
   3.385      }
   3.386  }
   3.387  
   3.388  void flip_v (Bitmap *src)
   3.389  {
   3.390 -  u8 *p1, *p2;
   3.391 +  word_type *p1, *p2;
   3.392  
   3.393 -  realloc_temp_buffer (src->rowbytes);
   3.394 +  realloc_temp_buffer (src->row_words * sizeof (word_type));
   3.395  
   3.396    p1 = src->bits;
   3.397 -  p2 = src->bits + src->rowbytes * (rect_height (& src->rect) - 1);
   3.398 +  p2 = src->bits + src->row_words * (rect_height (& src->rect) - 1);
   3.399    while (p1 < p2)
   3.400      {
   3.401 -      memcpy (temp_buffer, p1, src->rowbytes);
   3.402 -      memcpy (p1, p2, src->rowbytes);
   3.403 -      memcpy (p2, temp_buffer, src->rowbytes);
   3.404 -      p1 += src->rowbytes;
   3.405 -      p2 -= src->rowbytes;
   3.406 +      memcpy (temp_buffer, p1, src->row_words * sizeof (word_type));
   3.407 +      memcpy (p1, p2, src->row_words * sizeof (word_type));
   3.408 +      memcpy (p2, temp_buffer, src->row_words * sizeof (word_type));
   3.409 +      p1 += src->row_words;
   3.410 +      p2 -= src->row_words;
   3.411      }
   3.412  }
   3.413  
   3.414 @@ -285,10 +496,10 @@
   3.415  /* "in-place" transformations - will allocate new memory and free old */
   3.416  void transpose (Bitmap *src)
   3.417  {
   3.418 -  u32 new_rowbytes = CALC_ROWBYTES (rect_height (& src->rect));
   3.419 -  u8 *new_bits;
   3.420 +  u32 new_row_words = DIV_ROUND_UP (rect_height (& src->rect), 32);
   3.421 +  word_type *new_bits;
   3.422  
   3.423 -  new_bits = calloc (1, new_rowbytes * rect_width (& src->rect));
   3.424 +  new_bits = calloc (1, new_row_words * rect_width (& src->rect) * sizeof (word_type));
   3.425  
   3.426    /* $$$ more code needed here */
   3.427  }
     4.1 --- a/bitblt.h	Wed Jan 02 16:39:39 2002 +0000
     4.2 +++ b/bitblt.h	Tue Jan 22 09:42:42 2002 +0000
     4.3 @@ -20,11 +20,18 @@
     4.4    return (r->max.y - r->min.y);
     4.5  }
     4.6  
     4.7 +/*
     4.8 + * Despite the following two definitions, there are still some places
     4.9 + * in the code that depend on words having 32 bits.
    4.10 + */ 
    4.11 +#define BITS_PER_WORD 32
    4.12 +typedef u32 word_type;
    4.13 +
    4.14  typedef struct Bitmap
    4.15  {
    4.16 -  u8 *bits;
    4.17 +  word_type *bits;
    4.18    Rect rect;
    4.19 -  u32 rowbytes;
    4.20 +  u32 row_words;
    4.21  } Bitmap;
    4.22  
    4.23  
    4.24 @@ -45,7 +52,8 @@
    4.25  		Rect   *src_rect,
    4.26  		Bitmap *dest_bitmap,
    4.27  		Point  *dest_min,
    4.28 -		int tfn);
    4.29 +		int tfn,
    4.30 +		int background);
    4.31  
    4.32  
    4.33  /* in-place transformations */
     5.1 --- a/bitblt_test.c	Wed Jan 02 16:39:39 2002 +0000
     5.2 +++ b/bitblt_test.c	Tue Jan 22 09:42:42 2002 +0000
     5.3 @@ -1,4 +1,5 @@
     5.4  #include <stdio.h>
     5.5 +#include <stdlib.h>
     5.6  
     5.7  #include "type.h"
     5.8  #include "bitblt.h"
     5.9 @@ -24,8 +25,9 @@
    5.10  {
    5.11    Bitmap *b;
    5.12    Point p;
    5.13 +  Rect r = {{ 0, 0 }, { WIDTH, HEIGHT }};
    5.14  
    5.15 -  b = create_bitmap (WIDTH, HEIGHT);
    5.16 +  b = create_bitmap (& r);
    5.17    if (! b)
    5.18      return (NULL);
    5.19  
    5.20 @@ -39,10 +41,10 @@
    5.21  void print_bitmap (FILE *o, Bitmap *b)
    5.22  {
    5.23    Point p;
    5.24 -  printf ("rowbytes: %d\n", b->rowbytes);
    5.25 -  for (p.y = 0; p.y < b->height; p.y++)
    5.26 +  printf ("row_words: %d\n", b->row_words);
    5.27 +  for (p.y = b->rect.min.y; p.y < b->rect.max.y; p.y++)
    5.28      {
    5.29 -      for (p.x = 0; p.x < b->width; p.x++)
    5.30 +      for (p.x = b->rect.min.x; p.x < b->rect.max.x; p.x++)
    5.31  	fputc (".X" [get_pixel (b, p)], o);
    5.32        fprintf (o, "\n");
    5.33      }
    5.34 @@ -64,18 +66,19 @@
    5.35      }
    5.36  
    5.37    print_bitmap (stdout, b);
    5.38 +  printf ("\n");
    5.39  
    5.40 +  flip_v (b);
    5.41 +
    5.42 +  print_bitmap (stdout, b);
    5.43 +  printf ("\n");
    5.44 +
    5.45 +  flip_h (b);
    5.46 +
    5.47 +  print_bitmap (stdout, b);
    5.48    printf ("\n");
    5.49  
    5.50  #if 0
    5.51 -  b2 = create_bitmap (b->height, b->width);
    5.52 -  if (! b2)
    5.53 -    {
    5.54 -      fprintf (stderr, "create_bitmap failed\n");
    5.55 -      exit (2);
    5.56 -    }
    5.57 -#endif
    5.58 -
    5.59    r.upper_left.x = r.upper_left.y = 0;
    5.60    r.lower_right.x = b->width;
    5.61    r.lower_right.y = b->height;
    5.62 @@ -92,6 +95,7 @@
    5.63      }
    5.64  
    5.65    print_bitmap (stdout, b2);
    5.66 +#endif
    5.67  
    5.68    exit (0);
    5.69  }
     6.1 --- a/t2p.c	Wed Jan 02 16:39:39 2002 +0000
     6.2 +++ b/t2p.c	Tue Jan 22 09:42:42 2002 +0000
     6.3 @@ -5,7 +5,7 @@
     6.4   *           encoding.
     6.5   *
     6.6   * Main program
     6.7 - * $Id: t2p.c,v 1.14 2002/01/02 08:39:39 eric Exp $
     6.8 + * $Id: t2p.c,v 1.15 2002/01/22 01:42:42 eric Exp $
     6.9   * Copyright 2001 Eric Smith <eric@brouhaha.com>
    6.10   *
    6.11   * This program is free software; you can redistribute it and/or modify
    6.12 @@ -200,7 +200,7 @@
    6.13    dest_min.x = 0;
    6.14    dest_min.y = 0;
    6.15  
    6.16 -  dest = bitblt (src, & src_rect, NULL, & dest_min, TF_SRC);
    6.17 +  dest = bitblt (src, & src_rect, NULL, & dest_min, TF_SRC, 0);
    6.18    free_bitmap (src);
    6.19    return (dest);
    6.20  }
    6.21 @@ -244,8 +244,6 @@
    6.22    float x_resolution, y_resolution;
    6.23    float dest_x_resolution, dest_y_resolution;
    6.24  
    6.25 -  int scanline_size;
    6.26 -
    6.27    int width_points, height_points;  /* really 1/72 inch units rather than
    6.28  				       points */
    6.29  
    6.30 @@ -358,8 +356,6 @@
    6.31        dest_y_resolution = y_resolution;
    6.32      }
    6.33  
    6.34 -  scanline_size = TIFFScanlineSize (in);
    6.35 -
    6.36    rect.min.x = 0;
    6.37    rect.min.y = 0;
    6.38    rect.max.x = image_width;
    6.39 @@ -373,22 +369,9 @@
    6.40        goto fail;
    6.41      }
    6.42  
    6.43 -  if (bitmap->rowbytes != scanline_size)
    6.44 -    {
    6.45 -      printf ("image_width %d\n", image_width);
    6.46 -      printf ("rowbytes %d\n", bitmap->rowbytes);
    6.47 -      printf ("TIFFScanlineSize %d\n", scanline_size);
    6.48 -    }
    6.49 -
    6.50    for (row = 0; row < image_length; row++)
    6.51 -    TIFFReadScanline (in,
    6.52 -		      bitmap->bits + row * bitmap->rowbytes,
    6.53 -		      row,
    6.54 -		      0);
    6.55 -
    6.56 -  for (row = 0; row < dest_image_length; row++)
    6.57      if (1 != TIFFReadScanline (in,
    6.58 -			       bitmap->bits + row * bitmap->rowbytes,
    6.59 +			       bitmap->bits + row * bitmap->row_words,
    6.60  			       row,
    6.61  			       0))
    6.62        {
    6.63 @@ -435,7 +418,7 @@
    6.64  
    6.65    for (row = 0; row < rect_height (& bitmap->rect); row++)
    6.66      if (1 != TIFFWriteScanline (tiff_temp,
    6.67 -				bitmap->bits + row * bitmap->rowbytes,
    6.68 +				bitmap->bits + row * bitmap->row_words,
    6.69  				row,
    6.70  				0))
    6.71        {
     7.1 --- a/tumble.c	Wed Jan 02 16:39:39 2002 +0000
     7.2 +++ b/tumble.c	Tue Jan 22 09:42:42 2002 +0000
     7.3 @@ -5,7 +5,7 @@
     7.4   *           encoding.
     7.5   *
     7.6   * Main program
     7.7 - * $Id: tumble.c,v 1.14 2002/01/02 08:39:39 eric Exp $
     7.8 + * $Id: tumble.c,v 1.15 2002/01/22 01:42:42 eric Exp $
     7.9   * Copyright 2001 Eric Smith <eric@brouhaha.com>
    7.10   *
    7.11   * This program is free software; you can redistribute it and/or modify
    7.12 @@ -200,7 +200,7 @@
    7.13    dest_min.x = 0;
    7.14    dest_min.y = 0;
    7.15  
    7.16 -  dest = bitblt (src, & src_rect, NULL, & dest_min, TF_SRC);
    7.17 +  dest = bitblt (src, & src_rect, NULL, & dest_min, TF_SRC, 0);
    7.18    free_bitmap (src);
    7.19    return (dest);
    7.20  }
    7.21 @@ -244,8 +244,6 @@
    7.22    float x_resolution, y_resolution;
    7.23    float dest_x_resolution, dest_y_resolution;
    7.24  
    7.25 -  int scanline_size;
    7.26 -
    7.27    int width_points, height_points;  /* really 1/72 inch units rather than
    7.28  				       points */
    7.29  
    7.30 @@ -358,8 +356,6 @@
    7.31        dest_y_resolution = y_resolution;
    7.32      }
    7.33  
    7.34 -  scanline_size = TIFFScanlineSize (in);
    7.35 -
    7.36    rect.min.x = 0;
    7.37    rect.min.y = 0;
    7.38    rect.max.x = image_width;
    7.39 @@ -373,22 +369,9 @@
    7.40        goto fail;
    7.41      }
    7.42  
    7.43 -  if (bitmap->rowbytes != scanline_size)
    7.44 -    {
    7.45 -      printf ("image_width %d\n", image_width);
    7.46 -      printf ("rowbytes %d\n", bitmap->rowbytes);
    7.47 -      printf ("TIFFScanlineSize %d\n", scanline_size);
    7.48 -    }
    7.49 -
    7.50    for (row = 0; row < image_length; row++)
    7.51 -    TIFFReadScanline (in,
    7.52 -		      bitmap->bits + row * bitmap->rowbytes,
    7.53 -		      row,
    7.54 -		      0);
    7.55 -
    7.56 -  for (row = 0; row < dest_image_length; row++)
    7.57      if (1 != TIFFReadScanline (in,
    7.58 -			       bitmap->bits + row * bitmap->rowbytes,
    7.59 +			       bitmap->bits + row * bitmap->row_words,
    7.60  			       row,
    7.61  			       0))
    7.62        {
    7.63 @@ -435,7 +418,7 @@
    7.64  
    7.65    for (row = 0; row < rect_height (& bitmap->rect); row++)
    7.66      if (1 != TIFFWriteScanline (tiff_temp,
    7.67 -				bitmap->bits + row * bitmap->rowbytes,
    7.68 +				bitmap->bits + row * bitmap->row_words,
    7.69  				row,
    7.70  				0))
    7.71        {