Ticket #8792: float-scaler.patch

File float-scaler.patch, 5.5 KB (added by SF/ignazb, 16 years ago)
  • backends/platform/sdl/graphics.cpp

     
    3030#include "graphics/scaler.h"
    3131#include "graphics/surface.h"
    3232
     33#ifndef DISABLE_FLOAT_SCALER
     34#include "common/config-manager.h"
     35#include "common/singleton.h"
     36extern float gScale; // from scaler.cpp
     37#endif
     38
    3339static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
    3440        {"1x", "Normal (no scaling)", GFX_NORMAL},
    3541        {"2x", "2x", GFX_DOUBLESIZE},
     
    4551#endif
    4652        {"tv2x", "TV2x", GFX_TV2X},
    4753        {"dotmatrix", "DotMatrix", GFX_DOTMATRIX},
     54        {"user", "User defined float scaling", GFX_FLOAT},
    4855        {0, 0, 0}
    4956};
    5057
     
    7077                { GFX_NORMAL, GFX_SUPER2XSAI, -1, -1 },
    7178                { GFX_NORMAL, GFX_SUPEREAGLE, -1, -1 },
    7279                { GFX_NORMAL, GFX_TV2X, -1, -1 },
    73                 { GFX_NORMAL, GFX_DOTMATRIX, -1, -1 }
     80                { GFX_NORMAL, GFX_DOTMATRIX, -1, -1 },
     81                { GFX_NORMAL, GFX_FLOAT, -1, -1 }
    7482        };
    7583
    7684#ifndef DISABLE_SCALERS
     
    147155bool OSystem_SDL::setGraphicsMode(int mode) {
    148156        Common::StackLock lock(_graphicsMutex);
    149157
    150         int newScaleFactor = 1;
     158        scale_t newScaleFactor = 1;
    151159        ScalerProc *newScalerProc;
     160#ifndef DISABLE_FLOAT_SCALER
     161        float f;
     162        Common::String s;
     163#endif
    152164
    153165        switch(mode) {
    154166        case GFX_NORMAL:
     
    203215                newScaleFactor = 2;
    204216                newScalerProc = DotMatrix;
    205217                break;
     218#ifndef DISABLE_FLOAT_SCALER
     219        case GFX_FLOAT:
     220                s = Common::Singleton<Common::ConfigManager>::instance().get("gfx_scale");
     221                f = atof(s.c_str());
     222                if (f > 0.0f && f <= 3.0f) {
     223                        newScaleFactor = f;
     224                        gScale = f;
     225                } else {
     226                        newScaleFactor = 1.0f;
     227                        gScale = 1.0f;
     228                }
     229                newScalerProc = UserScaler;
     230                break;
     231#endif // DISABLE_FLOAT_SCALER
    206232#endif // DISABLE_SCALERS
    207233
    208234        default:
     
    14461472        // the game. This only works well with the non-blurring scalers so we
    14471473        // actually only use the 1x, 1.5x, 2x and AdvMame scalers.
    14481474
    1449         if (_cursorTargetScale == 1 && (_mode == GFX_DOUBLESIZE || _mode == GFX_TRIPLESIZE))
     1475        if (_cursorTargetScale == 1 && (_mode == GFX_DOUBLESIZE || _mode == GFX_TRIPLESIZE) ||
     1476                        _mode == GFX_FLOAT)
    14501477                scalerProc = _scalerProc;
    14511478        else
    1452                 scalerProc = scalersMagn[_cursorTargetScale - 1][_scaleFactor - 1];
     1479                scalerProc = scalersMagn[(int)_cursorTargetScale - 1][(int)_scaleFactor - 1];
    14531480
    14541481        scalerProc((byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch + 2,
    14551482                _mouseOrigSurface->pitch, (byte *)_mouseSurface->pixels, _mouseSurface->pitch,
     
    15141541        }
    15151542
    15161543        SDL_Rect dst;
    1517         int scale;
     1544        scale_t scale;
    15181545        int width, height;
    15191546        int hotX, hotY;
    15201547
  • backends/platform/sdl/sdl.h

     
    6464        GFX_HQ2X = 8,
    6565        GFX_HQ3X = 9,
    6666        GFX_TV2X = 10,
    67         GFX_DOTMATRIX = 11
     67        GFX_DOTMATRIX = 11,
     68        GFX_FLOAT = 12,
    6869};
    6970
    7071
     
    270271        bool _forceFull;
    271272        ScalerProc *_scalerProc;
    272273        int _scalerType;
    273         int _scaleFactor;
     274        scale_t _scaleFactor;
    274275        int _mode;
    275276        int _transactionMode;
    276277        bool _fullscreen;
     
    339340        SDL_Rect _mouseBackup;
    340341        MousePos _mouseCurState;
    341342        byte _mouseKeyColor;
    342         int _cursorTargetScale;
     343        scale_t _cursorTargetScale;
    343344        bool _cursorPaletteDisabled;
    344345        SDL_Surface *_mouseOrigSurface;
    345346        SDL_Surface *_mouseSurface;
  • common/scummsys.h

     
    441441        typedef unsigned short uint16;
    442442        typedef signed short int16;
    443443
     444#ifndef DISABLE_FLOAT_SCALER
     445        typedef float scale_t;
     446#else
     447        typedef int scale_t;
     448#endif
     449
    444450        #ifdef SCUMMVM_USE_LONG_INT
    445451        typedef unsigned long uint32;
    446452        typedef signed long int32;
  • graphics/scaler.cpp

     
    320320        }
    321321}
    322322
     323#ifndef DISABLE_FLOAT_SCALER
     324
     325float gScale;
     326void UserScaler(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
     327                                int width, int height) {
     328       
     329        float scale = gScale;
     330        if (scale <= 0.0f || scale > 3.0f)
     331                scale = 1.0f;
     332
     333        for (int y = 0; y < height; y++) {
     334                for (int x = 0; x < width; x++) {
     335                        int xMin, yMin;
     336                        uint16 pixel = *((uint16 *)(srcPtr + srcPitch * y) + x);
     337                        // calculate the point where this pixel would be on a scalar coordinate system
     338                        xMin = x * scale;
     339                        yMin = y * scale;
     340
     341#define DESTOF(a, b, c) do { *(uint16 *)((dstPtr + (dstPitch * (b)) + (a)*2)) = pixel; } while (0)
     342                        DESTOF(xMin, yMin, pixel);
     343                        if (scale > 1.0) {
     344                                DESTOF(xMin + 1, yMin, pixel);
     345                                DESTOF(xMin, yMin + 1, pixel);
     346                                DESTOF(xMin + 1, yMin + 1, pixel);
     347                                if (scale > 2.0 && x < width - 1 && y < height - 1) {
     348                                        DESTOF(xMin + 2, yMin, pixel);
     349                                        DESTOF(xMin + 2, yMin + 1, pixel);
     350                                        DESTOF(xMin + 2, yMin + 2, pixel);
     351                                        DESTOF(xMin + 1, yMin + 2, pixel);
     352                                        DESTOF(xMin, yMin + 2, pixel);
     353                                }
     354                        }
     355                }
     356        }
     357}
     358#endif // DISABLE_FLOAT_SCALER
     359
    323360#endif
  • graphics/scaler.h

     
    4848DECLARE_SCALER(Normal1o5x);
    4949DECLARE_SCALER(TV2x);
    5050DECLARE_SCALER(DotMatrix);
     51DECLARE_SCALER(UserScaler);
    5152
    5253#ifndef DISABLE_HQ_SCALERS
    5354DECLARE_SCALER(HQ2x);