]> git.imager.perl.org - imager.git/blob - imext.c
add mutex functions to the API
[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     im_io_new_fd,
151     im_io_new_bufchain,
152     im_io_new_buffer,
153     im_io_new_cb,
154     io_slurp,
155     io_glue_destroy,
156
157     /* level 8 */
158     get_context,
159     im_push_errorf,
160     im_lhead,
161     im_loog,
162     im_context_refinc,
163     im_context_refdec,
164     im_errors,
165     i_mutex_new,
166     i_mutex_destroy,
167     i_mutex_lock,
168     i_mutex_unlock
169   };
170
171 /* in general these functions aren't called by Imager internally, but
172    only via the pointers above, since faster macros that call the
173    image vtable pointers are used.
174
175    () are used around the function names to prevent macro replacement
176    on the function names.
177 */
178
179 /*
180 =item i_ppix(im, x, y, color)
181
182 =category Drawing
183
184 Sets the pixel at (x,y) to I<color>.
185
186 Returns 0 if the pixel was drawn, or -1 if not.
187
188 Does no alpha blending, just copies the channels from the supplied
189 color to the image.
190
191 =cut
192 */
193
194 int 
195 (i_ppix)(i_img *im, i_img_dim x, i_img_dim y, const i_color *val) {
196   return i_ppix(im, x, y, val);
197 }
198
199 /*
200 =item i_gpix(im, C<x>, C<y>, C<color>)
201
202 =category Drawing
203
204 Retrieves the C<color> of the pixel (x,y).
205
206 Returns 0 if the pixel was retrieved, or -1 if not.
207
208 =cut
209 */
210
211 int
212 (i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val) {
213   return i_gpix(im, x, y, val);
214 }
215
216 /*
217 =item i_ppixf(im, C<x>, C<y>, C<fcolor>)
218
219 =category Drawing
220
221 Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
222
223 Returns 0 if the pixel was drawn, or -1 if not.
224
225 Does no alpha blending, just copies the channels from the supplied
226 color to the image.
227
228 =cut
229 */
230 int
231 (i_ppixf)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val) {
232   return i_ppixf(im, x, y, val);
233 }
234
235 /*
236 =item i_gpixf(im, C<x>, C<y>, C<fcolor>)
237
238 =category Drawing
239
240 Retrieves the color of the pixel (x,y) as a floating point color into
241 C<fcolor>.
242
243 Returns 0 if the pixel was retrieved, or -1 if not.
244
245 =cut
246 */
247
248 int
249 (i_gpixf)(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val) {
250   return i_gpixf(im, x, y, val);
251 }
252
253 /*
254 =item i_plin(im, l, r, y, colors)
255
256 =category Drawing
257
258 Sets (r-l) pixels starting from (l,y) using (r-l) values from
259 I<colors>.
260
261 Returns the number of pixels set.
262
263 =cut
264 */
265
266 i_img_dim
267 (i_plin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) {
268   return i_plin(im, l, r, y, vals);
269 }
270
271 /*
272 =item i_glin(im, l, r, y, colors)
273
274 =category Drawing
275
276 Retrieves (r-l) pixels starting from (l,y) into I<colors>.
277
278 Returns the number of pixels retrieved.
279
280 =cut
281 */
282
283 i_img_dim
284 (i_glin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) {
285   return i_glin(im, l, r, y, vals);
286 }
287
288 /*
289 =item i_plinf(im, C<left>, C<right>, C<fcolors>)
290
291 =category Drawing
292
293 Sets (right-left) pixels starting from (left,y) using (right-left)
294 floating point colors from C<fcolors>.
295
296 Returns the number of pixels set.
297
298 =cut
299 */
300
301 i_img_dim
302 (i_plinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) {
303   return i_plinf(im, l, r, y, vals);
304 }
305
306 /*
307 =item i_glinf(im, l, r, y, colors)
308
309 =category Drawing
310
311 Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
312 point colors.
313
314 Returns the number of pixels retrieved.
315
316 =cut
317 */
318
319 i_img_dim
320 (i_glinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) {
321   return i_glinf(im, l, r, y, vals);
322 }
323
324 /*
325 =item i_gsamp(im, left, right, y, samples, channels, channel_count)
326
327 =category Drawing
328
329 Reads sample values from C<im> for the horizontal line (left, y) to
330 (right-1,y) for the channels specified by C<channels>, an array of int
331 with C<channel_count> elements.
332
333 If channels is NULL then the first channels_count channels are retrieved for
334 each pixel.
335
336 Returns the number of samples read (which should be (right-left) *
337 channel_count)
338
339 =cut
340 */
341 i_img_dim
342 (i_gsamp)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp, 
343                    const int *chans, int chan_count) {
344   return i_gsamp(im, l, r, y, samp, chans, chan_count);
345 }
346
347 /*
348 =item i_gsampf(im, left, right, y, samples, channels, channel_count)
349
350 =category Drawing
351
352 Reads floating point sample values from C<im> for the horizontal line
353 (left, y) to (right-1,y) for the channels specified by C<channels>, an
354 array of int with channel_count elements.
355
356 If C<channels> is NULL then the first C<channel_count> channels are
357 retrieved for each pixel.
358
359 Returns the number of samples read (which should be (C<right>-C<left>)
360 * C<channel_count>)
361
362 =cut
363 */
364 i_img_dim
365 (i_gsampf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp, 
366            const int *chans, int chan_count) {
367   return i_gsampf(im, l, r, y, samp, chans, chan_count);
368 }
369
370 /*
371 =item i_gsamp_bits(im, left, right, y, samples, channels, channel_count, bits)
372 =category Drawing
373
374 Reads integer samples scaled to C<bits> bits of precision into the
375 C<unsigned int> array C<samples>.
376
377 Expect this to be slow unless C<< bits == im->bits >>.
378
379 Returns the number of samples copied, or -1 on error.
380
381 Not all image types implement this method.
382
383 Pushes errors, but does not call C<i_clear_error()>.
384
385 =cut
386 */
387
388 /*
389 =item i_psamp_bits(im, left, right, y, samples, channels, channel_count, bits)
390 =category Drawing
391
392 Writes integer samples scaled to C<bits> bits of precision from the
393 C<unsigned int> array C<samples>.
394
395 Expect this to be slow unless C<< bits == im->bits >>.
396
397 Returns the number of samples copied, or -1 on error.
398
399 Not all image types implement this method.
400
401 Pushes errors, but does not call C<i_clear_error()>.
402
403 =cut
404 */
405
406 /*
407 =item i_gpal(im, left, right, y, indexes)
408
409 =category Drawing
410
411 Reads palette indexes for the horizontal line (left, y) to (right-1,
412 y) into C<indexes>.
413
414 Returns the number of indexes read.
415
416 Always returns 0 for direct color images.
417
418 =cut
419 */
420 i_img_dim
421 (i_gpal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals) {
422   return i_gpal(im, x, r, y, vals);
423 }
424
425 /*
426 =item i_ppal(im, left, right, y, indexes)
427
428 =category Drawing
429
430 Writes palette indexes for the horizontal line (left, y) to (right-1,
431 y) from C<indexes>.
432
433 Returns the number of indexes written.
434
435 Always returns 0 for direct color images.
436
437 =cut
438 */
439 i_img_dim
440 (i_ppal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals) {
441   return i_ppal(im, x, r, y, vals);
442 }
443
444 /*
445 =item i_addcolors(im, colors, count)
446
447 =category Paletted images
448
449 Adds colors to the image's palette.
450
451 On success returns the index of the lowest color added.
452
453 On failure returns -1.
454
455 Always fails for direct color images.
456
457 =cut
458 */
459
460 int
461 (i_addcolors)(i_img *im, const i_color *colors, int count) {
462   return i_addcolors(im, colors, count);
463 }
464
465 /*
466 =item i_getcolors(im, index, colors, count)
467
468 =category Paletted images
469
470 Retrieves I<count> colors starting from I<index> in the image's
471 palette.
472
473 On success stores the colors into I<colors> and returns true.
474
475 On failure returns false.
476
477 Always fails for direct color images.
478
479 Fails if there are less than I<index>+I<count> colors in the image's
480 palette.
481
482 =cut
483 */
484
485 int
486 (i_getcolors)(i_img *im, int i, i_color *colors, int count) {
487   return i_getcolors(im, i, colors, count);
488 }
489
490 /*
491 =item i_colorcount(im)
492
493 =category Paletted images
494
495 Returns the number of colors in the image's palette.
496
497 Returns -1 for direct images.
498
499 =cut
500 */
501
502 int
503 (i_colorcount)(i_img *im) {
504   return i_colorcount(im);
505 }
506
507 /*
508 =item i_maxcolors(im)
509
510 =category Paletted images
511
512 Returns the maximum number of colors the palette can hold for the
513 image.
514
515 Returns -1 for direct color images.
516
517 =cut
518 */
519
520 int
521 (i_maxcolors)(i_img *im) {
522   return i_maxcolors(im);
523 }
524
525 /*
526 =item i_findcolor(im, color, &entry)
527
528 =category Paletted images
529
530 Searches the images palette for the given color.
531
532 On success sets *I<entry> to the index of the color, and returns true.
533
534 On failure returns false.
535
536 Always fails on direct color images.
537
538 =cut
539 */
540 int
541 (i_findcolor)(i_img *im, const i_color *color, i_palidx *entry) {
542   return i_findcolor(im, color, entry);
543 }
544
545 /*
546 =item i_setcolors(im, index, colors, count)
547
548 =category Paletted images
549
550 Sets I<count> colors starting from I<index> in the image's palette.
551
552 On success returns true.
553
554 On failure returns false.
555
556 The image must have at least I<index>+I<count> colors in it's palette
557 for this to succeed.
558
559 Always fails on direct color images.
560
561 =cut
562 */
563 int
564 (i_setcolors)(i_img *im, int index, const i_color *colors, int count) {
565   return i_setcolors(im, index, colors, count);
566 }
567
568 /*
569 =item im_get_context()
570
571 Retrieve the context object for the current thread.
572
573 Inside Imager itself this is just a function pointer, which the
574 F<Imager.xs> BOOT handler initializes for use within perl.  If you're
575 taking the Imager code and embedding it elsewhere you need to
576 initialize the C<im_get_context> pointer at some point.
577
578 =cut
579 */
580
581 static im_context_t
582 get_context(void) {
583   return im_get_context();
584 }