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