From 48eee90ab2617b319d680eb50414f898cf093459 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 21 Nov 2002 00:48:15 +0000 Subject: [PATCH] Reenable and move iterative filtering into the zoom proper. --- stepmania/src/RageBitmapTexture.cpp | 27 +++---------------- stepmania/src/SDL_rotozoom.cpp | 42 ++++++++++++++++++++--------- stepmania/src/SDL_rotozoom.h | 2 +- stepmania/src/StepMania.cpp | 17 ++++-------- 4 files changed, 39 insertions(+), 49 deletions(-) diff --git a/stepmania/src/RageBitmapTexture.cpp b/stepmania/src/RageBitmapTexture.cpp index 001813944f..199058f274 100644 --- a/stepmania/src/RageBitmapTexture.cpp +++ b/stepmania/src/RageBitmapTexture.cpp @@ -212,30 +212,9 @@ void RageBitmapTexture::Create() ConvertSDLSurface(img, img->w, img->h, PixFmtMasks[mask][4], PixFmtMasks[mask][0], PixFmtMasks[mask][1], PixFmtMasks[mask][2], PixFmtMasks[mask][3]); - SDL_Surface *dst = zoomSurface(img, m_iImageWidth, m_iImageHeight ); - SDL_FreeSurface(img); - img = dst; - -// Commented out to see how things look without iterative filtering. -Chris -// while (m_iImageWidth != m_iTextureWidth || m_iImageHeight != m_iTextureHeight) { -// float xscale = float(m_iTextureWidth)/m_iImageWidth; -// float yscale = float(m_iTextureHeight)/m_iImageHeight; -// -// /* Our filter is a simple linear filter, so it can't scale to -// * less than .5 very well. If we need to go lower than .5, do -// * it iteratively. */ -// xscale = max(xscale, .5f); -// yscale = max(yscale, .5f); -// -// SDL_Surface *dst = zoomSurface(img, xscale, yscale); -// -// SDL_FreeSurface(img); -// img = dst; -// -// /* The new image size is the full texture size. */ -// m_iImageWidth = int(m_iImageWidth * xscale + .0001); -// m_iImageHeight = int(m_iImageHeight * yscale + .0001); -// } + zoomSurface(img, m_iTextureWidth, m_iTextureHeight ); + m_iImageWidth = m_iTextureWidth; + m_iImageHeight = m_iTextureHeight; } if( m_prefs.bDither ) diff --git a/stepmania/src/SDL_rotozoom.cpp b/stepmania/src/SDL_rotozoom.cpp index c670080765..52ed61739b 100644 --- a/stepmania/src/SDL_rotozoom.cpp +++ b/stepmania/src/SDL_rotozoom.cpp @@ -142,13 +142,11 @@ void zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst) */ -SDL_Surface *zoomSurface(SDL_Surface * src, int dstwidth, int dstheight) +SDL_Surface *zoomSurface_ll(SDL_Surface *src, int dstwidth, int dstheight) { SDL_Surface *rz_dst; - /* Sanity check */ - if (src == NULL) - return (NULL); + if (src == NULL) return NULL; /* Alloc space to completely contain the zoomed surface */ /* Target surface is 32bit with source RGBA/ABGR ordering */ @@ -157,18 +155,38 @@ SDL_Surface *zoomSurface(SDL_Surface * src, int dstwidth, int dstheight) src->format->Rmask, src->format->Gmask, src->format->Bmask, src->format->Amask); - /* - * Lock source surface - */ SDL_LockSurface(src); /* Call the 32bit transformation routine to do the zooming (using alpha) */ zoomSurfaceRGBA(src, rz_dst); - /* Turn on source-alpha support */ - SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); - /* Unlock source surface */ + SDL_UnlockSurface(src); - /* Return destination surface */ - return (rz_dst); + return rz_dst; +} + + +void zoomSurface(SDL_Surface *&src, int dstwidth, int dstheight) +{ + if (src == NULL) return; + + while (src->w != dstwidth || src->h != dstheight) { + float xscale = float(dstwidth)/src->w; + float yscale = float(dstheight)/src->h; + + /* Our filter is a simple linear filter, so it can't scale to + * less than .5 very well. If we need to go lower than .5, do + * it iteratively. */ + xscale = max(xscale, .5f); + yscale = max(yscale, .5f); + + int target_width = int(src->w*xscale + .5); + int target_height = int(src->h*yscale + .5); + + SDL_Surface *dst = zoomSurface_ll(src, target_width, target_height); + + SDL_FreeSurface(src); + + src = dst; + } } diff --git a/stepmania/src/SDL_rotozoom.h b/stepmania/src/SDL_rotozoom.h index 3572cf9836..09ee07f7a0 100644 --- a/stepmania/src/SDL_rotozoom.h +++ b/stepmania/src/SDL_rotozoom.h @@ -22,7 +22,7 @@ */ -SDL_Surface *zoomSurface(SDL_Surface * src, int dstwidth, int dstheight); +void zoomSurface(SDL_Surface *&src, int dstwidth, int dstheight); #endif diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 981b688856..519b44327a 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -247,12 +247,11 @@ void SetIcon() * this is here just in case it changes.) */ ConvertSDLSurface(srf, srf->w, srf->h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); - SDL_Surface *dst = zoomSurface(srf, 32, 32); + zoomSurface(srf, 32, 32); - SDL_SetAlpha( dst, SDL_SRCALPHA, SDL_ALPHA_OPAQUE ); - SDL_WM_SetIcon(dst, NULL /* derive from alpha */); + SDL_SetAlpha( srf, SDL_SRCALPHA, SDL_ALPHA_OPAQUE ); + SDL_WM_SetIcon(srf, NULL /* derive from alpha */); SDL_FreeSurface(srf); - SDL_FreeSurface(dst); } //----------------------------------------------------------------------------- @@ -308,7 +307,6 @@ int main(int argc, char* argv[]) SetIcon(); CreateLoadingWindow(); - loading_window->Paint(); // // Create game objects @@ -356,7 +354,7 @@ int main(int argc, char* argv[]) HWND hwnd = info.window; INPUTMAN = new RageInput( hwnd ); -// SOUNDMAN = new RageSoundManager( hwnd ); +// SOUNDMAN = new RageSoundManager(); // These things depend on the TextureManager, so do them after! FONT = new FontManager; @@ -475,10 +473,6 @@ void GameLoop() } } - DISPLAY->Clear(); - DISPLAY->ResetMatrixStack(); - - /* * Update */ @@ -501,7 +495,6 @@ void GameLoop() SCREENMAN->Update( fDeltaTime ); NETWORK->Update( fDeltaTime ); - static InputEventArray ieArray; ieArray.clear(); // empty the array INPUTFILTER->GetInputEvents( ieArray, fDeltaTime ); @@ -579,10 +572,10 @@ void GameLoop() SCREENMAN->Input( DeviceI, type, GameI, MenuI, StyleI ); } - /* * Render */ + DISPLAY->Clear(); DISPLAY->ResetMatrixStack(); RageMatrix mat;