/* !!! TEST ONLY !!! */
-
-#if 1
-
{
Bitmap *tst_bitmap = graphic_info[IMG_SAND].bitmap;
Bitmap *tmp_bitmap = ZoomBitmap(tst_bitmap,
FreeBitmap(tmp_bitmap);
}
-
-#else
-#ifdef TARGET_SDL
-
- {
- Bitmap tmp_bitmap;
- SDL_Surface *dst = SDLZoomSurface(graphic_info[IMG_SAND].bitmap->surface,
- 0.5, 0.5);
- tmp_bitmap.surface = dst;
-
- BlitBitmap(&tmp_bitmap, graphic_info[IMG_SAND].bitmap,
- 0, 0, 256, 224, 0, 448);
-
- SDL_FreeSurface(dst);
- }
-
-#elif defined(PLATFORM_MSDOS)
-
- stretch_blit((BITMAP *)(graphic_info[IMG_SAND].bitmap->drawable),
- (BITMAP *)(graphic_info[IMG_SAND].bitmap->drawable),
- 0, 0, 512, 448,
- 0, 448, 256, 224);
-
-#endif
-#endif
}
static void ReinitializeSounds()
display_bits_per_pixel = bitsPerPixelAtDepth(display, screen, depth);
display_bytes_per_pixel = (display_bits_per_pixel + 7) / 8;
- ximage = XCreateImage(display, visual, depth, ZPixmap, 0,
- NULL, image->width, image->height,
+ ximage = XCreateImage(display, visual, depth, ZPixmap,
+ 0, NULL, image->width, image->height,
8, image->width * display_bytes_per_pixel);
ximage->data =
checked_malloc(image->width * image->height * display_bytes_per_pixel);
return ximageinfo;
}
+/*
+ -----------------------------------------------------------------------------
+ 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!
+ -----------------------------------------------------------------------------
+*/
+
+void ZoomPixmap(Display *display, GC gc, Pixmap src_pixmap, Pixmap dst_pixmap,
+ int src_width, int src_height,
+ int dst_width, int dst_height)
+{
+ XImage *src_ximage, *dst_ximage;
+ byte *src_ptr, *dst_ptr;
+ int bits_per_pixel;
+ int bytes_per_pixel;
+ int x, y, i;
+ int zoom_factor = src_width / dst_width; /* currently very limited! */
+ int row_skip, col_skip;
+
+ /* copy source pixmap to temporary image */
+ src_ximage = XGetImage(display, src_pixmap, 0, 0,
+ src_width, src_height, AllPlanes, ZPixmap);
+
+ bits_per_pixel = src_ximage->bits_per_pixel;
+ bytes_per_pixel = (bits_per_pixel + 7) / 8;
+
+ dst_ximage = XCreateImage(display, visual, src_ximage->depth, ZPixmap,
+ 0, NULL, dst_width, dst_height,
+ 8, dst_width * bytes_per_pixel);
+ dst_ximage->data =
+ checked_malloc(dst_width * dst_height * bytes_per_pixel);
+ dst_ximage->byte_order = src_ximage->byte_order;
+
+ 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;
+
+ /* 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++;
+
+ /* copy scaled image to destination pixmap */
+ XPutImage(display, dst_pixmap, gc, dst_ximage, 0, 0, 0, 0,
+ MIN(src_width, dst_width), MIN(src_height, dst_height));
+
+ /* free temporary images */
+ XDestroyImage(src_ximage);
+ XDestroyImage(dst_ximage);
+}
+
void freeXImage(Image *image, XImageInfo *ximageinfo)
{
if (ximageinfo->index != NULL && ximageinfo->no > 0)
return new_window;
}
-inline void X11NativeZoomBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap)
-{
-}
-
void X11ZoomBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap)
{
#if defined(TARGET_ALLEGRO)
src_bitmap->width, src_bitmap->height,
dst_bitmap->width, dst_bitmap->height);
#else
- X11NativeZoomBitmap(src_bitmap, dst_bitmap);
+ ZoomPixmap(display, src_bitmap->gc,
+ src_bitmap->drawable, dst_bitmap->drawable,
+ src_bitmap->width, src_bitmap->height,
+ dst_bitmap->width, dst_bitmap->height);
#endif
}