rnd-20001130-1-src
[rocksndiamonds.git] / src / image.c
index 3cc85e34fc057f1a3eed88490c7015e42ead41c5..9dd4c249ec18004925481adf135f5e78e43cbc45 100644 (file)
 *  image.c                                                 *
 ***********************************************************/
 
+#if defined(TARGET_X11)
+
 #include "image.h"
+#include "pcx.h"
 #include "misc.h"
 
+/* for MS-DOS/Allegro, exclude all except newImage() and freeImage() */
+
+Image *newImage(unsigned int width, unsigned int height, unsigned int depth)
+{
+  Image *image;
+  const unsigned int bytes_per_pixel = 1;
+  int i;
+
+  if (depth > 8)
+    Error(ERR_EXIT, "images with more than 256 colors are not supported");
+
+  depth = 8;
+  image = checked_malloc(sizeof(Image));
+  image->data = checked_malloc(width * height * bytes_per_pixel);
+  image->width = width;
+  image->height = height;
+  image->depth = depth;
+  image->rgb.used = 0;
+  for (i=0; i<MAX_COLORS; i++)
+    image->rgb.color_used[i] = FALSE;
+
+  return image;
+}
+
+void freeImage(Image *image)
+{
+  free(image->data);
+  free(image);
+}
+
+#if defined(PLATFORM_UNIX)
+
 /* extra colors to try allocating in private color maps to minimize flashing */
 #define NOFLASH_COLORS 256
 
 
 static Pixmap Image_to_Mask(Image *image, Display *display, Window window)
 {
-  unsigned char *src_ptr, *dst_ptr, *dst_ptr2;
+  byte *src_ptr, *dst_ptr, *dst_ptr2;
   unsigned int bytes_per_row;
   unsigned int x, y;
-  unsigned char bitmask;
+  byte bitmask;
   byte *mask_data;
   Pixmap mask_pixmap;
 
@@ -72,7 +107,7 @@ static Pixmap Image_to_Mask(Image *image, Display *display, Window window)
     dst_ptr += bytes_per_row;  /* continue with leftmost byte of next row */
   }
 
-  mask_pixmap = XCreateBitmapFromData(display, window, mask_data,
+  mask_pixmap = XCreateBitmapFromData(display, window, (char *)mask_data,
                                      image->width, image->height);
   free(mask_data);
 
@@ -371,7 +406,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual,
   ximage->byte_order = MSBFirst;
 
   src_ptr = image->data;
-  dst_ptr = ximage->data;
+  dst_ptr = (byte *)ximage->data;
 
   switch (visual->class)
   {
@@ -463,36 +498,8 @@ void freeXImage(Image *image, XImageInfo *ximageinfo)
   free(ximageinfo);
 }
 
-Image *newImage(unsigned int width, unsigned int height, unsigned int depth)
-{
-  Image *image;
-  const unsigned int bytes_per_pixel = 1;
-  int i;
-
-  if (depth > 8)
-    Error(ERR_EXIT, "images with more than 256 colors are not supported");
-
-  depth = 8;
-  image = checked_malloc(sizeof(Image));
-  image->data = checked_malloc(width * height * bytes_per_pixel);
-  image->width = width;
-  image->height = height;
-  image->depth = depth;
-  image->rgb.used = 0;
-  for (i=0; i<MAX_COLORS; i++)
-    image->rgb.color_used[i] = FALSE;
-
-  return image;
-}
-
-void freeImage(Image *image)
-{
-  free(image->data);
-  free(image);
-}
-
-int Read_PCX_to_Pixmaps(Display *display, Window window, GC gc, char *filename,
-                       Pixmap *pixmap, Pixmap *pixmap_mask)
+int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename,
+                      Pixmap *pixmap, Pixmap *pixmap_mask)
 {
   Image *image;
   XImageInfo *ximageinfo;
@@ -506,7 +513,7 @@ int Read_PCX_to_Pixmaps(Display *display, Window window, GC gc, char *filename,
 
   /* read the graphic file in PCX format to image structure */
   if ((image = Read_PCX_to_Image(filename)) == NULL)
-    return PCX_FileInvalid;
+    return errno_pcx;
 
 #if DEBUG_TIMING
   printf("%s:\n", filename);
@@ -540,5 +547,8 @@ int Read_PCX_to_Pixmaps(Display *display, Window window, GC gc, char *filename,
   *pixmap = ximageinfo->pixmap;
   *pixmap_mask = ximageinfo->pixmap_mask;
 
-  return(PCX_Success);
+  return PCX_Success;
 }
+
+#endif /* PLATFORM_UNIX */
+#endif /* TARGET_X11 */