Ticket #8611: 32bit.patch

File 32bit.patch, 41.0 KB (added by DrMcCoy, 17 years ago)

The patch

  • backends/platform/sdl/graphics.cpp

     
    145145bool OSystem_SDL::setGraphicsMode(int mode) {
    146146        Common::StackLock lock(_graphicsMutex);
    147147
     148        bool needHotSwap = false;
    148149        int newScaleFactor = 1;
    149150        ScalerProc *newScalerProc;
    150151
     
    211212        _transactionDetails.normal1xScaler = (mode == GFX_NORMAL);
    212213
    213214        _mode = mode;
     215
     216#ifndef DISABLE_HQ_SCALERS
     217        // Hotswapping (to change the color depth) when switching to and from HQ-scalers
     218        if (_scalerProc != newScalerProc) {
     219                if (((newScalerProc == HQ2x) || (newScalerProc == HQ3x)) &&
     220                                (_curBytesPerPixel == 4))
     221                        needHotSwap = true;
     222                if (((_scalerProc == HQ2x) || (_scalerProc == HQ3x)) &&
     223                                (_bytesPerPixel > 2))
     224                        needHotSwap = true;
     225        }
     226#endif
     227
    214228        _scalerProc = newScalerProc;
    215229
    216230        if (_transactionMode == kTransactionActive) {
     
    230244        // NOTE: This should not be executed at transaction commit
    231245        //   Otherwise there is some unsolicited setGraphicsMode() call
    232246        //   which should be properly removed
    233         if (newScaleFactor != _scaleFactor) {
     247        if ((newScaleFactor != _scaleFactor) || needHotSwap) {
    234248                assert(_transactionMode != kTransactionCommit);
    235249
    236250                _scaleFactor = newScaleFactor;
     
    337351                error("allocating _screen failed");
    338352
    339353        //
    340         // Create the surface that contains the scaled graphics in 16 bit mode
     354        // Check whether to use 32 or 16 bit colors
    341355        //
    342356
    343         _hwscreen = SDL_SetVideoMode(hwW, hwH, 16,
     357        if ((_bytesPerPixel > 2) && (_scalerProc != HQ2x) && (_scalerProc != HQ3x))
     358                _curBytesPerPixel = 4;
     359        else
     360                _curBytesPerPixel = 2;
     361
     362        //
     363        // Create the surface that contains the scaled graphics in 32/16 bit mode
     364        //
     365
     366        _hwscreen = SDL_SetVideoMode(hwW, hwH, _curBytesPerPixel * 8,
    344367                _fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
    345368        );
    346369        if (_hwscreen == NULL) {
     
    369392        //
    370393
    371394        // Distinguish 555 and 565 mode
    372         if (_hwscreen->format->Rmask == 0x7C00)
    373                 InitScalers(555);
    374         else
    375                 InitScalers(565);
     395        if (_curBytesPerPixel == 2) {
     396                _Rmask = _hwscreen->format->Rmask;
     397                _Gmask = _hwscreen->format->Gmask;
     398                _Bmask = _hwscreen->format->Bmask;
     399                _Amask = _hwscreen->format->Amask;
     400                if (_Rmask == 0x7C00)
     401                        InitScalers(555);
     402                else
     403                        InitScalers(565);
     404        } else {
     405                _Rmask = 0xF800;
     406                _Gmask = 0x07E0;
     407                _Bmask = 0x001F;
     408                _Amask = 0x0000;
     409                InitScalers(8888);
     410        }
    376411
    377412        // Need some extra bytes around when using 2xSaI
    378413        _tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth + 3, _screenHeight + 3,
    379                                                 16,
     414                                                _curBytesPerPixel * 8,
    380415                                                _hwscreen->format->Rmask,
    381416                                                _hwscreen->format->Gmask,
    382417                                                _hwscreen->format->Bmask,
     
    386421                error("allocating _tmpscreen failed");
    387422
    388423        _overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth, _overlayHeight,
    389                                                 16,
    390                                                 _hwscreen->format->Rmask,
    391                                                 _hwscreen->format->Gmask,
    392                                                 _hwscreen->format->Bmask,
    393                                                 _hwscreen->format->Amask);
     424                                                16, _Rmask, _Gmask, _Bmask, _Amask);
    394425
    395426        if (_overlayscreen == NULL)
    396427                error("allocating _overlayscreen failed");
    397428
    398429        _tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth + 3, _overlayHeight + 3,
    399                                                 16,
     430                                                16, _Rmask, _Gmask, _Bmask, _Amask);
     431
     432        if (_tmpscreen2 == NULL)
     433                error("allocating _tmpscreen2 failed");
     434
     435        _tmpscreen3 = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth + 3, _screenHeight + 3,
     436                                                16, _Rmask, _Gmask, _Bmask, _Amask);
     437
     438        if (_tmpscreen3 == NULL)
     439                error("allocating _tmpscreen3 failed");
     440
     441        _tmpscreen4 = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth + 3, _overlayHeight + 3,
     442                                                _curBytesPerPixel * 8,
    400443                                                _hwscreen->format->Rmask,
    401444                                                _hwscreen->format->Gmask,
    402445                                                _hwscreen->format->Bmask,
    403446                                                _hwscreen->format->Amask);
    404447
    405         if (_tmpscreen2 == NULL)
    406                 error("allocating _tmpscreen2 failed");
     448        if (_tmpscreen4 == NULL)
     449                error("allocating _tmpscreen4 failed");
    407450
    408451#ifdef USE_OSD
    409452        _osdSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
    410453                                                _hwscreen->w,
    411454                                                _hwscreen->h,
    412                                                 16,
    413                                                 _hwscreen->format->Rmask,
    414                                                 _hwscreen->format->Gmask,
    415                                                 _hwscreen->format->Bmask,
    416                                                 _hwscreen->format->Amask);
     455                                                16, _Rmask, _Gmask, _Bmask, _Amask);
    417456        if (_osdSurface == NULL)
    418457                error("allocating _osdSurface failed");
    419458        SDL_SetColorKey(_osdSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kOSDColorKey);
     
    447486                _tmpscreen2 = NULL;
    448487        }
    449488
     489        if (_tmpscreen3) {
     490                SDL_FreeSurface(_tmpscreen3);
     491                _tmpscreen3 = NULL;
     492        }
     493
     494        if (_tmpscreen4) {
     495                SDL_FreeSurface(_tmpscreen4);
     496                _tmpscreen4 = NULL;
     497        }
     498
    450499        if (_overlayscreen) {
    451500                SDL_FreeSurface(_overlayscreen);
    452501                _overlayscreen = NULL;
     
    474523
    475524        SDL_FreeSurface(_tmpscreen);
    476525        SDL_FreeSurface(_tmpscreen2);
     526        SDL_FreeSurface(_tmpscreen3);
     527        SDL_FreeSurface(_tmpscreen4);
    477528
    478529#ifdef USE_OSD
    479530        // Release the OSD surface
     
    578629                scale1 = _scaleFactor;
    579630        } else {
    580631                origSurf = _overlayscreen;
    581                 srcSurf = _tmpscreen2;
     632                srcSurf = _tmpscreen4;
    582633                width = _overlayWidth;
    583634                height = _overlayHeight;
    584635                scalerProc = Normal1x;
     
    646697                                                dst_y = real2Aspect(dst_y);
    647698
    648699                                        assert(scalerProc != NULL);
    649                                         scalerProc((byte *)srcSurf->pixels + (r->x * 2 + 2) + (r->y + 1) * srcPitch, srcPitch,
    650                                                            (byte *)_hwscreen->pixels + rx1 * 2 + dst_y * dstPitch, dstPitch, r->w, dst_h);
     700                                        scalerProc((byte *)srcSurf->pixels +
     701                                                            (r->x * _curBytesPerPixel + _bytesPerPixel) +
     702                                                            (r->y + 1) * srcPitch, srcPitch,
     703                                                           (byte *)_hwscreen->pixels +
     704                                                            rx1 * _curBytesPerPixel +
     705                                                                dst_y * dstPitch, dstPitch,
     706                                                                r->w, dst_h, _curBytesPerPixel);
    651707                                }
    652708
    653709                                r->x = rx1;
     
    657713
    658714#ifndef DISABLE_SCALERS
    659715                                if (_adjustAspectRatio && orig_dst_y < height && !_overlayVisible)
    660                                         r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1);
     716                                        r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1, _curBytesPerPixel);
    661717#endif
    662718                        }
    663719                        SDL_UnlockSurface(srcSurf);
     
    11571213        dst.x = dst.y = 1;
    11581214        src.w = dst.w = _screenWidth;
    11591215        src.h = dst.h = _screenHeight;
    1160         if (SDL_BlitSurface(_screen, &src, _tmpscreen, &dst) != 0)
     1216        if (SDL_BlitSurface(_screen, &src, _tmpscreen3, &dst) != 0)
    11611217                error("SDL_BlitSurface failed: %s", SDL_GetError());
    11621218
    1163         SDL_LockSurface(_tmpscreen);
     1219        SDL_LockSurface(_tmpscreen3);
    11641220        SDL_LockSurface(_overlayscreen);
    1165         _scalerProc((byte *)(_tmpscreen->pixels) + _tmpscreen->pitch + 2, _tmpscreen->pitch,
     1221        _scalerProc((byte *)(_tmpscreen3->pixels) + _tmpscreen3->pitch + 2, _tmpscreen3->pitch,
    11661222        (byte *)_overlayscreen->pixels, _overlayscreen->pitch, _screenWidth, _screenHeight);
    11671223
    11681224#ifndef DISABLE_SCALERS
    11691225        if (_adjustAspectRatio)
    11701226                stretch200To240((uint8 *)_overlayscreen->pixels, _overlayscreen->pitch,
    1171                                                 _overlayWidth, _screenHeight * _scaleFactor, 0, 0, 0);
     1227                                                _overlayWidth, _screenHeight * _scaleFactor, 0, 0, 0, 2);
    11721228#endif
    1173         SDL_UnlockSurface(_tmpscreen);
     1229        SDL_UnlockSurface(_tmpscreen3);
    11741230        SDL_UnlockSurface(_overlayscreen);
    11751231
    11761232        _forceFull = true;
     
    13171373                _mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
    13181374                                                _mouseCurState.w + 2,
    13191375                                                _mouseCurState.h + 2,
    1320                                                 16,
    1321                                                 _hwscreen->format->Rmask,
    1322                                                 _hwscreen->format->Gmask,
    1323                                                 _hwscreen->format->Bmask,
    1324                                                 _hwscreen->format->Amask);
     1376                                                16, _Rmask, _Gmask, _Bmask, _Amask);
    13251377
    13261378                if (_mouseOrigSurface == NULL)
    13271379                        error("allocating _mouseOrigSurface failed");
     
    14381490                _mouseSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
    14391491                                                _mouseCurState.rW,
    14401492                                                _mouseCurState.rH,
    1441                                                 16,
    1442                                                 _hwscreen->format->Rmask,
    1443                                                 _hwscreen->format->Gmask,
    1444                                                 _hwscreen->format->Bmask,
    1445                                                 _hwscreen->format->Amask);
     1493                                                16, _Rmask, _Gmask, _Bmask, _Amask);
    14461494
    14471495                if (_mouseSurface == NULL)
    14481496                        error("allocating _mouseSurface failed");
  • backends/platform/sdl/sdl.cpp

     
    142142                error("Could not initialize SDL: %s", SDL_GetError());
    143143        }
    144144
     145        _bytesPerPixel = SDL_GetVideoInfo()->vfmt->BytesPerPixel;
    145146        _graphicsMutex = createMutex();
    146147
    147148        SDL_ShowCursor(SDL_DISABLE);
  • backends/platform/sdl/sdl-common.h

     
    221221        // temporary screen (for scalers)
    222222        SDL_Surface *_tmpscreen;
    223223        SDL_Surface *_tmpscreen2;
     224        SDL_Surface *_tmpscreen3;
     225        SDL_Surface *_tmpscreen4;
    224226
    225227        // overlay
    226228        SDL_Surface *_overlayscreen;
    227229        int _overlayWidth, _overlayHeight;
    228230        bool _overlayVisible;
    229231
     232        // color depth
     233        uint8 _bytesPerPixel;
     234        uint8 _curBytesPerPixel;
     235        uint32 _Rmask;
     236        uint32 _Gmask;
     237        uint32 _Bmask;
     238        uint32 _Amask;
     239
    230240        // Audio
    231241        int _samplesPerSec;
    232242
  • graphics/scaler.cpp

     
    107107                InitLUT<ColorMasks<555> >();
    108108        if (gBitFormat == 565)
    109109                InitLUT<ColorMasks<565> >();
     110        // Use 565-format for 16 bit surfaces in 32 bit mode
     111        if (gBitFormat == 8888)
     112                InitLUT<ColorMasks<565> >();
    110113#endif
    111114}
    112115
     
    116119 * source to the destionation.
    117120 */
    118121void Normal1x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
    119                                                         int width, int height) {
     122                                                        int width, int height, uint8 bytesPerPixel) {
    120123        while (height--) {
    121                 memcpy(dstPtr, srcPtr, 2 * width);
     124                memcpy(dstPtr, srcPtr, bytesPerPixel * width);
    122125                srcPtr += srcPitch;
    123126                dstPtr += dstPitch;
    124127        }
     
    129132 * Trivial nearest-neighbour 2x scaler.
    130133 */
    131134void Normal2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
    132                                                         int width, int height) {
     135                                                        int width, int height, uint8 bytesPerPixel) {
    133136        uint8 *r;
     137        const uint8 *s;
    134138
    135139        assert(((long)dstPtr & 3) == 0);
     140        width *= bytesPerPixel;
    136141        while (height--) {
    137142                r = dstPtr;
    138                 for (int i = 0; i < width; ++i, r += 4) {
    139                         uint32 color = *(((const uint16 *)srcPtr) + i);
    140 
    141                         color |= color << 16;
    142 
    143                         *(uint32 *)(r) = color;
    144                         *(uint32 *)(r + dstPitch) = color;
     143                for (int i = 0; i < width; i += bytesPerPixel, r += (bytesPerPixel * 2)) {
     144                        s = srcPtr + i;
     145                        memcpy(r, s, bytesPerPixel);
     146                        memcpy(r + bytesPerPixel, s, bytesPerPixel);
     147                        memcpy(r + dstPitch, s, bytesPerPixel);
     148                        memcpy(r + dstPitch + bytesPerPixel, s, bytesPerPixel);
    145149                }
    146150                srcPtr += srcPitch;
    147151                dstPtr += dstPitch << 1;
     
    152156 * Trivial nearest-neighbour 3x scaler.
    153157 */
    154158void Normal3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
    155                                                         int width, int height) {
     159                                                        int width, int height, uint8 bytesPerPixel) {
    156160        uint8 *r;
     161        const uint8 *s;
    157162        const uint32 dstPitch2 = dstPitch * 2;
    158163        const uint32 dstPitch3 = dstPitch * 3;
    159164
    160165        assert(((long)dstPtr & 1) == 0);
     166        width *= bytesPerPixel;
    161167        while (height--) {
    162168                r = dstPtr;
    163                 for (int i = 0; i < width; ++i, r += 6) {
    164                         uint16 color = *(((const uint16 *)srcPtr) + i);
    165 
    166                         *(uint16 *)(r + 0) = color;
    167                         *(uint16 *)(r + 2) = color;
    168                         *(uint16 *)(r + 4) = color;
    169                         *(uint16 *)(r + 0 + dstPitch) = color;
    170                         *(uint16 *)(r + 2 + dstPitch) = color;
    171                         *(uint16 *)(r + 4 + dstPitch) = color;
    172                         *(uint16 *)(r + 0 + dstPitch2) = color;
    173                         *(uint16 *)(r + 2 + dstPitch2) = color;
    174                         *(uint16 *)(r + 4 + dstPitch2) = color;
     169                for (int i = 0; i < width; i += bytesPerPixel, r += (bytesPerPixel * 3)) {
     170                        s = srcPtr + i;
     171                        memcpy(r, s, bytesPerPixel);
     172                        memcpy(r + bytesPerPixel, s, bytesPerPixel);
     173                        memcpy(r + bytesPerPixel * 2, s, bytesPerPixel);
     174                        memcpy(r + dstPitch, s, bytesPerPixel);
     175                        memcpy(r + dstPitch + bytesPerPixel, s, bytesPerPixel);
     176                        memcpy(r + dstPitch + bytesPerPixel * 2, s, bytesPerPixel);
     177                        memcpy(r + dstPitch2, s, bytesPerPixel);
     178                        memcpy(r + dstPitch2 + bytesPerPixel, s, bytesPerPixel);
     179                        memcpy(r + dstPitch2 + bytesPerPixel * 2, s, bytesPerPixel);
    175180                }
    176181                srcPtr += srcPitch;
    177182                dstPtr += dstPitch3;
     
    184189/**
    185190 * Trivial nearest-neighbour 1.5x scaler.
    186191 */
    187 template<int bitFormat>
    188 void Normal1o5xTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
     192template<int bitFormat, typename T>
     193void Normal1o5xTemplate(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch,
    189194                                                        int width, int height) {
    190         uint8 *r;
     195        dstPitch /= sizeof(T);
     196        srcPitch /= sizeof(T);
     197
     198        T *r;
    191199        const uint32 dstPitch2 = dstPitch * 2;
    192200        const uint32 dstPitch3 = dstPitch * 3;
    193201        const uint32 srcPitch2 = srcPitch * 2;
     
    195203        assert(((long)dstPtr & 1) == 0);
    196204        while (height > 0) {
    197205                r = dstPtr;
    198                 for (int i = 0; i < width; i += 2, r += 6) {
    199                         uint16 color0 = *(((const uint16 *)srcPtr) + i);
    200                         uint16 color1 = *(((const uint16 *)srcPtr) + i + 1);
    201                         uint16 color2 = *(((const uint16 *)(srcPtr + srcPitch)) + i);
    202                         uint16 color3 = *(((const uint16 *)(srcPtr + srcPitch)) + i + 1);
     206                for (int i = 0; i < width; i += 1, r += 3) {
     207                        T color0 = *(srcPtr + i);
     208                        T color1 = *(srcPtr + i + 1);
     209                        T color2 = *(srcPtr + srcPitch + i);
     210                        T color3 = *(srcPtr + srcPitch + i + 1);
    203211
    204                         *(uint16 *)(r + 0) = color0;
    205                         *(uint16 *)(r + 2) = interpolate32_1_1(color0, color1);
    206                         *(uint16 *)(r + 4) = color1;
    207                         *(uint16 *)(r + 0 + dstPitch) = interpolate32_1_1(color0, color2);
    208                         *(uint16 *)(r + 2 + dstPitch) = interpolate32_1_1_1_1(color0, color1, color2, color3);
    209                         *(uint16 *)(r + 4 + dstPitch) = interpolate32_1_1(color1, color3);
    210                         *(uint16 *)(r + 0 + dstPitch2) = color2;
    211                         *(uint16 *)(r + 2 + dstPitch2) = interpolate32_1_1(color2, color3);
    212                         *(uint16 *)(r + 4 + dstPitch2) = color3;
     212                        *(r + 0) = color0;
     213                        *(r + 1) = interpolate32_1_1(color0, color1);
     214                        *(r + 2) = color1;
     215                        *(r + 0 + dstPitch) = interpolate32_1_1(color0, color2);
     216                        *(r + 1 + dstPitch) = interpolate32_1_1_1_1(color0, color1, color2, color3);
     217                        *(r + 2 + dstPitch) = interpolate32_1_1(color1, color3);
     218                        *(r + 0 + dstPitch2) = color2;
     219                        *(r + 1 + dstPitch2) = interpolate32_1_1(color2, color3);
     220                        *(r + 2 + dstPitch2) = color3;
    213221                }
    214222                srcPtr += srcPitch2;
    215223                dstPtr += dstPitch3;
     
    223231 * See also http://scale2x.sourceforge.net
    224232 */
    225233void AdvMame2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
    226                                                          int width, int height) {
    227         scale(2, dstPtr, dstPitch, srcPtr - srcPitch, srcPitch, 2, width, height);
     234                                                         int width, int height, uint8 bytesPerPixel) {
     235        scale(2, dstPtr, dstPitch, srcPtr - srcPitch, srcPitch, bytesPerPixel, width, height);
    228236}
    229237
    230238/**
     
    232240 * See also http://scale2x.sourceforge.net
    233241 */
    234242void AdvMame3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
    235                                                          int width, int height) {
    236         scale(3, dstPtr, dstPitch, srcPtr - srcPitch, srcPitch, 2, width, height);
     243                                                         int width, int height, uint8 bytesPerPixel) {
     244        scale(3, dstPtr, dstPitch, srcPtr - srcPitch, srcPitch, bytesPerPixel, width, height);
    237245}
    238246
    239 template<int bitFormat>
    240 void TV2xTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
     247template<int bitFormat, typename T>
     248void TV2xTemplate(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch,
    241249                                        int width, int height) {
    242         const uint32 nextlineSrc = srcPitch / sizeof(uint16);
    243         const uint16 *p = (const uint16 *)srcPtr;
     250        dstPitch /= sizeof(T);
     251        srcPitch /= sizeof(T);
    244252
    245         const uint32 nextlineDst = dstPitch / sizeof(uint16);
    246         uint16 *q = (uint16 *)dstPtr;
    247 
    248253        while (height--) {
    249254                for (int i = 0, j = 0; i < width; ++i, j += 2) {
    250                         uint16 p1 = *(p + i);
     255                        T p1 = *(srcPtr + i);
    251256                        uint32 pi;
    252257
    253258                        pi = (((p1 & redblueMask) * 7) >> 3) & redblueMask;
    254259                        pi |= (((p1 & greenMask) * 7) >> 3) & greenMask;
    255260
    256                         *(q + j) = p1;
    257                         *(q + j + 1) = p1;
    258                         *(q + j + nextlineDst) = (uint16)pi;
    259                         *(q + j + nextlineDst + 1) = (uint16)pi;
     261                        *(dstPtr + j) = p1;
     262                        *(dstPtr + j + 1) = p1;
     263                        *(dstPtr + j + dstPitch) = (T)pi;
     264                        *(dstPtr + j + dstPitch + 1) = (T)pi;
    260265                }
    261                 p += nextlineSrc;
    262                 q += nextlineDst << 1;
     266                srcPtr += srcPitch;
     267                dstPtr += dstPitch << 1;
    263268        }
    264269}
    265270MAKE_WRAPPER(TV2x)
     
    277282        0x1CE7, 0x0000, 0x1CE7, 0x0000
    278283};
    279284
    280 static inline uint16 DOT_16(const uint16 *dotmatrix, uint16 c, int j, int i) {
     285static const uint32 dotmatrix_8888[16] = {
     286        0x00003F00, 0x0000003F, 0x001F0000, 0x00000000,
     287        0x001F3F3F, 0x00000000, 0x001F3F3F, 0x00000000,
     288        0x001F0000, 0x00000000, 0x00003F00, 0x0000003F,
     289        0x001F3F3F, 0x00000000, 0x001F3F3F, 0x00000000
     290};
     291
     292template<typename T>
     293static inline T DOT(const T *dotmatrix, T c, int j, int i) {
    281294        return c - ((c >> 2) & *(dotmatrix + ((j & 3) << 2) + (i & 3)));
    282295}
    283296
     
    287300// a way that also works together with aspect-ratio correction is left as an
    288301// exercise for the reader.)
    289302
     303template<typename T>
     304void DotMatrix(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch,
     305                                        int width, int height, const T *dotmatrix) {
     306        dstPitch /= sizeof(T);
     307        srcPitch /= sizeof(T);
     308
     309        for (int j = 0, jj = 0; j < height; ++j, jj += 2) {
     310                for (int i = 0, ii = 0; i < width; ++i, ii += 2) {
     311                        T c = *(srcPtr + i);
     312                        *(dstPtr + ii) = DOT(dotmatrix, c, jj, ii);
     313                        *(dstPtr + ii + 1) = DOT(dotmatrix, c, jj, ii + 1);
     314                        *(dstPtr + ii + dstPitch) = DOT(dotmatrix, c, jj + 1, ii);
     315                        *(dstPtr + ii + dstPitch + 1) = DOT(dotmatrix, c, jj + 1, ii + 1);
     316                }
     317                srcPtr += srcPitch;
     318                dstPtr += dstPitch << 1;
     319        }
     320}
     321
    290322void DotMatrix(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
    291                                         int width, int height) {
    292 
    293         const uint16 *dotmatrix;
     323                                        int width, int height, uint8 bytesPerPixel) {
    294324        if (gBitFormat == 565) {
    295                 dotmatrix = dotmatrix_565;
     325                DotMatrix((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height, dotmatrix_565);
    296326        } else if (gBitFormat == 555) {
    297                 dotmatrix = dotmatrix_555;
     327                DotMatrix((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height, dotmatrix_555);
     328        } else if (gBitFormat == 8888) {
     329                if (bytesPerPixel == 4)
     330                        DotMatrix((uint32*) srcPtr, srcPitch, (uint32*) dstPtr, dstPitch, width, height, dotmatrix_8888);
     331                else
     332                        DotMatrix((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height, dotmatrix_565);
    298333        } else {
    299334                error("Unknown bit format %d", gBitFormat);
    300335        }
    301 
    302         const uint32 nextlineSrc = srcPitch / sizeof(uint16);
    303         const uint16 *p = (const uint16 *)srcPtr;
    304 
    305         const uint32 nextlineDst = dstPitch / sizeof(uint16);
    306         uint16 *q = (uint16 *)dstPtr;
    307 
    308         for (int j = 0, jj = 0; j < height; ++j, jj += 2) {
    309                 for (int i = 0, ii = 0; i < width; ++i, ii += 2) {
    310                         uint16 c = *(p + i);
    311                         *(q + ii) = DOT_16(dotmatrix, c, jj, ii);
    312                         *(q + ii + 1) = DOT_16(dotmatrix, c, jj, ii + 1);
    313                         *(q + ii + nextlineDst) = DOT_16(dotmatrix, c, jj + 1, ii);
    314                         *(q + ii + nextlineDst + 1) = DOT_16(dotmatrix, c, jj + 1, ii + 1);
    315                 }
    316                 p += nextlineSrc;
    317                 q += nextlineDst << 1;
    318         }
    319336}
    320337
    321338#endif
  • graphics/scaler.h

     
    2929extern void InitScalers(uint32 BitFormat);
    3030
    3131typedef void ScalerProc(const uint8 *srcPtr, uint32 srcPitch,
    32                                                         uint8 *dstPtr, uint32 dstPitch, int width, int height);
     32                                                        uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel = 2);
    3333
    3434#define DECLARE_SCALER(x)       \
    3535        extern void x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, \
    36                                         uint32 dstPitch, int width, int height)
     36                                        uint32 dstPitch, int width, int height, uint8 bytesPerPixel = 2)
    3737
    3838DECLARE_SCALER(_2xSaI);
    3939DECLARE_SCALER(Super2xSaI);
     
    6262
    6363extern void makeRectStretchable(int &x, int &y, int &w, int &h);
    6464
    65 extern int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY);
     65extern int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY, uint8 bytesPerPixel = 2);
    6666
    6767// creates a 160x100 thumbnail for 320x200 games
    6868// and 160x120 thumbnail for 320x240 and 640x480 games
  • graphics/colormasks.h

     
    172172template<>
    173173struct ColorMasks<888> {
    174174        enum {
     175                highBits    = 0x00FEFEFE,
     176                lowBits     = 0x00010101,
     177                qhighBits   = 0x00FCFCFC,
     178                qlowBits    = 0x00030303,
    175179                kBytesPerPixel = 4,
    176180
    177181                kAlphaBits  = 0,
     
    196200template<>
    197201struct ColorMasks<8888> {
    198202        enum {
     203                highBits    = 0xFEFEFEFE,
     204                lowBits     = 0x01010101,
     205                qhighBits   = 0xFCFCFCFC,
     206                qlowBits    = 0x03030303,
    199207                kBytesPerPixel = 4,
    200208
    201209                kAlphaBits  = 8,
  • graphics/scaler/intern.h

     
    4646static inline uint32 interpolate32_1_1(uint32 A, uint32 B) {
    4747        return (((A & highBits) >> 1) + ((B & highBits) >> 1) + (A & B & lowBits));
    4848}
     49/**
     50 * Interpolate two 32 bit pixels with equal weights 1.
     51 */
     52template<>
     53static inline uint32 interpolate32_1_1<8888>(uint32 A, uint32 B) {
     54        return ((A & 0xFEFEFEFE) >> 1) + ((B & 0xFEFEFEFE) >> 1) + (A & B & 0x01010101);
     55}
    4956
    5057/**
    5158 * Interpolate two 16 bit pixel *pairs* at once with weights 3 resp. 1.
     
    6067        y &= qlowBits;
    6168        return x + y;
    6269}
     70/**
     71 * Interpolate two 32 bit pixels with weights 3 resp. 1.
     72 */
     73template<>
     74static inline uint32 interpolate32_3_1<8888>(uint32 A, uint32 B) {
     75        register uint32 x = ((A & 0xFCFCFCFC) >> 2) * 3 + ((B & 0xFCFCFCFC) >> 2);
     76        register uint32 y = ((A & 0x03030303) * 3 + (B & 0x03030303)) >> 2;
    6377
     78        y &= 0x03030303;
     79        return x + y;
     80}
     81
     82
    6483/**
    6584 * Interpolate four 16 bit pixel pairs at once with equal weights 1.
    6685 * In particular, A and B can contain two pixels/each in the upper
     
    7493        y &= qlowBits;
    7594        return x + y;
    7695}
     96/**
     97 * Interpolate four 32 bit pixels with equal weights 1.
     98 */
     99template<>
     100static inline uint32 interpolate32_1_1_1_1<8888>(uint32 A, uint32 B, uint32 C, uint32 D) {
     101        register uint32 x = ((A & 0xFCFCFCFC) >> 2) + ((B & 0xFCFCFCFC) >> 2) +
     102                ((C & 0xFCFCFCFC) >> 2) + ((D & 0xFCFCFCFC) >> 2);
     103        register uint32 y = ((A & 0x03030303) + (B & 0x03030303) +
     104                        (C & 0x03030303) + (D & 0x03030303)) >> 2;
    77105
     106        y &= 0x03030303;
     107        return x + y;
     108}
    78109
     110
    79111/**
    80112 * Interpolate two 16 bit pixels with the weights specified in the template
    81113 * parameters. Used by the hq scaler family.
    82114 * @note w1 and w2 must sum up to 2, 4, 8 or 16.
    83115 */
    84116template<int bitFormat, int w1, int w2>
    85 static inline uint16 interpolate16_2(uint16 p1, uint16 p2) {
     117static inline uint32 interpolate16_2(uint32 p1, uint32 p2) {
    86118        return ((((p1 & redblueMask) * w1 + (p2 & redblueMask) * w2) / (w1 + w2)) & redblueMask) |
    87119               ((((p1 & greenMask) * w1 + (p2 & greenMask) * w2) / (w1 + w2)) & greenMask);
    88120}
     121/**
     122 * Interpolate two 32 bit pixels with the weights specified in the template
     123 * parameters. Used by the hq scaler family.
     124 * @note w1 and w2 must sum up to 2, 4, 8 or 16.
     125 */
     126template<>
     127static inline uint32 interpolate16_2<8888, 1, 1>(uint32 p1, uint32 p2) {
     128        return ((((p1 & 0xFF00FF) * 1 + (p2 & 0xFF00FF) * 1) / (1 + 1)) & 0xFF00FF) |
     129               ((((p1 & 0x00FF00) * 1 + (p2 & 0x00FF00) * 1) / (1 + 1)) & 0x00FF00);
     130}
     131template<>
     132static inline uint32 interpolate16_2<8888, 3, 1>(uint32 p1, uint32 p2) {
     133        return ((((p1 & 0xFF00FF) * 3 + (p2 & 0xFF00FF) * 1) / (3 + 1)) & 0xFF00FF) |
     134               ((((p1 & 0x00FF00) * 3 + (p2 & 0x00FF00) * 1) / (3 + 1)) & 0x00FF00);
     135}
    89136
     137
    90138/**
    91139 * Interpolate three 16 bit pixels with the weights specified in the template
    92140 * parameters. Used by the hq scaler family.
    93141 * @note w1, w2 and w3 must sum up to 2, 4, 8 or 16.
    94142 */
    95143template<int bitFormat, int w1, int w2, int w3>
    96 static inline uint16 interpolate16_3(uint16 p1, uint16 p2, uint16 p3) {
     144static inline uint32 interpolate16_3(uint32 p1, uint32 p2, uint32 p3) {
    97145        return ((((p1 & redblueMask) * w1 + (p2 & redblueMask) * w2 + (p3 & redblueMask) * w3) / (w1 + w2 + w3)) & redblueMask) |
    98146                   ((((p1 & greenMask) * w1 + (p2 & greenMask) * w2 + (p3 & greenMask) * w3) / (w1 + w2 + w3)) & greenMask);
    99147}
     148/**
     149 * Interpolate three 32 bit pixels with the weights specified in the template
     150 * parameters. Used by the hq scaler family.
     151 */
     152template<>
     153static inline uint32 interpolate16_3<8888, 6, 1, 1>(uint32 p1, uint32 p2, uint32 p3) {
     154        return ((((p1 & 0xFF00FF) * 6 + (p2 & 0xFF00FF) * 1 + (p3 & 0xFF00FF) * 1) / (6 + 1 + 1)) & 0xFF00FF) |
     155                   ((((p1 & 0x00FF00) * 6 + (p2 & 0x00FF00) * 1 + (p3 & 0x00FF00) * 1) / (6 + 1 + 1)) & 0x00FF00);
     156}
    100157
    101158
    102159/**
     
    146203
    147204/** Auxiliary macro to simplify creating those template function wrappers. */
    148205#define MAKE_WRAPPER(FUNC) \
    149         void FUNC(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { \
    150                 if (gBitFormat == 565) \
    151                         FUNC ## Template<565>(srcPtr, srcPitch, dstPtr, dstPitch, width, height); \
     206        void FUNC(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel) { \
     207                if (gBitFormat == 8888) { \
     208                        if (bytesPerPixel == 4) \
     209                                FUNC ## Template<8888>((uint32*) srcPtr, srcPitch, (uint32*) dstPtr, dstPitch, width, height); \
     210                        else \
     211                                FUNC ## Template<565>((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height); \
     212                } \
     213                else if (gBitFormat == 565) \
     214                        FUNC ## Template<565>((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height); \
    152215                else \
    153                         FUNC ## Template<555>(srcPtr, srcPitch, dstPtr, dstPitch, width, height); \
     216                        FUNC ## Template<555>((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height); \
    154217        }
    155218
    156 /** Specifies the currently active 16bit pixel format, 555 or 565. */
     219
     220/** Specifies the currently active pixel format, 555, 565 or 8888. */
    157221extern int gBitFormat;
    158222
    159223#endif
  • graphics/scaler/aspect.cpp

     
    3434
    3535#if ASPECT_MODE == kSlowAndPerfectAspectMode
    3636
    37 template<int bitFormat, int scale>
    38 static inline uint16 interpolate5(uint16 A, uint16 B) {
    39         uint16 r = (uint16)(((A & redblueMask & 0xFF00) * scale + (B & redblueMask & 0xFF00) * (5 - scale)) / 5);
    40         uint16 g = (uint16)(((A & greenMask) * scale + (B & greenMask) * (5 - scale)) / 5);
    41         uint16 b = (uint16)(((A & redblueMask & 0x00FF) * scale + (B & redblueMask & 0x00FF) * (5 - scale)) / 5);
     37template<int bitFormat, int scale, typename T>
     38static inline T interpolate5(T A, T B) {
     39        T r = (T)(((A & redblueMask & 0xFF00) * scale + (B & redblueMask & 0xFF00) * (5 - scale)) / 5);
     40        T g = (T)(((A & greenMask) * scale + (B & greenMask) * (5 - scale)) / 5);
     41        T b = (T)(((A & redblueMask & 0x00FF) * scale + (B & redblueMask & 0x00FF) * (5 - scale)) / 5);
    4242
    43         return (uint16)((r & redblueMask & 0xFF00) | (g & greenMask) | (b & redblueMask & 0x00FF));
     43        return (T)((r & redblueMask & 0xFF00) | (g & greenMask) | (b & redblueMask & 0x00FF));
    4444}
     45template<>
     46static inline uint32 interpolate5<8888, 1>(uint32 A, uint32 B) {
     47        uint32 r = (uint32)(((A & 0xFF00FF & 0xFFFF0000) * 1 + (B & 0xFF00FF & 0xFFFF0000) * (5 - 1)) / 5);
     48        uint32 g = (uint32)(((A & 0x00FF00) * 1 + (B & 0x00FF00) * (5 - 1)) / 5);
     49        uint32 b = (uint32)(((A & 0xFF00FF & 0x0000FFFF) * 1 + (B & 0xFF00FF & 0x0000FFFF) * (5 - 1)) / 5);
    4550
     51        return (uint32)((r & 0xFF00FF & 0xFFFF0000) | (g & 0x00FF00) | (b & 0xFF00FF & 0x0000FFFF));
     52}
     53template<>
     54static inline uint32 interpolate5<8888, 2>(uint32 A, uint32 B) {
     55        uint32 r = (uint32)(((A & 0xFF00FF & 0xFFFF0000) * 2 + (B & 0xFF00FF & 0xFFFF0000) * (5 - 2)) / 5);
     56        uint32 g = (uint32)(((A & 0x00FF00) * 2 + (B & 0x00FF00) * (5 - 2)) / 5);
     57        uint32 b = (uint32)(((A & 0xFF00FF & 0x0000FFFF) * 2 + (B & 0xFF00FF & 0x0000FFFF) * (5 - 2)) / 5);
    4658
    47 template<int bitFormat, int scale>
    48 static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint16 *srcB, int width) {
     59        return (uint32)((r & 0xFF00FF & 0xFFFF0000) | (g & 0x00FF00) | (b & 0xFF00FF & 0x0000FFFF));
     60}
     61
     62
     63template<int bitFormat, int scale, typename T>
     64static inline void interpolate5Line(T *dst, const T *srcA, const T *srcB, int width) {
    4965        // Accurate but slightly slower code
    5066        while (width--) {
    5167                *dst++ = interpolate5<bitFormat, scale>(*srcA++, *srcB++);
     
    5571
    5672#if ASPECT_MODE == kFastAndNiceAspectMode
    5773
    58 template<int bitFormat, int scale>
    59 static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint16 *srcB, int width) {
     74template<int bitFormat, int scale, typename T>
     75static inline void interpolate5Line(T *dst, const T *srcA, const T *srcB, int width) {
    6076        // For efficiency reasons we blit two pixels at a time, so it is important
    6177        // that makeRectStretchable() guarantees that the width is even and that
    6278        // the rect starts on a well-aligned address. (Even where unaligned memory
     
    84100                }
    85101        }
    86102}
     103template<>
     104static inline void interpolate5Line<8888, 1>(uint32 *dst, const uint32 *srcA, const uint32 *srcB, int width) {
     105        while (width--)
     106                *dst++ = interpolate32_3_1<8888>(*srcB++, *srcA++);
     107}
     108template<>
     109static inline void interpolate5Line<8888, 2>(uint32 *dst, const uint32 *srcA, const uint32 *srcB, int width) {
     110        while (width--)
     111                *dst++ = interpolate32_1_1<8888>(*srcB++, *srcA++);
     112}
    87113#endif
    88114
    89115void makeRectStretchable(int &x, int &y, int &w, int &h) {
     
    131157 * srcY + height - 1, and it should be stretched to Y coordinates srcY
    132158 * through real2Aspect(srcY + height - 1).
    133159 */
    134 template<int bitFormat>
    135 int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) {
     160template<int bitFormat, typename T>
     161int stretch200To240(T *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) {
     162        pitch /= sizeof(T);
     163
    136164        int maxDstY = real2Aspect(origSrcY + height - 1);
    137165        int y;
    138         const uint8 *startSrcPtr = buf + srcX * 2 + (srcY - origSrcY) * pitch;
    139         uint8 *dstPtr = buf + srcX * 2 + maxDstY * pitch;
     166        const T *startSrcPtr = buf + srcX + (srcY - origSrcY) * pitch;
     167        T *dstPtr = buf + srcX + maxDstY * pitch;
    140168
    141169        for (y = maxDstY; y >= srcY; y--) {
    142                 const uint8 *srcPtr = startSrcPtr + aspect2Real(y) * pitch;
     170                const T *srcPtr = startSrcPtr + aspect2Real(y) * pitch;
    143171
    144172#if ASPECT_MODE == kVeryFastAndUglyAspectMode
    145173                if (srcPtr == dstPtr)
    146174                        break;
    147                 memcpy(dstPtr, srcPtr, width * 2);
     175                memcpy(dstPtr, srcPtr, width * sizeof(T));
    148176#else
    149177                // Bilinear filter
    150178                switch (y % 6) {
    151179                case 0:
    152180                case 5:
    153181                        if (srcPtr != dstPtr)
    154                                 memcpy(dstPtr, srcPtr, width * 2);
     182                                memcpy(dstPtr, srcPtr, width * sizeof(T));
    155183                        break;
    156184                case 1:
    157                         interpolate5Line<bitFormat, 1>((uint16 *)dstPtr, (const uint16 *)(srcPtr - pitch), (const uint16 *)srcPtr, width);
     185                        interpolate5Line<bitFormat, 1>(dstPtr, srcPtr - pitch, srcPtr, width);
    158186                        break;
    159187                case 2:
    160                         interpolate5Line<bitFormat, 2>((uint16 *)dstPtr, (const uint16 *)(srcPtr - pitch), (const uint16 *)srcPtr, width);
     188                        interpolate5Line<bitFormat, 2>(dstPtr, srcPtr - pitch, srcPtr, width);
    161189                        break;
    162190                case 3:
    163                         interpolate5Line<bitFormat, 2>((uint16 *)dstPtr, (const uint16 *)srcPtr, (const uint16 *)(srcPtr - pitch), width);
     191                        interpolate5Line<bitFormat, 2>(dstPtr, srcPtr, srcPtr - pitch, width);
    164192                        break;
    165193                case 4:
    166                         interpolate5Line<bitFormat, 1>((uint16 *)dstPtr, (const uint16 *)srcPtr, (const uint16 *)(srcPtr - pitch), width);
     194                        interpolate5Line<bitFormat, 1>(dstPtr, srcPtr, srcPtr - pitch, width);
    167195                        break;
    168196                }
    169197#endif
     
    173201        return 1 + maxDstY - srcY;
    174202}
    175203
    176 int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) {
    177         if (gBitFormat == 565)
    178                 return stretch200To240<565>(buf, pitch, width, height, srcX, srcY, origSrcY);
     204int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY, uint8 bytesPerPixel) {
     205        if (gBitFormat == 8888) {
     206                if (bytesPerPixel == 4)
     207                        return stretch200To240<8888>((uint32*) buf, pitch, width, height, srcX, srcY, origSrcY);
     208                else
     209                        return stretch200To240<565>((uint16*) buf, pitch, width, height, srcX, srcY, origSrcY);
     210        }
     211        else if (gBitFormat == 565)
     212                return stretch200To240<565>((uint16*) buf, pitch, width, height, srcX, srcY, origSrcY);
    179213        else // gBitFormat == 555
    180                 return stretch200To240<555>(buf, pitch, width, height, srcX, srcY, origSrcY);
     214                return stretch200To240<555>((uint16*) buf, pitch, width, height, srcX, srcY, origSrcY);
    181215}
    182216
  • graphics/scaler/hq2x.cpp

     
    3636
    3737}
    3838
    39 void HQ2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
     39void HQ2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel) {
    4040        hq2x_16(srcPtr, dstPtr, width, height, srcPitch, dstPitch);
    4141}
    4242
     
    110110#undef bitFormat
    111111
    112112
    113 void HQ2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
     113void HQ2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel) {
    114114        if (gBitFormat == 565)
    115115                HQ2x_565(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
    116116        else
  • graphics/scaler/hq3x.cpp

     
    3737
    3838}
    3939
    40 void HQ3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
     40void HQ3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel) {
    4141        hq3x_16(srcPtr, dstPtr, width, height, srcPitch, dstPitch);
    4242}
    4343
     
    113113#undef bitFormat
    114114
    115115
    116 void HQ3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
     116void HQ3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel) {
    117117        if (gBitFormat == 565)
    118118                HQ3x_565(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
    119119        else
  • graphics/scaler/2xsai.cpp

     
    4949#define interpolate_6_1_1       interpolate16_3<bitFormat, 6, 1, 1>
    5050#define interpolate_1_1_1_1     interpolate32_1_1_1_1<bitFormat>
    5151
    52 template<int bitFormat>
    53 void Super2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
    54         const uint16 *bP;
    55         uint16 *dP;
    56         const uint32 nextlineSrc = srcPitch >> 1;
     52template<int bitFormat, typename T>
     53void Super2xSaITemplate(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch, int width, int height) {
     54        const T *bP;
     55        T *dP;
    5756
     57        dstPitch /= sizeof(T);
     58        srcPitch /= sizeof(T);
     59
    5860        while (height--) {
    59                 bP = (const uint16 *)srcPtr;
    60                 dP = (uint16 *)dstPtr;
     61                bP = (const T *)srcPtr;
     62                dP = (T *)dstPtr;
    6163
    6264                for (int i = 0; i < width; ++i) {
    6365                        uint32 color4, color5, color6;
     
    7274//                                         1  2  3 S1
    7375//                                           A1 A2
    7476
    75                         colorB0 = *(bP - nextlineSrc - 1);
    76                         colorB1 = *(bP - nextlineSrc);
    77                         colorB2 = *(bP - nextlineSrc + 1);
    78                         colorB3 = *(bP - nextlineSrc + 2);
     77                        colorB0 = *(bP - srcPitch - 1);
     78                        colorB1 = *(bP - srcPitch);
     79                        colorB2 = *(bP - srcPitch + 1);
     80                        colorB3 = *(bP - srcPitch + 2);
    7981
    8082                        color4 = *(bP - 1);
    8183                        color5 = *(bP);
    8284                        color6 = *(bP + 1);
    8385                        colorS2 = *(bP + 2);
    8486
    85                         color1 = *(bP + nextlineSrc - 1);
    86                         color2 = *(bP + nextlineSrc);
    87                         color3 = *(bP + nextlineSrc + 1);
    88                         colorS1 = *(bP + nextlineSrc + 2);
     87                        color1 = *(bP + srcPitch - 1);
     88                        color2 = *(bP + srcPitch);
     89                        color3 = *(bP + srcPitch + 1);
     90                        colorS1 = *(bP + srcPitch + 2);
    8991
    90                         colorA0 = *(bP + 2 * nextlineSrc - 1);
    91                         colorA1 = *(bP + 2 * nextlineSrc);
    92                         colorA2 = *(bP + 2 * nextlineSrc + 1);
    93                         colorA3 = *(bP + 2 * nextlineSrc + 2);
     92                        colorA0 = *(bP + 2 * srcPitch - 1);
     93                        colorA1 = *(bP + 2 * srcPitch);
     94                        colorA2 = *(bP + 2 * srcPitch + 1);
     95                        colorA3 = *(bP + 2 * srcPitch + 2);
    9496
    9597//--------------------------------------
    9698                        if (color2 == color6 && color5 != color3) {
     
    142144                        else
    143145                                product1a = color5;
    144146
    145                         *(dP + 0) = (uint16) product1a;
    146                         *(dP + 1) = (uint16) product1b;
    147                         *(dP + dstPitch/2 + 0) = (uint16) product2a;
    148                         *(dP + dstPitch/2 + 1) = (uint16) product2b;
     147                        *(dP + 0) = (T) product1a;
     148                        *(dP + 1) = (T) product1b;
     149                        *(dP + dstPitch + 0) = (T) product2a;
     150                        *(dP + dstPitch + 1) = (T) product2b;
    149151
    150152                        bP += 1;
    151153                        dP += 2;
     
    158160
    159161MAKE_WRAPPER(Super2xSaI)
    160162
    161 template<int bitFormat>
    162 void SuperEagleTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
    163         const uint16 *bP;
    164         uint16 *dP;
    165         const uint32 nextlineSrc = srcPitch >> 1;
     163template<int bitFormat, typename T>
     164void SuperEagleTemplate(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch, int width, int height) {
     165        const T *bP;
     166        T *dP;
    166167
     168        dstPitch /= sizeof(T);
     169        srcPitch /= sizeof(T);
     170
    167171        while (height--) {
    168                 bP = (const uint16 *)srcPtr;
    169                 dP = (uint16 *)dstPtr;
     172                bP = (const T *)srcPtr;
     173                dP = (T *)dstPtr;
    170174                for (int i = 0; i < width; ++i) {
    171175                        uint32 color4, color5, color6;
    172176                        uint32 color1, color2, color3;
    173177                        uint32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2;
    174178                        uint32 product1a, product1b, product2a, product2b;
    175179
    176                         colorB1 = *(bP - nextlineSrc);
    177                         colorB2 = *(bP - nextlineSrc + 1);
     180                        colorB1 = *(bP - srcPitch);
     181                        colorB2 = *(bP - srcPitch + 1);
    178182
    179183                        color4 = *(bP - 1);
    180184                        color5 = *(bP);
    181185                        color6 = *(bP + 1);
    182186                        colorS2 = *(bP + 2);
    183187
    184                         color1 = *(bP + nextlineSrc - 1);
    185                         color2 = *(bP + nextlineSrc);
    186                         color3 = *(bP + nextlineSrc + 1);
    187                         colorS1 = *(bP + nextlineSrc + 2);
     188                        color1 = *(bP + srcPitch - 1);
     189                        color2 = *(bP + srcPitch);
     190                        color3 = *(bP + srcPitch + 1);
     191                        colorS1 = *(bP + srcPitch + 2);
    188192
    189                         colorA1 = *(bP + 2 * nextlineSrc);
    190                         colorA2 = *(bP + 2 * nextlineSrc + 1);
     193                        colorA1 = *(bP + 2 * srcPitch);
     194                        colorA2 = *(bP + 2 * srcPitch + 1);
    191195
    192196                        // --------------------------------------
    193197                        if (color5 != color3) {
     
    247251                                }
    248252                        }
    249253
    250                         *(dP + 0) = (uint16) product1a;
    251                         *(dP + 1) = (uint16) product1b;
    252                         *(dP + dstPitch/2 + 0) = (uint16) product2a;
    253                         *(dP + dstPitch/2 + 1) = (uint16) product2b;
     254                        *(dP + 0) = (T) product1a;
     255                        *(dP + 1) = (T) product1b;
     256                        *(dP + dstPitch + 0) = (T) product2a;
     257                        *(dP + dstPitch + 1) = (T) product2b;
    254258
    255259                        bP += 1;
    256260                        dP += 2;
     
    263267
    264268MAKE_WRAPPER(SuperEagle)
    265269
    266 template<int bitFormat>
    267 void _2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
    268         const uint16 *bP;
    269         uint16 *dP;
    270         const uint32 nextlineSrc = srcPitch >> 1;
     270template<int bitFormat, typename T>
     271void _2xSaITemplate(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch, int width, int height) {
     272        const T *bP;
     273        T *dP;
    271274
     275        dstPitch /= sizeof(T);
     276        srcPitch /= sizeof(T);
     277
    272278        while (height--) {
    273                 bP = (const uint16 *)srcPtr;
    274                 dP = (uint16 *)dstPtr;
     279                bP = (const T *)srcPtr;
     280                dP = (T *)dstPtr;
    275281
    276282                for (int i = 0; i < width; ++i) {
    277283
     
    285291//                                       G|A B|K
    286292//                                       H|C D|L
    287293//                                       M|N O|P
    288                         colorI = *(bP - nextlineSrc - 1);
    289                         colorE = *(bP - nextlineSrc);
    290                         colorF = *(bP - nextlineSrc + 1);
    291                         colorJ = *(bP - nextlineSrc + 2);
     294                        colorI = *(bP - srcPitch - 1);
     295                        colorE = *(bP - srcPitch);
     296                        colorF = *(bP - srcPitch + 1);
     297                        colorJ = *(bP - srcPitch + 2);
    292298
    293299                        colorG = *(bP - 1);
    294300                        colorA = *(bP);
    295301                        colorB = *(bP + 1);
    296302                        colorK = *(bP + 2);
    297303
    298                         colorH = *(bP + nextlineSrc - 1);
    299                         colorC = *(bP + nextlineSrc);
    300                         colorD = *(bP + nextlineSrc + 1);
    301                         colorL = *(bP + nextlineSrc + 2);
     304                        colorH = *(bP + srcPitch - 1);
     305                        colorC = *(bP + srcPitch);
     306                        colorD = *(bP + srcPitch + 1);
     307                        colorL = *(bP + srcPitch + 2);
    302308
    303                         colorM = *(bP + 2 * nextlineSrc - 1);
    304                         colorN = *(bP + 2 * nextlineSrc);
    305                         colorO = *(bP + 2 * nextlineSrc + 1);
    306                         colorP = *(bP + 2 * nextlineSrc + 2);
     309                        colorM = *(bP + 2 * srcPitch - 1);
     310                        colorN = *(bP + 2 * srcPitch);
     311                        colorO = *(bP + 2 * srcPitch + 1);
     312                        colorP = *(bP + 2 * srcPitch + 2);
    307313
    308314                        if ((colorA == colorD) && (colorB != colorC)) {
    309315                                if (((colorA == colorE) && (colorB == colorL)) ||
     
    383389                                }
    384390                        }
    385391
    386                         *(dP + 0) = (uint16) colorA;
    387                         *(dP + 1) = (uint16) product;
    388                         *(dP + dstPitch/2 + 0) = (uint16) product1;
    389                         *(dP + dstPitch/2 + 1) = (uint16) product2;
     392                        *(dP + 0) = (T) colorA;
     393                        *(dP + 1) = (T) product;
     394                        *(dP + dstPitch + 0) = (T) product1;
     395                        *(dP + dstPitch + 1) = (T) product2;
    390396
    391397                        bP += 1;
    392398                        dP += 2;