forked from brouhaha/tumble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitblt.c
796 lines (668 loc) · 18.4 KB
/
bitblt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
/*
* tumble: build a PDF file from image files
*
* bitblt routines
* Copyright 2001, 2002, 2003, 2017 Eric Smith <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. Note that permission is
* not granted to redistribute this program under the terms of any
* other version of the General Public License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
*/
#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bitblt.h"
#include "bitblt_tables.h"
#define SWAP(type,a,b) do { type temp; temp = a; a = b; b = temp; } while (0)
#define DIV_ROUND_UP(count,pow2) (((count) - 1) / (pow2) + 1)
void reverse_bits (uint8_t *p, int byte_count)
{
while (byte_count--)
{
(*p) = bit_reverse_byte [*p];
p++;
}
}
static word_t bit_reverse_word (word_t d)
{
return (bit_reverse_byte [d >> 24] |
(bit_reverse_byte [(d >> 16) & 0xff] << 8) |
(bit_reverse_byte [(d >> 8) & 0xff] << 16) |
(bit_reverse_byte [d & 0xff] << 24));
}
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;
static void realloc_temp_buffer (uint32_t size)
{
if (size <= temp_buffer_size)
return;
temp_buffer = realloc (temp_buffer, size);
if (! temp_buffer)
{
fprintf (stderr, "realloc failed in bitblt library\n");
exit (2);
}
temp_buffer_size = size;
}
static inline word_t pixel_mask (int x)
{
#if defined (MIXED_ENDIAN) /* disgusting hack for mixed-endian */
word_t m;
m = 0x80 >> (x & 7);
m <<= (x & 24);
return (m);
#elif defined (LSB_RIGHT)
return (1U << ((BITS_PER_WORD - 1) - x));
#else
return (1U << x);
#endif
};
/* mask for range of bits left..right, inclusive */
static inline word_t pixel_range_mask (int left, int right)
{
word_t m1, m2, val;
/* $$$ one of these cases is wrong! */
#if defined (LSB_RIGHT)
m1 = (~ 0U) >> left;
m2 = (~ 0U) << (BITS_PER_WORD - 1 - right);
#else
m1 = (~ 0U) << left;
m2 = (~ 0U) >> (BITS_PER_WORD - 1 - right);
#endif
val = m1 & m2;
printf ("left %d, right %d, mask %08x\n", left, right, val);
return (val);
};
Bitmap *create_bitmap (Rect *rect)
{
Bitmap *bitmap;
uint32_t width = rect_width (rect);
uint32_t height = rect_height (rect);
if ((width <= 0) || (height <= 0))
return (NULL);
bitmap = calloc (1, sizeof (Bitmap));
if (! bitmap)
return (NULL);
bitmap->rect = * rect;
bitmap->row_words = DIV_ROUND_UP (width, BITS_PER_WORD);
bitmap->bits = calloc (1, height * bitmap->row_words * sizeof (word_t));
if (! bitmap->bits)
{
free (bitmap);
return (NULL);
}
return (bitmap);
}
void free_bitmap (Bitmap *bitmap)
{
free (bitmap->bits);
free (bitmap);
}
bool get_pixel (Bitmap *bitmap, Point coord)
{
word_t *p;
int w,b;
if ((coord.x < bitmap->rect.min.x) ||
(coord.x >= bitmap->rect.max.x) ||
(coord.y < bitmap->rect.min.y) ||
(coord.y >= bitmap->rect.max.y))
return (0);
coord.y -= bitmap->rect.min.y;
coord.x -= bitmap->rect.min.x;
w = coord.x / BITS_PER_WORD;
b = coord.x & (BITS_PER_WORD - 1);
p = bitmap->bits + coord.y * bitmap->row_words + w;
return (((*p) & pixel_mask (b)) != 0);
}
void set_pixel (Bitmap *bitmap, Point coord, bool value)
{
word_t *p;
int w,b;
if ((coord.x < bitmap->rect.min.x) ||
(coord.x >= bitmap->rect.max.x) ||
(coord.y < bitmap->rect.min.y) ||
(coord.y >= bitmap->rect.max.y))
return;
coord.y -= bitmap->rect.min.y;
coord.x -= bitmap->rect.min.x;
w = coord.x / BITS_PER_WORD;
b = coord.x & (BITS_PER_WORD - 1);
p = bitmap->bits + coord.y * bitmap->row_words + w;
if (value)
(*p) |= pixel_mask (b);
else
(*p) &= ~pixel_mask (b);
}
/* modifies rect1 to be the intersection of rect1 and rect2;
returns true if intersection is non-null */
static bool clip_rect (Rect *rect1, Rect *rect2)
{
if (rect1->min.y > rect2->max.y)
goto empty;
if (rect1->min.y < rect2->min.y)
{
if (rect1->max.y < rect2->max.y)
goto empty;
rect1->min.y = rect2->min.y;
}
if (rect1->max.y > rect2->max.y)
rect1->max.y = rect2->max.y;
if (rect1->min.x > rect2->max.x)
goto empty;
if (rect1->min.x < rect2->min.x)
{
if (rect1->max.x < rect2->max.x)
goto empty;
rect1->min.x = rect2->min.x;
}
if (rect1->max.x > rect2->max.x)
rect1->max.x = rect2->max.x;
empty:
rect1->min.x = rect1->min.y =
rect1->max.x = rect1->max.y = 0;
return (0);
}
static void blt_background (Bitmap *dest_bitmap,
Rect dest_rect)
{
uint32_t y;
word_t *rp;
uint32_t left_bit, left_word;
uint32_t right_bit, right_word;
word_t left_mask, right_mask;
int32_t word_count;
/* This function requires a non-null dest rect */
assert (dest_rect.min.x < dest_rect.max.x);
assert (dest_rect.min.y < dest_rect.max.y);
/* and that the rows of the dest rect lie entirely within the dest bitmap */
assert (dest_rect.min.y >= dest_bitmap->rect.min.y);
assert (dest_rect.max.y <= dest_bitmap->rect.max.y);
/* clip the x axis of the dest_rect to the bounds of the dest bitmap */
if (dest_rect.min.x < dest_bitmap->rect.min.x)
dest_rect.min.x = dest_bitmap->rect.min.x;
if (dest_rect.max.x > dest_bitmap->rect.max.x)
dest_rect.max.x = dest_bitmap->rect.max.x;
rp = dest_bitmap->bits +
(dest_rect.min.y - dest_bitmap->rect.min.y) * dest_bitmap->row_words +
(dest_rect.min.x - dest_bitmap->rect.min.x) / BITS_PER_WORD;
left_bit = dest_rect.min.x % BITS_PER_WORD;
left_word = dest_rect.min.x / BITS_PER_WORD;
right_bit = (dest_rect.max.x - 1) % BITS_PER_WORD;
right_word = (dest_rect.max.x - 1) / BITS_PER_WORD;
word_count = right_word + 1 - left_word;
/* special case if entire horizontal range fits in a single word */
if (word_count == 1)
{
left_mask = 0;
right_mask = ~ pixel_range_mask (left_bit, right_bit);
word_count = 0;
}
else
{
if (left_bit)
{
left_mask = ~ pixel_range_mask (left_bit, BITS_PER_WORD - 1);
word_count--;
}
if (right_bit != (BITS_PER_WORD - 1))
{
right_mask = ~ pixel_range_mask (0, right_bit);
word_count--;
}
}
for (y = 0; y < rect_height (& dest_rect); y++)
{
word_t *wp = rp;
/* partial word at left, if any */
if (left_mask)
*(wp++) &= left_mask;
/* use Duff's Device for the full words */
if (word_count)
{
int32_t i = word_count;
switch (i % 8)
{
while (i > 0)
{
*(wp++) = 0;
case 7: *(wp++) = 0;
case 6: *(wp++) = 0;
case 5: *(wp++) = 0;
case 4: *(wp++) = 0;
case 3: *(wp++) = 0;
case 2: *(wp++) = 0;
case 1: *(wp++) = 0;
case 0: i -= 8;
}
}
}
/* partial word at right, if any */
if (right_mask)
*wp &= right_mask;
/* advance to next row */
rp += dest_bitmap->row_words;
}
}
#if 0
static void blt (Bitmap *src_bitmap,
Rect *src_rect,
Bitmap *dest_bitmap,
Rect *dest_rect)
{
int32_t y;
word_t *rp;
/* This function requires a non-null src rect */
assert (dest_rect->min.x < dest_rect->max.x);
assert (dest_rect->min.y < dest_rect->max.y);
/* and a non-null dest rect */
assert (dest_rect->min.x < dest_rect->max.x);
assert (dest_rect->min.y < dest_rect->max.y);
/* and that the widths and heights of the rects match */
assert (rect_width (src_rect) == rect_width (dest_rect));
assert (rect_height (src_rect) == rect_height (dest_rect));
/* and that the rows of the src rect lie entirely within the src bitmap */
assert (dest_rect->min.y >= dest_bitmap->rect->min.y);
assert (dest_rect->max.y <= dest_bitmap->rect->max.y);
/* and that the rows of the dest rect lie entirely within the dest bitmap */
assert (dest_rect->min.y >= dest_bitmap->rect->min.y);
assert (dest_rect->max.y <= dest_bitmap->rect->max.y);
/* clip the x axis of the dest_rect to the bounds of the dest bitmap,
and adjust the src_rect to match */
if (dest_rect->min.x < dest_bitmap->rect.min.x)
{
src_rect->min.x += ???;
dest_rect->min.x = dest_bitmap->rect.min.x;
}
if (dest_rect->max.x > dest_bitmap->rect.max.x)
{
dest_rect->max.x = dest_bitmap->rect.max.x;
}
rp = ???;
for (y = 0; y < rect_height (dest_rect); y++)
{
???;
rp += dest_bitmap->row_words;
}
}
/*
* The destination rectangle is first clipped to the dest bitmap, and
* the source rectangle is adjusted in the corresponding manner.
* What's left is divided into five sections, any of which may be
* null. The portion that actually corresponds to the intersection of
* the source rectangle and the source bitmpa is the "middle". The
* other four sections will use the background color as the source
* operand.
*
*
* y0 -> -------------------------------------------------
* | top |
* | |
* y1 -> -------------------------------------------------
* | left | middle | right |
* | | | |
* y2 -> -------------------------------------------------
* | bottom |
* | |
* y3 -> -------------------------------------------------
*
* ^ ^ ^ ^
* | | | |
* x0 x1 x2 x3
*
* */
Bitmap *bitblt (Bitmap *src_bitmap,
Rect *src_rect,
Bitmap *dest_bitmap,
Point *dest_min,
int tfn,
int background)
{
Rect sr, dr; /* src and dest rects, clipped to visible portion of
dest rect */
uint32_t drw, drh; /* dest rect width, height - gets adjusted */
Point src_point, dest_point;
/* dest coordinates: */
uint32_t x0, x1, x2, x3;
uint32_t y0, y1, y2, y3;
{
sr = * src_rect;
uint32_t srw = rect_width (& sr);
uint32_t srh = rect_height (& sr);
if ((srw < 0) || (srh < 0))
goto done; /* the source rect is empty! */
dr.min.x = dest_min->x;
dr.min.y = dest_min->y;
dr.max.x = dr.min.x + srw;
dr.max.y = dr.min.y + srh;
}
if (! dest_bitmap)
{
dest_bitmap = create_bitmap (& dr);
if (! dest_bitmap)
return (NULL);
}
if ((dr.min.x >= dest_bitmap->rect.max.x) ||
(dr.min.y >= dest_bitmap->rect.max.y))
goto done; /* the dest rect isn't even in the dest bitmap! */
/* crop dest rect to dest bitmap */
delta = dest_bitmap->rect.min.x - dr.min.x;
if (delta > 0)
{
sr.min.x += delta;
dr.min.x += delta;
}
delta = dest_bitmap->rect.min.y - dr.min.y;
if (delta > 0)
{
sr.min.y += delta;
dr.min.y += delta;
}
delta = dr.max.x - dest_bitmap->rect.max.x;
if (delta > 0)
{
sr.max.x -= delta;
dr.max.x -= delta;
}
delta = dr.max.y - dest_bitmap->rect.max.y;
if (delta > 0)
{
sr.max.x -= delta;
dr.max.x -= delta;
}
drw = rect_width (& dr);
drh = rect_height (& dh);
x0 = dr.min.x;
y0 = dr.min.y;
x3 = dr.max.x;
y3 = dr.max.y;
#if 0
/* if the source rect min y is >= the source bitmap max y,
we transfer background color to the entire dest rect */
if (sr.min.y >= src->rect.max.y)
{
blt_background (dest_bitmap, dr);
goto done;
}
#endif
/* top */
if (y0 != y1)
{
dr2.min.x = x0;
dr2.max.x = x3;
dr2.min.y = y0;
dr2.max.y = y1;
blt_background (dest_bitmap, & dr2);
}
/*
* top: if the source rect min y is less than the source bitmap min y,
* we need to transfer some backgound color to the top part of the dest
* rect
*/
if (sr.min.y < src->rect.min.y)
{
Rect dr2;
uint32 bg_height;
bg_height = src->rect.min.y - sr.min.y;
if (bg_height > sh)
bg_height = sh;
dr2 = dr;
dr2.max.y = dr2.min.y + bg_height;
blt_background (dest_bitmap, & dr2);
/* now reduce the rect height by the number of lines of background
color */
sr.min.y += bg_height;
dr.min.y += bg_height;
sh -= bg_height;
dh -= bg_height;
if (sr.min.y == sr.max.y)
goto done;
}
if (y1 != y2)
{
/* left */
if (x0 != x1)
{
dr2.min.x = x1;
dr2.max.x = x1;
dr2.min.y = y1;
dr2.max.y = y2
blt_background (dest_bitmap, & dr2);
}
/* middle */
if (x1 != x2)
{
/* ??? */
}
/* right */
if (x2 != x3)
{
dr2.min.x = x2;
dr2.max.x = x3;
dr2.min.y = y1;
dr2.max.y = y2
blt_background (dest_bitmap, & dr2);
}
}
/* bottom */
if (y2 != y3)
{
dr2.min.x = x0;
dr2.max.x = x3;
dr2.min.y = y2;
dr2.max.y = y3;
blt_background (dest_bitmap, & dr2);
}
done:
return (dest_bitmap);
}
#else
Bitmap *bitblt (Bitmap *src_bitmap,
Rect *src_rect,
Bitmap *dest_bitmap,
Point *dest_min,
int tfn,
int background)
{
Point src_point, dest_point;
if (! dest_bitmap)
{
Rect dest_rect = {{ 0, 0 }, { dest_min->x + rect_width (src_rect),
dest_min->y + rect_height (src_rect) }};
dest_bitmap = create_bitmap (& dest_rect);
if (! dest_bitmap)
return (NULL);
}
if (tfn == TF_SRC)
{
for (src_point.y = src_rect->min.y;
src_point.y < src_rect->max.y;
src_point.y++)
{
dest_point.y = dest_min->y + src_point.y - src_rect->min.y;
for (src_point.x = src_rect->min.x;
src_point.x < src_rect->max.x;
src_point.x++)
{
bool a;
dest_point.x = dest_min->x + src_point.x - src_rect->min.x;
a = get_pixel (src_bitmap, src_point);
set_pixel (dest_bitmap, dest_point, a);
}
}
}
else
{
for (src_point.y = src_rect->min.y;
src_point.y < src_rect->max.y;
src_point.y++)
{
dest_point.y = dest_min->y + src_point.y - src_rect->min.y;
for (src_point.x = src_rect->min.x;
src_point.x < src_rect->max.x;
src_point.x++)
{
bool a, b, c;
dest_point.x = dest_min->x + src_point.x - src_rect->min.x;
a = get_pixel (src_bitmap, src_point);
b = get_pixel (dest_bitmap, dest_point);
c = (tfn & (1 << (a * 2 + b))) != 0;
set_pixel (dest_bitmap, dest_point, c);
}
}
}
return (dest_bitmap);
}
#endif
/* in-place transformations */
void flip_h (Bitmap *src)
{
word_t *rp; /* row pointer */
int32_t y;
int shift1, shift2;
rp = src->bits;
if ((rect_width (& src->rect) & 7) == 0)
{
for (y = src->rect.min.y; y < src->rect.max.y; y++)
{
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;
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;
p2 = rp;
d2 = *(p1--);
while (p1 >= temp_buffer)
{
word_t t;
d1 = *(p1--);
t = (d1 >> shift1) | (d2 << shift2);
*(p2++) = bit_reverse_word (t);
d2 = d1;
}
rp += src->row_words;
}
}
void flip_v (Bitmap *src)
{
word_t *p1, *p2;
realloc_temp_buffer (src->row_words * sizeof (word_t));
p1 = src->bits;
p2 = src->bits + src->row_words * (rect_height (& src->rect) - 1);
while (p1 < p2)
{
memcpy (temp_buffer, p1, src->row_words * sizeof (word_t));
memcpy (p1, p2, src->row_words * sizeof (word_t));
memcpy (p2, temp_buffer, src->row_words * sizeof (word_t));
p1 += src->row_words;
p2 -= src->row_words;
}
}
void rot_180 (Bitmap *src) /* combination of flip_h and flip_v */
{
flip_h (src);
flip_v (src);
}
/* "in-place" transformations - will allocate new memory and free old */
// XXX hideously inefficient!
void transpose (Bitmap *src)
{
Rect transposed_rect;
Bitmap *dest;
Point src_coord, dest_coord;
transposed_rect.min.x = src->rect.min.y;
transposed_rect.max.x = src->rect.max.y;
transposed_rect.min.y = src->rect.min.x;
transposed_rect.max.y = src->rect.max.x;
dest = create_bitmap (& transposed_rect);
for (src_coord.y = src->rect.min.y; src_coord.y < src->rect.max.y; src_coord.y++)
{
dest_coord.x = src_coord.y;
for (src_coord.x = src->rect.min.x; src_coord.x < src->rect.max.x; src_coord.x++)
{
dest_coord.y = src_coord.x;
set_pixel(dest, dest_coord, get_pixel(src, src_coord));
}
}
SWAP(Bitmap, *src, *dest);
free_bitmap(dest);
}
void rot_90 (Bitmap *src) /* transpose + flip_h */
{
transpose (src);
flip_h (src);
}
void rot_270 (Bitmap *src) /* transpose + flip_v */
{
transpose (src);
flip_v (src);
}
/* frees original! */
Bitmap *resize_bitmap (Bitmap *src,
int width_pixels,
int height_pixels)
{
Rect src_rect;
Point dest_min;
Bitmap *dest;
src_rect.min.x = (rect_width (& src->rect) - width_pixels) / 2;
src_rect.min.y = (rect_height (& src->rect) - height_pixels) / 2;
src_rect.max.x = src_rect.min.x + width_pixels;
src_rect.max.y = src_rect.min.y + height_pixels;
dest_min.x = 0;
dest_min.y = 0;
dest = bitblt (src, & src_rect, NULL, & dest_min, TF_SRC, 0);
free_bitmap (src);
return (dest);
}
/* "in place" rotation */
void rotate_bitmap (Bitmap *src, int rotation)
{
switch (rotation)
{
case 0: break;
case 90: rot_90 (src); break;
case 180: rot_180 (src); break;
case 270: rot_270 (src); break;
default:
fprintf (stderr, "rotation %d, but must be 0, 90, 180, or 270\n", rotation);
}
}