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