]> git.imager.perl.org - imager.git/blame - imdatatypes.h
update sub-manifests
[imager.git] / imdatatypes.h
CommitLineData
02d1d628
AMH
1#ifndef _DATATYPES_H_
2#define _DATATYPES_H_
3
50c75381 4#include <stddef.h>
92bda632 5#include "imconfig.h"
d5477d3d 6#include "imio.h"
02d1d628
AMH
7
8#define MAXCHANNELS 4
9
faa9b3e7
TC
10/* used for palette indices in some internal code (which might be
11 exposed at some point
12*/
13typedef unsigned char i_palidx;
14
15/* We handle 2 types of sample, this is hopefully the most common, and the
16 smaller of the ones we support */
17typedef unsigned char i_sample_t;
18
19typedef struct { i_sample_t gray_color; } gray_color;
20typedef struct { i_sample_t r,g,b; } rgb_color;
21typedef struct { i_sample_t r,g,b,a; } rgba_color;
22typedef struct { i_sample_t c,m,y,k; } cmyk_color;
02d1d628
AMH
23
24typedef int undef_int; /* special value to put in typemaps to retun undef on 0 and 1 on 1 */
25
6cfee9d1
TC
26/*
27=item i_color
28=category Data Types
29=synopsis i_color black;
30=synopsis black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
31
32Type for 8-bit/sample color.
33
34Samples as per;
35
36 i_color c;
37
38i_color is a union of:
39
40=over
41
42=item *
43
5715f7c3 44gray - contains a single element gray_color, eg. C<c.gray.gray_color>
6cfee9d1
TC
45
46=item *
47
5715f7c3 48C<rgb> - contains three elements C<r>, C<g>, C<b>, eg. C<c.rgb.r>
6cfee9d1
TC
49
50=item *
51
5715f7c3 52C<rgba> - contains four elements C<r>, C<g>, C<b>, C<a>, eg. C<c.rgba.a>
6cfee9d1
TC
53
54=item *
55
5715f7c3
TC
56C<cmyk> - contains four elements C<c>, C<m>, C<y>, C<k>,
57eg. C<c.cmyk.y>. Note that Imager never uses CMYK colors except when
58reading/writing files.
6cfee9d1
TC
59
60=item *
61
62channels - an array of four channels, eg C<c.channels[2]>.
63
64=back
65
66=cut
67*/
68
02d1d628
AMH
69typedef union {
70 gray_color gray;
71 rgb_color rgb;
72 rgba_color rgba;
73 cmyk_color cmyk;
faa9b3e7 74 i_sample_t channel[MAXCHANNELS];
02d1d628
AMH
75 unsigned int ui;
76} i_color;
77
faa9b3e7
TC
78/* this is the larger sample type, it should be able to accurately represent
79 any sample size we use */
80typedef double i_fsample_t;
02d1d628 81
faa9b3e7
TC
82typedef struct { i_fsample_t gray_color; } i_fgray_color_t;
83typedef struct { i_fsample_t r, g, b; } i_frgb_color_t;
84typedef struct { i_fsample_t r, g, b, a; } i_frgba_color_t;
85typedef struct { i_fsample_t c, m, y, k; } i_fcmyk_color_t;
86
6cfee9d1
TC
87/*
88=item i_fcolor
89=category Data Types
90
91This is the double/sample color type.
92
93Its layout exactly corresponds to i_color.
94
95=cut
96*/
97
faa9b3e7
TC
98typedef union {
99 i_fgray_color_t gray;
100 i_frgb_color_t rgb;
101 i_frgba_color_t rgba;
102 i_fcmyk_color_t cmyk;
103 i_fsample_t channel[MAXCHANNELS];
104} i_fcolor;
105
106typedef enum {
107 i_direct_type, /* direct colour, keeps RGB values per pixel */
26fd367b 108 i_palette_type /* keeps a palette index per pixel */
faa9b3e7
TC
109} i_img_type_t;
110
111typedef enum {
112 /* bits per sample, not per pixel */
113 /* a paletted image might have one bit per sample */
114 i_8_bits = 8,
115 i_16_bits = 16,
26fd367b 116 i_double_bits = sizeof(double) * 8
faa9b3e7
TC
117} i_img_bits_t;
118
119typedef struct {
120 char *name; /* name of a given tag, might be NULL */
121 int code; /* number of a given tag, -1 if it has no meaning */
122 char *data; /* value of a given tag if it's not an int, may be NULL */
123 int size; /* size of the data */
124 int idata; /* value of a given tag if data is NULL */
125} i_img_tag;
126
127typedef struct {
128 int count; /* how many tags have been set */
129 int alloc; /* how many tags have been allocated for */
130 i_img_tag *tags;
131} i_img_tags;
132
133typedef struct i_img_ i_img;
97ac0a96
TC
134typedef int (*i_f_ppix_t)(i_img *im, int x, int y, const i_color *pix);
135typedef int (*i_f_ppixf_t)(i_img *im, int x, int y, const i_fcolor *pix);
136typedef int (*i_f_plin_t)(i_img *im, int x, int r, int y, const i_color *vals);
137typedef int (*i_f_plinf_t)(i_img *im, int x, int r, int y, const i_fcolor *vals);
faa9b3e7
TC
138typedef int (*i_f_gpix_t)(i_img *im, int x, int y, i_color *pix);
139typedef int (*i_f_gpixf_t)(i_img *im, int x, int y, i_fcolor *pix);
140typedef int (*i_f_glin_t)(i_img *im, int x, int r, int y, i_color *vals);
141typedef int (*i_f_glinf_t)(i_img *im, int x, int r, int y, i_fcolor *vals);
142
143typedef int (*i_f_gsamp_t)(i_img *im, int x, int r, int y, i_sample_t *samp,
18accb2a 144 const int *chans, int chan_count);
faa9b3e7 145typedef int (*i_f_gsampf_t)(i_img *im, int x, int r, int y, i_fsample_t *samp,
18accb2a 146 const int *chan, int chan_count);
faa9b3e7
TC
147
148typedef int (*i_f_gpal_t)(i_img *im, int x, int r, int y, i_palidx *vals);
97ac0a96
TC
149typedef int (*i_f_ppal_t)(i_img *im, int x, int r, int y, const i_palidx *vals);
150typedef int (*i_f_addcolors_t)(i_img *im, const i_color *colors, int count);
faa9b3e7
TC
151typedef int (*i_f_getcolors_t)(i_img *im, int i, i_color *, int count);
152typedef int (*i_f_colorcount_t)(i_img *im);
153typedef int (*i_f_maxcolors_t)(i_img *im);
97ac0a96
TC
154typedef int (*i_f_findcolor_t)(i_img *im, const i_color *color, i_palidx *entry);
155typedef int (*i_f_setcolors_t)(i_img *im, int index, const i_color *colors,
faa9b3e7
TC
156 int count);
157
158typedef void (*i_f_destroy_t)(i_img *im);
159
bd8052a6
TC
160typedef int (*i_f_gsamp_bits_t)(i_img *im, int x, int r, int y, unsigned *samp,
161 const int *chans, int chan_count, int bits);
162typedef int (*i_f_psamp_bits_t)(i_img *im, int x, int r, int y, unsigned const *samp,
163 const int *chans, int chan_count, int bits);
164
6cfee9d1
TC
165/*
166=item i_img_dim
167=category Data Types
168=synopsis i_img_dim x;
169=order 90
170
171A signed integer type that represents an image dimension or ordinate.
172
173May be larger than int on some platforms.
174
175=cut
176*/
50c75381 177
d5477d3d
TC
178typedef int i_img_dim;
179
bd8052a6
TC
180/*
181=item i_img
182=category Data Types
183=synopsis i_img *img;
6cfee9d1 184=order 10
bd8052a6
TC
185
186This is Imager's image type.
187
188It contains the following members:
189
190=over
191
192=item *
193
5715f7c3 194C<channels> - the number of channels in the image
bd8052a6
TC
195
196=item *
197
5715f7c3 198C<xsize>, C<ysize> - the width and height of the image in pixels
bd8052a6
TC
199
200=item *
201
5715f7c3 202C<bytes> - the number of bytes used to store the image data. Undefined
bd8052a6
TC
203where virtual is non-zero.
204
205=item *
206
5715f7c3 207C<ch_mask> - a mask of writable channels. eg. if this is 6 then only
bd8052a6
TC
208channels 1 and 2 are writable. There may be bits set for which there
209are no channels in the image.
210
211=item *
212
5715f7c3 213C<bits> - the number of bits stored per sample. Should be one of
bd8052a6
TC
214i_8_bits, i_16_bits, i_double_bits.
215
216=item *
217
5715f7c3 218C<type> - either i_direct_type for direct color images, or i_palette_type
bd8052a6
TC
219for paletted images.
220
221=item *
222
5715f7c3
TC
223C<virtual> - if zero then this image is-self contained. If non-zero
224then this image could be an interface to some other implementation.
bd8052a6
TC
225
226=item *
227
5715f7c3 228C<idata> - the image data. This should not be directly accessed. A new
bd8052a6
TC
229image implementation can use this to store its image data.
230i_img_destroy() will myfree() this pointer if it's non-null.
231
232=item *
233
5715f7c3 234C<tags> - a structure storing the image's tags. This should only be
bd8052a6
TC
235accessed via the i_tags_*() functions.
236
237=item *
238
5715f7c3 239C<ext_data> - a pointer for use internal to an image implementation.
bd8052a6
TC
240This should be freed by the image's destroy handler.
241
242=item *
243
5715f7c3 244C<im_data> - data internal to Imager. This is initialized by
bd8052a6
TC
245i_img_init().
246
247=item *
248
249i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
250i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
251of the required image functions. An image implementation should
252initialize these between calling i_img_alloc() and i_img_init().
253
254=item *
255
256i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
257i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
258paletted image function.
259
260=item *
261
262i_f_destroy - custom image destruction function. This should be used
263to release memory if necessary.
264
265=item *
266
267i_f_gsamp_bits - implements i_gsamp_bits() for this image.
268
269=item *
270
271i_f_psamp_bits - implements i_psamp_bits() for this image.
272
273=back
274
275=cut
276*/
277
faa9b3e7 278struct i_img_ {
02d1d628 279 int channels;
d5477d3d
TC
280 i_img_dim xsize,ysize;
281 size_t bytes;
02d1d628 282 unsigned int ch_mask;
faa9b3e7
TC
283 i_img_bits_t bits;
284 i_img_type_t type;
285 int virtual; /* image might not keep any data, must use functions */
286 unsigned char *idata; /* renamed to force inspection of existing code */
287 /* can be NULL if virtual is non-zero */
288 i_img_tags tags;
02d1d628 289
02d1d628 290 void *ext_data;
02d1d628 291
faa9b3e7
TC
292 /* interface functions */
293 i_f_ppix_t i_f_ppix;
294 i_f_ppixf_t i_f_ppixf;
295 i_f_plin_t i_f_plin;
296 i_f_plinf_t i_f_plinf;
297 i_f_gpix_t i_f_gpix;
298 i_f_gpixf_t i_f_gpixf;
299 i_f_glin_t i_f_glin;
300 i_f_glinf_t i_f_glinf;
301 i_f_gsamp_t i_f_gsamp;
302 i_f_gsampf_t i_f_gsampf;
303
304 /* only valid for type == i_palette_type */
305 i_f_gpal_t i_f_gpal;
306 i_f_ppal_t i_f_ppal;
307 i_f_addcolors_t i_f_addcolors;
308 i_f_getcolors_t i_f_getcolors;
309 i_f_colorcount_t i_f_colorcount;
310 i_f_maxcolors_t i_f_maxcolors;
311 i_f_findcolor_t i_f_findcolor;
312 i_f_setcolors_t i_f_setcolors;
313
314 i_f_destroy_t i_f_destroy;
bd8052a6
TC
315
316 /* as of 0.61 */
317 i_f_gsamp_bits_t i_f_gsamp_bits;
318 i_f_psamp_bits_t i_f_psamp_bits;
319
320 void *im_data;
faa9b3e7 321};
02d1d628 322
faa9b3e7
TC
323/* ext_data for paletted images
324 */
325typedef struct {
326 int count; /* amount of space used in palette (in entries) */
327 int alloc; /* amount of space allocated for palette (in entries) */
328 i_color *pal;
329 int last_found;
330} i_img_pal_ext;
02d1d628 331
faa9b3e7 332/* Helper datatypes
02d1d628
AMH
333 The types in here so far are:
334
335 doubly linked bucket list - pretty efficient
336 octtree - no idea about goodness
337
338 needed: hashes.
339
340*/
341
02d1d628
AMH
342/* bitmap mask */
343
344struct i_bitmap {
345 int xsize,ysize;
346 char *data;
347};
348
349struct i_bitmap* btm_new(int xsize,int ysize);
350void btm_destroy(struct i_bitmap *btm);
351int btm_test(struct i_bitmap *btm,int x,int y);
352void btm_set(struct i_bitmap *btm,int x,int y);
353
354
02d1d628
AMH
355/* Stack/Linked list */
356
357struct llink {
358 struct llink *p,*n;
359 void *data;
360 int fill; /* Number used in this link */
361};
362
363struct llist {
364 struct llink *h,*t;
365 int multip; /* # of copies in a single chain */
366 int ssize; /* size of each small element */
367 int count; /* number of elements on the list */
368};
369
370
371/* Links */
372
373struct llink *llink_new( struct llink* p,int size );
374int llist_llink_push( struct llist *lst, struct llink *lnk, void *data );
375
376/* Lists */
377
378struct llist *llist_new( int multip, int ssize );
379void llist_destroy( struct llist *l );
380void llist_push( struct llist *l, void *data );
381void llist_dump( struct llist *l );
382int llist_pop( struct llist *l,void *data );
383
384
385
386
387/* Octtree */
388
389struct octt {
390 struct octt *t[8];
391 int cnt;
392};
393
faa9b3e7 394struct octt *octt_new(void);
02d1d628
AMH
395int octt_add(struct octt *ct,unsigned char r,unsigned char g,unsigned char b);
396void octt_dump(struct octt *ct);
397void octt_count(struct octt *ct,int *tot,int max,int *overflow);
398void octt_delete(struct octt *ct);
a60905e4 399void octt_histo(struct octt *ct, unsigned int **col_usage_it_adr);
02d1d628 400
3799c4d1
TC
401/* font bounding box results */
402enum bounding_box_index_t {
403 BBOX_NEG_WIDTH,
404 BBOX_GLOBAL_DESCENT,
405 BBOX_POS_WIDTH,
406 BBOX_GLOBAL_ASCENT,
407 BBOX_DESCENT,
408 BBOX_ASCENT,
409 BBOX_ADVANCE_WIDTH,
dc35bde9 410 BBOX_RIGHT_BEARING,
3799c4d1
TC
411 BOUNDING_BOX_COUNT
412};
413
92bda632
TC
414/* Generic fills */
415struct i_fill_tag;
416
417typedef void (*i_fill_with_color_f)
50c75381 418(struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels,
92bda632
TC
419 i_color *data);
420typedef void (*i_fill_with_fcolor_f)
50c75381 421 (struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels,
92bda632
TC
422 i_fcolor *data);
423typedef void (*i_fill_destroy_f)(struct i_fill_tag *fill);
9b1ec2b8
TC
424
425/* combine functions modify their target and are permitted to modify
426 the source to prevent having to perform extra copying/memory
427 allocations, etc
428 The out array has I<channels> channels.
429
430 The in array has I<channels> channels + an alpha channel if one
431 isn't included in I<channels>.
432*/
433
92bda632 434typedef void (*i_fill_combine_f)(i_color *out, i_color *in, int channels,
50c75381 435 i_img_dim count);
92bda632 436typedef void (*i_fill_combinef_f)(i_fcolor *out, i_fcolor *in, int channels,
50c75381 437 i_img_dim count);
92bda632
TC
438
439/* fountain fill types */
440typedef enum {
441 i_fst_linear,
442 i_fst_curved,
443 i_fst_sine,
444 i_fst_sphere_up,
445 i_fst_sphere_down,
446 i_fst_end
447} i_fountain_seg_type;
448typedef enum {
449 i_fc_direct,
450 i_fc_hue_up,
451 i_fc_hue_down,
452 i_fc_end
453} i_fountain_color;
454typedef struct {
455 double start, middle, end;
456 i_fcolor c[2];
457 i_fountain_seg_type type;
458 i_fountain_color color;
459} i_fountain_seg;
460typedef enum {
461 i_fr_none,
462 i_fr_sawtooth,
463 i_fr_triangle,
464 i_fr_saw_both,
465 i_fr_tri_both
466} i_fountain_repeat;
467typedef enum {
468 i_ft_linear,
469 i_ft_bilinear,
470 i_ft_radial,
471 i_ft_radial_square,
472 i_ft_revolution,
473 i_ft_conical,
474 i_ft_end
475} i_fountain_type;
476typedef enum {
477 i_fts_none,
478 i_fts_grid,
479 i_fts_random,
480 i_fts_circle
481} i_ft_supersample;
482
6cfee9d1
TC
483/*
484=item i_fill_t
485=category Data Types
486=synopsis i_fill_t *fill;
487
488This is the "abstract" base type for Imager's fill types.
489
490Unless you're implementing a new fill type you'll typically treat this
491as an opaque type.
492
493=cut
494*/
92bda632
TC
495
496typedef struct i_fill_tag
497{
498 /* called for 8-bit/sample image (and maybe lower) */
499 /* this may be NULL, if so call fill_with_fcolor */
9b1ec2b8 500 i_fill_with_color_f f_fill_with_color;
92bda632
TC
501
502 /* called for other sample sizes */
503 /* this must be non-NULL */
9b1ec2b8 504 i_fill_with_fcolor_f f_fill_with_fcolor;
92bda632
TC
505
506 /* called if non-NULL to release any extra resources */
507 i_fill_destroy_f destroy;
508
509 /* if non-zero the caller will fill data with the original data
510 from the image */
511 i_fill_combine_f combine;
512 i_fill_combinef_f combinef;
513} i_fill_t;
514
515typedef enum {
516 ic_none,
517 ic_normal,
518 ic_multiply,
519 ic_dissolve,
520 ic_add,
521 ic_subtract,
522 ic_diff,
523 ic_lighten,
524 ic_darken,
525 ic_hue,
526 ic_sat,
527 ic_value,
528 ic_color
529} i_combine_t;
530
531/*
532 describes an axis of a MM font.
533 Modelled on FT2's FT_MM_Axis.
534 It would be nice to have a default entry too, but FT2
535 doesn't support it.
536*/
537typedef struct i_font_mm_axis_tag {
538 char const *name;
539 int minimum;
540 int maximum;
541} i_font_mm_axis;
542
543#define IM_FONT_MM_MAX_AXES 4
544
545/*
546 multiple master information for a font, if any
547 modelled on FT2's FT_Multi_Master.
548*/
549typedef struct i_font_mm_tag {
550 int num_axis;
551 int num_designs; /* provided but not necessarily useful */
552 i_font_mm_axis axis[IM_FONT_MM_MAX_AXES];
553} i_font_mm;
554
555#ifdef HAVE_LIBTT
556
557struct TT_Fonthandle_;
558
559typedef struct TT_Fonthandle_ TT_Fonthandle;
560
561#endif
562
92bda632
TC
563/* transparency handling for quantized output */
564typedef enum i_transp_tag {
565 tr_none, /* ignore any alpha channel */
566 tr_threshold, /* threshold the transparency - uses tr_threshold */
567 tr_errdiff, /* error diffusion */
568 tr_ordered /* an ordered dither */
569} i_transp;
570
571/* controls how we build the colour map */
572typedef enum i_make_colors_tag {
573 mc_none, /* user supplied colour map only */
574 mc_web_map, /* Use the 216 colour web colour map */
575 mc_addi, /* Addi's algorithm */
576 mc_median_cut, /* median cut - similar to giflib, hopefully */
9c106321 577 mc_mono, /* fixed mono color map */
92bda632
TC
578 mc_mask = 0xFF /* (mask for generator) */
579} i_make_colors;
580
581/* controls how we translate the colours */
582typedef enum i_translate_tag {
583 pt_giflib, /* get gif lib to do it (ignores make_colours) */
584 pt_closest, /* just use the closest match within the hashbox */
585 pt_perturb, /* randomly perturb the data - uses perturb_size*/
586 pt_errdiff /* error diffusion dither - uses errdiff */
587} i_translate;
588
589/* Which error diffusion map to use */
590typedef enum i_errdiff_tag {
591 ed_floyd, /* floyd-steinberg */
592 ed_jarvis, /* Jarvis, Judice and Ninke */
593 ed_stucki, /* Stucki */
594 ed_custom, /* the map found in ed_map|width|height|orig */
595 ed_mask = 0xFF, /* mask to get the map */
596 ed_bidir = 0x100 /* change direction for each row */
597} i_errdiff;
598
599/* which ordered dither map to use
600 currently only available for transparency
601 I don't know of a way to do ordered dither of an image against some
602 general palette
603 */
604typedef enum i_ord_dith_tag
605{
606 od_random, /* sort of random */
607 od_dot8, /* large dot */
608 od_dot4,
609 od_hline,
610 od_vline,
611 od_slashline, /* / line dither */
612 od_backline, /* \ line dither */
613 od_tiny, /* small checkerbox */
614 od_custom /* custom 8x8 map */
615} i_ord_dith;
616
617typedef struct i_gif_pos_tag {
618 int x, y;
619} i_gif_pos;
620
621/* passed into i_writegif_gen() to control quantization */
622typedef struct i_quantize_tag {
ec6d8908
TC
623 int version;
624
92bda632
TC
625 /* how to handle transparency */
626 i_transp transp;
627 /* the threshold at which to make pixels opaque */
628 int tr_threshold;
629 i_errdiff tr_errdiff;
630 i_ord_dith tr_orddith;
631 unsigned char tr_custom[64];
632
633 /* how to make the colour map */
634 i_make_colors make_colors;
635
636 /* any existing colours
637 mc_existing is an existing colour table
638 mc_count is the number of existing colours
639 mc_size is the total size of the array that mc_existing points
640 at - this must be at least 256
641 */
642 i_color *mc_colors;
643 int mc_size;
644 int mc_count;
645
646 /* how we translate the colours */
647 i_translate translate;
648
649 /* the error diffusion map to use if translate is mc_errdiff */
650 i_errdiff errdiff;
651 /* the following define the error diffusion values to use if
652 errdiff is ed_custom. ed_orig is the column on the top row that
653 represents the current
654 */
655 int *ed_map;
656 int ed_width, ed_height, ed_orig;
657
658 /* the amount of perturbation to use for translate is mc_perturb */
659 int perturb;
ec6d8908 660 /* version 2 members after here */
92bda632
TC
661} i_quantize;
662
663typedef struct i_gif_opts {
664 /* each image has a local color map */
665 int each_palette;
666
667 /* images are interlaced */
668 int interlace;
669
670 /* time for which image is displayed
671 (in 1/100 seconds)
672 default: 0
673 */
674 int delay_count;
675 int *delays;
676
677 /* user input flags
678 default: 0
679 */
680 int user_input_count;
681 char *user_input_flags;
682
683 /* disposal
684 default: 0 */
685 int disposal_count;
686 char *disposal;
687
688 /* this is added to the color table when we make an image transparent */
689 i_color tran_color;
690
691 /* image positions */
692 int position_count;
693 i_gif_pos *positions;
694
695 /* Netscape loop extension - number of loops */
696 int loop_count;
697
698 /* should be eliminate unused colors? */
699 int eliminate_unused;
700} i_gif_opts;
701
e310e5f9
TC
702/* distance measures used by some filters */
703enum {
704 i_dmeasure_euclidean = 0,
705 i_dmeasure_euclidean_squared = 1,
706 i_dmeasure_manhatten = 2,
707 i_dmeasure_limit = 2,
708};
92bda632 709
0778adbf 710#include "iolayert.h"
92bda632 711
50c75381 712typedef struct i_render_tag i_render;
9c106321 713
02d1d628
AMH
714#endif
715