-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimext.c
725 lines (549 loc) · 14.8 KB
/
imext.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
#include "imexttypes.h"
#include "imager.h"
#include "imio.h"
#include "imexif.h"
static im_context_t get_context(void);
static i_img *mathom_i_img_8_new(i_img_dim, i_img_dim, int);
static i_img *mathom_i_img_16_new(i_img_dim, i_img_dim, int);
static i_img *mathom_i_img_double_new(i_img_dim, i_img_dim, int);
static i_img *mathom_i_img_pal_new(i_img_dim, i_img_dim, int, int);
static void mathom_i_clear_error(void);
static void mathom_i_push_error(int, const char *);
static void mathom_i_push_errorvf(int, const char *, va_list);
static int mathom_i_set_image_file_limits(i_img_dim, i_img_dim, size_t);
static int mathom_i_get_image_file_limits(i_img_dim*, i_img_dim*, size_t*);
static int
mathom_i_int_check_image_file_limits(i_img_dim, i_img_dim, int, size_t);
static i_img *mathom_i_img_alloc(void);
static void mathom_i_img_init(i_img *);
static i_io_glue_t *mathom_io_new_fd(int);
static i_io_glue_t *mathom_io_new_bufchain(void);
static i_io_glue_t *
mathom_io_new_buffer(const char *data, size_t, i_io_closebufp_t, void *);
static i_io_glue_t *
mathom_io_new_cb(void *, i_io_readl_t, i_io_writel_t, i_io_seekl_t,
i_io_closel_t, i_io_destroyl_t);
/*
DON'T ADD CASTS TO THESE
*/
im_ext_funcs imager_function_table =
{
IMAGER_API_VERSION,
IMAGER_API_LEVEL,
mymalloc,
myfree,
myrealloc,
mymalloc_file_line,
myfree_file_line,
myrealloc_file_line,
mathom_i_img_8_new,
mathom_i_img_16_new,
mathom_i_img_double_new,
mathom_i_img_pal_new,
i_img_destroy,
i_sametype,
i_sametype_chans,
i_img_info,
i_ppix,
i_gpix,
i_ppixf,
i_gpixf,
i_plin,
i_glin,
i_plinf,
i_glinf,
i_gsamp,
i_gsampf,
i_gpal,
i_ppal,
i_addcolors,
i_getcolors,
i_colorcount,
i_maxcolors,
i_findcolor,
i_setcolors,
i_new_fill_solid,
i_new_fill_solidf,
i_new_fill_hatch,
i_new_fill_hatchf,
i_new_fill_image,
i_new_fill_fount,
i_fill_destroy,
i_quant_makemap,
i_quant_translate,
i_quant_transparent,
mathom_i_clear_error,
mathom_i_push_error,
i_push_errorf,
mathom_i_push_errorvf,
i_tags_new,
i_tags_set,
i_tags_setn,
i_tags_destroy,
i_tags_find,
i_tags_findn,
i_tags_delete,
i_tags_delbyname,
i_tags_delbycode,
i_tags_get_float,
i_tags_set_float,
i_tags_set_float2,
i_tags_get_int,
i_tags_get_string,
i_tags_get_color,
i_tags_set_color,
i_box,
i_box_filled,
i_box_cfill,
i_line,
i_line_aa,
i_arc,
i_arc_aa,
i_arc_cfill,
i_arc_aa_cfill,
i_circle_aa,
i_flood_fill,
i_flood_cfill,
i_copyto,
i_copyto_trans,
i_copy,
i_rubthru,
/* IMAGER_API_LEVEL 2 functions */
mathom_i_set_image_file_limits,
mathom_i_get_image_file_limits,
mathom_i_int_check_image_file_limits,
i_flood_fill_border,
i_flood_cfill_border,
/* IMAGER_API_LEVEL 3 functions */
i_img_setmask,
i_img_getmask,
i_img_getchannels,
i_img_get_width,
i_img_get_height,
i_lhead,
i_loog,
/* IMAGER_API_LEVEL 4 functions */
mathom_i_img_alloc,
mathom_i_img_init,
/* IMAGER_API_LEVEL 5 functions */
i_img_is_monochrome,
i_gsamp_bg,
i_gsampf_bg,
i_get_file_background,
i_get_file_backgroundf,
i_utf8_advance,
i_render_new,
i_render_delete,
i_render_color,
i_render_fill,
i_render_line,
i_render_linef,
/* level 6 */
i_io_getc_imp,
i_io_peekc_imp,
i_io_peekn,
i_io_putc_imp,
i_io_read,
i_io_write,
i_io_seek,
i_io_flush,
i_io_close,
i_io_set_buffered,
i_io_gets,
mathom_io_new_fd,
mathom_io_new_bufchain,
mathom_io_new_buffer,
mathom_io_new_cb,
io_slurp,
io_glue_destroy,
/* level 8 */
im_img_8_new,
im_img_16_new,
im_img_double_new,
im_img_pal_new,
im_clear_error,
im_push_error,
im_push_errorvf,
im_push_errorf,
im_set_image_file_limits,
im_get_image_file_limits,
im_int_check_image_file_limits,
im_img_alloc,
im_img_init,
im_io_new_fd,
im_io_new_bufchain,
im_io_new_buffer,
im_io_new_cb,
get_context,
im_lhead,
im_loog,
im_context_refinc,
im_context_refdec,
im_errors,
i_mutex_new,
i_mutex_destroy,
i_mutex_lock,
i_mutex_unlock,
im_context_slot_new,
im_context_slot_set,
im_context_slot_get,
/* level 9 */
i_poly_poly_aa,
i_poly_poly_aa_cfill,
i_poly_aa_m,
i_poly_aa_cfill_m,
i_img_alpha_channel,
i_img_color_model,
i_img_color_channels,
/* level 10 */
im_decode_exif
/* level 11 */
};
/* in general these functions aren't called by Imager internally, but
only via the pointers above, since faster macros that call the
image vtable pointers are used.
() are used around the function names to prevent macro replacement
on the function names.
*/
/*
=item i_ppix(im, x, y, color)
=category Drawing
Sets the pixel at (x,y) to I<color>.
Returns 0 if the pixel was drawn, or -1 if not.
Does no alpha blending, just copies the channels from the supplied
color to the image.
=cut
*/
int
(i_ppix)(i_img *im, i_img_dim x, i_img_dim y, const i_color *val) {
return i_ppix(im, x, y, val);
}
/*
=item i_gpix(im, C<x>, C<y>, C<color>)
=category Drawing
Retrieves the C<color> of the pixel (x,y).
Returns 0 if the pixel was retrieved, or -1 if not.
=cut
*/
int
(i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val) {
return i_gpix(im, x, y, val);
}
/*
=item i_ppixf(im, C<x>, C<y>, C<fcolor>)
=category Drawing
Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
Returns 0 if the pixel was drawn, or -1 if not.
Does no alpha blending, just copies the channels from the supplied
color to the image.
=cut
*/
int
(i_ppixf)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val) {
return i_ppixf(im, x, y, val);
}
/*
=item i_gpixf(im, C<x>, C<y>, C<fcolor>)
=category Drawing
Retrieves the color of the pixel (x,y) as a floating point color into
C<fcolor>.
Returns 0 if the pixel was retrieved, or -1 if not.
=cut
*/
int
(i_gpixf)(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val) {
return i_gpixf(im, x, y, val);
}
/*
=item i_plin(im, l, r, y, colors)
=category Drawing
Sets (r-l) pixels starting from (l,y) using (r-l) values from
I<colors>.
Returns the number of pixels set.
=cut
*/
i_img_dim
(i_plin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) {
return i_plin(im, l, r, y, vals);
}
/*
=item i_glin(im, l, r, y, colors)
=category Drawing
Retrieves (r-l) pixels starting from (l,y) into I<colors>.
Returns the number of pixels retrieved.
=cut
*/
i_img_dim
(i_glin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) {
return i_glin(im, l, r, y, vals);
}
/*
=item i_plinf(im, C<left>, C<right>, C<fcolors>)
=category Drawing
Sets (right-left) pixels starting from (left,y) using (right-left)
floating point colors from C<fcolors>.
Returns the number of pixels set.
=cut
*/
i_img_dim
(i_plinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) {
return i_plinf(im, l, r, y, vals);
}
/*
=item i_glinf(im, l, r, y, colors)
=category Drawing
Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
point colors.
Returns the number of pixels retrieved.
=cut
*/
i_img_dim
(i_glinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) {
return i_glinf(im, l, r, y, vals);
}
/*
=item i_gsamp(im, left, right, y, samples, channels, channel_count)
=category Drawing
Reads sample values from C<im> for the horizontal line (left, y) to
(right-1,y) for the channels specified by C<channels>, an array of int
with C<channel_count> elements.
If channels is NULL then the first channels_count channels are retrieved for
each pixel.
Returns the number of samples read (which should be (right-left) *
channel_count)
=cut
*/
i_img_dim
(i_gsamp)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp,
const int *chans, int chan_count) {
return i_gsamp(im, l, r, y, samp, chans, chan_count);
}
/*
=item i_gsampf(im, left, right, y, samples, channels, channel_count)
=category Drawing
Reads floating point sample values from C<im> for the horizontal line
(left, y) to (right-1,y) for the channels specified by C<channels>, an
array of int with channel_count elements.
If C<channels> is NULL then the first C<channel_count> channels are
retrieved for each pixel.
Returns the number of samples read (which should be (C<right>-C<left>)
* C<channel_count>)
=cut
*/
i_img_dim
(i_gsampf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
const int *chans, int chan_count) {
return i_gsampf(im, l, r, y, samp, chans, chan_count);
}
/*
=item i_gsamp_bits(im, left, right, y, samples, channels, channel_count, bits)
=category Drawing
Reads integer samples scaled to C<bits> bits of precision into the
C<unsigned int> array C<samples>.
Expect this to be slow unless C<< bits == im->bits >>.
Returns the number of samples copied, or -1 on error.
Not all image types implement this method.
Pushes errors, but does not call C<i_clear_error()>.
=cut
*/
/*
=item i_psamp_bits(im, left, right, y, samples, channels, channel_count, bits)
=category Drawing
Writes integer samples scaled to C<bits> bits of precision from the
C<unsigned int> array C<samples>.
Expect this to be slow unless C<< bits == im->bits >>.
Returns the number of samples copied, or -1 on error.
Not all image types implement this method.
Pushes errors, but does not call C<i_clear_error()>.
=cut
*/
/*
=item i_gpal(im, left, right, y, indexes)
=category Drawing
Reads palette indexes for the horizontal line (left, y) to (right-1,
y) into C<indexes>.
Returns the number of indexes read.
Always returns 0 for direct color images.
=cut
*/
i_img_dim
(i_gpal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals) {
return i_gpal(im, x, r, y, vals);
}
/*
=item i_ppal(im, left, right, y, indexes)
=category Drawing
Writes palette indexes for the horizontal line (left, y) to (right-1,
y) from C<indexes>.
Returns the number of indexes written.
Always returns 0 for direct color images.
=cut
*/
i_img_dim
(i_ppal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals) {
return i_ppal(im, x, r, y, vals);
}
/*
=item i_addcolors(im, colors, count)
=category Paletted images
Adds colors to the image's palette.
On success returns the index of the lowest color added.
On failure returns -1.
Always fails for direct color images.
=cut
*/
int
(i_addcolors)(i_img *im, const i_color *colors, int count) {
return i_addcolors(im, colors, count);
}
/*
=item i_getcolors(im, index, colors, count)
=category Paletted images
Retrieves I<count> colors starting from I<index> in the image's
palette.
On success stores the colors into I<colors> and returns true.
On failure returns false.
Always fails for direct color images.
Fails if there are less than I<index>+I<count> colors in the image's
palette.
=cut
*/
int
(i_getcolors)(i_img *im, int i, i_color *colors, int count) {
return i_getcolors(im, i, colors, count);
}
/*
=item i_colorcount(im)
=category Paletted images
Returns the number of colors in the image's palette.
Returns -1 for direct images.
=cut
*/
int
(i_colorcount)(i_img *im) {
return i_colorcount(im);
}
/*
=item i_maxcolors(im)
=category Paletted images
Returns the maximum number of colors the palette can hold for the
image.
Returns -1 for direct color images.
=cut
*/
int
(i_maxcolors)(i_img *im) {
return i_maxcolors(im);
}
/*
=item i_findcolor(im, color, &entry)
=category Paletted images
Searches the images palette for the given color.
On success sets *I<entry> to the index of the color, and returns true.
On failure returns false.
Always fails on direct color images.
=cut
*/
int
(i_findcolor)(i_img *im, const i_color *color, i_palidx *entry) {
return i_findcolor(im, color, entry);
}
/*
=item i_setcolors(im, index, colors, count)
=category Paletted images
Sets I<count> colors starting from I<index> in the image's palette.
On success returns true.
On failure returns false.
The image must have at least I<index>+I<count> colors in it's palette
for this to succeed.
Always fails on direct color images.
=cut
*/
int
(i_setcolors)(i_img *im, int index, const i_color *colors, int count) {
return i_setcolors(im, index, colors, count);
}
/*
=item im_get_context()
Retrieve the context object for the current thread.
Inside Imager itself this is just a function pointer, which the
F<Imager.xs> BOOT handler initializes for use within perl. If you're
taking the Imager code and embedding it elsewhere you need to
initialize the C<im_get_context> pointer at some point.
=cut
*/
static im_context_t
get_context(void) {
return im_get_context();
}
static i_img *
mathom_i_img_8_new(i_img_dim xsize, i_img_dim ysize, int channels) {
return i_img_8_new(xsize, ysize, channels);
}
static i_img *
mathom_i_img_16_new(i_img_dim xsize, i_img_dim ysize, int channels) {
return i_img_16_new(xsize, ysize, channels);
}
static i_img *
mathom_i_img_double_new(i_img_dim xsize, i_img_dim ysize, int channels) {
return i_img_double_new(xsize, ysize, channels);
}
static i_img *
mathom_i_img_pal_new(i_img_dim xsize, i_img_dim ysize, int channels,
int maxpal) {
return i_img_pal_new(xsize, ysize, channels, maxpal);
}
static void
mathom_i_clear_error(void) {
i_clear_error();
}
static void
mathom_i_push_error(int code, const char *msg) {
i_push_error(code, msg);
}
static void
mathom_i_push_errorvf(int code, const char *fmt, va_list args) {
i_push_errorvf(code, fmt, args);
}
static int
mathom_i_set_image_file_limits(i_img_dim max_width, i_img_dim max_height,
size_t max_bytes) {
return i_set_image_file_limits(max_width, max_height, max_bytes);
}
static int
mathom_i_get_image_file_limits(i_img_dim *pmax_width, i_img_dim *pmax_height,
size_t *pmax_bytes) {
return i_get_image_file_limits(pmax_width, pmax_height, pmax_bytes);
}
static int
mathom_i_int_check_image_file_limits(i_img_dim width, i_img_dim height,
int channels, size_t sample_size) {
return i_int_check_image_file_limits(width, height, channels, sample_size);
}
static i_img *
mathom_i_img_alloc(void) {
return i_img_alloc();
}
static void
mathom_i_img_init(i_img *im) {
i_img_init(im);
}
static i_io_glue_t *
mathom_io_new_fd(int fd) {
return io_new_fd(fd);
}
static i_io_glue_t *
mathom_io_new_bufchain(void) {
return io_new_bufchain();
}
static i_io_glue_t *
mathom_io_new_buffer(const char *data, size_t size, i_io_closebufp_t closefp,
void *close_data) {
return io_new_buffer(data, size, closefp, close_data);
}
static i_io_glue_t *
mathom_io_new_cb(void *p, i_io_readl_t readcb, i_io_writel_t writecb,
i_io_seekl_t seekcb, i_io_closel_t closecb,
i_io_destroyl_t destroycb) {
return io_new_cb(p, readcb, writecb, seekcb, closecb, destroycb);
}