1 /*
2 * tumble: build a PDF file from image files
3 *
4 * bitblt routines
5 * Copyright 2001, 2002, 2003, 2017 Eric Smith <spacewar@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. Note that permission is
10 * not granted to redistribute this program under the terms of any
11 * other version of the General Public License.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
21 *
22 * 2009-03-13 [JDB] pm_config.h (part of NETPBM) defines BITS_PER_WORD but
23 * apparently doesn't use it externally. We undefine it here
24 * so that our version takes precedence and warnings are not
25 * generated.
26 */
27
28 #undef BITS_PER_WORD
29
30
31 typedef struct Point
32 {
33 int32_t x;
34 int32_t y;
35 } Point;
36
37 typedef struct Rect
38 {
39 Point min;
40 Point max;
41 } Rect;
42
rect_width(Rect * r)43 static inline int32_t rect_width (Rect *r)
44 {
45 return (r->max.x - r->min.x);
46 }
47
rect_height(Rect * r)48 static inline int32_t rect_height (Rect *r)
49 {
50 return (r->max.y - r->min.y);
51 }
52
53
54 /* word_t should be the largest native type that can be handled
55 efficiently, so it shouldn't be a 64-bit type on a processor that
56 doesn't have native 64-bit operations. */
57 typedef uint32_t word_t;
58 #define BITS_PER_WORD (8 * sizeof (word_t))
59 #define ALL_ONES (~ 0UL)
60
61
62 typedef struct Bitmap
63 {
64 word_t *bits;
65 Rect rect;
66 uint32_t row_words;
67 } Bitmap;
68
69
70 #define TF_SRC 0xc
71 #define TF_AND 0x8
72 #define TF_OR 0xe
73 #define TF_XOR 0x6
74
75
76 void bitblt_init (void);
77
78
79 Bitmap *create_bitmap (Rect *rect);
80 void free_bitmap (Bitmap *bitmap);
81
82 bool get_pixel (Bitmap *bitmap, Point coord);
83 void set_pixel (Bitmap *bitmap, Point coord, bool value);
84
85
86 Bitmap *bitblt (Bitmap *src_bitmap,
87 Rect *src_rect,
88 Bitmap *dest_bitmap,
89 Point *dest_min,
90 int tfn,
91 int background);
92
93
94 /* in-place transformations */
95 void flip_h (Bitmap *src);
96 void flip_v (Bitmap *src);
97
98 void rot_180 (Bitmap *src); /* combination of flip_h and flip_v */
99
100 /* "in-place" transformations - will allocate new memory and free old */
101 void transpose (Bitmap *src);
102
103 void rot_90 (Bitmap *src); /* transpose + flip_h */
104 void rot_270 (Bitmap *src); /* transpose + flip_v */
105
106
107 void reverse_bits (uint8_t *p, int byte_count);
108
109
110 void bitblt_write_g4 (Bitmap *bitmap, FILE *f);
111
112
113 /* frees original! */
114 Bitmap *resize_bitmap (Bitmap *src,
115 int width_pixels,
116 int height_pixels);
117
118 /* "in place" rotation */
119 void rotate_bitmap (Bitmap *src, int rotation);
120