rnd-20131212-1-src
[rocksndiamonds.git] / src / libgame / image.c
index cb8de4c87ed46ab8397a46f8f6a852843cb3344b..50dce1d713b0df9c49b12be304610cf013adecdb 100644 (file)
@@ -1,7 +1,7 @@
 /***********************************************************
 * Artsoft Retro-Game Library                               *
 *----------------------------------------------------------*
-* (c) 1994-2002 Artsoft Entertainment                      *
+* (c) 1994-2006 Artsoft Entertainment                      *
 *               Holger Schemel                             *
 *               Detmolder Strasse 189                      *
 *               33604 Bielefeld                            *
@@ -64,28 +64,28 @@ void freeImage(Image *image)
    note: the internal format is big endian */
 
 #define memory_to_value(ptr, len) (                                        \
-(len) == 1 ? (unsigned long)(                 *( (byte *)(ptr))         ) : \
-(len) == 2 ? (unsigned long)(((unsigned long)(*( (byte *)(ptr))   ))<< 8)   \
-                         + (                 *(((byte *)(ptr))+1)      ) : \
-(len) == 3 ? (unsigned long)(((unsigned long)(*( (byte *)(ptr))   ))<<16)   \
-                         + (((unsigned long)(*(((byte *)(ptr))+1)))<< 8)   \
-                         + (                 *(((byte *)(ptr))+2)      ) : \
-            (unsigned long)(((unsigned long)(*( (byte *)(ptr))   ))<<24)   \
-                         + (((unsigned long)(*(((byte *)(ptr))+1)))<<16)   \
-                         + (((unsigned long)(*(((byte *)(ptr))+2)))<< 8)   \
-                         + (                 *(((byte *)(ptr))+3)      ) )
+(len) == 1 ? (unsigned int)(                *( (byte *)(ptr))         ) : \
+(len) == 2 ? (unsigned int)(((unsigned int)(*( (byte *)(ptr))   ))<< 8)   \
+                        + (                *(((byte *)(ptr))+1)      ) : \
+(len) == 3 ? (unsigned int)(((unsigned int)(*( (byte *)(ptr))   ))<<16)   \
+                        + (((unsigned int)(*(((byte *)(ptr))+1)))<< 8)   \
+                        + (                *(((byte *)(ptr))+2)      ) : \
+            (unsigned int)(((unsigned int)(*( (byte *)(ptr))   ))<<24)   \
+                        + (((unsigned int)(*(((byte *)(ptr))+1)))<<16)   \
+                        + (((unsigned int)(*(((byte *)(ptr))+2)))<< 8)   \
+                        + (                *(((byte *)(ptr))+3)      ) )
 
 
 #define value_to_memory(value, ptr, len) (                             \
 (len) == 1 ? (*( (byte *)(ptr)   ) = ( value     ) ) :                 \
-(len) == 2 ? (*( (byte *)(ptr)   ) = (((unsigned long)(value))>> 8),   \
+(len) == 2 ? (*( (byte *)(ptr)   ) = (((unsigned int)(value))>> 8),    \
              *(((byte *)(ptr))+1) = ( value     ) ) :                  \
-(len) == 3 ? (*( (byte *)(ptr)   ) = (((unsigned long)(value))>>16),   \
-             *(((byte *)(ptr))+1) = (((unsigned long)(value))>> 8),    \
+(len) == 3 ? (*( (byte *)(ptr)   ) = (((unsigned int)(value))>>16),    \
+             *(((byte *)(ptr))+1) = (((unsigned int)(value))>> 8),     \
              *(((byte *)(ptr))+2) = ( value     ) ) :                  \
-             (*( (byte *)(ptr)   ) = (((unsigned long)(value))>>24),   \
-             *(((byte *)(ptr))+1) = (((unsigned long)(value))>>16),    \
-             *(((byte *)(ptr))+2) = (((unsigned long)(value))>> 8),    \
+             (*( (byte *)(ptr)   ) = (((unsigned int)(value))>>24),    \
+             *(((byte *)(ptr))+1) = (((unsigned int)(value))>>16),     \
+             *(((byte *)(ptr))+2) = (((unsigned int)(value))>> 8),     \
              *(((byte *)(ptr))+3) = ( value     ) ))
 
 static Pixmap Image_to_Mask(Image *image, Display *display, Window window)
@@ -385,7 +385,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual,
          if (!private_cmap)
          {
            if (options.verbose)
-             Error(ERR_RETURN, "switching to private colormap");
+             Error(ERR_INFO, "switching to private colormap");
 
            /* we just filled up the default colormap -- get a private one
               which contains all already allocated colors */
@@ -486,7 +486,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual,
       break;
   
     default:
-      Error(ERR_RETURN,"DirectColor, TrueColor or PseudoColor display needed");
+      Error(ERR_INFO,"DirectColor, TrueColor or PseudoColor display needed");
       SetError(error, "display class not supported");
 
       return NULL;
@@ -560,7 +560,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual,
        }
 
         default:
-         Error(ERR_RETURN, "RGB or TrueColor image needed");
+         Error(ERR_INFO, "RGB or TrueColor image needed");
          SetError(error, "image type not supported");
 
          return NULL;
@@ -594,7 +594,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual,
     }
 
     default:
-      Error(ERR_RETURN,"DirectColor, TrueColor or PseudoColor display needed");
+      Error(ERR_INFO,"DirectColor, TrueColor or PseudoColor display needed");
       SetError(error, "display class not supported");
 
       return NULL;
@@ -649,7 +649,11 @@ void ZoomPixmap(Display *display, GC gc, Pixmap src_pixmap, Pixmap dst_pixmap,
 
   if (scale_down)
   {
+#if 1
+    zoom_factor = MIN(src_width / dst_width, src_height / dst_height);
+#else
     zoom_factor = src_width / dst_width;
+#endif
 
     /* adjust source image size to integer multiple of destination size */
     src_width  = dst_width  * zoom_factor;
@@ -657,7 +661,11 @@ void ZoomPixmap(Display *display, GC gc, Pixmap src_pixmap, Pixmap dst_pixmap,
   }
   else
   {
+#if 1
+    zoom_factor = MIN(dst_width / src_width, dst_height / src_height);
+#else
     zoom_factor = dst_width / src_width;
+#endif
 
     /* no adjustment needed when scaling up (some pixels may be left blank) */
   }
@@ -824,7 +832,11 @@ typedef struct ImageInfo ImageInfo;
 
 static struct ArtworkListInfo *image_info = NULL;
 
+#if 1
+static void *Load_Image(char *filename)
+#else
 static void *Load_PCX(char *filename)
+#endif
 {
   ImageInfo *img_info;
 
@@ -1022,7 +1034,11 @@ void InitImageList(struct ConfigInfo *config_list, int num_file_list_entries,
 
   /* ---------- initialize artwork loading/freeing functions ---------- */
 
+#if 1
+  image_info->load_artwork = Load_Image;
+#else
   image_info->load_artwork = Load_PCX;
+#endif
   image_info->free_artwork = FreeImage;
 }
 
@@ -1032,8 +1048,15 @@ void ReloadCustomImages()
   printf("::: reloading images '%s' ...\n", artwork.gfx_current_identifier);
 #endif
 
+  print_timestamp_init("ReloadCustomImages");
+
   LoadArtworkConfig(image_info);
+  print_timestamp_time("LoadArtworkConfig");
+
   ReloadCustomArtworkList(image_info);
+  print_timestamp_time("ReloadCustomArtworkList");
+
+  print_timestamp_done("ReloadCustomImages");
 }
 
 void CreateImageWithSmallImages(int pos, int zoom_factor)