beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / luafontloader / fontforge / inc / gimage.h
blobc4f5b8a089a19b093927eb968a2044c6c3c19cc9
1 /* Copyright (C) 2000-2008 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:
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
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.
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.
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.
27 #ifndef _GIMAGE_H
28 #define _GIMAGE_H
29 #include "basics.h"
31 typedef uint32 Color;
33 #define COLOR_UNKNOWN ((Color) 0xffffffff)
34 #define COLOR_TRANSPARENT ((Color) 0xffffffff)
35 #define COLOR_DEFAULT ((Color) 0xfffffffe)
36 #define COLOR_CREATE(r,g,b) (((r)<<16) | ((g)<<8) | (b))
37 #define COLOR_ALPHA(col) (((col)>>24))
38 #define COLOR_RED(col) (((col)>>16) & 0xff)
39 #define COLOR_GREEN(col) (((col)>>8) & 0xff)
40 #define COLOR_BLUE(col) ((col)&0xff)
42 struct hslrgb {
43 double h,s,l,v;
44 double r,g,b;
45 uint8 rgb, hsl, hsv;
48 typedef struct clut {
49 int16 clut_len;
50 unsigned int is_grey: 1;
51 uint32 trans_index; /* will be ignored for cluts in images, use base->trans instead */
52 Color clut[256];
53 } GClut;
55 typedef struct revcmap RevCMap;
57 enum image_type { it_mono, it_bitmap=it_mono, it_index, it_true, it_rgba };
59 struct _GImage {
60 /* Format: bitmaps are stored with the most significant bit first in byte units
61 indexed images are stored in byte units
62 true color images are stored in 4 byte units, 0,red,green,blue
63 rgba images are stored in 4 byte units, alpha,red,green blue
65 unsigned int image_type: 2;
66 int16 delay; /* for animated GIFs, delay to next frame */
67 int32 width, height;
68 int32 bytes_per_line;
69 uint8 *data;
70 GClut *clut;
71 Color trans; /* PNG supports more than one transparent color, we don't */
72 /* for non-true color images this is the index, not a color */
75 /* We deal with 1 bit, 8 bit and 32 bit images internal. 1 bit images may have*/
76 /* a clut (if they don't assume bw, 0==black, 1==white), 8 bit must have a */
77 /* clut, 32bit are actually 24 bit RGB images, but we pad them for easy */
78 /* accessing. it_screen means that we've got an image that can be drawn */
79 /* directly on the screen */
80 typedef struct gimage {
81 short list_len; /* length of list */
82 union { /* depends on whether has_list is set */
83 struct _GImage *image;
84 struct _GImage **images;
85 } u;
86 void *userdata;
87 } GImage;
89 enum pastetrans_type { ptt_paste_trans_to_trans, ptt_old_shines_through};
91 typedef struct grect {
92 int32 x,y,width,height;
93 } GRect;
95 typedef struct gpoint {
96 int16 x,y;
97 } GPoint;
99 extern GImage *GImageCreate(enum image_type type, int32 width, int32 height);
100 extern GImage *_GImage_Create(enum image_type type, int32 width, int32 height);
101 extern void GImageDestroy(GImage *gi);
102 extern GImage *GImageCreateAnimation(GImage **images, int n);
103 extern GImage *GImageAddImageBefore(GImage *dest, GImage *src, int pos);
105 extern GImage *GImageBaseGetSub(struct _GImage *base, enum image_type it, GRect *src, GClut *nclut, RevCMap *rev);
106 extern GImage *GImageGetSub(GImage *image,enum image_type it, GRect *src, GClut *nclut, RevCMap *rev);
107 extern int GImageInsertToBase(struct _GImage *tobase, GImage *from, GRect *src, RevCMap *rev,
108 int to_x, int to_y, enum pastetrans_type ptt );
109 extern int GImageInsert(GImage *to, GImage *from, GRect *src, RevCMap *rev,
110 int to_x, int to_y, enum pastetrans_type ptt );
111 extern Color _GImageGetPixelColor(struct _GImage *base,int x, int y); /* Obsolete */
112 extern Color GImageGetPixelColor(GImage *base,int x, int y); /* Obsolete */
113 extern Color GImageGetPixelRGBA(GImage *base,int x, int y);
114 extern int GImageGetWidth(GImage *);
115 extern int GImageGetHeight(GImage *);
116 extern void *GImageGetUserData(GImage *img);
117 extern void GImageSetUserData(GImage *img,void *userdata);
118 extern void GImageResize(struct _GImage *tobase, struct _GImage *fbase,
119 GRect *src, RevCMap *rev);
120 extern GImage *GImageResize32(GImage *from, GRect *src, int width, int height, Color trans);
121 extern GImage *GImageResizeSame(GImage *from, GRect *src, int width, int height, RevCMap *rev);
122 extern RevCMap *GClutReverse(GClut *clut,int side_size);
123 void GClut_RevCMapFree(RevCMap *rev);
124 extern GClut *GImageFindCLUT(GImage *image,GClut *clut,int clutmax);
125 extern int GImageSameClut(GClut *clut,GClut *nclut);
126 extern int GImageGreyClut(GClut *clut);
127 extern Color GImageColourFName(unichar_t *name);
128 extern Color _GImage_ColourFName(char *name);
129 extern char *GImageNameFColour(Color col);
130 extern Color GDrawColorDarken(Color col, int by);
131 extern Color GDrawColorBrighten(Color col, int by);
133 extern int GImageWriteGImage(GImage *gi, char *filename);
134 extern int GImageWrite_Bmp(GImage *gi, FILE *fp);
135 extern int GImageWriteBmp(GImage *gi, char *filename);
136 extern GImage *GImageRead_Bmp(FILE *file);
137 extern GImage *GImageReadBmp(char *filename);
138 extern int GImageWriteXbm(GImage *gi, char *filename);
139 extern GImage *GImageReadXbm(char *filename);
140 extern int GImageWriteXpm(GImage *gi, char *filename);
141 extern GImage *GImageReadXpm(char *filename);
142 extern int GImageWriteEps(GImage *gi, char *filename);
143 extern GImage *GImageReadTiff(char *filename);
144 extern GImage *GImageReadJpeg(char *filename);
145 extern GImage *GImageRead_Jpeg(FILE *fp);
146 extern int GImageWrite_Jpeg(GImage *gi, FILE *outfile, int quality, int progressive);
147 extern int GImageWriteJpeg(GImage *gi, char *filename, int quality, int progressive);
148 extern GImage *GImageRead_Png(FILE *fp);
149 extern GImage *GImageReadPng(char *filename);
150 extern int GImageWrite_Png(GImage *gi, FILE *fp, int progressive);
151 extern int GImageWritePng(GImage *gi, char *filename, int progressive);
152 extern GImage *GImageReadGif(char *filename);
153 extern int GImageWriteGif(GImage *gi,char *filename,int progressive);
154 extern GImage *GImageReadRas(char *filename); /* Sun Raster */
155 extern GImage *GImageReadRgb(char *filename); /* SGI */
156 extern GImage *GImageRead(char *filename);
158 extern void GImageDrawRect(GImage *img,GRect *r,Color col);
159 extern void GImageDrawImage(GImage *dest,GImage *src,void *junk,int x, int y);
161 extern void gRGB2HSL(struct hslrgb *col);
162 extern void gHSL2RGB(struct hslrgb *col);
163 extern void gRGB2HSV(struct hslrgb *col);
164 extern void gHSV2RGB(struct hslrgb *col);
165 extern void gColor2Hslrgb(struct hslrgb *col,Color from);
166 extern Color gHslrgb2Color(struct hslrgb *col);
168 #endif