11
/* Exported functions: */
12
extern void gdImageGd (gdImagePtr im, FILE * out);
15
/* Use this for commenting out debug-print statements. */
16
/* Just use the first '#define' to allow all the prints... */
17
/*#define GD2_DBG(s) (s) */
21
/* Shared code to read color tables from gd file. */
24
_gdGetColors (gdIOCtx * in, gdImagePtr im, int gd2xFlag)
29
if (!gdGetByte (&im->trueColor, in))
33
/* This should have been a word all along */
36
if (!gdGetWord (&im->colorsTotal, in))
41
/* Int to accommodate truecolor single-color transparency */
42
if (!gdGetInt (&im->transparent, in))
49
if (!gdGetByte (&im->colorsTotal, in))
53
if (!gdGetWord (&im->transparent, in))
57
if (im->transparent == 257)
59
im->transparent = (-1);
62
GD2_DBG (printf ("Pallette had %d colours (T=%d)\n", im->colorsTotal, im->transparent));
64
for (i = 0; (i < gdMaxColors); i++)
66
if (!gdGetByte (&im->red[i], in))
70
if (!gdGetByte (&im->green[i], in))
74
if (!gdGetByte (&im->blue[i], in))
80
if (!gdGetByte (&im->alpha[i], in))
87
for (i = 0; (i < im->colorsTotal); i++)
98
/* Use the common basic header info to make the image object. */
99
/* This is also called from _gd2CreateFromFile */
103
_gdCreateFromFile (gdIOCtx * in, int *sx, int *sy)
107
if (!gdGetWord (sx, in))
113
/* This is a gd 2.0 .gd file */
115
if (!gdGetWord (sx, in))
120
if (!gdGetWord (sy, in))
125
GD2_DBG (printf ("Image is %dx%d\n", *sx, *sy));
127
im = gdImageCreate (*sx, *sy);
129
if (!_gdGetColors (in, im, gd2xFlag))
142
gdImageCreateFromGd (FILE * inFile)
147
in = gdNewFileCtx (inFile);
148
im = gdImageCreateFromGdCtx (in);
156
gdImageCreateFromGdCtx (gdIOCtxPtr in)
162
/* Read the header */
163
im = _gdCreateFromFile (in, &sx, &sy);
170
/* Then the data... */
171
for (y = 0; (y < sy); y++)
173
for (x = 0; (x < sx); x++)
181
/* ROW-MAJOR IN GD 1.3 */
182
im->pixels[y][x] = ch;
195
_gdPutColors (gdImagePtr im, gdIOCtx * out)
200
gdPutC (im->trueColor, out);
203
gdPutWord (im->colorsTotal, out);
205
gdPutInt (im->transparent, out);
208
for (i = 0; (i < gdMaxColors); i++)
210
gdPutC ((unsigned char) im->red[i], out);
211
gdPutC ((unsigned char) im->green[i], out);
212
gdPutC ((unsigned char) im->blue[i], out);
213
gdPutC ((unsigned char) im->alpha[i], out);
220
_gdPutHeader (gdImagePtr im, gdIOCtx * out)
222
/* 65535 indicates this is a gd 2.x .gd file. */
223
gdPutWord (65535, out);
224
gdPutWord (im->sx, out);
225
gdPutWord (im->sy, out);
227
_gdPutColors (im, out);
232
_gdImageGd (gdImagePtr im, gdIOCtx * out)
236
_gdPutHeader (im, out);
238
for (y = 0; (y < im->sy); y++)
240
for (x = 0; (x < im->sx); x++)
242
/* ROW-MAJOR IN GD 1.3 */
245
gdPutInt (im->tpixels[y][x], out);
249
gdPutC ((unsigned char) im->pixels[y][x], out);
256
gdImageGd (gdImagePtr im, FILE * outFile)
258
gdIOCtx *out = gdNewFileCtx (outFile);
259
_gdImageGd (im, out);
264
gdImageGdPtr (gdImagePtr im, int *size)
267
gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
268
_gdImageGd (im, out);
269
rv = gdDPExtractData (out, size);