/* add ability to load xpm files to gd, requires the xpm library. Caolan.McNamara@ul.ie http://www.csn.ul.ie/~caolan */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "gd.h" #include "gdhelpers.h" #ifdef HAVE_XPM #include <X11/xpm.h> gdImagePtr gdImageCreateFromXpm (char *filename) { XpmInfo info; XpmImage image; int i, j, k, number; char buf[5]; gdImagePtr im = 0; int *pointer; int red = 0, green = 0, blue = 0; int *colors; int ret; ret = XpmReadFileToXpmImage(filename, &image, &info); if (ret != XpmSuccess) { return 0; } number = image.ncolors; for(i = 0; i < number; i++) { if (!image.colorTable[i].c_color) { goto done; } } if (!(im = gdImageCreate(image.width, image.height))) { goto done; } colors = (int *) safe_emalloc(number, sizeof(int), 0); for (i = 0; i < number; i++) { switch (strlen (image.colorTable[i].c_color)) { case 4: buf[1] = '\0'; buf[0] = image.colorTable[i].c_color[1]; red = strtol(buf, NULL, 16); buf[0] = image.colorTable[i].c_color[2]; green = strtol(buf, NULL, 16); buf[0] = image.colorTable[i].c_color[3]; blue = strtol(buf, NULL, 16); break; case 7: buf[2] = '\0'; buf[0] = image.colorTable[i].c_color[1]; buf[1] = image.colorTable[i].c_color[2]; red = strtol(buf, NULL, 16); buf[0] = image.colorTable[i].c_color[3]; buf[1] = image.colorTable[i].c_color[4]; green = strtol(buf, NULL, 16); buf[0] = image.colorTable[i].c_color[5]; buf[1] = image.colorTable[i].c_color[6]; blue = strtol(buf, NULL, 16); break; case 10: buf[3] = '\0'; buf[0] = image.colorTable[i].c_color[1]; buf[1] = image.colorTable[i].c_color[2]; buf[2] = image.colorTable[i].c_color[3]; red = strtol(buf, NULL, 16); red /= 64; buf[0] = image.colorTable[i].c_color[4]; buf[1] = image.colorTable[i].c_color[5]; buf[2] = image.colorTable[i].c_color[6]; green = strtol(buf, NULL, 16); green /= 64; buf[0] = image.colorTable[i].c_color[7]; buf[1] = image.colorTable[i].c_color[8]; buf[2] = image.colorTable[i].c_color[9]; blue = strtol(buf, NULL, 16); blue /= 64; break; case 13: buf[4] = '\0'; buf[0] = image.colorTable[i].c_color[1]; buf[1] = image.colorTable[i].c_color[2]; buf[2] = image.colorTable[i].c_color[3]; buf[3] = image.colorTable[i].c_color[4]; red = strtol(buf, NULL, 16); red /= 256; buf[0] = image.colorTable[i].c_color[5]; buf[1] = image.colorTable[i].c_color[6]; buf[2] = image.colorTable[i].c_color[7]; buf[3] = image.colorTable[i].c_color[8]; green = strtol(buf, NULL, 16); green /= 256; buf[0] = image.colorTable[i].c_color[9]; buf[1] = image.colorTable[i].c_color[10]; buf[2] = image.colorTable[i].c_color[11]; buf[3] = image.colorTable[i].c_color[12]; blue = strtol(buf, NULL, 16); blue /= 256; break; } colors[i] = gdImageColorResolve(im, red, green, blue); } pointer = (int *) image.data; for (i = 0; i < image.height; i++) { for (j = 0; j < image.width; j++) { k = *pointer++; gdImageSetPixel(im, j, i, colors[k]); } } gdFree(colors); done: XpmFreeXpmImage(&image); XpmFreeXpmInfo(&info); return im; } #endif
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
gd.c | File | 72.75 KB | 0644 |
|
gd.h | File | 32.2 KB | 0644 |
|
gd_arc.c | File | 1.66 KB | 0644 |
|
gd_color.c | File | 1.5 KB | 0644 |
|
gd_crop.c | File | 9.04 KB | 0644 |
|
gd_filter.c | File | 10.3 KB | 0644 |
|
gd_gd.c | File | 5.2 KB | 0644 |
|
gd_gd2.c | File | 19.73 KB | 0644 |
|
gd_gif_in.c | File | 13.89 KB | 0644 |
|
gd_gif_out.c | File | 20.54 KB | 0644 |
|
gd_interpolation.c | File | 71.93 KB | 0644 |
|
gd_io.c | File | 2.69 KB | 0644 |
|
gd_io.h | File | 963 B | 0644 |
|
gd_io_dp.c | File | 6.93 KB | 0644 |
|
gd_io_file.c | File | 2.31 KB | 0644 |
|
gd_io_ss.c | File | 2.66 KB | 0644 |
|
gd_jpeg.c | File | 26.21 KB | 0644 |
|
gd_matrix.c | File | 7.78 KB | 0644 |
|
gd_pixelate.c | File | 1.33 KB | 0644 |
|
gd_png.c | File | 22 KB | 0644 |
|
gd_rotate.c | File | 12.98 KB | 0644 |
|
gd_security.c | File | 671 B | 0644 |
|
gd_ss.c | File | 1.08 KB | 0644 |
|
gd_topal.c | File | 63.08 KB | 0644 |
|
gd_transform.c | File | 1.27 KB | 0644 |
|
gd_wbmp.c | File | 5.17 KB | 0644 |
|
gd_webp.c | File | 5.04 KB | 0644 |
|
gdcache.c | File | 4.99 KB | 0644 |
|
gdcache.h | File | 2.68 KB | 0644 |
|
gdfontg.c | File | 113.25 KB | 0644 |
|
gdfontg.h | File | 529 B | 0644 |
|
gdfontl.c | File | 108.5 KB | 0644 |
|
gdfontl.h | File | 527 B | 0644 |
|
gdfontmb.c | File | 79.24 KB | 0644 |
|
gdfontmb.h | File | 495 B | 0644 |
|
gdfonts.c | File | 69.46 KB | 0644 |
|
gdfonts.h | File | 491 B | 0644 |
|
gdfontt.c | File | 38.49 KB | 0644 |
|
gdfontt.h | File | 522 B | 0644 |
|
gdft.c | File | 32.57 KB | 0644 |
|
gdhelpers.c | File | 1.19 KB | 0644 |
|
gdhelpers.h | File | 1.32 KB | 0644 |
|
gdkanji.c | File | 12.11 KB | 0644 |
|
gdtables.c | File | 5.45 KB | 0644 |
|
gdxpm.c | File | 3.21 KB | 0644 |
|
wbmp.c | File | 6.76 KB | 0644 |
|
wbmp.h | File | 1.25 KB | 0644 |
|
webpimg.c | File | 28.33 KB | 0644 |
|
webpimg.h | File | 7.04 KB | 0644 |
|
xbm.c | File | 5.3 KB | 0644 |
|