X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fimage.c;h=13cfce001e50e03caf5a01eee2241bbfccc4b9b5;hb=28f0f8708f4b4f8c4f39f1b23bc5fc7e0fed7579;hp=9b89100b75548709fcc6ec8b2df7966c9250efea;hpb=93806fb4c23f4b6ef58d9562e908a1b89ece869d;p=rocksndiamonds.git diff --git a/src/libgame/image.c b/src/libgame/image.c index 9b89100b..13cfce00 100644 --- a/src/libgame/image.c +++ b/src/libgame/image.c @@ -1,7 +1,7 @@ /*********************************************************** * Artsoft Retro-Game Library * *----------------------------------------------------------* -* (c) 1994-2001 Artsoft Entertainment * +* (c) 1994-2002 Artsoft Entertainment * * Holger Schemel * * Detmolder Strasse 189 * * 33604 Bielefeld * @@ -16,6 +16,10 @@ #include "misc.h" +/* ========================================================================= */ +/* PLATFORM SPECIFIC IMAGE FUNCTIONS */ +/* ========================================================================= */ + #if defined(TARGET_X11) /* for MS-DOS/Allegro, exclude all except newImage() and freeImage() */ @@ -245,6 +249,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, bluestep = 256 / bluecolors; redbottom = greenbottom = bluebottom = 0; redtop = greentop = bluetop = 0; + for (a=0; amap_entries; a++) { if (redbottom < 256) @@ -275,10 +280,12 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, /* something completely unexpected happened */ fprintf(stderr, "Image_to_Pixmap: XAllocColor failed on a TrueColor/Directcolor visual\n"); + free(redvalue); free(greenvalue); free(bluevalue); free(ximageinfo); + return NULL; } @@ -291,6 +298,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, while ((bluebottom < 256) && (bluebottom < bluetop)) bluevalue[bluebottom++] = xcolor.pixel & visual->blue_mask; } + break; } @@ -421,6 +429,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, default: Error(ERR_RETURN,"DirectColor, TrueColor or PseudoColor display needed"); SetError(error, "display class not supported"); + return NULL; } @@ -467,6 +476,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, dst_ptr += display_bytes_per_pixel; } } + break; } @@ -486,14 +496,17 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, dst_ptr += display_bytes_per_pixel; } } + break; } default: Error(ERR_RETURN, "RGB or TrueColor image needed"); SetError(error, "image type not supported"); + return NULL; } + break; } @@ -517,12 +530,14 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, } } } + break; } default: Error(ERR_RETURN,"DirectColor, TrueColor or PseudoColor display needed"); SetError(error, "display class not supported"); + return NULL; } @@ -544,11 +559,9 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, XPutImage(ximageinfo->display, ximageinfo->pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); - free(ximage->data); - ximage->data = NULL; XDestroyImage(ximage); - return(ximageinfo); + return ximageinfo; } void freeXImage(Image *image, XImageInfo *ximageinfo) @@ -593,7 +606,11 @@ int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename, /* convert image structure to X11 Pixmap */ if (!(ximageinfo = Image_to_Pixmap(display, screen, visual, window, gc, depth, image))) + { + freeImage(image); + return PCX_OtherError; + } /* if a private colormap has been created, install it */ if (ximageinfo->cmap != DefaultColormap(display, screen)) @@ -613,8 +630,37 @@ int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename, *pixmap = ximageinfo->pixmap; *pixmap_mask = ximageinfo->pixmap_mask; + /* free generic image and ximageinfo after native Pixmap has been created */ + free(ximageinfo); + freeImage(image); + return PCX_Success; } #endif /* PLATFORM_UNIX */ #endif /* TARGET_X11 */ + + +/* ========================================================================= */ +/* PLATFORM INDEPENDANT IMAGE FUNCTIONS */ +/* ========================================================================= */ + +struct ImageInfo +{ + char *source_filename; + int num_references; +}; +typedef struct ImageInfo ImageInfo; + +static ImageInfo **ImageList = NULL; +static struct ArtworkConfigInfo *image_config = NULL; +static int num_images = 0; + +void InitImageList(struct ArtworkConfigInfo *config_list, int num_list_entries) +{ + if (ImageList == NULL) + ImageList = checked_calloc(num_list_entries * sizeof(ImageInfo *)); + + image_config = config_list; + num_images = num_list_entries; +}