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
|
=encoding UTF-8
=head1 NAME
BH_Bitmap - bitmap/image access
=head1 SYNTAX
#include <BH/Bitmap.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Bitmap module provides methods for accessing the pixel data of a bitmap
(image) and for converting between different pixel formats.
=head1 FORMATS
Currently, the following pixel formats are supported:
=over
=item B<BH_BITMAP_INDEX1>
1-bit indexed/paletted
=item B<BH_BITMAP_INDEX2>
2-bit indexed/paletted
=item B<BH_BITMAP_INDEX4>
4-bit indexed/paletted
=item B<BH_BITMAP_INDEX8>
8-bit indexed/paletted
=item B<BH_BITMAP_GRAY8>
8-bit grayscale
=item B<BH_BITMAP_GRAY16>
16-bit grayscale
=item B<BH_BITMAP_RGBA32>
32-bit RGB with alpha represented in uint32_t value. The layout is: 0xAARRGGBB
=item B<BH_BITMAP_RGBA64>
64-bit RGB with alpha represented in uint64_t value. The layout is:
0xAAAARRRRGGGGBBBB
=item B<BH_BITMAP_RGB565>
16-bit RGB
=item B<BH_BITMAP_RGB888>
24-bit RGB
=item B<BH_BITMAP_RGBA8888>
32-bit RGB with alpha
=item B<BH_BITMAP_RGB161616>
48-bit RGB
=item B<BH_BITMAP_RGBA16161616>
64-bit RGB with alpha
=item B<BH_BITMAP_RGBA1010102>
32-bit RGB with alpha
=back
All pixel formats use the current machine endianness.
The flag I<BH_BITMAP_BGR> can be used to change the order of the color channels
(RGB -> BGR). The flag has no effect on the following pixel formats:
I<BH_BITMAP_INDEX1>, I<BH_BITMAP_INDEX2>, I<BH_BITMAP_INDEX4>,
I<BH_BITMAP_INDEX8>, I<BH_BITMAP_GRAY8>, I<BH_BITMAP_GRAY16>,
I<BH_BITMAP_RGBA32> and I<BH_BITMAP_RGBA64>.
The flag I<BH_BITMAP_LSB> can be used to change the start of the bit order for
indexed images. This flag only affects the following pixel formats:
I<BH_BITMAP_INDEX1>, I<BH_BITMAP_INDEX2>, I<BH_BITMAP_INDEX4> and
I<BH_BITMAP_INDEX8>.
The flag I<BH_BITMAP_NOALPHA> can be used to indicate that the alpha channel is
not used and should always be set to the maximum value (255 for 8-bit and 65535
for 16-bit).
The flag I<BH_BITMAP_PREMULT> can be used to indicate that color values are in
premultiplied form.
The color palette is assumed to contain exactly 256 colors and is stored in the
I<BH_BITMAP_RGBA32> pixel format.
=head1 API CALLS
=head2 BH_BitmapNew
BH_Bitmap *BH_BitmapNew(uint32_t width,
uint32_t height,
int format,
int flags,
void *data,
void *palette);
Creates the bitmap with the specified I<width>, I<height> and pixel I<format>.
The I<flags> parameter can take a combination of the following values:
=over
=item B<BH_BITMAP_FLAG_ALIGN32>
Rows are aligned to 32-bit boundary
=back
The optional I<data> parameter specifies pointer to the existing data.
The optional I<palette> parameter specifies pointer to the existing palette.
This function returns a pointer to a new BH_Bitmap object or NULL.
=head2 BH_BitmapFree
void BH_BitmapFree(BH_Bitmap *bitmap);
Destroys the bitmap object.
=head2 BH_BitmapColor
void BH_BitmapColor(const BH_Bitmap *bitmap,
uint32_t x,
uint32_t y,
BH_Color *value);
Reads color value of the pixel at specified position.
The I<x> and I<y> parameters specify a position on the bitmap.
=head2 BH_BitmapSetColor
void BH_BitmapSetColor(BH_Bitmap *bitmap,
uint32_t x,
uint32_t y,
const BH_Color *value);
Writes color value of the pixel at specified position.
The I<x> and I<y> parameters specify a position on the bitmap.
=head2 BH_BitmapIndex
uint8_t BH_BitmapIndex(const BH_Bitmap *bitmap,
uint32_t x,
uint32_t y);
Returns the index value at the specified position.
The I<x> and I<y> parameters specify a position on the bitmap.
=head2 BH_BitmapSetIndex
void BH_BitmapSetIndex(BH_Bitmap *bitmap,
uint32_t x,
uint32_t y,
uint8_t index);
Sets the index value at the specified position.
The I<x> and I<y> parameters specify a position on the bitmap.
=head2 BH_BitmapCopy
BH_Bitmap *BH_BitmapCopy(BH_Bitmap *bitmap,
uint32_t x,
uint32_t y,
uint32_t width,
uint32_t height,
int shallow);
Creates a copy of the bitmap region by the given position and size.
The I<x> and I<y> parameters specify a position on the bitmap.
The I<width> and I<height> parameters specify size of the new bitmap.
The I<shallow> parameter specifies whether the new bitmap is a shallow copy (or
a view) of the existing bitmap or a deep copy. For the shallow copy to work, the
region should be within the existing bitmap.
This function returns a pointer to a new BH_Bitmap object or NULL.
=head2 BH_BitmapScanline
void *BH_BitmapScanline(const BH_Bitmap *bitmap,
uint32_t y);
Returns address of the scanline in the bitmap.
=head2 BH_BitmapAt
void *BH_BitmapAt(const BH_Bitmap *bitmap,
uint32_t x,
uint32_t y);
Returns address of the pixel in the bitmap.
=head2 BH_BitmapWidth
uint32_t BH_BitmapWidth(BH_Bitmap *bitmap);
Returns width of the bitmap.
=head2 BH_BitmapHeight
uint32_t BH_BitmapHeight(BH_Bitmap *bitmap);
Returns height of the bitmap.
=head2 BH_BitmapFormat
int BH_BitmapFormat(BH_Bitmap *bitmap);
Returns pixel format of the bitmap.
=head2 BH_BitmapStride
size_t BH_BitmapStride(BH_Bitmap *bitmap);
Returns row stride of the bitmap.
=head2 BH_BitmapData
void *BH_BitmapData(BH_Bitmap *bitmap);
Returns pointer to the pixel data of the bitmap.
=head2 BH_BitmapPalette
void *BH_BitmapPalette(BH_Bitmap *bitmap);
Returns pointer to the bitmap's palette.
=head2 BH_BitmapFlags
int BH_BitmapFlags(BH_Bitmap *bitmap);
Returns bitmap's flags.
The result can be a combination of the following values:
=over
=item B<BH_BITMAP_FLAG_ALIGN32>
Rows are aligned to 32-bit boundary
=item B<BH_BITMAP_FLAG_EXT_DATA>
Bitmap doesn't own the pixel data
=item B<BH_BITMAP_FLAG_EXT_PALETTE>
Bitmap doesn't own palette data
=back
=head2 BH_BitmapConvertRow
void BH_BitmapConvertRow(void *src,
int srcFormat,
void *srcPalette,
void *dest,
int destFormat,
void *destPalette,
size_t count);
Converts a row of source data from one pixel format to another pixel format.
The parameter I<src> and I<srcFormat> specify the source of the data and its
pixel format.
The parameter I<srcPalette> specify the source palette (if required by the pixel
format).
The parameter I<dest> and I<destFormat> specify the destination of the data and
its pixel format.
The parameter I<destPalette> specify the destination palette (if required by the
pixel format).
The parameter I<count> specifies the number of pixel for conversion.
=head1 SEE ALSO
L<BH>
|