X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fimage.c;h=42c3384a0cd6c8f518b97138750a370de561134c;hb=391f8c019bdd5591015f8f310d97cf077de93fa2;hp=108fd39c3fc4d80033e2748b64170bc1ee5f88a1;hpb=1c636a51bb573815d24a27dcc20b3283d89d1b8b;p=rocksndiamonds.git diff --git a/src/libgame/image.c b/src/libgame/image.c index 108fd39c..42c3384a 100644 --- a/src/libgame/image.c +++ b/src/libgame/image.c @@ -569,8 +569,8 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, ----------------------------------------------------------------------------- ZoomPixmap - Important note: The scaling code currently only supports scaling down the - image by a power of 2 -- scaling up is currently not supported at all! + Important note: The scaling code currently only supports scaling of the image + up or down by a power of 2 -- other scaling factors currently not supported! ----------------------------------------------------------------------------- */ @@ -582,13 +582,29 @@ void ZoomPixmap(Display *display, GC gc, Pixmap src_pixmap, Pixmap dst_pixmap, byte *src_ptr, *dst_ptr; int bits_per_pixel; int bytes_per_pixel; - int x, y, i; + int x, y, xx, yy, i; +#if 1 + boolean scale_down = (src_width > dst_width); + int zoom_factor; +#else int zoom_factor = src_width / dst_width; /* currently very limited! */ +#endif int row_skip, col_skip; - /* adjust source image size to integer multiple of destination image size */ - src_width = dst_width * zoom_factor; - src_height = dst_height * zoom_factor; + if (scale_down) + { + zoom_factor = src_width / dst_width; + + /* adjust source image size to integer multiple of destination size */ + src_width = dst_width * zoom_factor; + src_height = dst_height * zoom_factor; + } + else + { + zoom_factor = dst_width / src_width; + + /* no adjustment needed when scaling up (some pixels may be left blank) */ + } /* copy source pixmap to temporary image */ src_ximage = XGetImage(display, src_pixmap, 0, 0, src_width, src_height, @@ -607,14 +623,40 @@ void ZoomPixmap(Display *display, GC gc, Pixmap src_pixmap, Pixmap dst_pixmap, src_ptr = (byte *)src_ximage->data; dst_ptr = (byte *)dst_ximage->data; - col_skip = (zoom_factor - 1) * bytes_per_pixel; - row_skip = col_skip * src_width; + if (scale_down) + { + col_skip = (zoom_factor - 1) * bytes_per_pixel; + row_skip = col_skip * src_width; + + /* scale image down by scaling factor 'zoom_factor' */ + for (y = 0; y < src_height; y += zoom_factor, src_ptr += row_skip) + for (x = 0; x < src_width; x += zoom_factor, src_ptr += col_skip) + for (i = 0; i < bytes_per_pixel; i++) + *dst_ptr++ = *src_ptr++; + } + else + { + row_skip = src_width * bytes_per_pixel; + + /* scale image up by scaling factor 'zoom_factor' */ + for (y = 0; y < src_height; y++) + { + for (yy = 0; yy < zoom_factor; yy++) + { + if (yy > 0) + src_ptr -= row_skip; + + for (x = 0; x < src_width; x++) + { + for (xx = 0; xx < zoom_factor; xx++) + for (i = 0; i < bytes_per_pixel; i++) + *dst_ptr++ = *(src_ptr + i); - /* scale image down by scaling factor 'zoom_factor' */ - for (y = 0; y < src_height; y += zoom_factor, src_ptr += row_skip) - for (x = 0; x < src_width; x += zoom_factor, src_ptr += col_skip) - for (i = 0; i < bytes_per_pixel; i++) - *dst_ptr++ = *src_ptr++; + src_ptr += i; + } + } + } + } /* copy scaled image to destination pixmap */ XPutImage(display, dst_pixmap, gc, dst_ximage, 0, 0, 0, 0, @@ -845,7 +887,7 @@ struct PropertyMapping *getImageListPropertyMapping() } void InitImageList(struct ConfigInfo *config_list, int num_file_list_entries, - struct ConfigInfo *config_suffix_list, + struct ConfigTypeInfo *config_suffix_list, char **base_prefixes, char **ext1_suffixes, char **ext2_suffixes, char **ext3_suffixes, char **ignore_tokens)