2
add ability to load xpm files to gd, requires the xpm
5
http://www.csn.ul.ie/~caolan
12
gdImagePtr gdImageCreateFromXpm(char *filename)
14
fprintf(stderr,"libgd was not built with xpm support\n");
22
gdImagePtr gdImageCreateFromXpm(char *filename)
31
int red=0,green=0,blue=0,color=0;
35
ret = XpmReadFileToXpmImage(filename,&image,&info);
36
if (ret != XpmSuccess)
39
if (!(im = gdImageCreate(image.width, image.height)))
42
number = image.ncolors;
43
colors = (int*)malloc(sizeof(int) * number);
46
for (i = 0; i < number; i++)
48
switch(strlen(image.colorTable[i].c_color))
52
buf[0] = image.colorTable[i].c_color[1];
53
red = strtol(buf,NULL,16);
55
buf[0] = image.colorTable[i].c_color[3];
56
green = strtol(buf,NULL,16);
58
buf[0] = image.colorTable[i].c_color[5];
59
blue = strtol(buf,NULL,16);
63
buf[0] = image.colorTable[i].c_color[1];
64
buf[1] = image.colorTable[i].c_color[2];
65
red = strtol(buf,NULL,16);
67
buf[0] = image.colorTable[i].c_color[3];
68
buf[1] = image.colorTable[i].c_color[4];
69
green = strtol(buf,NULL,16);
71
buf[0] = image.colorTable[i].c_color[5];
72
buf[1] = image.colorTable[i].c_color[6];
73
blue = strtol(buf,NULL,16);
77
buf[0] = image.colorTable[i].c_color[1];
78
buf[1] = image.colorTable[i].c_color[2];
79
buf[2] = image.colorTable[i].c_color[3];
80
red = strtol(buf,NULL,16);
83
buf[0] = image.colorTable[i].c_color[4];
84
buf[1] = image.colorTable[i].c_color[5];
85
buf[2] = image.colorTable[i].c_color[6];
86
green = strtol(buf,NULL,16);
89
buf[0] = image.colorTable[i].c_color[7];
90
buf[1] = image.colorTable[i].c_color[8];
91
buf[2] = image.colorTable[i].c_color[9];
92
blue = strtol(buf,NULL,16);
97
buf[0] = image.colorTable[i].c_color[1];
98
buf[1] = image.colorTable[i].c_color[2];
99
buf[2] = image.colorTable[i].c_color[3];
100
buf[3] = image.colorTable[i].c_color[4];
101
red = strtol(buf,NULL,16);
104
buf[0] = image.colorTable[i].c_color[5];
105
buf[1] = image.colorTable[i].c_color[6];
106
buf[2] = image.colorTable[i].c_color[7];
107
buf[3] = image.colorTable[i].c_color[8];
108
green = strtol(buf,NULL,16);
111
buf[0] = image.colorTable[i].c_color[9];
112
buf[1] = image.colorTable[i].c_color[10];
113
buf[2] = image.colorTable[i].c_color[11];
114
buf[3] = image.colorTable[i].c_color[12];
115
blue = strtol(buf,NULL,16);
121
colors[i] = gdImageColorResolve(im,red,green,blue);
123
fprintf(stderr,"ARRRGH\n");
126
apixel = (char *)malloc(image.cpp+1);
129
apixel[image.cpp] = '\0';
131
pointer = image.data;
132
for(i=0;i<image.height;i++)
134
for(j=0;j<image.width;j++)
137
gdImageSetPixel(im,j,i,colors[k]);