Debian Codegraph @

inc/gimage.h

raw symbols SCIP
1 /* Copyright (C) 2000-2012 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef FONTFORGE_GIMAGE_H
29 #define FONTFORGE_GIMAGE_H
30
31 #include "basics.h"
32
33 typedef uint32_t Color;
34
35 #define COLOR_UNKNOWN ((Color) 0xffffffff)
36 #define COLOR_TRANSPARENT ((Color) 0xffffffff)
37 #define COLOR_DEFAULT ((Color) 0xfffffffe)
38 #define COLOR_WARNING ((Color) 0xfffffffd)
39 #define COLOR_WHITE ((Color) 0xffffff)
40 #define COLOR_CREATE(r,g,b) (((r)<<16) | ((g)<<8) | (b))
41 #define COLOR_ALPHA(col) (((col)>>24))
42 #define COLOR_RED(col) (((col)>>16) & 0xff)
43 #define COLOR_GREEN(col) (((col)>>8) & 0xff)
44 #define COLOR_BLUE(col) ((col)&0xff)
45
46 struct hslrgb {
47 double h,s,l,v;
48 double r,g,b;
49 uint8_t rgb, hsl, hsv;
50 };
51
52 struct hslrgba {
53 double h,s,l,v;
54 double r,g,b;
55 uint8_t rgb, hsl, hsv, has_alpha;
56 double alpha;
57 };
58
59 typedef struct clut {
60 int16_t clut_len;
61 unsigned int is_grey: 1;
62 uint32_t trans_index; /* will be ignored for cluts in images, use base->trans instead */
63 Color clut[256];
64 } GClut;
65
66 #define GCLUT_CLUT_EMPTY \
67 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
68 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
69 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
70 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
71 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
72 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
73 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
74 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
75 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
76 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
77 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
78 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
81 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
83 }
84
85
86 typedef struct revcmap RevCMap;
87
88 enum image_type { it_mono, it_bitmap=it_mono, it_index, it_true, it_rgba };
89
90 struct _GImage {
91 /* Format: bitmaps are stored with the most significant bit first in byte units
92 indexed images are stored in byte units
93 true color images are stored in 4 byte units, 0,red,green,blue
94 rgba images are stored in 4 byte units, alpha,red,green blue
95 */
96 enum image_type image_type: 2;
97 int16_t delay; /* for animated GIFs, delay to next frame */
98 int32_t width, height;
99 int32_t bytes_per_line;
100 uint8_t *data;
101 GClut *clut;
102 Color trans; /* PNG supports more than one transparent color, we don't */
103 /* for non-true color images this is the index, not a color */
104 };
105
106 /* We deal with 1 bit, 8 bit and 32 bit images internal. 1 bit images may have*/
107 /* a clut (if they don't assume bw, 0==black, 1==white), 8 bit must have a */
108 /* clut, 32bit are actually 24 bit RGB images, but we pad them for easy */
109 /* accessing. it_screen means that we've got an image that can be drawn */
110 /* directly on the screen */
111 typedef struct gimage {
112 short list_len; /* length of list */
113 union { /* depends on whether has_list is set */
114 struct _GImage *image;
115 struct _GImage **images;
116 } u;
117 void *userdata;
118 } GImage;
119
120 enum pastetrans_type { ptt_paste_trans_to_trans, ptt_old_shines_through};
121
122 typedef struct grect {
123 int32_t x,y,width,height;
124 } GRect;
125
126 #define GRECT_EMPTY { 0, 0, 0, 0 }
127
128
129 typedef struct gpoint {
130 int16_t x,y;
131 } GPoint;
132
133 #define GPOINT_EMPTY { 0, 0 }
134
135 #ifdef __cplusplus
136 extern "C" {
137 #endif
138
139 extern GImage *GImageCreate(enum image_type type, int32_t width, int32_t height);
140 extern GImage *_GImage_Create(enum image_type type, int32_t width, int32_t height);
141 extern void GImageDestroy(GImage *gi);
142 extern GImage *GImageCreateAnimation(GImage **images, int n);
143 extern GImage *GImageAddImageBefore(GImage *dest, GImage *src, int pos);
144
145 extern Color GImageGetPixelRGBA(GImage *base,int x, int y);
146 extern int GImageGetWidth(GImage *);
147 extern int GImageGetHeight(GImage *);
148 extern void *GImageGetUserData(GImage *img);
149 extern void GImageSetUserData(GImage *img,void *userdata);
150 extern RevCMap *GClutReverse(GClut *clut,int side_size);
151 void GClut_RevCMapFree(RevCMap *rev);
152 extern GClut *GImageFindCLUT(GImage *image,GClut *clut,int clutmax);
153 extern int GImageGreyClut(GClut *clut);
154 extern Color _GImage_ColourFName(char *name);
155 extern Color GDrawColorDarken(Color col, int by);
156 extern Color GDrawColorBrighten(Color col, int by);
157
158 extern int GImageWriteGImage(GImage *gi, char *filename);
159 extern int GImageWrite_Bmp(GImage *gi, FILE *fp);
160 extern int GImageWriteBmp(GImage *gi, char *filename);
161 extern GImage *GImageRead_Bmp(FILE *file);
162 extern GImage *GImageReadBmp(char *filename);
163 extern int GImageWriteXbm(GImage *gi, char *filename);
164 extern GImage *GImageReadXbm(char *filename);
165 extern int GImageWriteXpm(GImage *gi, char *filename);
166 extern GImage *GImageReadXpm(char *filename);
167 extern GImage *GImageReadTiff(char *filename);
168 extern GImage *GImageReadJpeg(char *filename);
169 extern GImage *GImageRead_Jpeg(FILE *fp);
170 extern int GImageWrite_Jpeg(GImage *gi, FILE *outfile, int quality, int progressive);
171 extern int GImageWriteJpeg(GImage *gi, char *filename, int quality, int progressive);
172 extern GImage *GImageRead_Png(FILE *fp);
173 extern GImage *GImageReadPng(char *filename);
174 extern GImage *GImageReadPngBuf(char* buf, size_t sz);
175 extern int GImageWrite_Png(GImage *gi, FILE *fp, int progressive);
176 extern int GImageWritePng(GImage *gi, char *filename, int progressive);
177 extern int GImageWritePngBuf(GImage *gi, char** buf, size_t* sz, int compression_level, int progressive);
178 extern GImage *GImageReadGif(char *filename);
179 extern int GImageWriteGif(GImage *gi,char *filename,int progressive);
180 extern GImage *GImageReadRas(char *filename); /* Sun Raster */
181 extern GImage *GImageReadRgb(char *filename); /* SGI */
182 extern GImage *GImageRead(char *filename);
183
184 extern void GImageDrawRect(GImage *img,GRect *r,Color col);
185 extern void GImageDrawImage(GImage *dest,GImage *src,GRect *junk,int x, int y);
186 extern void GImageBlendOver(GImage *dest,GImage *src,GRect *from,int x, int y);
187
188 extern void gRGB2HSL(struct hslrgb *col);
189 extern void gHSL2RGB(struct hslrgb *col);
190 extern void gRGB2HSV(struct hslrgb *col);
191 extern void gHSV2RGB(struct hslrgb *col);
192 extern void gColor2Hslrgb(struct hslrgb *col,Color from);
193 extern void gColor2Hslrgba(struct hslrgba *col,Color from);
194 extern Color gHslrgb2Color(struct hslrgb *col);
195 extern Color gHslrgba2Color(struct hslrgba *col);
196
197 #ifdef __cplusplus
198 }
199 #endif
200
201 #endif /* FONTFORGE_GIMAGE_H */