1 #ifndef GD_H 2 #define GD_H 1 3 4 /* gd.h: declarations file for the graphic-draw module. 5 * Permission to use, copy, modify, and distribute this software and its 6 * documentation for any purpose and without fee is hereby granted, provided 7 * that the above copyright notice appear in all copies and that both that 8 * copyright notice and this permission notice appear in supporting 9 * documentation. This software is provided "AS IS." Thomas Boutell and 10 * Boutell.Com, Inc. disclaim all warranties, either express or implied, 11 * including but not limited to implied warranties of merchantability and 12 * fitness for a particular purpose, with respect to this code and accompanying 13 * documentation. */ 14 15 /* stdio is needed for file I/O. */ 16 #include <stdio.h> 17 #include "gd_io.h" 18 19 /* This can't be changed in the current palette-only version of gd. */ 20 21 #define gdMaxColors 256 22 23 /* Image type. See functions below; you will not need to change 24 the elements directly. Use the provided macros to 25 access sx, sy, the color table, and colorsTotal for 26 read-only purposes. */ 27 28 typedef struct gdImageStruct { 29 unsigned char ** pixels; 30 int sx; 31 int sy; 32 int colorsTotal; 33 int red[gdMaxColors]; 34 int green[gdMaxColors]; 35 int blue[gdMaxColors]; 36 int open[gdMaxColors]; 37 int transparent; 38 int *polyInts; 39 int polyAllocated; 40 struct gdImageStruct *brush; 41 struct gdImageStruct *tile; 42 int brushColorMap[gdMaxColors]; 43 int tileColorMap[gdMaxColors]; 44 int styleLength; 45 int stylePos; 46 int *style; 47 int interlace; 48 } gdImage; 49 50 typedef gdImage * gdImagePtr; 51 52 typedef struct { 53 /* # of characters in font */ 54 int nchars; 55 /* First character is numbered... (usually 32 = space) */ 56 int offset; 57 /* Character width and height */ 58 int w; 59 int h; 60 /* Font data; array of characters, one row after another. 61 Easily included in code, also easily loaded from 62 data files. */ 63 char *data; 64 } gdFont; 65 66 /* Text functions take these. */ 67 typedef gdFont *gdFontPtr; 68 69 /* For backwards compatibility only. Use gdImageSetStyle() 70 for MUCH more flexible line drawing. Also see 71 gdImageSetBrush(). */ 72 #define gdDashSize 4 73 74 /* Special colors. */ 75 76 #define gdStyled (-2) 77 #define gdBrushed (-3) 78 #define gdStyledBrushed (-4) 79 #define gdTiled (-5) 80 81 /* NOT the same as the transparent color index. 82 This is used in line styles only. */ 83 #define gdTransparent (-6) 84 85 /* Functions to manipulate images. */ 86 87 gdImagePtr gdImageCreate(int sx, int sy); 88 gdImagePtr gdImageCreateFromPng(FILE *fd); 89 gdImagePtr gdImageCreateFromPngCtx(gdIOCtxPtr in); 90 91 /* A custom data source. */ 92 /* The source function must return -1 on error, otherwise the number 93 of bytes fetched. 0 is EOF, not an error! */ 94 /* context will be passed to your source function. */ 95 96 typedef struct { 97 int (*source) (void *context, char *buffer, int len); 98 void *context; 99 } gdSource, *gdSourcePtr; 100 101 gdImagePtr gdImageCreateFromPngSource(gdSourcePtr in); 102 103 gdImagePtr gdImageCreateFromGd(FILE *in); 104 gdImagePtr gdImageCreateFromGdCtx(gdIOCtxPtr in); 105 106 gdImagePtr gdImageCreateFromGd2(FILE *in); 107 gdImagePtr gdImageCreateFromGd2Ctx(gdIOCtxPtr in); 108 109 gdImagePtr gdImageCreateFromGd2Part(FILE *in, int srcx, int srcy, int w, int h); 110 gdImagePtr gdImageCreateFromGd2PartCtx(gdIOCtxPtr in, int srcx, int srcy, int w, int h); 111 112 gdImagePtr gdImageCreateFromXbm(FILE *fd); 113 114 void gdImageDestroy(gdImagePtr im); 115 void gdImageSetPixel(gdImagePtr im, int x, int y, int color); 116 int gdImageGetPixel(gdImagePtr im, int x, int y); 117 void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color); 118 /* For backwards compatibility only. Use gdImageSetStyle() 119 for much more flexible line drawing. */ 120 void gdImageDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color); 121 /* Corners specified (not width and height). Upper left first, lower right 122 second. */ 123 void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color); 124 /* Solid bar. Upper left corner first, lower right corner second. */ 125 void gdImageFilledRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color); 126 int gdImageBoundsSafe(gdImagePtr im, int x, int y); 127 void gdImageChar(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color); 128 void gdImageCharUp(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color); 129 130 void gdImageString(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color); 131 void gdImageStringUp(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color); 132 /* void gdImageString(gdImagePtr im, gdFontPtr f, int x, int y, char *s, int color); this avoids gcc4 warning */ 133 /* void gdImageStringUp(gdImagePtr im, gdFontPtr f, int x, int y, char *s, int color); this avoids gcc4 warning */ 134 135 void gdImageString16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color); 136 void gdImageStringUp16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color); 137 138 char *gdImageStringTTF(gdImage *im, int *brect, int fg, char *fontname, 139 double ptsize, double angle, int x, int y, char *string); 140 141 /* Point type for use in polygon drawing. */ 142 143 typedef struct { 144 int x, y; 145 } gdPoint, *gdPointPtr; 146 147 void gdImagePolygon(gdImagePtr im, gdPointPtr p, int n, int c); 148 void gdImageFilledPolygon(gdImagePtr im, gdPointPtr p, int n, int c); 149 150 int gdImageColorAllocate(gdImagePtr im, int r, int g, int b); 151 int gdImageColorClosest(gdImagePtr im, int r, int g, int b); 152 int gdImageColorExact(gdImagePtr im, int r, int g, int b); 153 int gdImageColorResolve(gdImagePtr im, int r, int g, int b); 154 void gdImageColorDeallocate(gdImagePtr im, int color); 155 void gdImageColorTransparent(gdImagePtr im, int color); 156 void gdImagePaletteCopy(gdImagePtr dst, gdImagePtr src); 157 void gdImagePng(gdImagePtr im, FILE *out); 158 void gdImagePngCtx(gdImagePtr im, gdIOCtx *out); 159 160 /* A custom data sink. */ 161 /* The sink function must return -1 on error, otherwise the number 162 of bytes written, which must be equal to len. */ 163 /* context will be passed to your sink function. */ 164 typedef struct { 165 int (*sink) (void *context, const char *buffer, int len); 166 void *context; 167 } gdSink, *gdSinkPtr; 168 169 void gdImagePngToSink(gdImagePtr im, gdSinkPtr out); 170 171 void gdImageGd(gdImagePtr im, FILE *out); 172 void gdImageGd2(gdImagePtr im, FILE *out, int cs, int fmt); 173 void* gdImagePngPtr(gdImagePtr im, int *size); 174 void* gdImageGdPtr(gdImagePtr im, int *size); 175 void* gdImageGd2Ptr(gdImagePtr im, int cs, int fmt, int *size); 176 void gdImageArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color); 177 void gdImageFillToBorder(gdImagePtr im, int x, int y, int border, int color); 178 void gdImageFill(gdImagePtr im, int x, int y, int color); 179 void gdImageCopy(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h); 180 void gdImageCopyMerge(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, 181 int srcX, int srcY, int w, int h, int pct); 182 void gdImageCopyMergeGray(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, 183 int srcX, int srcY, int w, int h, int pct); 184 185 /* Stretches or shrinks to fit, as needed */ 186 void gdImageCopyResized(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH); 187 void gdImageSetBrush(gdImagePtr im, gdImagePtr brush); 188 void gdImageSetTile(gdImagePtr im, gdImagePtr tile); 189 void gdImageSetStyle(gdImagePtr im, int *style, int noOfPixels); 190 /* On or off (1 or 0) */ 191 void gdImageInterlace(gdImagePtr im, int interlaceArg); 192 193 /* Macros to access information about images. READ ONLY. Changing 194 these values will NOT have the desired result. */ 195 #define gdImageSX(im) ((im)->sx) 196 #define gdImageSY(im) ((im)->sy) 197 #define gdImageColorsTotal(im) ((im)->colorsTotal) 198 #define gdImageRed(im, c) ((im)->red[(c)]) 199 #define gdImageGreen(im, c) ((im)->green[(c)]) 200 #define gdImageBlue(im, c) ((im)->blue[(c)]) 201 #define gdImageGetTransparent(im) ((im)->transparent) 202 #define gdImageGetInterlaced(im) ((im)->interlace) 203 204 /* I/O Support routines. */ 205 206 gdIOCtx* gdNewFileCtx(FILE*); 207 gdIOCtx* gdNewDynamicCtx(int, void*); 208 gdIOCtx* gdNewSSCtx(gdSourcePtr in, gdSinkPtr out); 209 void* gdDPExtractData(struct gdIOCtx* ctx, int *size); 210 211 212 #define GD2_CHUNKSIZE 128 213 #define GD2_CHUNKSIZE_MIN 64 214 #define GD2_CHUNKSIZE_MAX 4096 215 216 #define GD2_VERS 1 217 #define GD2_ID "gd2" 218 #define GD2_FMT_RAW 1 219 #define GD2_FMT_COMPRESSED 2 220 221 /* Image comparison definitions */ 222 int gdImageCompare(gdImagePtr im1, gdImagePtr im2); 223 224 #define GD_CMP_IMAGE 1 /* Actual image IS different */ 225 #define GD_CMP_NUM_COLORS 2 /* Number of Colours in pallette differ */ 226 #define GD_CMP_COLOR 4 /* Image colours differ */ 227 #define GD_CMP_SIZE_X 8 /* Image width differs */ 228 #define GD_CMP_SIZE_Y 16 /* Image heights differ */ 229 #define GD_CMP_TRANSPARENT 32 /* Transparent colour */ 230 #define GD_CMP_BACKGROUND 64 /* Background colour */ 231 #define GD_CMP_INTERLACE 128 /* Interlaced setting */ 232 #endif 233