Image scaling wrt hotspot; re-added bilinear; minor gfx refactoring

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2827 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2007-08-01 03:25:08 +00:00
parent 2dcea171b5
commit 8669bbaf99
13 changed files with 604 additions and 291 deletions
+3
View File
@@ -1,4 +1,7 @@
Changes towards version 0.7: Changes towards version 0.7:
- Scaling images with respect to their hotspots: stabilizes compound
Melee objects; re-added bilinear Melee scaler; zooming planet uses
bilinear; fixes bug #685 - Alex
- Added --keepaspectratio to keep correct aspect ratio when using - Added --keepaspectratio to keep correct aspect ratio when using
custom resolutions in OpenGL mode - Mika custom resolutions in OpenGL mode - Mika
- Add /var/tmp as possible location for temporary files. Don't try - Add /var/tmp as possible location for temporary files. Don't try
+4
View File
@@ -19,6 +19,7 @@
#include "battle.h" #include "battle.h"
#include "controls.h" #include "controls.h"
#include "options.h"
#include "init.h" #include "init.h"
#include "intel.h" #include "intel.h"
#ifdef NETPLAY #ifdef NETPLAY
@@ -422,6 +423,9 @@ Battle (void)
battle_counter[0] = CountLinks (&race_q[0]); battle_counter[0] = CountLinks (&race_q[0]);
battle_counter[1] = CountLinks (&race_q[1]); battle_counter[1] = CountLinks (&race_q[1]);
if (optMeleeScale != TFB_SCALE_STEP)
SetGraphicScaleMode (optMeleeScale);
setupBattleInputOrder (); setupBattleInputOrder ();
#ifdef NETPLAY #ifdef NETPLAY
initBattleInputBuffers (); initBattleInputBuffers ();
+8 -4
View File
@@ -585,20 +585,23 @@ DoPresentation (void *pIS)
int cargs; int cargs;
int draw_what; int draw_what;
int index, x, y, scale, angle; int index, x, y, scale, angle;
int scale_mode;
char ImgName[16]; char ImgName[16];
int OldScale; int old_scale, old_mode;
STAMP s; STAMP s;
if (1 == sscanf (pStr, "%15s", ImgName) if (1 == sscanf (pStr, "%15s", ImgName)
&& strcmp (strupr (ImgName), "SIS") == 0) && strcmp (strupr (ImgName), "SIS") == 0)
{ {
draw_what = PRES_DRAW_SIS; draw_what = PRES_DRAW_SIS;
scale_mode = TFB_SCALE_NEAREST;
cargs = sscanf (pStr, "%*s %d %d %d %d", cargs = sscanf (pStr, "%*s %d %d %d %d",
&x, &y, &scale, &angle) + 1; &x, &y, &scale, &angle) + 1;
} }
else else
{ {
draw_what = PRES_DRAW_INDEX; draw_what = PRES_DRAW_INDEX;
scale_mode = TFB_SCALE_BILINEAR;
cargs = sscanf (pStr, "%d %d %d %d %d", cargs = sscanf (pStr, "%d %d %d %d %d",
&index, &x, &y, &scale, &angle); &index, &x, &y, &scale, &angle);
} }
@@ -646,11 +649,12 @@ DoPresentation (void *pIS)
s.origin.y = y; s.origin.y = y;
if (!pPIS->Batched) if (!pPIS->Batched)
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
OldScale = GetGraphicScale (); old_mode = SetGraphicScaleMode (scale_mode);
SetGraphicScale (scale); old_scale = SetGraphicScale (scale);
SetContextClipping (TRUE); SetContextClipping (TRUE);
DrawStamp (&s); DrawStamp (&s);
SetGraphicScale (OldScale); SetGraphicScale (old_scale);
SetGraphicScaleMode (old_mode);
if (!pPIS->Batched) if (!pPIS->Batched)
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
@@ -34,6 +34,9 @@ int ScreenColorDepth;
int GraphicsDriver; int GraphicsDriver;
int TFB_DEBUG_HALT = 0; int TFB_DEBUG_HALT = 0;
static int gscale = GSCALE_IDENTITY;
static int gscale_mode = TFB_SCALE_NEAREST;
// Status: Ignored (only used in fmv.c) // Status: Ignored (only used in fmv.c)
void void
SetGraphicUseOtherExtra (int other) //Could this possibly be more cryptic?!? :) SetGraphicUseOtherExtra (int other) //Could this possibly be more cryptic?!? :)
@@ -62,3 +65,31 @@ LoadIntoExtraScreen (RECT *r)
TFB_DrawScreen_Copy(r, TFB_SCREEN_MAIN, TFB_SCREEN_EXTRA); TFB_DrawScreen_Copy(r, TFB_SCREEN_MAIN, TFB_SCREEN_EXTRA);
} }
int
SetGraphicScale (int scale)
{
int old_scale = gscale;
gscale = (scale ? scale : GSCALE_IDENTITY);
return old_scale;
}
int
GetGraphicScale (void)
{
return gscale;
}
int
SetGraphicScaleMode (int mode)
{
int old_mode = gscale_mode;
assert (mode >= TFB_SCALE_NEAREST && mode <= TFB_SCALE_TRILINEAR);
gscale_mode = mode;
return old_mode;
}
int
GetGraphicScaleMode (void)
{
return gscale_mode;
}
+11 -4
View File
@@ -67,15 +67,22 @@ int TFB_InitGraphics (int driver, int flags, int width, int height);
void TFB_UninitGraphics (void); void TFB_UninitGraphics (void);
void TFB_ProcessEvents (void); void TFB_ProcessEvents (void);
// 3DO Graphics Stuff
#define GSCALE_IDENTITY 256 #define GSCALE_IDENTITY 256
typedef enum {
TFB_SCALE_STEP, /* not really a scaler */
TFB_SCALE_NEAREST,
TFB_SCALE_BILINEAR,
TFB_SCALE_TRILINEAR
} SCALE;
void LoadIntoExtraScreen (RECT *r); void LoadIntoExtraScreen (RECT *r);
void DrawFromExtraScreen (RECT *r); void DrawFromExtraScreen (RECT *r);
void SetGraphicGrabOther (int grab_other); void SetGraphicGrabOther (int grab_other);
void SetGraphicScale (int scale); int SetGraphicScale (int scale);
int GetGraphicScale (void); int GetGraphicScale (void);
int SetGraphicScaleMode (int mode /* enum SCALE */);
int GetGraphicScaleMode (void);
void SetGraphicUseOtherExtra (int other); void SetGraphicUseOtherExtra (int other);
void SetTransitionSource (RECT *pRect); void SetTransitionSource (RECT *pRect);
void ScreenTransition (int transition, RECT *pRect); void ScreenTransition (int transition, RECT *pRect);
@@ -22,20 +22,6 @@
#include "graphics/tfb_draw.h" #include "graphics/tfb_draw.h"
#include "libs/log.h" #include "libs/log.h"
static int gscale = GSCALE_IDENTITY;
void
SetGraphicScale (int scale)
{
gscale = (scale ? scale : GSCALE_IDENTITY);
}
int
GetGraphicScale ()
{
return gscale;
}
static void static void
read_screen (RECT *lpRect, FRAME DstFramePtr) read_screen (RECT *lpRect, FRAME DstFramePtr)
{ {
@@ -191,7 +191,6 @@ FRAME stretch_frame (FRAME FramePtr, int neww, int newh, int destroy)
CREATE_FLAGS flags; CREATE_FLAGS flags;
TFB_Image *tfbImg; TFB_Image *tfbImg;
TFB_Canvas src, dst; TFB_Canvas src, dst;
EXTENT ext;
flags = GetFrameParentDrawable (FramePtr)->Flags; flags = GetFrameParentDrawable (FramePtr)->Flags;
NewFrame = CaptureDrawable ( NewFrame = CaptureDrawable (
@@ -200,9 +199,7 @@ FRAME stretch_frame (FRAME FramePtr, int neww, int newh, int destroy)
LockMutex (tfbImg->mutex); LockMutex (tfbImg->mutex);
src = tfbImg->NormalImg; src = tfbImg->NormalImg;
dst = NewFrame->image->NormalImg; dst = NewFrame->image->NormalImg;
ext.width = neww; TFB_DrawCanvas_Rescale_Nearest (src, dst, -1, NULL, NULL, NULL);
ext.height = newh;
TFB_DrawCanvas_Rescale_Nearest (src, dst, ext);
UnlockMutex (tfbImg->mutex); UnlockMutex (tfbImg->mutex);
if (destroy) if (destroy)
DestroyDrawable (ReleaseDrawable (FramePtr)); DestroyDrawable (ReleaseDrawable (FramePtr));
File diff suppressed because it is too large Load Diff
+17 -14
View File
@@ -292,6 +292,7 @@ TFB_DrawImage_New (TFB_Canvas canvas)
img->MipmapHs = NullHs; img->MipmapHs = NullHs;
img->last_scale_hs = NullHs; img->last_scale_hs = NullHs;
img->last_scale_type = -1; img->last_scale_type = -1;
img->last_scale = 0;
TFB_DrawCanvas_GetExtent (canvas, &img->extent); TFB_DrawCanvas_GetExtent (canvas, &img->extent);
img->Palette = TFB_DrawCanvas_ExtractPalette (canvas); img->Palette = TFB_DrawCanvas_ExtractPalette (canvas);
@@ -322,6 +323,7 @@ TFB_DrawImage_CreateForScreen (int w, int h, BOOLEAN withalpha)
img->MipmapHs = NullHs; img->MipmapHs = NullHs;
img->last_scale_hs = NullHs; img->last_scale_hs = NullHs;
img->last_scale_type = -1; img->last_scale_type = -1;
img->last_scale = 0;
img->Palette = NULL; img->Palette = NULL;
img->extent.width = w; img->extent.width = w;
img->extent.height = h; img->extent.height = h;
@@ -389,28 +391,29 @@ TFB_DrawImage_Delete (TFB_Image *image)
void void
TFB_DrawImage_FixScaling (TFB_Image *image, int target, int type) TFB_DrawImage_FixScaling (TFB_Image *image, int target, int type)
{ {
EXTENT old = image->extent; if (image->dirty || !image->ScaledImg ||
HOT_SPOT oldhs = image->last_scale_hs; target != image->last_scale ||
TFB_DrawCanvas_GetScaledExtent (image->NormalImg, image->NormalHs, type != image->last_scale_type)
image->MipmapImg, image->MipmapHs, target,
&image->extent, &image->last_scale_hs);
if ((old.width != image->extent.width) ||
(old.height != image->extent.height) || image->dirty ||
!image->ScaledImg || type != image->last_scale_type ||
(oldhs.x != image->last_scale_hs.x) ||
(oldhs.y != image->last_scale_hs.y))
{ {
image->dirty = FALSE; image->dirty = FALSE;
image->ScaledImg = TFB_DrawCanvas_New_ScaleTarget (image->NormalImg, image->ScaledImg = TFB_DrawCanvas_New_ScaleTarget (image->NormalImg,
image->ScaledImg, type, image->last_scale_type); image->ScaledImg, type, image->last_scale_type);
image->last_scale_type = type;
if (type == TFB_SCALE_NEAREST) if (type == TFB_SCALE_NEAREST)
TFB_DrawCanvas_Rescale_Nearest (image->NormalImg, TFB_DrawCanvas_Rescale_Nearest (image->NormalImg,
image->ScaledImg, image->extent); image->ScaledImg, target, &image->NormalHs,
&image->extent, &image->last_scale_hs);
else if (type == TFB_SCALE_BILINEAR)
TFB_DrawCanvas_Rescale_Bilinear (image->NormalImg,
image->ScaledImg, target, &image->NormalHs,
&image->extent, &image->last_scale_hs);
else else
TFB_DrawCanvas_Rescale_Trilinear (image->NormalImg, TFB_DrawCanvas_Rescale_Trilinear (image->NormalImg,
image->ScaledImg, image->MipmapImg, image->extent); image->MipmapImg, image->ScaledImg, target,
&image->NormalHs, &image->MipmapHs,
&image->extent, &image->last_scale_hs);
image->last_scale_type = type;
image->last_scale = target;
} }
} }
+12 -11
View File
@@ -32,12 +32,6 @@ typedef enum {
TFB_GFX_NUMSCREENS TFB_GFX_NUMSCREENS
} SCREEN; } SCREEN;
typedef enum {
TFB_SCALE_STEP, /* not really a scaler */
TFB_SCALE_NEAREST,
TFB_SCALE_TRILINEAR
} SCALE;
typedef struct tfb_palette typedef struct tfb_palette
{ {
UBYTE r; UBYTE r;
@@ -61,6 +55,7 @@ typedef struct tfb_image
HOT_SPOT NormalHs; HOT_SPOT NormalHs;
HOT_SPOT MipmapHs; HOT_SPOT MipmapHs;
HOT_SPOT last_scale_hs; HOT_SPOT last_scale_hs;
int last_scale;
int last_scale_type; int last_scale_type;
TFB_Palette last_fill; TFB_Palette last_fill;
EXTENT extent; EXTENT extent;
@@ -125,11 +120,16 @@ TFB_Canvas TFB_DrawCanvas_New_ScaleTarget (TFB_Canvas canvas, TFB_Canvas oldcanv
TFB_Canvas TFB_DrawCanvas_New_RotationTarget (TFB_Canvas src, int angle); TFB_Canvas TFB_DrawCanvas_New_RotationTarget (TFB_Canvas src, int angle);
TFB_Canvas TFB_DrawCanvas_ToScreenFormat (TFB_Canvas canvas); TFB_Canvas TFB_DrawCanvas_ToScreenFormat (TFB_Canvas canvas);
BOOLEAN TFB_DrawCanvas_IsPaletted (TFB_Canvas canvas); BOOLEAN TFB_DrawCanvas_IsPaletted (TFB_Canvas canvas);
void TFB_DrawCanvas_Rescale_Nearest (TFB_Canvas src, TFB_Canvas dst, EXTENT size); void TFB_DrawCanvas_Rescale_Nearest (TFB_Canvas src, TFB_Canvas dst,
void TFB_DrawCanvas_Rescale_Trilinear (TFB_Canvas src, TFB_Canvas dst, TFB_Canvas mipmap, EXTENT size); int scale, HOT_SPOT* src_hs, EXTENT* size, HOT_SPOT* dst_hs);
void TFB_DrawCanvas_GetScaledExtent (TFB_Canvas src_canvas, HOT_SPOT src_hs, void TFB_DrawCanvas_Rescale_Bilinear (TFB_Canvas src, TFB_Canvas dst,
TFB_Canvas src_mipmap, HOT_SPOT mm_hs, int scale, HOT_SPOT* src_hs, EXTENT* size, HOT_SPOT* dst_hs);
int scale, EXTENT *size, HOT_SPOT *hs); void TFB_DrawCanvas_Rescale_Trilinear (TFB_Canvas src, TFB_Canvas mipmap,
TFB_Canvas dst, int scale, HOT_SPOT* src_hs, HOT_SPOT* mm_hs,
EXTENT* size, HOT_SPOT* dst_hs);
void TFB_DrawCanvas_GetScaledExtent (TFB_Canvas src_canvas, HOT_SPOT* src_hs,
TFB_Canvas src_mipmap, HOT_SPOT* mm_hs,
int scale, int type, EXTENT *size, HOT_SPOT *hs);
void TFB_DrawCanvas_Rotate (TFB_Canvas src, TFB_Canvas dst, int angle, EXTENT size); void TFB_DrawCanvas_Rotate (TFB_Canvas src, TFB_Canvas dst, int angle, EXTENT size);
void TFB_DrawCanvas_GetRotatedExtent (TFB_Canvas src, int angle, EXTENT *size); void TFB_DrawCanvas_GetRotatedExtent (TFB_Canvas src, int angle, EXTENT *size);
void TFB_DrawCanvas_GetExtent (TFB_Canvas canvas, EXTENT *size); void TFB_DrawCanvas_GetExtent (TFB_Canvas canvas, EXTENT *size);
@@ -148,6 +148,7 @@ int TFB_DrawCanvas_GetTransparentIndex (TFB_Canvas canvas);
void TFB_DrawCanvas_SetTransparentIndex (TFB_Canvas canvas, int i, BOOLEAN rleaccel); void TFB_DrawCanvas_SetTransparentIndex (TFB_Canvas canvas, int i, BOOLEAN rleaccel);
BOOLEAN TFB_DrawCanvas_GetTransparentColor (TFB_Canvas canvas, int *r, int *g, int *b); BOOLEAN TFB_DrawCanvas_GetTransparentColor (TFB_Canvas canvas, int *r, int *g, int *b);
void TFB_DrawCanvas_SetTransparentColor (TFB_Canvas canvas, int r, int g, int b, BOOLEAN rleaccel); void TFB_DrawCanvas_SetTransparentColor (TFB_Canvas canvas, int r, int g, int b, BOOLEAN rleaccel);
void TFB_DrawCanvas_CopyTransparencyInfo (TFB_Canvas src, TFB_Canvas dst);
void TFB_DrawCanvas_Initialize (void); void TFB_DrawCanvas_Initialize (void);
void TFB_DrawCanvas_GetScreenFormat (TFB_PixelFormat *fmt); void TFB_DrawCanvas_GetScreenFormat (TFB_PixelFormat *fmt);
void* TFB_DrawCanvas_GetLine (TFB_Canvas canvas, int line); void* TFB_DrawCanvas_GetLine (TFB_Canvas canvas, int line);
+5 -3
View File
@@ -54,7 +54,8 @@ RotatePlanet (int x, int dx, int dy, COUNT scale_amt, UBYTE zoom_from,
{ {
STAMP s; STAMP s;
FRAME pFrame[2]; FRAME pFrame[2];
COUNT i, num_frames, old_scale; COUNT i, num_frames;
int old_scale, old_mode;
RECT *rp = NULL; RECT *rp = NULL;
CONTEXT OldContext; CONTEXT OldContext;
PLANET_ORBIT *Orbit = &pSolarSysState->Orbit; PLANET_ORBIT *Orbit = &pSolarSysState->Orbit;
@@ -97,14 +98,15 @@ RotatePlanet (int x, int dx, int dy, COUNT scale_amt, UBYTE zoom_from,
RepairBackRect (rp); RepairBackRect (rp);
s.origin.x = dx; s.origin.x = dx;
s.origin.y = dy; s.origin.y = dy;
old_scale = GetGraphicScale (); old_mode = SetGraphicScaleMode (TFB_SCALE_BILINEAR);
SetGraphicScale (scale_amt); old_scale = SetGraphicScale (scale_amt);
for (i = 0; i < num_frames; i++) for (i = 0; i < num_frames; i++)
{ {
s.frame = pFrame[i]; s.frame = pFrame[i];
DrawStamp (&s); DrawStamp (&s);
} }
SetGraphicScale (old_scale); SetGraphicScale (old_scale);
SetGraphicScaleMode (old_mode);
UnbatchGraphics (); UnbatchGraphics ();
SetContext (OldContext); SetContext (OldContext);
} }
+2 -2
View File
@@ -1077,8 +1077,8 @@ GetGlobalOptions (GLOBALOPTS *opts)
opts->shield = (optWhichShield == OPT_3DO) ? OPTVAL_3DO : OPTVAL_PC; opts->shield = (optWhichShield == OPT_3DO) ? OPTVAL_3DO : OPTVAL_PC;
opts->fps = (GfxFlags & TFB_GFXFLAGS_SHOWFPS) ? opts->fps = (GfxFlags & TFB_GFXFLAGS_SHOWFPS) ?
OPTVAL_ENABLED : OPTVAL_DISABLED; OPTVAL_ENABLED : OPTVAL_DISABLED;
opts->meleezoom = (optMeleeScale == TFB_SCALE_TRILINEAR) ? opts->meleezoom = (optMeleeScale == TFB_SCALE_STEP) ?
OPTVAL_3DO : OPTVAL_PC; OPTVAL_PC : OPTVAL_3DO;
opts->stereo = optStereoSFX ? OPTVAL_ENABLED : OPTVAL_DISABLED; opts->stereo = optStereoSFX ? OPTVAL_ENABLED : OPTVAL_DISABLED;
/* These values are read in, but won't change during a run. */ /* These values are read in, but won't change during a run. */
opts->music = (optWhichMusic == OPT_3DO) ? OPTVAL_3DO : OPTVAL_PC; opts->music = (optWhichMusic == OPT_3DO) ? OPTVAL_3DO : OPTVAL_PC;
+2 -1
View File
@@ -396,7 +396,6 @@ main (int argc, char *argv[])
return optionsResult; return optionsResult;
} }
/* TODO: Once threading is gone, these become local variables /* TODO: Once threading is gone, these become local variables
again. In the meantime, they must be global so that again. In the meantime, they must be global so that
initAudio (in StarCon2Main) can see them. initAudio needed initAudio (in StarCon2Main) can see them. initAudio needed
@@ -660,6 +659,8 @@ parseOptions (int argc, char *argv[], struct options_struct *options)
options->meleeScale = TFB_SCALE_TRILINEAR; options->meleeScale = TFB_SCALE_TRILINEAR;
else if (!strcmp (optarg, "step") || !strcmp (optarg, "pc")) else if (!strcmp (optarg, "step") || !strcmp (optarg, "pc"))
options->meleeScale = TFB_SCALE_STEP; options->meleeScale = TFB_SCALE_STEP;
else if (!strcmp (optarg, "bilinear"))
options->meleeScale = TFB_SCALE_BILINEAR;
else else
{ {
InvalidArgument (optarg, "--meleezoom or -b"); InvalidArgument (optarg, "--meleezoom or -b");