From: Holger Schemel Date: Mon, 16 Aug 2004 01:11:24 +0000 (+0200) Subject: rnd-20040816-2-src X-Git-Tag: 3.1.1^2~81 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=391f8c019bdd5591015f8f310d97cf077de93fa2;p=rocksndiamonds.git rnd-20040816-2-src * fixed big memory leak in function "CreateBitmapWithSmallBitmaps()" (which creates scaled down graphics for level editor and preview); there's still a memory leak somewhere in the artwork handling code * added "scale image up" functionality to X11 version of zoom function --- diff --git a/ChangeLog b/ChangeLog index 8abe1ff2..eebef01e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-08-16 + * fixed big memory leak in function "CreateBitmapWithSmallBitmaps()" + (which creates scaled down graphics for level editor and preview); + there's still a memory leak somewhere in the artwork handling code + * added "scale image up" functionality to X11 version of zoom function + 2004-08-07 * fixed bug in gadget code which caused reset of CEs in level editor (example: pressing 'b' [grab brush] on CE config page erased values) diff --git a/src/conftime.h b/src/conftime.h index d022fcf1..9883f12c 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2004-08-16 00:11]" +#define COMPILE_DATE_STRING "[2004-08-16 03:09]" diff --git a/src/libem/cave.c b/src/libem/cave.c index 25de9a57..60478c28 100644 --- a/src/libem/cave.c +++ b/src/libem/cave.c @@ -1,3 +1,6 @@ + +#if defined(TARGET_X11) + /* 2000-08-10T16:43:50Z * * cave data structures @@ -147,3 +150,5 @@ void free_cave_list(void) } cave_list = 0; } + +#endif diff --git a/src/libem/convert.c b/src/libem/convert.c index fdd58537..18f52e18 100644 --- a/src/libem/convert.c +++ b/src/libem/convert.c @@ -1,3 +1,6 @@ + +#if defined(TARGET_X11) + /* 2000-08-20T09:41:18Z * * identify all emerald mine caves and turn them into v6 format. @@ -391,3 +394,5 @@ void convert_emerald(unsigned char *src) for(y = 0; y < HEIGHT; y++) for(x = 0; x < WIDTH; x++) Next[y][x] = Cave[y][x]; for(y = 0; y < HEIGHT; y++) for(x = 0; x < WIDTH; x++) Draw[y][x] = Cave[y][x]; } + +#endif diff --git a/src/libem/graphics.c b/src/libem/graphics.c index fb667b6e..6b640db1 100644 --- a/src/libem/graphics.c +++ b/src/libem/graphics.c @@ -1,3 +1,6 @@ + +#if defined(TARGET_X11) + /* 2000-08-13T14:36:17Z * * graphics manipulation crap @@ -393,3 +396,5 @@ void title_string(unsigned int y, unsigned int left, unsigned int right, char *s } XSetClipMask(display, screenGC, None); } + +#endif diff --git a/src/libem/init.c b/src/libem/init.c index 33012f9c..72283c7e 100644 --- a/src/libem/init.c +++ b/src/libem/init.c @@ -1,3 +1,6 @@ + +#if defined(TARGET_X11) + /* 2000-08-10T18:03:54Z * * open X11 display and sound @@ -117,6 +120,7 @@ static int gotWhite; #if 1 static Bitmap *pcxBitmaps[4]; +static Bitmap *pcxBitmapsX2[4]; #endif #if 0 @@ -341,6 +345,27 @@ int open_all(void) ttlmaskBitmap = pcxBitmaps[3]->clip_mask; #endif +#if 0 + for (i = 0; i < 4; i++) + pcxBitmapsX2[i] = ZoomBitmap(pcxBitmaps[i], + pcxBitmaps[i]->width * 2, + pcxBitmaps[i]->height * 2); + + objBitmap = pcxBitmapsX2[0]; + botBitmap = pcxBitmapsX2[1]; + sprBitmap = pcxBitmapsX2[2]; + ttlBitmap = pcxBitmapsX2[3]; + + objPixmap = pcxBitmapsX2[0]->drawable; + botPixmap = pcxBitmapsX2[1]->drawable; + sprPixmap = pcxBitmapsX2[2]->drawable; + ttlPixmap = pcxBitmapsX2[3]->drawable; + objmaskBitmap = pcxBitmapsX2[0]->clip_mask; + botmaskBitmap = pcxBitmapsX2[1]->clip_mask; + sprmaskBitmap = pcxBitmapsX2[2]->clip_mask; + ttlmaskBitmap = pcxBitmapsX2[3]->clip_mask; +#endif + #if 1 screenBitmap = CreateBitmap(22 * TILEX, 14 * TILEY, DEFAULT_DEPTH); scoreBitmap = CreateBitmap(20 * TILEX, SCOREY, DEFAULT_DEPTH); @@ -577,3 +602,5 @@ static int xpmFreeColoursFunc(Display *display, Colormap colourmap, unsigned lon if(colourmap != privateColourmap) XFreeColors(display, colourmap, pixels, npixels, 0); return(1); /* non-zero for success */ } + +#endif diff --git a/src/libem/input.c b/src/libem/input.c index 3ccf6a4f..2aafb665 100644 --- a/src/libem/input.c +++ b/src/libem/input.c @@ -1,3 +1,6 @@ + +#if defined(TARGET_X11) + /* 2000-08-13T15:29:40Z * * handle input from x11 and keyboard and joystick @@ -323,3 +326,5 @@ void input_eventloop(void) input_esc = 0; for(i = 0; i < 1; i++) if(keymatrix[escKeyCode[i] >> 3] & 1 << (escKeyCode[i] & 7)) input_esc = 1; } + +#endif diff --git a/src/libem/main.c b/src/libem/main.c index ca79044c..71376b28 100644 --- a/src/libem/main.c +++ b/src/libem/main.c @@ -1,3 +1,6 @@ + +#if defined(TARGET_X11) + /* Emerald Mine * * David Tritscher @@ -99,3 +102,13 @@ void snprintf_overflow(char *description) fprintf(stderr, "%s %s\n", "Fault occured while attempting to", description); abort(); } + +#else + +int em_main() +{ + /* temporary dummy until X11->SDL conversion finished */ + return 0; +} + +#endif diff --git a/src/libem/sound.c b/src/libem/sound.c index 57fec5a1..4f89139e 100644 --- a/src/libem/sound.c +++ b/src/libem/sound.c @@ -1,3 +1,6 @@ + +#if defined(TARGET_X11) + /* 2000-08-10T17:39:15Z * * handle sounds in emerald mine @@ -335,3 +338,5 @@ fail: } #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */ + +#endif diff --git a/src/libem/synchro_1.c b/src/libem/synchro_1.c index 8b2f47f8..9f4309c5 100644 --- a/src/libem/synchro_1.c +++ b/src/libem/synchro_1.c @@ -1,4 +1,6 @@ +#if defined(TARGET_X11) + /* first part of synchro. * * game logic for players. @@ -792,3 +794,5 @@ static void player(struct PLAYER *ply) } } } + +#endif diff --git a/src/libem/synchro_2.c b/src/libem/synchro_2.c index 731e9faa..8dc78463 100644 --- a/src/libem/synchro_2.c +++ b/src/libem/synchro_2.c @@ -1,4 +1,6 @@ +#if defined(TARGET_X11) + /* second part of synchro. * * game logic for monsters. @@ -3811,3 +3813,5 @@ done: void *temp = Cave; Cave = Next; Next = Draw; Draw = temp; /* triple buffering */ } } + +#endif diff --git a/src/libem/synchro_3.c b/src/libem/synchro_3.c index 1d85e6bb..e0b86f97 100644 --- a/src/libem/synchro_3.c +++ b/src/libem/synchro_3.c @@ -1,4 +1,6 @@ +#if defined(TARGET_X11) + /* third part of synchro. * * handle global elements. @@ -86,3 +88,5 @@ void synchro_3(void) Next[y][x] = Cave[y][x]; } } + +#endif diff --git a/src/libem/tab_generate.c b/src/libem/tab_generate.c index d11cc77a..22ffef4c 100644 --- a/src/libem/tab_generate.c +++ b/src/libem/tab_generate.c @@ -1,3 +1,6 @@ + +#if defined(TARGET_X11) + /* 2000-04-19T13:26:05Z * * construct some tables to be included directly in emerald mine source. @@ -4678,3 +4681,5 @@ void tab_generate() create_spr(); create_ttl(); } + +#endif diff --git a/src/libem/ulaw_generate.c b/src/libem/ulaw_generate.c index b877b76d..5a8453c9 100644 --- a/src/libem/ulaw_generate.c +++ b/src/libem/ulaw_generate.c @@ -1,3 +1,6 @@ + +#if defined(TARGET_X11) + /* 2000-08-10T04:29:10Z * * generate ulaw<->linear conversion tables to be included @@ -174,3 +177,5 @@ unsigned char calc_linear_to_ulaw(int sample) } #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */ + +#endif diff --git a/src/libgame/image.c b/src/libgame/image.c index 977111f4..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, diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index e9d10df5..1bc222a9 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -1116,9 +1116,8 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst) ----------------------------------------------------------------------------- zoomSurface() - Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. + Zooms a 32bit or 8bit 'src' surface to newly created 'dst' surface. 'zoomx' and 'zoomy' are scaling factors for width and height. - If 'smooth' is 1 then the destination 32bit surface is anti-aliased. If the surface is not 8bit or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. ----------------------------------------------------------------------------- diff --git a/src/libgame/system.c b/src/libgame/system.c index 8f26dc77..93d251e9 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -814,6 +814,7 @@ Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height) void CreateBitmapWithSmallBitmaps(Bitmap *src_bitmap) { + Bitmap swap_bitmap; Bitmap *tmp_bitmap, *tmp_bitmap_2, *tmp_bitmap_8; int src_width, src_height; int tmp_width, tmp_height; @@ -838,6 +839,8 @@ void CreateBitmapWithSmallBitmaps(Bitmap *src_bitmap) FreeBitmap(tmp_bitmap_2); FreeBitmap(tmp_bitmap_8); +#if 0 + #if defined(TARGET_SDL) /* !!! what about the old src_bitmap->surface ??? FIX ME !!! */ src_bitmap->surface = tmp_bitmap->surface; @@ -846,6 +849,20 @@ void CreateBitmapWithSmallBitmaps(Bitmap *src_bitmap) /* !!! see above !!! */ src_bitmap->drawable = tmp_bitmap->drawable; tmp_bitmap->drawable = None; +#endif + +#else + +#if defined(TARGET_SDL) + swap_bitmap.surface = src_bitmap->surface; + src_bitmap->surface = tmp_bitmap->surface; + tmp_bitmap->surface = swap_bitmap.surface; +#else + swap_bitmap.drawable = src_bitmap->drawable; + src_bitmap->drawable = tmp_bitmap->drawable; + tmp_bitmap->drawable = swap_bitmap.drawable; +#endif + #endif src_bitmap->height = tmp_bitmap->height;