]> git.imager.perl.org - imager.git/blob - imext.c
Merge the I/O buffering branch
[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     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
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
169 Sets the pixel at (x,y) to I<color>.
170
171 Returns 0 if the pixel was drawn, or -1 if not.
172
173 Does no alpha blending, just copies the channels from the supplied
174 color to the image.
175
176 =cut
177 */
178
179 int 
180 (i_ppix)(i_img *im, i_img_dim x, i_img_dim y, const i_color *val) {
181   return i_ppix(im, x, y, val);
182 }
183
184 /*
185 =item i_gpix(im, C<x>, C<y>, C<color>)
186
187 =category Drawing
188
189 Retrieves the C<color> of the pixel (x,y).
190
191 Returns 0 if the pixel was retrieved, or -1 if not.
192
193 =cut
194 */
195
196 int
197 (i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val) {
198   return i_gpix(im, x, y, val);
199 }
200
201 /*
202 =item i_ppixf(im, C<x>, C<y>, C<fcolor>)
203
204 =category Drawing
205
206 Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
207
208 Returns 0 if the pixel was drawn, or -1 if not.
209
210 Does no alpha blending, just copies the channels from the supplied
211 color to the image.
212
213 =cut
214 */
215 int
216 (i_ppixf)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val) {
217   return i_ppixf(im, x, y, val);
218 }
219
220 /*
221 =item i_gpixf(im, C<x>, C<y>, C<fcolor>)
222
223 =category Drawing
224
225 Retrieves the color of the pixel (x,y) as a floating point color into
226 C<fcolor>.
227
228 Returns 0 if the pixel was retrieved, or -1 if not.
229
230 =cut
231 */
232
233 int
234 (i_gpixf)(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val) {
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
243 Sets (r-l) pixels starting from (l,y) using (r-l) values from
244 I<colors>.
245
246 Returns the number of pixels set.
247
248 =cut
249 */
250
251 i_img_dim
252 (i_plin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) {
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
261 Retrieves (r-l) pixels starting from (l,y) into I<colors>.
262
263 Returns the number of pixels retrieved.
264
265 =cut
266 */
267
268 i_img_dim
269 (i_glin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) {
270   return i_glin(im, l, r, y, vals);
271 }
272
273 /*
274 =item i_plinf(im, C<left>, C<right>, C<fcolors>)
275
276 =category Drawing
277
278 Sets (right-left) pixels starting from (left,y) using (right-left)
279 floating point colors from C<fcolors>.
280
281 Returns the number of pixels set.
282
283 =cut
284 */
285
286 i_img_dim
287 (i_plinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) {
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
296 Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
297 point colors.
298
299 Returns the number of pixels retrieved.
300
301 =cut
302 */
303
304 i_img_dim
305 (i_glinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) {
306   return i_glinf(im, l, r, y, vals);
307 }
308
309 /*
310 =item i_gsamp(im, left, right, y, samples, channels, channel_count)
311
312 =category Drawing
313
314 Reads 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
316 with C<channel_count> elements.
317
318 If channels is NULL then the first channels_count channels are retrieved for
319 each pixel.
320
321 Returns the number of samples read (which should be (right-left) *
322 channel_count)
323
324 =cut
325 */
326 i_img_dim
327 (i_gsamp)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp, 
328                    const int *chans, int chan_count) {
329   return i_gsamp(im, l, r, y, samp, chans, chan_count);
330 }
331
332 /*
333 =item i_gsampf(im, left, right, y, samples, channels, channel_count)
334
335 =category Drawing
336
337 Reads 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
339 array of int with channel_count elements.
340
341 If C<channels> is NULL then the first C<channel_count> channels are
342 retrieved for each pixel.
343
344 Returns the number of samples read (which should be (C<right>-C<left>)
345 * C<channel_count>)
346
347 =cut
348 */
349 i_img_dim
350 (i_gsampf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp, 
351            const int *chans, int chan_count) {
352   return i_gsampf(im, l, r, y, samp, chans, chan_count);
353 }
354
355 /*
356 =item i_gpal(im, left, right, y, indexes)
357
358 =category Drawing
359
360 Reads palette indexes for the horizontal line (left, y) to (right-1,
361 y) into C<indexes>.
362
363 Returns the number of indexes read.
364
365 Always returns 0 for direct color images.
366
367 =cut
368 */
369 i_img_dim
370 (i_gpal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals) {
371   return i_gpal(im, x, r, y, vals);
372 }
373
374 /*
375 =item i_ppal(im, left, right, y, indexes)
376
377 =category Drawing
378
379 Writes palette indexes for the horizontal line (left, y) to (right-1,
380 y) from C<indexes>.
381
382 Returns the number of indexes written.
383
384 Always returns 0 for direct color images.
385
386 =cut
387 */
388 i_img_dim
389 (i_ppal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals) {
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
398 Adds colors to the image's palette.
399
400 On success returns the index of the lowest color added.
401
402 On failure returns -1.
403
404 Always fails for direct color images.
405
406 =cut
407 */
408
409 int
410 (i_addcolors)(i_img *im, const i_color *colors, int count) {
411   return i_addcolors(im, colors, count);
412 }
413
414 /*
415 =item i_getcolors(im, index, colors, count)
416
417 =category Paletted images
418
419 Retrieves I<count> colors starting from I<index> in the image's
420 palette.
421
422 On success stores the colors into I<colors> and returns true.
423
424 On failure returns false.
425
426 Always fails for direct color images.
427
428 Fails if there are less than I<index>+I<count> colors in the image's
429 palette.
430
431 =cut
432 */
433
434 int
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
444 Returns the number of colors in the image's palette.
445
446 Returns -1 for direct images.
447
448 =cut
449 */
450
451 int
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
461 Returns the maximum number of colors the palette can hold for the
462 image.
463
464 Returns -1 for direct color images.
465
466 =cut
467 */
468
469 int
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
479 Searches the images palette for the given color.
480
481 On success sets *I<entry> to the index of the color, and returns true.
482
483 On failure returns false.
484
485 Always fails on direct color images.
486
487 =cut
488 */
489 int
490 (i_findcolor)(i_img *im, const i_color *color, i_palidx *entry) {
491   return i_findcolor(im, color, entry);
492 }
493
494 /*
495 =item i_setcolors(im, index, colors, count)
496
497 =category Paletted images
498
499 Sets I<count> colors starting from I<index> in the image's palette.
500
501 On success returns true.
502
503 On failure returns false.
504
505 The image must have at least I<index>+I<count> colors in it's palette
506 for this to succeed.
507
508 Always fails on direct color images.
509
510 =cut
511 */
512 int
513 (i_setcolors)(i_img *im, int index, const i_color *colors, int count) {
514   return i_setcolors(im, index, colors, count);
515 }
516