Committed my patch #2216641 "GRAPHICS: PixelFormat introduction".
svn-id: r34875
This commit is contained in:
parent
d0c9b0cb23
commit
985c02ee7d
8 changed files with 108 additions and 12 deletions
|
@ -396,6 +396,18 @@ void OSystem_SDL::loadGFXMode() {
|
||||||
if (_overlayscreen == NULL)
|
if (_overlayscreen == NULL)
|
||||||
error("allocating _overlayscreen failed");
|
error("allocating _overlayscreen failed");
|
||||||
|
|
||||||
|
_overlayFormat.bytesPerPixel = _overlayscreen->format->BytesPerPixel;
|
||||||
|
|
||||||
|
_overlayFormat.rLoss = _overlayscreen->format->Rloss;
|
||||||
|
_overlayFormat.gLoss = _overlayscreen->format->Gloss;
|
||||||
|
_overlayFormat.bLoss = _overlayscreen->format->Bloss;
|
||||||
|
_overlayFormat.aLoss = _overlayscreen->format->Aloss;
|
||||||
|
|
||||||
|
_overlayFormat.rShift = _overlayscreen->format->Rshift;
|
||||||
|
_overlayFormat.gShift = _overlayscreen->format->Gshift;
|
||||||
|
_overlayFormat.bShift = _overlayscreen->format->Bshift;
|
||||||
|
_overlayFormat.aShift = _overlayscreen->format->Ashift;
|
||||||
|
|
||||||
_tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth + 3, _overlayHeight + 3,
|
_tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth + 3, _overlayHeight + 3,
|
||||||
16,
|
16,
|
||||||
_hwscreen->format->Rmask,
|
_hwscreen->format->Rmask,
|
||||||
|
|
|
@ -176,6 +176,7 @@ public:
|
||||||
void deleteMutex(MutexRef mutex);
|
void deleteMutex(MutexRef mutex);
|
||||||
|
|
||||||
// Overlay
|
// Overlay
|
||||||
|
virtual Graphics::PixelFormat getOverlayFormat() const { return _overlayFormat; }
|
||||||
virtual void showOverlay();
|
virtual void showOverlay();
|
||||||
virtual void hideOverlay();
|
virtual void hideOverlay();
|
||||||
virtual void clearOverlay();
|
virtual void clearOverlay();
|
||||||
|
@ -246,6 +247,7 @@ protected:
|
||||||
SDL_Surface *_overlayscreen;
|
SDL_Surface *_overlayscreen;
|
||||||
int _overlayWidth, _overlayHeight;
|
int _overlayWidth, _overlayHeight;
|
||||||
bool _overlayVisible;
|
bool _overlayVisible;
|
||||||
|
Graphics::PixelFormat _overlayFormat;
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
int _samplesPerSec;
|
int _samplesPerSec;
|
||||||
|
|
|
@ -62,11 +62,11 @@ bool OSystem::setGraphicsMode(const char *name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
OverlayColor OSystem::RGBToColor(uint8 r, uint8 g, uint8 b) {
|
OverlayColor OSystem::RGBToColor(uint8 r, uint8 g, uint8 b) {
|
||||||
return ::RGBToColor<ColorMasks<565> >(r, g, b);
|
return Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSystem::colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b) {
|
void OSystem::colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b) {
|
||||||
::colorToRGB<ColorMasks<565> >(color, r, g, b);
|
Graphics::colorToRGB<Graphics::ColorMasks<565> >(color, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
OverlayColor OSystem::ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b) {
|
OverlayColor OSystem::ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b) {
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
#include "common/noncopyable.h"
|
#include "common/noncopyable.h"
|
||||||
#include "common/rect.h"
|
#include "common/rect.h"
|
||||||
|
|
||||||
|
#include "graphics/colormasks.h"
|
||||||
|
|
||||||
namespace Audio {
|
namespace Audio {
|
||||||
class Mixer;
|
class Mixer;
|
||||||
}
|
}
|
||||||
|
@ -570,6 +572,12 @@ public:
|
||||||
/** Deactivate the overlay mode. */
|
/** Deactivate the overlay mode. */
|
||||||
virtual void hideOverlay() = 0;
|
virtual void hideOverlay() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the pixel format description of the overlay.
|
||||||
|
* @see Graphics::PixelFormat
|
||||||
|
*/
|
||||||
|
virtual Graphics::PixelFormat getOverlayFormat() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the overlay.
|
* Reset the overlay.
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#ifndef GRAPHICS_COLORMASKS_H
|
#ifndef GRAPHICS_COLORMASKS_H
|
||||||
#define GRAPHICS_COLORMASKS_H
|
#define GRAPHICS_COLORMASKS_H
|
||||||
|
|
||||||
|
namespace Graphics {
|
||||||
|
|
||||||
template<int bitFormat>
|
template<int bitFormat>
|
||||||
struct ColorMasks {
|
struct ColorMasks {
|
||||||
};
|
};
|
||||||
|
@ -251,4 +253,76 @@ void colorToARGB(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b) {
|
||||||
b = ((color & T::kBlueMask) >> T::kBlueShift) << (8 - T::kBlueBits);
|
b = ((color & T::kBlueMask) >> T::kBlueShift) << (8 - T::kBlueBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pixel format description.
|
||||||
|
*
|
||||||
|
* Like ColorMasks it includes the given values to create colors from RGB
|
||||||
|
* values and to retrieve RGB values from colors.
|
||||||
|
*
|
||||||
|
* Unlike ColorMasks it is not dependend on knowing the exact pixel format
|
||||||
|
* on compile time.
|
||||||
|
*
|
||||||
|
* A minor difference between ColorMasks and PixelFormat is that ColorMasks
|
||||||
|
* stores the bit count per channel in 'kFooBits', while PixelFormat stores
|
||||||
|
* the loss compared to 8 bits per channel in '#Loss'.
|
||||||
|
*/
|
||||||
|
struct PixelFormat {
|
||||||
|
byte bytesPerPixel; /**< Number of bytes used in the pixel format. */
|
||||||
|
|
||||||
|
byte rLoss, gLoss, bLoss, aLoss; /**< Precision loss of each color component. */
|
||||||
|
byte rShift, gShift, bShift, aShift; /**< Binary left shift of each color component in the pixel value. */
|
||||||
|
|
||||||
|
uint32 rMask, gMask, bMask, aMask; /**< Binary mask used to retrieve individual color values. */
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class Mask>
|
||||||
|
PixelFormat createPixelFormatFromMask() {
|
||||||
|
PixelFormat format;
|
||||||
|
|
||||||
|
format.bytesPerPixel = Mask::kBytesPerPixel;
|
||||||
|
|
||||||
|
format.rLoss = 8 - Mask::kRedBits;
|
||||||
|
format.gLoss = 8 - Mask::kGreenBits;
|
||||||
|
format.bLoss = 8 - Mask::kBlueBits;
|
||||||
|
format.aLoss = 8 - Mask::kAlphaBits;
|
||||||
|
|
||||||
|
format.rShift = Mask::kRedShift;
|
||||||
|
format.gShift = Mask::kGreenShift;
|
||||||
|
format.bShift = Mask::kBlueShift;
|
||||||
|
format.aShift = Mask::kAlphaShift;
|
||||||
|
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint32 RGBToColor(uint8 r, uint8 g, uint8 b, const PixelFormat &fmt) {
|
||||||
|
return
|
||||||
|
((0xFF >> fmt.aLoss) << fmt.aShift) |
|
||||||
|
(( r >> fmt.rLoss) << fmt.rShift) |
|
||||||
|
(( g >> fmt.gLoss) << fmt.gShift) |
|
||||||
|
(( b >> fmt.bLoss) << fmt.bShift);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint32 ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b, const PixelFormat &fmt) {
|
||||||
|
return
|
||||||
|
((a >> fmt.aLoss) << fmt.aShift) |
|
||||||
|
((r >> fmt.rLoss) << fmt.rShift) |
|
||||||
|
((g >> fmt.gLoss) << fmt.gShift) |
|
||||||
|
((b >> fmt.bLoss) << fmt.bShift);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void colorToRGB(uint32 color, uint8 &r, uint8 &g, uint8 &b, const PixelFormat &fmt) {
|
||||||
|
r = ((color >> fmt.rShift) << fmt.rLoss) & 0xFF;
|
||||||
|
g = ((color >> fmt.gShift) << fmt.gLoss) & 0xFF;
|
||||||
|
b = ((color >> fmt.bShift) << fmt.bLoss) & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void colorToARGB(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b, const PixelFormat &fmt) {
|
||||||
|
a = ((color >> fmt.aShift) << fmt.aLoss) & 0xFF;
|
||||||
|
r = ((color >> fmt.rShift) << fmt.rLoss) & 0xFF;
|
||||||
|
g = ((color >> fmt.gShift) << fmt.gLoss) & 0xFF;
|
||||||
|
b = ((color >> fmt.bShift) << fmt.bLoss) & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of namespace Graphics
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -105,9 +105,9 @@ void InitScalers(uint32 BitFormat) {
|
||||||
gBitFormat = BitFormat;
|
gBitFormat = BitFormat;
|
||||||
#ifndef DISABLE_HQ_SCALERS
|
#ifndef DISABLE_HQ_SCALERS
|
||||||
if (gBitFormat == 555)
|
if (gBitFormat == 555)
|
||||||
InitLUT<ColorMasks<555> >();
|
InitLUT<Graphics::ColorMasks<555> >();
|
||||||
if (gBitFormat == 565)
|
if (gBitFormat == 565)
|
||||||
InitLUT<ColorMasks<565> >();
|
InitLUT<Graphics::ColorMasks<565> >();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,12 @@
|
||||||
#include "graphics/colormasks.h"
|
#include "graphics/colormasks.h"
|
||||||
|
|
||||||
|
|
||||||
#define highBits ColorMasks<bitFormat>::highBits
|
#define highBits Graphics::ColorMasks<bitFormat>::highBits
|
||||||
#define lowBits ColorMasks<bitFormat>::lowBits
|
#define lowBits Graphics::ColorMasks<bitFormat>::lowBits
|
||||||
#define qhighBits ColorMasks<bitFormat>::qhighBits
|
#define qhighBits Graphics::ColorMasks<bitFormat>::qhighBits
|
||||||
#define qlowBits ColorMasks<bitFormat>::qlowBits
|
#define qlowBits Graphics::ColorMasks<bitFormat>::qlowBits
|
||||||
#define redblueMask ColorMasks<bitFormat>::kRedBlueMask
|
#define redblueMask Graphics::ColorMasks<bitFormat>::kRedBlueMask
|
||||||
#define greenMask ColorMasks<bitFormat>::kGreenMask
|
#define greenMask Graphics::ColorMasks<bitFormat>::kGreenMask
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -118,7 +118,7 @@ static bool grabScreen565(Graphics::Surface *surf) {
|
||||||
g = palette[((uint8*)screen->pixels)[y * screen->pitch + x] * 4 + 1];
|
g = palette[((uint8*)screen->pixels)[y * screen->pitch + x] * 4 + 1];
|
||||||
b = palette[((uint8*)screen->pixels)[y * screen->pitch + x] * 4 + 2];
|
b = palette[((uint8*)screen->pixels)[y * screen->pitch + x] * 4 + 2];
|
||||||
|
|
||||||
((uint16*)surf->pixels)[y * surf->w + x] = RGBToColor<ColorMasks<565> >(r, g, b);
|
((uint16*)surf->pixels)[y * surf->w + x] = Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ bool createThumbnail(Graphics::Surface *surf, const uint8 *pixels, int w, int h,
|
||||||
g = palette[pixels[y * w + x] * 3 + 1];
|
g = palette[pixels[y * w + x] * 3 + 1];
|
||||||
b = palette[pixels[y * w + x] * 3 + 2];
|
b = palette[pixels[y * w + x] * 3 + 2];
|
||||||
|
|
||||||
((uint16 *)screen.pixels)[y * screen.w + x] = RGBToColor<ColorMasks<565> >(r, g, b);
|
((uint16 *)screen.pixels)[y * screen.w + x] = Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue