]> git.imager.perl.org - imager.git/blob - datatypes.h
fixes to quant.c and a minor enhancement
[imager.git] / datatypes.h
1 #ifndef _DATATYPES_H_
2 #define _DATATYPES_H_
3
4 #include "io.h"
5
6 #define MAXCHANNELS 4
7
8 typedef struct { unsigned char gray_color; } gray_color;
9 typedef struct { unsigned char r,g,b; } rgb_color;
10 typedef struct { unsigned char r,g,b,a; } rgba_color;
11 typedef struct { unsigned char c,m,y,k; } cmyk_color;
12
13 typedef int undef_int; /* special value to put in typemaps to retun undef on 0 and 1 on 1 */
14
15 typedef union {
16   gray_color gray;
17   rgb_color rgb;
18   rgba_color rgba;
19   cmyk_color cmyk;
20   unsigned char channel[MAXCHANNELS];
21   unsigned int ui;
22 } i_color;
23
24
25 struct _i_img {
26   int channels;
27   int xsize,ysize,bytes;
28   unsigned char *data;
29   unsigned int ch_mask;
30
31   int (*i_f_ppix) (struct _i_img *,int,int,i_color *); 
32   int (*i_f_gpix) (struct _i_img *,int,int,i_color *);
33   void *ext_data;
34 };
35
36 typedef struct _i_img i_img;
37
38 /* used for palette indices in some internal code (which might be 
39    exposed at some point
40 */
41 typedef unsigned char i_palidx;
42
43 /* Helper datatypes
44   The types in here so far are:
45
46   doubly linked bucket list - pretty efficient
47   octtree - no idea about goodness
48   
49   needed: hashes.
50
51 */
52
53
54
55
56
57 /* bitmap mask */
58
59 struct i_bitmap {
60   int xsize,ysize;
61   char *data;
62 };
63
64 struct i_bitmap* btm_new(int xsize,int ysize);
65 void btm_destroy(struct i_bitmap *btm);
66 int btm_test(struct i_bitmap *btm,int x,int y);
67 void btm_set(struct i_bitmap *btm,int x,int y);
68
69
70
71
72
73
74
75
76 /* Stack/Linked list */
77
78 struct llink {
79   struct llink *p,*n;
80   void *data;
81   int fill;             /* Number used in this link */
82 };
83
84 struct llist {
85   struct llink *h,*t;
86   int multip;           /* # of copies in a single chain  */
87   int ssize;            /* size of each small element     */
88   int count;           /* number of elements on the list */
89 };
90
91
92 /* Links */
93
94 struct llink *llink_new( struct llink* p,int size );
95 int  llist_llink_push( struct llist *lst, struct llink *lnk, void *data );
96
97 /* Lists */
98
99 struct llist *llist_new( int multip, int ssize );
100 void llist_destroy( struct llist *l );
101 void llist_push( struct llist *l, void *data );
102 void llist_dump( struct llist *l );
103 int llist_pop( struct llist *l,void *data );
104
105
106
107
108 /* Octtree */
109
110 struct octt {
111   struct octt *t[8]; 
112   int cnt;
113 };
114
115 struct octt *octt_new();
116 int octt_add(struct octt *ct,unsigned char r,unsigned char g,unsigned char b);
117 void octt_dump(struct octt *ct);
118 void octt_count(struct octt *ct,int *tot,int max,int *overflow);
119 void octt_delete(struct octt *ct);
120
121 #endif
122