diff --git a/sc2/src/sc2code/libs/graphics/sdl/canvas.c b/sc2/src/sc2code/libs/graphics/sdl/canvas.c index 04273f184..5e7f9bb0b 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/canvas.c +++ b/sc2/src/sc2code/libs/graphics/sdl/canvas.c @@ -162,14 +162,12 @@ TFB_DrawCanvas_New_Paletted (int w, int h, TFB_Palette *palette, int transparent return new_surf; } -#define TFB_SCALETARGET_FACTOR 4 - TFB_Canvas TFB_DrawCanvas_New_ScaleTarget (TFB_Canvas canvas) { SDL_Surface *src = (SDL_Surface *)canvas; - SDL_Surface *newsurf = SDL_CreateRGBSurface (SDL_SWSURFACE, src->w * TFB_SCALETARGET_FACTOR, - src->h * TFB_SCALETARGET_FACTOR, + SDL_Surface *newsurf = SDL_CreateRGBSurface (SDL_SWSURFACE, src->w, + src->h, src->format->BitsPerPixel, src->format->Rmask, src->format->Gmask, @@ -290,6 +288,12 @@ TFB_DrawCanvas_Rescale (TFB_Canvas src_canvas, TFB_Canvas dest_canvas, EXTENT si fprintf (stderr, "TFB_DrawCanvas_Scale: Tried to zoom an image to be larger than the screen! Failing.\n"); return; } + if (size.width > dst->w || size.height > dst->h) + { + fprintf (stderr, "TFB_DrawCanvas_Scale: Tried to scale image to size %d %d when dest_canvas has only dimensions of %d %d! Failing.\n", + size.width, size.height, dst->w, dst->h); + return; + } sx = (int) (65536.0 * (float) src->w / (float) size.width); sy = (int) (65536.0 * (float) src->h / (float) size.height); diff --git a/sc2/src/sc2code/libs/graphics/tfb_draw.c b/sc2/src/sc2code/libs/graphics/tfb_draw.c index 9d872c6a5..90f2643cc 100644 --- a/sc2/src/sc2code/libs/graphics/tfb_draw.c +++ b/sc2/src/sc2code/libs/graphics/tfb_draw.c @@ -263,7 +263,7 @@ TFB_DrawImage_New (TFB_Canvas canvas) img->NormalImg = TFB_DrawCanvas_ToScreenFormat (canvas); } - img->ScaledImg = TFB_DrawCanvas_New_ScaleTarget (img->NormalImg); + img->ScaledImg = NULL; return img; } @@ -303,6 +303,8 @@ TFB_DrawImage_FixScaling (TFB_Image *image, int target) if ((old.width != image->extent.width) || (old.height != image->extent.height) || image->dirty) { image->dirty = FALSE; + if (!image->ScaledImg) + image->ScaledImg = TFB_DrawCanvas_New_ScaleTarget (image->NormalImg); TFB_DrawCanvas_Rescale (image->NormalImg, image->ScaledImg, image->extent); } /*