Ticket #8934: pixelformat_v1.patch

File pixelformat_v1.patch, 8.3 KB (added by lordhoto, 15 years ago)

Patch against r34871.

  • common/system.h

     
    3131#include "common/noncopyable.h"
    3232#include "common/rect.h"
    3333
     34#include "graphics/colormasks.h"
     35
    3436namespace Audio {
    3537        class Mixer;
    3638}
     
    571573        virtual void hideOverlay() = 0;
    572574
    573575        /**
     576         * Returns the pixel format description of the overlay.
     577         * @see Graphics::PixelFormat
     578         */
     579        virtual Graphics::PixelFormat getOverlayFormat() const = 0;
     580
     581        /**
    574582         * Reset the overlay.
    575583         *
    576584         * After calling this method while the overlay mode is active, the user
  • common/system.cpp

     
    6262}
    6363
    6464OverlayColor OSystem::RGBToColor(uint8 r, uint8 g, uint8 b) {
    65         return ::RGBToColor<ColorMasks<565> >(r, g, b);
     65        return Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
    6666}
    6767
    6868void OSystem::colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b) {
    69         ::colorToRGB<ColorMasks<565> >(color, r, g, b);
     69        Graphics::colorToRGB<Graphics::ColorMasks<565> >(color, r, g, b);
    7070}
    7171
    7272OverlayColor OSystem::ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b) {
  • graphics/scaler.cpp

     
    105105        gBitFormat = BitFormat;
    106106#ifndef DISABLE_HQ_SCALERS
    107107        if (gBitFormat == 555)
    108                 InitLUT<ColorMasks<555> >();
     108                InitLUT<Graphics::ColorMasks<555> >();
    109109        if (gBitFormat == 565)
    110                 InitLUT<ColorMasks<565> >();
     110                InitLUT<Graphics::ColorMasks<565> >();
    111111#endif
    112112}
    113113
  • graphics/scaler/thumbnail_intern.cpp

     
    118118                        g = palette[((uint8*)screen->pixels)[y * screen->pitch + x] * 4 + 1];
    119119                        b = palette[((uint8*)screen->pixels)[y * screen->pitch + x] * 4 + 2];
    120120
    121                         ((uint16*)surf->pixels)[y * surf->w + x] = RGBToColor<ColorMasks<565> >(r, g, b);
     121                        ((uint16*)surf->pixels)[y * surf->w + x] = Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
    122122                }
    123123        }
    124124
     
    209209                        g = palette[pixels[y * w + x] * 3 + 1];
    210210                        b = palette[pixels[y * w + x] * 3 + 2];
    211211
    212                         ((uint16 *)screen.pixels)[y * screen.w + x] = RGBToColor<ColorMasks<565> >(r, g, b);
     212                        ((uint16 *)screen.pixels)[y * screen.w + x] = Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
    213213                }
    214214        }
    215215
  • graphics/scaler/intern.h

     
    3030#include "graphics/colormasks.h"
    3131
    3232
    33 #define highBits        ColorMasks<bitFormat>::highBits
    34 #define lowBits         ColorMasks<bitFormat>::lowBits
    35 #define qhighBits       ColorMasks<bitFormat>::qhighBits
    36 #define qlowBits        ColorMasks<bitFormat>::qlowBits
    37 #define redblueMask     ColorMasks<bitFormat>::kRedBlueMask
    38 #define greenMask       ColorMasks<bitFormat>::kGreenMask
     33#define highBits        Graphics::ColorMasks<bitFormat>::highBits
     34#define lowBits         Graphics::ColorMasks<bitFormat>::lowBits
     35#define qhighBits       Graphics::ColorMasks<bitFormat>::qhighBits
     36#define qlowBits        Graphics::ColorMasks<bitFormat>::qlowBits
     37#define redblueMask     Graphics::ColorMasks<bitFormat>::kRedBlueMask
     38#define greenMask       Graphics::ColorMasks<bitFormat>::kGreenMask
    3939
    4040
    4141/**
  • graphics/colormasks.h

     
    2626#ifndef GRAPHICS_COLORMASKS_H
    2727#define GRAPHICS_COLORMASKS_H
    2828
     29namespace Graphics {
     30
    2931template<int bitFormat>
    3032struct ColorMasks {
    3133};
     
    251253        b = ((color & T::kBlueMask) >> T::kBlueShift) << (8 - T::kBlueBits);
    252254}
    253255
     256/**
     257 * A pixel format description.
     258 *
     259 * Like ColorMasks it includes the given values to create colors from RGB
     260 * values and to retrieve RGB values from colors.
     261 *
     262 * Unlike ColorMasks it is not dependend on knowing the exact pixel format
     263 * on compile time.
     264 *
     265 * A minor difference between ColorMasks and PixelFormat is that ColorMasks
     266 * stores the bit count per channel in 'kFooBits', while PixelFormat stores
     267 * the loss compared to 8 bits per channel in '#Loss'.
     268 */
     269struct PixelFormat {
     270        PixelFormat() {}
     271
     272        template<class Mask>
     273        PixelFormat() {
     274                bytesPerPixel = Mask::kBytesPerPixel;
     275
     276                rLoss = 8 - Mask::kRedBits;
     277                gLoss = 8 - Mask::kGreenBits;
     278                bLoss = 8 - Mask::kBlueBits;
     279                aLoss = 8 - Mask::kAlphaBits;
     280
     281                rShift = Mask::kRedShift;
     282                gShift = Mask::kGreenShift;
     283                bShift = Mask::kBlueShift;
     284                aShift = Mask::kAlphaShift;
     285
     286                rMask = Mask::kRedMask;
     287                gMask = Mask::kGreenMask;
     288                bMask = Mask::kBlueMask;
     289                aMask = Mask::kAlphaMask;
     290        }
     291
     292        byte bytesPerPixel; /**< Number of bytes used in the pixel format. */
     293
     294        byte rLoss, gLoss, bLoss, aLoss; /**< Precision loss of each color component. */
     295        byte rShift, gShift, bShift, aShift; /**< Binary left shift of each color component in the pixel value. */
     296
     297        uint32 rMask, gMask, bMask, aMask; /**< Binary mask used to retrieve individual color values. */
     298};
     299
     300inline uint32 RGBToColor(uint8 r, uint8 g, uint8 b, const PixelFormat &fmt) {
     301        return fmt.aMask |
     302                (((r >> fmt.rLoss) << fmt.rShift) & fmt.rMask) |
     303                (((g >> fmt.gLoss) << fmt.gShift) & fmt.gMask) |
     304                (((b >> fmt.bLoss) << fmt.bShift) & fmt.bMask);
     305}
     306
     307inline uint32 ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b, const PixelFormat &fmt) {
     308        return
     309                (((a >> fmt.aLoss) << fmt.aShift) & fmt.aMask) |
     310                (((r >> fmt.rLoss) << fmt.rShift) & fmt.rMask) |
     311                (((g >> fmt.gLoss) << fmt.gShift) & fmt.gMask) |
     312                (((b >> fmt.bLoss) << fmt.bShift) & fmt.bMask);
     313}
     314
     315inline void colorToRGB(uint32 color, uint8 &r, uint8 &g, uint8 &b, const PixelFormat &fmt) {
     316        r = ((color & fmt.rMask) >> fmt.rShift) << fmt.rLoss;
     317        g = ((color & fmt.gMask) >> fmt.gShift) << fmt.gLoss;
     318        b = ((color & fmt.bMask) >> fmt.bShift) << fmt.bLoss;
     319}
     320
     321inline void colorToARGB(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b, const PixelFormat &fmt) {
     322        a = ((color & fmt.aMask) >> fmt.aShift) << fmt.aLoss;
     323        r = ((color & fmt.rMask) >> fmt.rShift) << fmt.rLoss;
     324        g = ((color & fmt.gMask) >> fmt.gShift) << fmt.gLoss;
     325        b = ((color & fmt.bMask) >> fmt.bShift) << fmt.bLoss;
     326}
     327
     328} // end of namespace Graphics
     329
    254330#endif
  • backends/platform/sdl/graphics.cpp

     
    396396        if (_overlayscreen == NULL)
    397397                error("allocating _overlayscreen failed");
    398398
     399        _overlayFormat.bytesPerPixel = _overlayscreen->format->BytesPerPixel;
     400
     401        _overlayFormat.rMask = _overlayscreen->format->Rmask;
     402        _overlayFormat.gMask = _overlayscreen->format->Gmask;
     403        _overlayFormat.bMask = _overlayscreen->format->Bmask;
     404        _overlayFormat.aMask = _overlayscreen->format->Amask;
     405
     406        _overlayFormat.rLoss = _overlayscreen->format->Rloss;
     407        _overlayFormat.gLoss = _overlayscreen->format->Gloss;
     408        _overlayFormat.bLoss = _overlayscreen->format->Bloss;
     409        _overlayFormat.aLoss = _overlayscreen->format->Aloss;
     410
     411        _overlayFormat.rShift = _overlayscreen->format->Rshift;
     412        _overlayFormat.gShift = _overlayscreen->format->Gshift;
     413        _overlayFormat.bShift = _overlayscreen->format->Bshift;
     414        _overlayFormat.aShift = _overlayscreen->format->Ashift;
     415
    399416        _tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth + 3, _overlayHeight + 3,
    400417                                                16,
    401418                                                _hwscreen->format->Rmask,
  • backends/platform/sdl/sdl.h

     
    176176        void deleteMutex(MutexRef mutex);
    177177
    178178        // Overlay
     179        virtual Graphics::PixelFormat getOverlayFormat() const { return _overlayFormat; }
    179180        virtual void showOverlay();
    180181        virtual void hideOverlay();
    181182        virtual void clearOverlay();
     
    246247        SDL_Surface *_overlayscreen;
    247248        int _overlayWidth, _overlayHeight;
    248249        bool _overlayVisible;
     250        Graphics::PixelFormat _overlayFormat;
    249251
    250252        // Audio
    251253        int _samplesPerSec;