]> git.imager.perl.org - imager.git/blame - imdatatypes.h
add the add_file_magic() class method
[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"
02d1d628
AMH
6
7#define MAXCHANNELS 4
8
7a6d192f
TC
9/*
10=item im_context_t
11=category Data Types
12
13Imager's per-thread context.
14
15=cut
16*/
17
74315ca9
TC
18typedef struct im_context_tag *im_context_t;
19
7a6d192f
TC
20/*
21=item im_slot_t
22=category Data Types
23
24Represents a slot in the context object.
25
26=cut
27*/
28
fc02e376
TC
29typedef ptrdiff_t im_slot_t;
30typedef void (*im_slot_destroy_t)(void *);
31
5824f4c2
TC
32/* just so we can use our own input typemap */
33typedef double im_double;
34typedef float im_float;
35
faa9b3e7
TC
36/* used for palette indices in some internal code (which might be
37 exposed at some point
38*/
39typedef unsigned char i_palidx;
40
41/* We handle 2 types of sample, this is hopefully the most common, and the
42 smaller of the ones we support */
43typedef unsigned char i_sample_t;
44
45typedef struct { i_sample_t gray_color; } gray_color;
46typedef struct { i_sample_t r,g,b; } rgb_color;
47typedef struct { i_sample_t r,g,b,a; } rgba_color;
48typedef struct { i_sample_t c,m,y,k; } cmyk_color;
02d1d628
AMH
49
50typedef int undef_int; /* special value to put in typemaps to retun undef on 0 and 1 on 1 */
51
8d14daab
TC
52/*
53=item i_img_dim
54=category Data Types
55=synopsis i_img_dim x, y;
56=order 90
57
58A signed integer type that represents an image dimension or ordinate.
59
60May be larger than int on some platforms.
61
62=cut
63*/
64
65typedef ptrdiff_t i_img_dim;
7a6d192f
TC
66
67/*
68=item i_img_dim_u
69=category Data Types
70=synopsis i_img_dim_u limit;
71=order 90
72
73An unsigned variant of L</i_img_dim>.
74
75=cut
76*/
77
91fb86b0 78typedef size_t i_img_dim_u;
8d14daab 79
498a7bc2
TC
80#define i_img_dim_MAX ((i_img_dim)(~(i_img_dim_u)0 >> 1))
81
6cfee9d1
TC
82/*
83=item i_color
84=category Data Types
85=synopsis i_color black;
86=synopsis black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
87
88Type for 8-bit/sample color.
89
90Samples as per;
91
92 i_color c;
93
94i_color is a union of:
95
96=over
97
98=item *
99
5715f7c3 100gray - contains a single element gray_color, eg. C<c.gray.gray_color>
6cfee9d1
TC
101
102=item *
103
5715f7c3 104C<rgb> - contains three elements C<r>, C<g>, C<b>, eg. C<c.rgb.r>
6cfee9d1
TC
105
106=item *
107
5715f7c3 108C<rgba> - contains four elements C<r>, C<g>, C<b>, C<a>, eg. C<c.rgba.a>
6cfee9d1
TC
109
110=item *
111
5715f7c3
TC
112C<cmyk> - contains four elements C<c>, C<m>, C<y>, C<k>,
113eg. C<c.cmyk.y>. Note that Imager never uses CMYK colors except when
114reading/writing files.
6cfee9d1
TC
115
116=item *
117
118channels - an array of four channels, eg C<c.channels[2]>.
119
120=back
121
122=cut
123*/
124
02d1d628
AMH
125typedef union {
126 gray_color gray;
127 rgb_color rgb;
128 rgba_color rgba;
129 cmyk_color cmyk;
faa9b3e7 130 i_sample_t channel[MAXCHANNELS];
02d1d628
AMH
131 unsigned int ui;
132} i_color;
133
faa9b3e7
TC
134/* this is the larger sample type, it should be able to accurately represent
135 any sample size we use */
136typedef double i_fsample_t;
02d1d628 137
faa9b3e7
TC
138typedef struct { i_fsample_t gray_color; } i_fgray_color_t;
139typedef struct { i_fsample_t r, g, b; } i_frgb_color_t;
140typedef struct { i_fsample_t r, g, b, a; } i_frgba_color_t;
141typedef struct { i_fsample_t c, m, y, k; } i_fcmyk_color_t;
142
6cfee9d1
TC
143/*
144=item i_fcolor
145=category Data Types
146
147This is the double/sample color type.
148
149Its layout exactly corresponds to i_color.
150
151=cut
152*/
153
faa9b3e7
TC
154typedef union {
155 i_fgray_color_t gray;
156 i_frgb_color_t rgb;
157 i_frgba_color_t rgba;
158 i_fcmyk_color_t cmyk;
159 i_fsample_t channel[MAXCHANNELS];
160} i_fcolor;
161
162typedef enum {
163 i_direct_type, /* direct colour, keeps RGB values per pixel */
26fd367b 164 i_palette_type /* keeps a palette index per pixel */
faa9b3e7
TC
165} i_img_type_t;
166
167typedef enum {
168 /* bits per sample, not per pixel */
169 /* a paletted image might have one bit per sample */
170 i_8_bits = 8,
171 i_16_bits = 16,
26fd367b 172 i_double_bits = sizeof(double) * 8
faa9b3e7
TC
173} i_img_bits_t;
174
175typedef struct {
176 char *name; /* name of a given tag, might be NULL */
177 int code; /* number of a given tag, -1 if it has no meaning */
178 char *data; /* value of a given tag if it's not an int, may be NULL */
179 int size; /* size of the data */
180 int idata; /* value of a given tag if data is NULL */
181} i_img_tag;
182
183typedef struct {
184 int count; /* how many tags have been set */
185 int alloc; /* how many tags have been allocated for */
186 i_img_tag *tags;
187} i_img_tags;
188
189typedef struct i_img_ i_img;
8d14daab
TC
190typedef int (*i_f_ppix_t)(i_img *im, i_img_dim x, i_img_dim y, const i_color *pix);
191typedef int (*i_f_ppixf_t)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *pix);
192typedef i_img_dim (*i_f_plin_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_color *vals);
193typedef i_img_dim (*i_f_plinf_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_fcolor *vals);
194typedef int (*i_f_gpix_t)(i_img *im, i_img_dim x, i_img_dim y, i_color *pix);
195typedef int (*i_f_gpixf_t)(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *pix);
196typedef i_img_dim (*i_f_glin_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_color *vals);
197typedef i_img_dim (*i_f_glinf_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_fcolor *vals);
198
199typedef i_img_dim (*i_f_gsamp_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_sample_t *samp,
18accb2a 200 const int *chans, int chan_count);
8d14daab 201typedef i_img_dim (*i_f_gsampf_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_fsample_t *samp,
18accb2a 202 const int *chan, int chan_count);
faa9b3e7 203
8d14daab
TC
204typedef i_img_dim (*i_f_gpal_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals);
205typedef i_img_dim (*i_f_ppal_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals);
97ac0a96 206typedef int (*i_f_addcolors_t)(i_img *im, const i_color *colors, int count);
faa9b3e7
TC
207typedef int (*i_f_getcolors_t)(i_img *im, int i, i_color *, int count);
208typedef int (*i_f_colorcount_t)(i_img *im);
209typedef int (*i_f_maxcolors_t)(i_img *im);
97ac0a96
TC
210typedef int (*i_f_findcolor_t)(i_img *im, const i_color *color, i_palidx *entry);
211typedef int (*i_f_setcolors_t)(i_img *im, int index, const i_color *colors,
faa9b3e7
TC
212 int count);
213
214typedef void (*i_f_destroy_t)(i_img *im);
215
8d14daab 216typedef i_img_dim (*i_f_gsamp_bits_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, unsigned *samp,
bd8052a6 217 const int *chans, int chan_count, int bits);
8d14daab 218typedef i_img_dim (*i_f_psamp_bits_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, unsigned const *samp,
bd8052a6 219 const int *chans, int chan_count, int bits);
836d9f54
TC
220typedef i_img_dim
221(*i_f_psamp_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y,
222 const i_sample_t *samp, const int *chan, int chan_count);
223typedef i_img_dim
224(*i_f_psampf_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y,
225 const i_fsample_t *samp, const int *chan, int chan_count);
bd8052a6 226
bd8052a6
TC
227/*
228=item i_img
229=category Data Types
230=synopsis i_img *img;
6cfee9d1 231=order 10
bd8052a6
TC
232
233This is Imager's image type.
234
235It contains the following members:
236
237=over
238
239=item *
240
5715f7c3 241C<channels> - the number of channels in the image
bd8052a6
TC
242
243=item *
244
5715f7c3 245C<xsize>, C<ysize> - the width and height of the image in pixels
bd8052a6
TC
246
247=item *
248
5715f7c3 249C<bytes> - the number of bytes used to store the image data. Undefined
bd8052a6
TC
250where virtual is non-zero.
251
252=item *
253
5715f7c3 254C<ch_mask> - a mask of writable channels. eg. if this is 6 then only
bd8052a6
TC
255channels 1 and 2 are writable. There may be bits set for which there
256are no channels in the image.
257
258=item *
259
5715f7c3 260C<bits> - the number of bits stored per sample. Should be one of
bd8052a6
TC
261i_8_bits, i_16_bits, i_double_bits.
262
263=item *
264
5715f7c3 265C<type> - either i_direct_type for direct color images, or i_palette_type
bd8052a6
TC
266for paletted images.
267
268=item *
269
5715f7c3
TC
270C<virtual> - if zero then this image is-self contained. If non-zero
271then this image could be an interface to some other implementation.
bd8052a6
TC
272
273=item *
274
5715f7c3 275C<idata> - the image data. This should not be directly accessed. A new
bd8052a6
TC
276image implementation can use this to store its image data.
277i_img_destroy() will myfree() this pointer if it's non-null.
278
279=item *
280
5715f7c3 281C<tags> - a structure storing the image's tags. This should only be
bd8052a6
TC
282accessed via the i_tags_*() functions.
283
284=item *
285
5715f7c3 286C<ext_data> - a pointer for use internal to an image implementation.
bd8052a6
TC
287This should be freed by the image's destroy handler.
288
289=item *
290
5715f7c3 291C<im_data> - data internal to Imager. This is initialized by
bd8052a6
TC
292i_img_init().
293
294=item *
295
296i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
297i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
298of the required image functions. An image implementation should
299initialize these between calling i_img_alloc() and i_img_init().
300
301=item *
302
303i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
304i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
305paletted image function.
306
307=item *
308
309i_f_destroy - custom image destruction function. This should be used
310to release memory if necessary.
311
312=item *
313
314i_f_gsamp_bits - implements i_gsamp_bits() for this image.
315
316=item *
317
318i_f_psamp_bits - implements i_psamp_bits() for this image.
319
836d9f54
TC
320=item *
321
322i_f_psamp - implements psamp() for this image.
323
324=item *
325
326i_f_psampf - implements psamp() for this image.
327
696cb85d
TC
328=item *
329
330C<im_data> - image specific data internal to Imager.
331
332=item *
333
334C<context> - the Imager API context this image belongs to.
335
bd8052a6
TC
336=back
337
338=cut
339*/
340
faa9b3e7 341struct i_img_ {
02d1d628 342 int channels;
d5477d3d
TC
343 i_img_dim xsize,ysize;
344 size_t bytes;
02d1d628 345 unsigned int ch_mask;
faa9b3e7
TC
346 i_img_bits_t bits;
347 i_img_type_t type;
348 int virtual; /* image might not keep any data, must use functions */
349 unsigned char *idata; /* renamed to force inspection of existing code */
350 /* can be NULL if virtual is non-zero */
351 i_img_tags tags;
02d1d628 352
02d1d628 353 void *ext_data;
02d1d628 354
faa9b3e7
TC
355 /* interface functions */
356 i_f_ppix_t i_f_ppix;
357 i_f_ppixf_t i_f_ppixf;
358 i_f_plin_t i_f_plin;
359 i_f_plinf_t i_f_plinf;
360 i_f_gpix_t i_f_gpix;
361 i_f_gpixf_t i_f_gpixf;
362 i_f_glin_t i_f_glin;
363 i_f_glinf_t i_f_glinf;
364 i_f_gsamp_t i_f_gsamp;
365 i_f_gsampf_t i_f_gsampf;
366
367 /* only valid for type == i_palette_type */
368 i_f_gpal_t i_f_gpal;
369 i_f_ppal_t i_f_ppal;
370 i_f_addcolors_t i_f_addcolors;
371 i_f_getcolors_t i_f_getcolors;
372 i_f_colorcount_t i_f_colorcount;
373 i_f_maxcolors_t i_f_maxcolors;
374 i_f_findcolor_t i_f_findcolor;
375 i_f_setcolors_t i_f_setcolors;
376
377 i_f_destroy_t i_f_destroy;
bd8052a6
TC
378
379 /* as of 0.61 */
380 i_f_gsamp_bits_t i_f_gsamp_bits;
381 i_f_psamp_bits_t i_f_psamp_bits;
382
836d9f54
TC
383 /* as of 0.88 */
384 i_f_psamp_t i_f_psamp;
385 i_f_psampf_t i_f_psampf;
386
bd8052a6 387 void *im_data;
696cb85d
TC
388
389 /* 0.91 */
390 im_context_t context;
faa9b3e7 391};
02d1d628 392
faa9b3e7
TC
393/* ext_data for paletted images
394 */
395typedef struct {
396 int count; /* amount of space used in palette (in entries) */
397 int alloc; /* amount of space allocated for palette (in entries) */
398 i_color *pal;
399 int last_found;
400} i_img_pal_ext;
02d1d628 401
faa9b3e7 402/* Helper datatypes
02d1d628
AMH
403 The types in here so far are:
404
405 doubly linked bucket list - pretty efficient
406 octtree - no idea about goodness
407
408 needed: hashes.
409
410*/
411
02d1d628
AMH
412/* bitmap mask */
413
414struct i_bitmap {
8d14daab 415 i_img_dim xsize,ysize;
02d1d628
AMH
416 char *data;
417};
418
8d14daab 419struct i_bitmap* btm_new(i_img_dim xsize,i_img_dim ysize);
02d1d628 420void btm_destroy(struct i_bitmap *btm);
8d14daab
TC
421int btm_test(struct i_bitmap *btm,i_img_dim x,i_img_dim y);
422void btm_set(struct i_bitmap *btm,i_img_dim x,i_img_dim y);
02d1d628
AMH
423
424
02d1d628
AMH
425/* Stack/Linked list */
426
427struct llink {
428 struct llink *p,*n;
429 void *data;
430 int fill; /* Number used in this link */
431};
432
433struct llist {
434 struct llink *h,*t;
435 int multip; /* # of copies in a single chain */
8d14daab 436 size_t ssize; /* size of each small element */
02d1d628
AMH
437 int count; /* number of elements on the list */
438};
439
440
02d1d628
AMH
441/* Lists */
442
8d14daab 443struct llist *llist_new( int multip, size_t ssize );
02d1d628 444void llist_destroy( struct llist *l );
8d14daab 445void llist_push( struct llist *l, const void *data );
02d1d628
AMH
446void llist_dump( struct llist *l );
447int llist_pop( struct llist *l,void *data );
448
449
450
451
452/* Octtree */
453
454struct octt {
455 struct octt *t[8];
456 int cnt;
457};
458
faa9b3e7 459struct octt *octt_new(void);
02d1d628
AMH
460int octt_add(struct octt *ct,unsigned char r,unsigned char g,unsigned char b);
461void octt_dump(struct octt *ct);
462void octt_count(struct octt *ct,int *tot,int max,int *overflow);
463void octt_delete(struct octt *ct);
a60905e4 464void octt_histo(struct octt *ct, unsigned int **col_usage_it_adr);
02d1d628 465
3799c4d1
TC
466/* font bounding box results */
467enum bounding_box_index_t {
468 BBOX_NEG_WIDTH,
469 BBOX_GLOBAL_DESCENT,
470 BBOX_POS_WIDTH,
471 BBOX_GLOBAL_ASCENT,
472 BBOX_DESCENT,
473 BBOX_ASCENT,
474 BBOX_ADVANCE_WIDTH,
dc35bde9 475 BBOX_RIGHT_BEARING,
3799c4d1
TC
476 BOUNDING_BOX_COUNT
477};
478
7a6d192f
TC
479/*
480=item i_polygon_t
481=category Data Types
482
483Represents a polygon. Has the following members:
484
485=over
486
487=item *
488
489C<x>, C<y> - arrays of x and y locations of vertices.
490
491=item *
492
493C<count> - the number of entries in the C<x> and C<y> arrays.
494
495=back
496
497=cut
498*/
499
7a5914b9
TC
500typedef struct i_polygon_tag {
501 const double *x;
502 const double *y;
503 size_t count;
504} i_polygon_t;
505
7a6d192f
TC
506/*
507=item i_poly_fill_mode_t
508=category Data Types
509
510Control how polygons are filled. Has the following values:
511
512=over
513
514=item *
515
516C<i_pfm_evenodd> - simple even-odd fills.
517
518=item *
519
520C<i_pfm_nonzero> - non-zero winding rule fills.
521
522=back
523
524=cut
525*/
526
0d80f37e
TC
527typedef enum i_poly_fill_mode_tag {
528 i_pfm_evenodd,
529 i_pfm_nonzero
530} i_poly_fill_mode_t;
531
92bda632
TC
532/* Generic fills */
533struct i_fill_tag;
534
535typedef void (*i_fill_with_color_f)
50c75381 536(struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels,
92bda632
TC
537 i_color *data);
538typedef void (*i_fill_with_fcolor_f)
50c75381 539 (struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels,
92bda632
TC
540 i_fcolor *data);
541typedef void (*i_fill_destroy_f)(struct i_fill_tag *fill);
9b1ec2b8
TC
542
543/* combine functions modify their target and are permitted to modify
544 the source to prevent having to perform extra copying/memory
545 allocations, etc
546 The out array has I<channels> channels.
547
548 The in array has I<channels> channels + an alpha channel if one
549 isn't included in I<channels>.
550*/
551
92bda632 552typedef void (*i_fill_combine_f)(i_color *out, i_color *in, int channels,
50c75381 553 i_img_dim count);
92bda632 554typedef void (*i_fill_combinef_f)(i_fcolor *out, i_fcolor *in, int channels,
50c75381 555 i_img_dim count);
92bda632
TC
556
557/* fountain fill types */
558typedef enum {
559 i_fst_linear,
560 i_fst_curved,
561 i_fst_sine,
562 i_fst_sphere_up,
563 i_fst_sphere_down,
564 i_fst_end
565} i_fountain_seg_type;
566typedef enum {
567 i_fc_direct,
568 i_fc_hue_up,
569 i_fc_hue_down,
570 i_fc_end
571} i_fountain_color;
572typedef struct {
573 double start, middle, end;
574 i_fcolor c[2];
575 i_fountain_seg_type type;
576 i_fountain_color color;
577} i_fountain_seg;
578typedef enum {
579 i_fr_none,
580 i_fr_sawtooth,
581 i_fr_triangle,
582 i_fr_saw_both,
583 i_fr_tri_both
584} i_fountain_repeat;
585typedef enum {
586 i_ft_linear,
587 i_ft_bilinear,
588 i_ft_radial,
589 i_ft_radial_square,
590 i_ft_revolution,
591 i_ft_conical,
592 i_ft_end
593} i_fountain_type;
594typedef enum {
595 i_fts_none,
596 i_fts_grid,
597 i_fts_random,
598 i_fts_circle
599} i_ft_supersample;
600
6cfee9d1
TC
601/*
602=item i_fill_t
603=category Data Types
604=synopsis i_fill_t *fill;
605
606This is the "abstract" base type for Imager's fill types.
607
608Unless you're implementing a new fill type you'll typically treat this
609as an opaque type.
610
611=cut
612*/
92bda632
TC
613
614typedef struct i_fill_tag
615{
616 /* called for 8-bit/sample image (and maybe lower) */
617 /* this may be NULL, if so call fill_with_fcolor */
9b1ec2b8 618 i_fill_with_color_f f_fill_with_color;
92bda632
TC
619
620 /* called for other sample sizes */
621 /* this must be non-NULL */
9b1ec2b8 622 i_fill_with_fcolor_f f_fill_with_fcolor;
92bda632
TC
623
624 /* called if non-NULL to release any extra resources */
625 i_fill_destroy_f destroy;
626
627 /* if non-zero the caller will fill data with the original data
628 from the image */
629 i_fill_combine_f combine;
630 i_fill_combinef_f combinef;
631} i_fill_t;
632
633typedef enum {
634 ic_none,
635 ic_normal,
636 ic_multiply,
637 ic_dissolve,
638 ic_add,
639 ic_subtract,
640 ic_diff,
641 ic_lighten,
642 ic_darken,
643 ic_hue,
644 ic_sat,
645 ic_value,
646 ic_color
647} i_combine_t;
648
24c9233d
TC
649/*
650=item i_mutex_t
651X<i_mutex>
652=category mutex
653=synopsis i_mutex_t mutex;
654
655Opaque type for Imager's mutex API.
656
657=cut
658 */
659typedef struct i_mutex_tag *i_mutex_t;
660
92bda632
TC
661/*
662 describes an axis of a MM font.
663 Modelled on FT2's FT_MM_Axis.
664 It would be nice to have a default entry too, but FT2
665 doesn't support it.
666*/
667typedef struct i_font_mm_axis_tag {
668 char const *name;
669 int minimum;
670 int maximum;
671} i_font_mm_axis;
672
673#define IM_FONT_MM_MAX_AXES 4
674
675/*
676 multiple master information for a font, if any
677 modelled on FT2's FT_Multi_Master.
678*/
679typedef struct i_font_mm_tag {
680 int num_axis;
681 int num_designs; /* provided but not necessarily useful */
682 i_font_mm_axis axis[IM_FONT_MM_MAX_AXES];
683} i_font_mm;
684
685#ifdef HAVE_LIBTT
686
687struct TT_Fonthandle_;
688
689typedef struct TT_Fonthandle_ TT_Fonthandle;
690
691#endif
692
7a6d192f
TC
693/*
694=item i_transp
695=category Data Types
696
697An enumerated type for controlling how transparency is handled during
698quantization.
699
700This has the following possible values:
701
702=over
703
704=item *
705
706C<tr_none> - ignore the alpha channel
707
708=item *
709
710C<tr_threshold> - simple transparency thresholding.
711
712=item *
713
714C<tr_errdiff> - use error diffusion to control which pixels are
715transparent.
716
717=item *
718
719C<tr_ordered> - use ordered dithering to control which pixels are
720transparent.
721
722=back
723
724=cut
725*/
726
92bda632
TC
727/* transparency handling for quantized output */
728typedef enum i_transp_tag {
729 tr_none, /* ignore any alpha channel */
730 tr_threshold, /* threshold the transparency - uses tr_threshold */
731 tr_errdiff, /* error diffusion */
732 tr_ordered /* an ordered dither */
733} i_transp;
734
7a6d192f
TC
735/*
736=item i_make_colors
737=category Data Types
738
739An enumerated type used to control the method used for produce the
740color map:
741
742=over
743
744=item *
745
746C<mc_none> - the user supplied map is used.
747
748=item *
749
750C<mc_web_map> - use the classic web map. Any existing fixed colors
751are ignored.
752
753=item *
754
755C<mc_median_cut> - use median cut
756
757=item *
758
759C<mono> - use a fixed black and white map.
760
761=item *
762
763C<gray> - 256 step gray map.
764
765=item *
766
767C<gray4> - 4 step gray map.
768
769=item *
770
771C<gray16> - 16 step gray map.
772
773=back
774
775=cut
776*/
777
92bda632
TC
778typedef enum i_make_colors_tag {
779 mc_none, /* user supplied colour map only */
780 mc_web_map, /* Use the 216 colour web colour map */
781 mc_addi, /* Addi's algorithm */
782 mc_median_cut, /* median cut - similar to giflib, hopefully */
9c106321 783 mc_mono, /* fixed mono color map */
5e9a7fbd
TC
784 mc_gray, /* 256 gray map */
785 mc_gray4, /* four step gray map */
786 mc_gray16, /* sixteen step gray map */
92bda632
TC
787 mc_mask = 0xFF /* (mask for generator) */
788} i_make_colors;
789
7a6d192f
TC
790/*
791=item i_translate
792=category Data Types
793
794An enumerated type that controls how colors are translated:
795
796=over
797
798=item *
799
800C<pt_giflib> - obsolete, forces C<make_colors> to use median cut and
801acts like C<pt_closest>.
802
803=item *
804
805C<pt_closest> - always use the closest color.
806
807=item *
808
809C<pt_perturb> - add random values to each sample and find the closest
810color.
811
812=item *
813
814C<pt_errdiff> - error diffusion dither.
815
816=back
817
818=cut
819*/
820
92bda632
TC
821/* controls how we translate the colours */
822typedef enum i_translate_tag {
823 pt_giflib, /* get gif lib to do it (ignores make_colours) */
824 pt_closest, /* just use the closest match within the hashbox */
825 pt_perturb, /* randomly perturb the data - uses perturb_size*/
826 pt_errdiff /* error diffusion dither - uses errdiff */
827} i_translate;
828
7a6d192f
TC
829/*
830=item i_errdiff
831=category Data Types
832
833Controls the type of error diffusion to use:
834
835=over
836
837=item *
838
839C<ed_floyd> - floyd-steinberg
840
841=item *
842
843C<ed_jarvis> - Jarvis, Judice and Ninke
844
845=item *
846
847C<ed_stucki> - Stucki
848
849=item *
850
851C<ed_custom> - not usable for transparency dithering, allows a custom
852error diffusion map to be used.
853
854=item *
855
856C<ed_bidir> - or with the error diffusion type to use alternate
857directions on each line of the dither.
858
859=back
860
861=cut
862*/
863
92bda632
TC
864/* Which error diffusion map to use */
865typedef enum i_errdiff_tag {
866 ed_floyd, /* floyd-steinberg */
867 ed_jarvis, /* Jarvis, Judice and Ninke */
868 ed_stucki, /* Stucki */
869 ed_custom, /* the map found in ed_map|width|height|orig */
870 ed_mask = 0xFF, /* mask to get the map */
871 ed_bidir = 0x100 /* change direction for each row */
872} i_errdiff;
873
7a6d192f
TC
874/*
875=item i_ord_dith
876=category Data Types
877
878Which ordered dither map to use, currently only available for
879transparency. Values are:
880
881=over
882
883=item *
884
885C<od_random> - a pre-generated random map.
886
887=item *
888
889C<od_dot8> - large dot dither.
890
891=item *
892
893C<od_dot4> - smaller dot dither
894
895=item *
896
897C<od_hline> - horizontal line dither.
898
899=item *
900
901C<od_vline> - vertical line dither.
902
903=item *
904
905C<od_slashline> - C</> line dither.
906
907=item *
908
909C<od_backline> - C<\> line dither.
910
911=item *
912
913C<od_tiny> - small checkbox dither
914
915=item *
916
917C<od_custom> - custom dither map.
918
919=back
920
921=cut
922
92bda632
TC
923 I don't know of a way to do ordered dither of an image against some
924 general palette
925 */
926typedef enum i_ord_dith_tag
927{
928 od_random, /* sort of random */
929 od_dot8, /* large dot */
930 od_dot4,
931 od_hline,
932 od_vline,
933 od_slashline, /* / line dither */
934 od_backline, /* \ line dither */
935 od_tiny, /* small checkerbox */
936 od_custom /* custom 8x8 map */
937} i_ord_dith;
938
7a6d192f
TC
939/*
940=item i_quantize
941=category Data Types
942
943A structure type used to supply image quantization, ie. when
944converting a direct color image to a paletted image.
945
946This has the following members:
947
948=over
949
950=item *
951
952C<transp> - how to handle transparency, see L</i_transp>.
953
954=item *
955
956C<threshold> - when C<transp> is C<tr_threshold>, this is the alpha
957level at which pixels become transparent.
958
959=item *
960
961C<tr_errdiff> - when C<transp> is C<tr_errdiff> this controls the type
962of error diffusion to be done. This may not be C<ed_custom> for this
963member.
964
965=item *
966
967C<tr_orddith> - when C<transp> is C<tr_ordered> this controls the
968patten used for dithering transparency.
969
970=item *
971
972C<tr_custom> - when C<tr_orddith> is C<tr_custom> this is the ordered
973dither mask.
974
975=item *
976
977C<make_colors> - the method used to generate the color palette, see
978L</i_make_colors>.
979
980=item *
981
982C<mc_colors> - an array of C<mc_size> L</i_color> entries used to
983define the fixed colors (controlled by C<mc_count> and to return the
984generated color list.
985
986=item *
987
988C<mc_size> - the size of the buffer allocated to C<mc_colors> in
989C<sizeof(i_color)> units.
990
991=item *
992
993C<mc_count> - the number of initialized colors in C<mc_colors>.
994
995=item *
996
997C<translate> - how RGB colors are translated to palette indexes, see
998L</i_translate>.
999
1000=item *
1001
1002C<errdiff> - when C<translate> is C<pt_errdiff> this controls the type
1003of error diffusion to be done.
1004
1005=item *
1006
1007C<ed_map>, C<ed_width>, C<ed_height>, C<ed_orig> - when C<errdiff> is
1008C<ed_custom> this controls the error diffusion map. C<ed_map> is an
1009array of C<ed_width * ed_height> integers. C<ed_orig> is the position
1010of the current pixel in the error diffusion map, always on the top
1011row.
1012
1013=item *
1014
1015C<perturb> - the amount to perturb pixels when C<translate> is
1016C<mc_perturb>.
1017
1018=back
1019
1020=cut
1021*/
92bda632 1022typedef struct i_quantize_tag {
ec6d8908
TC
1023 int version;
1024
92bda632
TC
1025 /* how to handle transparency */
1026 i_transp transp;
1027 /* the threshold at which to make pixels opaque */
1028 int tr_threshold;
1029 i_errdiff tr_errdiff;
1030 i_ord_dith tr_orddith;
1031 unsigned char tr_custom[64];
1032
1033 /* how to make the colour map */
1034 i_make_colors make_colors;
1035
1036 /* any existing colours
1037 mc_existing is an existing colour table
1038 mc_count is the number of existing colours
1039 mc_size is the total size of the array that mc_existing points
1040 at - this must be at least 256
1041 */
1042 i_color *mc_colors;
1043 int mc_size;
1044 int mc_count;
1045
1046 /* how we translate the colours */
1047 i_translate translate;
1048
1049 /* the error diffusion map to use if translate is mc_errdiff */
1050 i_errdiff errdiff;
1051 /* the following define the error diffusion values to use if
1052 errdiff is ed_custom. ed_orig is the column on the top row that
1053 represents the current
1054 */
1055 int *ed_map;
1056 int ed_width, ed_height, ed_orig;
1057
1058 /* the amount of perturbation to use for translate is mc_perturb */
1059 int perturb;
ec6d8908 1060 /* version 2 members after here */
92bda632
TC
1061} i_quantize;
1062
e310e5f9
TC
1063/* distance measures used by some filters */
1064enum {
1065 i_dmeasure_euclidean = 0,
1066 i_dmeasure_euclidean_squared = 1,
1067 i_dmeasure_manhatten = 2,
1068 i_dmeasure_limit = 2,
1069};
92bda632 1070
0778adbf 1071#include "iolayert.h"
92bda632 1072
8b30e240
TC
1073/* error message information returned by im_errors() */
1074
1075typedef struct {
1076 char *msg;
1077 int code;
1078} i_errmsg;
1079
50c75381 1080typedef struct i_render_tag i_render;
9c106321 1081
35db02fc
TC
1082/*
1083=item i_color_model_t
1084=category Data Types
1085=order 95
1086
7a6d192f 1087Returned by L</i_img_color_model(im)> to indicate the color model of
35db02fc
TC
1088the image.
1089
1090An enumerated type with the following possible values:
1091
1092=over
1093
1094=item *
1095
1096C<icm_unknown> - the image has no usable color data. In future
1097versions of Imager this will be returned in a few limited cases,
1098eg. when the source image is CMYK and the user has requested no color
1099translation is done.
1100
1101=item *
1102
1103C<icm_gray> - gray scale with no alpha channel.
1104
1105=item *
1106
1107C<icm_gray_alpha> - gray scale with an alpha channel.
1108
1109=item *
1110
1111C<icm_rgb> - RGB
1112
1113=item *
1114
1115C<icm_rgb_alpha> - RGB with an alpha channel.
1116
1117=back
1118
1119=cut
1120*/
1121
1122typedef enum {
1123 icm_unknown,
1124 icm_gray,
1125 icm_gray_alpha,
1126 icm_rgb,
1127 icm_rgb_alpha
1128} i_color_model_t;
1129
8d14daab
TC
1130#ifdef IMAGER_FORMAT_ATTR
1131#define I_FORMAT_ATTR(format_index, va_index) \
1132 __attribute ((format (printf, format_index, va_index)))
1133#else
1134#define I_FORMAT_ATTR(format_index, va_index)
1135#endif
1136
336ce474
TC
1137#ifdef _MSC_VER
1138# ifndef vsnprintf
1139# define vsnprintf _vsnprintf
1140# endif
1141# ifndef snprintf
1142# define snprintf _snprintf
1143# endif
1144#endif
1145
8d14daab
TC
1146/*
1147=item i_DF
1148=category Data Types
1149=synopsis printf("left %" i_DF "\n", i_DFc(x));
1150=order 95
1151
1152This is a constant string that can be used with functions like
1153printf() to format i_img_dim values after they're been cast with i_DFc().
1154
1155Does not include the leading C<%>.
1156
1157=cut
1158
1159=item i_DFc
1160=category Data Types
1161=order 95
1162
1163Cast an C<i_img_dim> value to a type for use with the i_DF format
1164string.
1165
1166=cut
1167
1168=item i_DFp
1169=category Data Types
1170=synopsis printf("point (" i_DFp ")\n", i_DFcp(x, y));
1171=order 95
1172
1173Format a pair of C<i_img_dim> values. This format string I<does>
1174include the leading C<%>.
1175
1176=cut
1177
1178=item i_DFcp
1179=category Data Types
1180=order 95
1181
1182Casts two C<i_img_dim> values for use with the i_DF (or i_DFp) format.
1183
1184=cut
1185 */
1186
1187#define i_DFc(x) ((i_dim_format_t)(x))
1188#define i_DFcp(x, y) i_DFc(x), i_DFc(y)
1189#define i_DFp "%" i_DF ", %" i_DF
1190
02d1d628
AMH
1191#endif
1192