--- graphics.c.orig Sun Sep 16 17:42:20 2001 +++ graphics.c Sun Sep 16 17:49:13 2001 @@ -24,6 +24,10 @@ #include #include "gtkpixcomm.h" +#ifdef HAVE_LIBZ +# include +#endif + #include "game.h" #include "log.h" #include "mem.h" @@ -292,6 +296,9 @@ { static char *ext[] = { +#ifdef HAVE_LIBZ + "xpm.gz", +#endif "xpm", NULL }; @@ -309,8 +316,33 @@ SPRITE *mysprite; int w, h; - if(!(im=gdk_imlib_load_image((char*)filename))) { - freelog(LOG_FATAL, "Failed reading XPM file: %s", filename); + /* gdk claims it takes char* ; probably because they forgot or didn't + want to use const, but this lets us be defensive about it. + Plus, it makes it easy to substitute another name, since now we always + need to free local_fname at the end. + */ + char *local_fname = strdup(filename); + +#ifdef HAVE_LIBZ + /* If it's a compressed XPM file, uncompress it */ + w = strlen(local_fname); /* usurp w to avoid calling strlen twice */ + if(w > 7 && !strcmp(local_fname+w-7, ".xpm.gz")) { + char uncomp_name[15] = "civ-xpm.XXXXXX"; + gzFile compressed = gzopen(local_fname, "rb"); + int uncomp_fd = mkstemp(uncomp_name); /* also changes uncomp_name */ + FILE * uncomp = fdopen(uncomp_fd, "wb"); + int c; + while( (c=gzgetc(compressed)) != EOF ) + putc(c, uncomp); + gzclose(compressed); + fclose(uncomp); + free(local_fname); + local_fname = strdup(uncomp_name); + } +#endif + + if(!(im=gdk_imlib_load_image(local_fname))) { + freelog(LOG_FATAL, "Failed reading image file: %s", local_fname); exit(1); } @@ -319,7 +351,7 @@ w=im->rgb_width; h=im->rgb_height; if(!gdk_imlib_render (im, w, h)) { - freelog(LOG_FATAL, "failed render of sprite struct for %s", filename); + freelog(LOG_FATAL, "failed render of sprite struct for %s", local_fname); exit(1); } @@ -331,6 +363,7 @@ mysprite->height = h; gdk_imlib_destroy_image (im); + free(local_fname); return mysprite; }