]> git.imager.perl.org - imager.git/blame - imext.c
[rt #69879] various T1 improvments
[imager.git] / imext.c
CommitLineData
92bda632
TC
1#include "imexttypes.h"
2#include "imager.h"
50c75381 3#include "imio.h"
92bda632
TC
4
5/*
6 DON'T ADD CASTS TO THESE
7*/
8im_ext_funcs imager_function_table =
9 {
d1f5892c
TC
10 IMAGER_API_VERSION,
11 IMAGER_API_LEVEL,
12
92bda632
TC
13 mymalloc,
14 myfree,
15 myrealloc,
16
e310e5f9
TC
17 mymalloc_file_line,
18 myfree_file_line,
19 myrealloc_file_line,
20
92bda632
TC
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,
2b405c9e
TC
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,
3efb0915
TC
105
106 i_flood_fill_border,
107 i_flood_cfill_border,
d5477d3d
TC
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,
bd8052a6
TC
116 i_loog,
117
118 /* IMAGER_API_LEVEL 4 functions */
119 i_img_alloc,
120 i_img_init,
e5ee047b
TC
121
122 /* IMAGER_API_LEVEL 5 functions */
797a9f9c
TC
123 i_img_is_monochrome,
124 i_gsamp_bg,
125 i_gsampf_bg,
126 i_get_file_background,
718b8c97 127 i_get_file_backgroundf,
50c75381
TC
128 i_utf8_advance,
129 i_render_new,
130 i_render_delete,
131 i_render_color,
132 i_render_fill,
133 i_render_line,
6d5c85a2
TC
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 i_io_set_buffered,
147 i_io_gets,
148 io_new_fd,
149 io_new_bufchain,
150 io_new_buffer,
151 io_new_cb,
152 io_slurp,
153 io_glue_destroy
92bda632
TC
154 };
155
156/* in general these functions aren't called by Imager internally, but
157 only via the pointers above, since faster macros that call the
158 image vtable pointers are used.
159
160 () are used around the function names to prevent macro replacement
161 on the function names.
162*/
163
164/*
165=item i_ppix(im, x, y, color)
166
167=category Drawing
168
169Sets the pixel at (x,y) to I<color>.
170
171Returns 0 if the pixel was drawn, or -1 if not.
172
173Does no alpha blending, just copies the channels from the supplied
174color to the image.
175
176=cut
177*/
178
179int
8d14daab 180(i_ppix)(i_img *im, i_img_dim x, i_img_dim y, const i_color *val) {
92bda632
TC
181 return i_ppix(im, x, y, val);
182}
183
184/*
5715f7c3 185=item i_gpix(im, C<x>, C<y>, C<color>)
92bda632
TC
186
187=category Drawing
188
5715f7c3 189Retrieves the C<color> of the pixel (x,y).
92bda632
TC
190
191Returns 0 if the pixel was retrieved, or -1 if not.
192
193=cut
194*/
195
196int
8d14daab 197(i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val) {
92bda632
TC
198 return i_gpix(im, x, y, val);
199}
200
201/*
5715f7c3 202=item i_ppixf(im, C<x>, C<y>, C<fcolor>)
92bda632
TC
203
204=category Drawing
205
5715f7c3 206Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
92bda632
TC
207
208Returns 0 if the pixel was drawn, or -1 if not.
209
210Does no alpha blending, just copies the channels from the supplied
211color to the image.
212
213=cut
214*/
215int
8d14daab 216(i_ppixf)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val) {
92bda632
TC
217 return i_ppixf(im, x, y, val);
218}
219
220/*
5715f7c3 221=item i_gpixf(im, C<x>, C<y>, C<fcolor>)
92bda632
TC
222
223=category Drawing
224
225Retrieves the color of the pixel (x,y) as a floating point color into
5715f7c3 226C<fcolor>.
92bda632
TC
227
228Returns 0 if the pixel was retrieved, or -1 if not.
229
230=cut
231*/
232
233int
8d14daab 234(i_gpixf)(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val) {
92bda632
TC
235 return i_gpixf(im, x, y, val);
236}
237
238/*
239=item i_plin(im, l, r, y, colors)
240
241=category Drawing
242
243Sets (r-l) pixels starting from (l,y) using (r-l) values from
244I<colors>.
245
246Returns the number of pixels set.
247
248=cut
249*/
250
8d14daab
TC
251i_img_dim
252(i_plin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) {
92bda632
TC
253 return i_plin(im, l, r, y, vals);
254}
255
256/*
257=item i_glin(im, l, r, y, colors)
258
259=category Drawing
260
261Retrieves (r-l) pixels starting from (l,y) into I<colors>.
262
263Returns the number of pixels retrieved.
264
265=cut
266*/
267
8d14daab
TC
268i_img_dim
269(i_glin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) {
92bda632
TC
270 return i_glin(im, l, r, y, vals);
271}
272
273/*
5715f7c3 274=item i_plinf(im, C<left>, C<right>, C<fcolors>)
92bda632
TC
275
276=category Drawing
277
5715f7c3
TC
278Sets (right-left) pixels starting from (left,y) using (right-left)
279floating point colors from C<fcolors>.
92bda632
TC
280
281Returns the number of pixels set.
282
283=cut
284*/
285
8d14daab
TC
286i_img_dim
287(i_plinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) {
92bda632
TC
288 return i_plinf(im, l, r, y, vals);
289}
290
291/*
292=item i_glinf(im, l, r, y, colors)
293
294=category Drawing
295
296Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
297point colors.
298
299Returns the number of pixels retrieved.
300
301=cut
302*/
303
8d14daab
TC
304i_img_dim
305(i_glinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) {
92bda632
TC
306 return i_glinf(im, l, r, y, vals);
307}
308
309/*
5715f7c3 310=item i_gsamp(im, left, right, y, samples, channels, channel_count)
92bda632
TC
311
312=category Drawing
313
5715f7c3
TC
314Reads sample values from C<im> for the horizontal line (left, y) to
315(right-1,y) for the channels specified by C<channels>, an array of int
316with C<channel_count> elements.
92bda632 317
5715f7c3 318If channels is NULL then the first channels_count channels are retrieved for
92bda632
TC
319each pixel.
320
5715f7c3
TC
321Returns the number of samples read (which should be (right-left) *
322channel_count)
92bda632
TC
323
324=cut
325*/
8d14daab
TC
326i_img_dim
327(i_gsamp)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp,
92bda632
TC
328 const int *chans, int chan_count) {
329 return i_gsamp(im, l, r, y, samp, chans, chan_count);
330}
331
332/*
5715f7c3 333=item i_gsampf(im, left, right, y, samples, channels, channel_count)
92bda632
TC
334
335=category Drawing
336
5715f7c3
TC
337Reads floating point sample values from C<im> for the horizontal line
338(left, y) to (right-1,y) for the channels specified by C<channels>, an
339array of int with channel_count elements.
92bda632 340
5715f7c3
TC
341If C<channels> is NULL then the first C<channel_count> channels are
342retrieved for each pixel.
92bda632 343
5715f7c3
TC
344Returns the number of samples read (which should be (C<right>-C<left>)
345* C<channel_count>)
92bda632
TC
346
347=cut
348*/
8d14daab
TC
349i_img_dim
350(i_gsampf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
92bda632
TC
351 const int *chans, int chan_count) {
352 return i_gsampf(im, l, r, y, samp, chans, chan_count);
353}
354
355/*
5715f7c3 356=item i_gpal(im, left, right, y, indexes)
92bda632
TC
357
358=category Drawing
359
5715f7c3
TC
360Reads palette indexes for the horizontal line (left, y) to (right-1,
361y) into C<indexes>.
92bda632
TC
362
363Returns the number of indexes read.
364
365Always returns 0 for direct color images.
366
367=cut
368*/
8d14daab
TC
369i_img_dim
370(i_gpal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals) {
92bda632
TC
371 return i_gpal(im, x, r, y, vals);
372}
373
374/*
5715f7c3 375=item i_ppal(im, left, right, y, indexes)
92bda632
TC
376
377=category Drawing
378
5715f7c3
TC
379Writes palette indexes for the horizontal line (left, y) to (right-1,
380y) from C<indexes>.
92bda632
TC
381
382Returns the number of indexes written.
383
384Always returns 0 for direct color images.
385
386=cut
387*/
8d14daab
TC
388i_img_dim
389(i_ppal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals) {
92bda632
TC
390 return i_ppal(im, x, r, y, vals);
391}
392
393/*
394=item i_addcolors(im, colors, count)
395
396=category Paletted images
397
398Adds colors to the image's palette.
399
400On success returns the index of the lowest color added.
401
402On failure returns -1.
403
404Always fails for direct color images.
405
406=cut
407*/
408
409int
97ac0a96 410(i_addcolors)(i_img *im, const i_color *colors, int count) {
92bda632
TC
411 return i_addcolors(im, colors, count);
412}
413
414/*
415=item i_getcolors(im, index, colors, count)
416
417=category Paletted images
418
419Retrieves I<count> colors starting from I<index> in the image's
420palette.
421
422On success stores the colors into I<colors> and returns true.
423
424On failure returns false.
425
426Always fails for direct color images.
427
428Fails if there are less than I<index>+I<count> colors in the image's
429palette.
430
431=cut
432*/
433
434int
435(i_getcolors)(i_img *im, int i, i_color *colors, int count) {
436 return i_getcolors(im, i, colors, count);
437}
438
439/*
440=item i_colorcount(im)
441
442=category Paletted images
443
444Returns the number of colors in the image's palette.
445
446Returns -1 for direct images.
447
448=cut
449*/
450
451int
452(i_colorcount)(i_img *im) {
453 return i_colorcount(im);
454}
455
456/*
457=item i_maxcolors(im)
458
459=category Paletted images
460
461Returns the maximum number of colors the palette can hold for the
462image.
463
464Returns -1 for direct color images.
465
466=cut
467*/
468
469int
470(i_maxcolors)(i_img *im) {
471 return i_maxcolors(im);
472}
473
474/*
475=item i_findcolor(im, color, &entry)
476
477=category Paletted images
478
479Searches the images palette for the given color.
480
481On success sets *I<entry> to the index of the color, and returns true.
482
483On failure returns false.
484
485Always fails on direct color images.
486
487=cut
488*/
489int
97ac0a96 490(i_findcolor)(i_img *im, const i_color *color, i_palidx *entry) {
92bda632
TC
491 return i_findcolor(im, color, entry);
492}
493
494/*
495=item i_setcolors(im, index, colors, count)
496
497=category Paletted images
498
499Sets I<count> colors starting from I<index> in the image's palette.
500
5715f7c3 501On success returns true.
92bda632
TC
502
503On failure returns false.
504
505The image must have at least I<index>+I<count> colors in it's palette
506for this to succeed.
507
508Always fails on direct color images.
509
510=cut
511*/
512int
97ac0a96 513(i_setcolors)(i_img *im, int index, const i_color *colors, int count) {
92bda632
TC
514 return i_setcolors(im, index, colors, count);
515}
516