Gfxlib cleanup: move stretch_frame() out of SDL domain and rename to RescaleFrame()

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3470 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-12-25 08:47:06 +00:00
parent 98b3cc75c5
commit 23c2ca27e7
4 changed files with 48 additions and 30 deletions
+2
View File
@@ -352,6 +352,8 @@ extern FRAME SetEquFrameIndex (FRAME DstFrame, FRAME SrcFrame);
extern FRAME IncFrameIndex (FRAME Frame); extern FRAME IncFrameIndex (FRAME Frame);
extern FRAME DecFrameIndex (FRAME Frame); extern FRAME DecFrameIndex (FRAME Frame);
extern DRAWABLE RotateFrame (FRAME Frame, int angle_deg); extern DRAWABLE RotateFrame (FRAME Frame, int angle_deg);
extern DRAWABLE RescaleFrame (FRAME, int width, int height);
extern void SetFrameTransparentColor (FRAME, Color); extern void SetFrameTransparentColor (FRAME, Color);
// If the frame is an active SCREEN_DRAWABLE, this call must be // If the frame is an active SCREEN_DRAWABLE, this call must be
+42
View File
@@ -296,3 +296,45 @@ GetFramePixel (FRAME frame, POINT pixelPt)
pixelPt.x, pixelPt.y); pixelPt.x, pixelPt.y);
} }
// Creates a new DRAWABLE of specified size and scales the passed
// frame onto it. The aspect ratio is not preserved.
DRAWABLE
RescaleFrame (FRAME frame, int width, int height)
{
DRAWABLE drawable;
FRAME newFrame;
CREATE_FLAGS flags;
TFB_Image *img;
TFB_Canvas src, dst;
if (!frame)
return NULL;
flags = GetFrameParentDrawable (frame)->Flags;
drawable = CreateDrawable (flags, width, height, 1);
if (!drawable)
return NULL;
newFrame = CaptureDrawable (drawable);
if (!newFrame)
{
FreeDrawable (drawable);
return NULL;
}
// scale the hot-spot
newFrame->HotSpot.x = frame->HotSpot.x * width / frame->Bounds.width;
newFrame->HotSpot.y = frame->HotSpot.y * height / frame->Bounds.height;
img = frame->image;
LockMutex (img->mutex);
src = img->NormalImg;
dst = newFrame->image->NormalImg;
TFB_DrawCanvas_Rescale_Nearest (src, dst, -1, NULL, NULL, NULL);
UnlockMutex (img->mutex);
ReleaseDrawable (newFrame);
return drawable;
}
-25
View File
@@ -25,31 +25,6 @@
#include "primitives.h" #include "primitives.h"
// stretch_frame
// create a new frame of size neww x newh, and blit a scaled version FramePtr
// into it.
// destroy the old frame if 'destroy' is 1
FRAME stretch_frame (FRAME FramePtr, int neww, int newh, int destroy)
{
FRAME NewFrame;
CREATE_FLAGS flags;
TFB_Image *tfbImg;
TFB_Canvas src, dst;
flags = GetFrameParentDrawable (FramePtr)->Flags;
NewFrame = CaptureDrawable (
CreateDrawable (flags, (SIZE)neww, (SIZE)newh, 1));
tfbImg = FramePtr->image;
LockMutex (tfbImg->mutex);
src = tfbImg->NormalImg;
dst = NewFrame->image->NormalImg;
TFB_DrawCanvas_Rescale_Nearest (src, dst, -1, NULL, NULL, NULL);
UnlockMutex (tfbImg->mutex);
if (destroy)
DestroyDrawable (ReleaseDrawable (FramePtr));
return (NewFrame);
}
void process_rgb_bmp (FRAME FramePtr, Uint32 *rgba, int maxx, int maxy) void process_rgb_bmp (FRAME FramePtr, Uint32 *rgba, int maxx, int maxy)
{ {
int x, y; int x, y;
+4 -5
View File
@@ -42,7 +42,6 @@
extern DWORD frame_mapRGBA (FRAME FramePtr, UBYTE r, UBYTE g, extern DWORD frame_mapRGBA (FRAME FramePtr, UBYTE r, UBYTE g,
UBYTE b, UBYTE a); UBYTE b, UBYTE a);
extern void process_rgb_bmp (FRAME FramePtr, DWORD *rgba, int maxx, int maxy); extern void process_rgb_bmp (FRAME FramePtr, DWORD *rgba, int maxx, int maxy);
extern FRAME stretch_frame (FRAME FramePtr, int neww, int newh, int destroy);
extern void fill_frame_rgb (FRAME FramePtr, DWORD color, int x0, int y0, extern void fill_frame_rgb (FRAME FramePtr, DWORD color, int x0, int y0,
int x, int y); int x, int y);
extern void arith_frame_blit (FRAME srcFrame, const RECT *rsrc, extern void arith_frame_blit (FRAME srcFrame, const RECT *rsrc,
@@ -1752,8 +1751,8 @@ GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, FRAME SurfDefFrame)
if (GetFrameWidth (SurfDefFrame) != MAP_WIDTH if (GetFrameWidth (SurfDefFrame) != MAP_WIDTH
|| GetFrameHeight (SurfDefFrame) != MAP_HEIGHT) || GetFrameHeight (SurfDefFrame) != MAP_HEIGHT)
{ {
pSolarSysState->TopoFrame = stretch_frame (SurfDefFrame, pSolarSysState->TopoFrame = CaptureDrawable (RescaleFrame (
MAP_WIDTH, MAP_HEIGHT, 0); SurfDefFrame, MAP_WIDTH, MAP_HEIGHT));
// will not need the passed FRAME anymore // will not need the passed FRAME anymore
DeleteDef = TRUE; DeleteDef = TRUE;
} }
@@ -1769,8 +1768,8 @@ GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, FRAME SurfDefFrame)
if (GetFrameWidth (ElevFrame) != MAP_WIDTH if (GetFrameWidth (ElevFrame) != MAP_WIDTH
|| GetFrameHeight (ElevFrame) != MAP_HEIGHT) || GetFrameHeight (ElevFrame) != MAP_HEIGHT)
{ {
ElevFrame = stretch_frame (ElevFrame, MAP_WIDTH, ElevFrame = CaptureDrawable (RescaleFrame (ElevFrame,
MAP_HEIGHT, 0); MAP_WIDTH, MAP_HEIGHT));
} }
// grab the elevation data in 1 byte per pixel format // grab the elevation data in 1 byte per pixel format