10
/* Exported functions: */
11
extern void gdImageGd(gdImagePtr im, FILE *out);
14
/* Use this for commenting out debug-print statements. */
15
/* Just use the first '#define' to allow all the prints... */
16
/*#define GD2_DBG(s) (s) */
20
/* Shared code to read color tables from gd file. */
22
int _gdGetColors(gdIOCtx *in, gdImagePtr im)
26
if (!gdGetByte(&im->colorsTotal, in)) {
29
if (!gdGetWord(&im->transparent, in)) {
32
if (im->transparent == 257) {
33
im->transparent = (-1);
36
GD2_DBG(printf("Pallette had %d colours (T=%d)\n",im->colorsTotal, im->transparent));
38
for (i=0; (i<gdMaxColors); i++) {
39
if (!gdGetByte(&im->red[i], in)) {
42
if (!gdGetByte(&im->green[i], in)) {
45
if (!gdGetByte(&im->blue[i], in)) {
50
for (i=0; (i < im->colorsTotal); i++) {
60
/* Use the common basic header info to make the image object. */
61
/* This is also called from _gd2CreateFromFile */
64
gdImagePtr _gdCreateFromFile(gdIOCtx *in, int *sx, int *sy)
68
if (!gdGetWord(sx, in)) {
71
if (!gdGetWord(sy, in)) {
75
GD2_DBG(printf("Image is %dx%d\n", *sx, *sy));
77
im = gdImageCreate(*sx, *sy);
79
if (!_gdGetColors(in, im)) {
90
gdImagePtr gdImageCreateFromGd(FILE *inFile)
95
in = gdNewFileCtx(inFile);
96
im = gdImageCreateFromGdCtx(in);
103
gdImagePtr gdImageCreateFromGdCtx(gdIOCtxPtr in)
109
/* Read the header */
110
im = _gdCreateFromFile(in, &sx, &sy);
116
/* Then the data... */
117
for (y=0; (y<sy); y++) {
118
for (x=0; (x<sx); x++) {
124
/* ROW-MAJOR IN GD 1.3 */
125
im->pixels[y][x] = ch;
137
void _gdPutColors(gdImagePtr im, gdIOCtx *out)
142
gdPutC((unsigned char)im->colorsTotal, out);
143
trans = im->transparent;
147
gdPutWord(trans, out);
148
for (i=0; (i<gdMaxColors); i++) {
149
gdPutC((unsigned char)im->red[i], out);
150
gdPutC((unsigned char)im->green[i], out);
151
gdPutC((unsigned char)im->blue[i], out);
156
void _gdPutHeader(gdImagePtr im, gdIOCtx *out)
158
gdPutWord(im->sx, out);
159
gdPutWord(im->sy, out);
161
_gdPutColors(im, out);
165
static void _gdImageGd(gdImagePtr im, gdIOCtx *out)
169
_gdPutHeader(im, out);
171
for (y=0; (y < im->sy); y++) {
172
for (x=0; (x < im->sx); x++) {
173
/* ROW-MAJOR IN GD 1.3 */
174
gdPutC((unsigned char)im->pixels[y][x], out);
179
void gdImageGd(gdImagePtr im, FILE *outFile)
181
gdIOCtx *out = gdNewFileCtx(outFile);
186
void* gdImageGdPtr(gdImagePtr im, int *size)
189
gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
191
rv = gdDPExtractData(out,size);