]> git.imager.perl.org - imager.git/blob - imext.c
- constify the Imager API
[imager.git] / imext.c
1 #include "imexttypes.h"
2 #include "imager.h"
3
4 /*
5  DON'T ADD CASTS TO THESE
6 */
7 im_ext_funcs imager_function_table =
8   {
9     mymalloc,
10     myfree,
11     myrealloc,
12
13     i_img_8_new,
14     i_img_16_new,
15     i_img_double_new,
16     i_img_pal_new,
17     i_img_destroy,
18     i_sametype,
19     i_sametype_chans,
20     i_img_info,
21
22     i_ppix,
23     i_gpix,
24     i_ppixf,
25     i_gpixf,
26     i_plin,
27     i_glin,
28     i_plinf,
29     i_glinf,
30     i_gsamp,
31     i_gsampf,
32     i_gpal,
33     i_ppal,
34     i_addcolors,
35     i_getcolors,
36     i_colorcount,
37     i_maxcolors,
38     i_findcolor,
39     i_setcolors,
40
41     i_new_fill_solid,
42     i_new_fill_solidf,
43     i_new_fill_hatch,
44     i_new_fill_hatchf,
45     i_new_fill_image,
46     i_new_fill_fount,
47     i_fill_destroy,
48
49     i_quant_makemap,
50     i_quant_translate,
51     i_quant_transparent,
52
53     i_clear_error,
54     i_push_error,
55     i_push_errorf,
56     i_push_errorvf,
57
58     i_tags_new,
59     i_tags_set,
60     i_tags_setn,
61     i_tags_destroy,
62     i_tags_find,
63     i_tags_findn,
64     i_tags_delete,
65     i_tags_delbyname,
66     i_tags_delbycode,
67     i_tags_get_float,
68     i_tags_set_float,
69     i_tags_set_float2,
70     i_tags_get_int,
71     i_tags_get_string,
72     i_tags_get_color,
73     i_tags_set_color,
74
75     i_box,
76     i_box_filled,
77     i_box_cfill,
78     i_line,
79     i_line_aa,
80     i_arc,
81     i_arc_aa,
82     i_arc_cfill,
83     i_arc_aa_cfill,
84     i_circle_aa,
85     i_flood_fill,
86     i_flood_cfill,
87
88     i_copyto,
89     i_copyto_trans,
90     i_copy,
91     i_rubthru,
92   };
93
94 /* in general these functions aren't called by Imager internally, but
95    only via the pointers above, since faster macros that call the
96    image vtable pointers are used.
97
98    () are used around the function names to prevent macro replacement
99    on the function names.
100 */
101
102 /*
103 =item i_ppix(im, x, y, color)
104
105 =category Drawing
106
107 Sets the pixel at (x,y) to I<color>.
108
109 Returns 0 if the pixel was drawn, or -1 if not.
110
111 Does no alpha blending, just copies the channels from the supplied
112 color to the image.
113
114 =cut
115 */
116
117 int 
118 (i_ppix)(i_img *im, int x, int y, const i_color *val) {
119   return i_ppix(im, x, y, val);
120 }
121
122 /*
123 =item i_gpix(im, x, y, color)
124
125 =category Drawing
126
127 Retrieves the I<color> of the pixel (x,y).
128
129 Returns 0 if the pixel was retrieved, or -1 if not.
130
131 =cut
132 */
133
134 int
135 (i_gpix)(i_img *im,int x,int y,i_color *val) {
136   return i_gpix(im, x, y, val);
137 }
138
139 /*
140 =item i_ppixf(im, x, y, fcolor)
141
142 =category Drawing
143
144 Sets the pixel at (x,y) to the floating point color I<fcolor>.
145
146 Returns 0 if the pixel was drawn, or -1 if not.
147
148 Does no alpha blending, just copies the channels from the supplied
149 color to the image.
150
151 =cut
152 */
153 int
154 (i_ppixf)(i_img *im, int x, int y, const i_fcolor *val) {
155   return i_ppixf(im, x, y, val);
156 }
157
158 /*
159 =item i_gpixf(im, x, y, fcolor)
160
161 =category Drawing
162
163 Retrieves the color of the pixel (x,y) as a floating point color into
164 I<fcolor>.
165
166 Returns 0 if the pixel was retrieved, or -1 if not.
167
168 =cut
169 */
170
171 int
172 (i_gpixf)(i_img *im,int x,int y,i_fcolor *val) {
173   return i_gpixf(im, x, y, val);
174 }
175
176 /*
177 =item i_plin(im, l, r, y, colors)
178
179 =category Drawing
180
181 Sets (r-l) pixels starting from (l,y) using (r-l) values from
182 I<colors>.
183
184 Returns the number of pixels set.
185
186 =cut
187 */
188
189 int
190 (i_plin)(i_img *im, int l, int r, int y, const i_color *vals) {
191   return i_plin(im, l, r, y, vals);
192 }
193
194 /*
195 =item i_glin(im, l, r, y, colors)
196
197 =category Drawing
198
199 Retrieves (r-l) pixels starting from (l,y) into I<colors>.
200
201 Returns the number of pixels retrieved.
202
203 =cut
204 */
205
206 int
207 (i_glin)(i_img *im, int l, int r, int y, i_color *vals) {
208   return i_glin(im, l, r, y, vals);
209 }
210
211 /*
212 =item i_plinf(im, l, r, fcolors)
213
214 =category Drawing
215
216 Sets (r-l) pixels starting from (l,y) using (r-l) floating point
217 colors from I<colors>.
218
219 Returns the number of pixels set.
220
221 =cut
222 */
223
224 int
225 (i_plinf)(i_img *im, int l, int r, int y, const i_fcolor *vals) {
226   return i_plinf(im, l, r, y, vals);
227 }
228
229 /*
230 =item i_glinf(im, l, r, y, colors)
231
232 =category Drawing
233
234 Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
235 point colors.
236
237 Returns the number of pixels retrieved.
238
239 =cut
240 */
241
242 int
243 (i_glinf)(i_img *im, int l, int r, int y, i_fcolor *vals) {
244   return i_glinf(im, l, r, y, vals);
245 }
246
247 /*
248 =item i_gsamp(im, l, r, y, samp, chans, chan_count)
249
250 =category Drawing
251
252 Reads sample values from im for the horizontal line (l, y) to (r-1,y)
253 for the channels specified by chans, an array of int with chan_count
254 elements.
255
256 If chans is NULL then the first chan_count channels are retrieved for
257 each pixel.
258
259 Returns the number of samples read (which should be (r-l) *
260 chan_count)
261
262 =cut
263 */
264 int
265 (i_gsamp)(i_img *im, int l, int r, int y, i_sample_t *samp, 
266                    const int *chans, int chan_count) {
267   return i_gsamp(im, l, r, y, samp, chans, chan_count);
268 }
269
270 /*
271 =item i_gsampf(im, l, r, y, samp, chans, chan_count)
272
273 =category Drawing
274
275 Reads floating point sample values from im for the horizontal line (l,
276 y) to (r-1,y) for the channels specified by chans, an array of int
277 with chan_count elements.
278
279 If chans is NULL then the first chan_count channels are retrieved for
280 each pixel.
281
282 Returns the number of samples read (which should be (r-l) *
283 chan_count)
284
285 =cut
286 */
287 int
288 (i_gsampf)(i_img *im, int l, int r, int y, i_fsample_t *samp, 
289            const int *chans, int chan_count) {
290   return i_gsampf(im, l, r, y, samp, chans, chan_count);
291 }
292
293 /*
294 =item i_gpal(im, x, r, y, indexes)
295
296 =category Drawing
297
298 Reads palette indexes for the horizontal line (x, y) to (r-1, y) into
299 indexes.
300
301 Returns the number of indexes read.
302
303 Always returns 0 for direct color images.
304
305 =cut
306 */
307 int
308 (i_gpal)(i_img *im, int x, int r, int y, i_palidx *vals) {
309   return i_gpal(im, x, r, y, vals);
310 }
311
312 /*
313 =item i_ppal(im, x, r, y, indexes)
314
315 =category Drawing
316
317 Writes palette indexes for the horizontal line (x, y) to (r-1, y) from
318 indexes.
319
320 Returns the number of indexes written.
321
322 Always returns 0 for direct color images.
323
324 =cut
325 */
326 int
327 (i_ppal)(i_img *im, int x, int r, int y, const i_palidx *vals) {
328   return i_ppal(im, x, r, y, vals);
329 }
330
331 /*
332 =item i_addcolors(im, colors, count)
333
334 =category Paletted images
335
336 Adds colors to the image's palette.
337
338 On success returns the index of the lowest color added.
339
340 On failure returns -1.
341
342 Always fails for direct color images.
343
344 =cut
345 */
346
347 int
348 (i_addcolors)(i_img *im, const i_color *colors, int count) {
349   return i_addcolors(im, colors, count);
350 }
351
352 /*
353 =item i_getcolors(im, index, colors, count)
354
355 =category Paletted images
356
357 Retrieves I<count> colors starting from I<index> in the image's
358 palette.
359
360 On success stores the colors into I<colors> and returns true.
361
362 On failure returns false.
363
364 Always fails for direct color images.
365
366 Fails if there are less than I<index>+I<count> colors in the image's
367 palette.
368
369 =cut
370 */
371
372 int
373 (i_getcolors)(i_img *im, int i, i_color *colors, int count) {
374   return i_getcolors(im, i, colors, count);
375 }
376
377 /*
378 =item i_colorcount(im)
379
380 =category Paletted images
381
382 Returns the number of colors in the image's palette.
383
384 Returns -1 for direct images.
385
386 =cut
387 */
388
389 int
390 (i_colorcount)(i_img *im) {
391   return i_colorcount(im);
392 }
393
394 /*
395 =item i_maxcolors(im)
396
397 =category Paletted images
398
399 Returns the maximum number of colors the palette can hold for the
400 image.
401
402 Returns -1 for direct color images.
403
404 =cut
405 */
406
407 int
408 (i_maxcolors)(i_img *im) {
409   return i_maxcolors(im);
410 }
411
412 /*
413 =item i_findcolor(im, color, &entry)
414
415 =category Paletted images
416
417 Searches the images palette for the given color.
418
419 On success sets *I<entry> to the index of the color, and returns true.
420
421 On failure returns false.
422
423 Always fails on direct color images.
424
425 =cut
426 */
427 int
428 (i_findcolor)(i_img *im, const i_color *color, i_palidx *entry) {
429   return i_findcolor(im, color, entry);
430 }
431
432 /*
433 =item i_setcolors(im, index, colors, count)
434
435 =category Paletted images
436
437 Sets I<count> colors starting from I<index> in the image's palette.
438
439 On sucess returns true.
440
441 On failure returns false.
442
443 The image must have at least I<index>+I<count> colors in it's palette
444 for this to succeed.
445
446 Always fails on direct color images.
447
448 =cut
449 */
450 int
451 (i_setcolors)(i_img *im, int index, const i_color *colors, int count) {
452   return i_setcolors(im, index, colors, count);
453 }
454