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