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