+char*gfximage_asXPM(gfximage_t*img, int depth)
+{
+ int d= 256/depth;
+ char*str = (char*)malloc(img->width*img->height*4 + 500 + 16*depth*depth*depth);
+ char*p = str;
+ p+= sprintf(p, "static char *noname[] = {\n\"%d %d 262144 3\",\n");
+ int r,g,b;
+ for(r=0;r<depth;r++)
+ for(g=0;g<depth;g++)
+ for(b=0;b<depth;b++) {
+ p += sprintf(p, "\"%c%c%c c #%02x%02x%02x\",\n", r+32,g+32,b+32, r*d,g*d,b*d);
+ }
+ int y;
+ for(y=0;y<img->height;y++) {
+ p+=sprintf(p, "\"");
+ gfxcolor_t*col = &img->data[y*img->height];
+ int x;
+ for(x=0;x<img->width;x++) {
+ p+=sprintf(p, "%c%c%c", 32+(col->r/d), 32+(col->g/d), 32+(col->b/d));
+ }
+ p+=sprintf(p, "\",\n");
+ }
+ *p = 0;
+ return p;
+}