diff options
author | Max Horn | 2009-01-22 04:35:10 +0000 |
---|---|---|
committer | Max Horn | 2009-01-22 04:35:10 +0000 |
commit | abc06ca18e69c336d701707933b4dc490dd86e94 (patch) | |
tree | a6dc57ffd954e3e85f7be813fe25d8341180c2ea /graphics | |
parent | a2c671da977acda9f9503413fb38490dcceda76d (diff) | |
download | scummvm-rg350-abc06ca18e69c336d701707933b4dc490dd86e94.tar.gz scummvm-rg350-abc06ca18e69c336d701707933b4dc490dd86e94.tar.bz2 scummvm-rg350-abc06ca18e69c336d701707933b4dc490dd86e94.zip |
Moved Graphics::PixelFormat into its own header file; turned RGBToColor etc. into methods, and added an operator==
svn-id: r35993
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/colormasks.h | 59 | ||||
-rw-r--r-- | graphics/imagedec.cpp | 2 | ||||
-rw-r--r-- | graphics/pixelformat.h | 89 | ||||
-rw-r--r-- | graphics/thumbnail.cpp | 3 | ||||
-rw-r--r-- | graphics/video/mpeg_player.cpp | 6 |
5 files changed, 104 insertions, 55 deletions
diff --git a/graphics/colormasks.h b/graphics/colormasks.h index af72dbdf8c..6afc8cdd77 100644 --- a/graphics/colormasks.h +++ b/graphics/colormasks.h @@ -26,6 +26,8 @@ #ifndef GRAPHICS_COLORMASKS_H #define GRAPHICS_COLORMASKS_H +#include "graphics/pixelformat.h" + namespace Graphics { template<int bitFormat> @@ -81,7 +83,7 @@ struct ColorMasks<565> { kGreenBits = 6, kBlueBits = 5, - kAlphaShift = kRedBits+kGreenBits+kBlueBits, + kAlphaShift = 0, kRedShift = kGreenBits+kBlueBits, kGreenShift = kBlueBits, kBlueShift = 0, @@ -112,7 +114,7 @@ struct ColorMasks<555> { kGreenBits = 5, kBlueBits = 5, - kAlphaShift = kRedBits+kGreenBits+kBlueBits, + kAlphaShift = 0, kRedShift = kGreenBits+kBlueBits, kGreenShift = kBlueBits, kBlueShift = 0, @@ -184,7 +186,7 @@ struct ColorMasks<888> { kGreenBits = 8, kBlueBits = 8, - kAlphaShift = kRedBits+kGreenBits+kBlueBits, + kAlphaShift = 0, kRedShift = kGreenBits+kBlueBits, kGreenShift = kBlueBits, kBlueShift = 0, @@ -253,27 +255,12 @@ void colorToARGB(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b) { 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'. It also doesn't - * contain mask values. - */ -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. */ -}; +/** + * Convert a 'bitFormat' as defined by one of the ColorMasks + * into a PixelFormat. + */ template<int bitFormat> PixelFormat createPixelFormat() { PixelFormat format; @@ -293,34 +280,6 @@ PixelFormat createPixelFormat() { 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 diff --git a/graphics/imagedec.cpp b/graphics/imagedec.cpp index 93a895ae03..267a331deb 100644 --- a/graphics/imagedec.cpp +++ b/graphics/imagedec.cpp @@ -127,7 +127,7 @@ Surface *BMPDecoder::decodeImage(Common::SeekableReadStream &stream) { b = stream.readByte(); g = stream.readByte(); r = stream.readByte(); - *curPixel = RGBToColor(r, g, b, overlayFormat); + *curPixel = overlayFormat.RGBToColor(r, g, b); ++curPixel; } stream.seek(pitchAdd, SEEK_CUR); diff --git a/graphics/pixelformat.h b/graphics/pixelformat.h new file mode 100644 index 0000000000..bfec28fabd --- /dev/null +++ b/graphics/pixelformat.h @@ -0,0 +1,89 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef GRAPHICS_PIXELFORMAT_H +#define GRAPHICS_PIXELFORMAT_H + +namespace Graphics { + + +/** + * 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'. It also doesn't + * contain mask values. + */ +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. */ + + inline bool operator==(const PixelFormat &fmt) const { + // TODO: If aLoss==8, then the value of aShift is irrelevant, and should be ignored. + return 0 == memcmp(this, &fmt, sizeof(PixelFormat)); + } + + inline uint32 RGBToColor(uint8 r, uint8 g, uint8 b) const { + return + ((0xFF >> aLoss) << aShift) | + (( r >> rLoss) << rShift) | + (( g >> gLoss) << gShift) | + (( b >> bLoss) << bShift); + } + + inline uint32 ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b) const { + return + ((a >> aLoss) << aShift) | + ((r >> rLoss) << rShift) | + ((g >> gLoss) << gShift) | + ((b >> bLoss) << bShift); + } + + inline void colorToRGB(uint32 color, uint8 &r, uint8 &g, uint8 &b) const { + r = ((color >> rShift) << rLoss) & 0xFF; + g = ((color >> gShift) << gLoss) & 0xFF; + b = ((color >> bShift) << bLoss) & 0xFF; + } + + inline void colorToARGB(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b) const { + a = ((color >> aShift) << aLoss) & 0xFF; + r = ((color >> rShift) << rLoss) & 0xFF; + g = ((color >> gShift) << gLoss) & 0xFF; + b = ((color >> bShift) << bLoss) & 0xFF; + } +}; + +} // end of namespace Graphics + +#endif diff --git a/graphics/thumbnail.cpp b/graphics/thumbnail.cpp index 1d88dc5147..de8c2eb2d9 100644 --- a/graphics/thumbnail.cpp +++ b/graphics/thumbnail.cpp @@ -24,6 +24,7 @@ #include "graphics/thumbnail.h" #include "graphics/scaler.h" +#include "graphics/colormasks.h" #include "common/endian.h" #include "common/system.h" @@ -115,7 +116,7 @@ bool loadThumbnail(Common::SeekableReadStream &in, Graphics::Surface &to) { colorToRGB<ColorMasks<565> >(in.readUint16BE(), r, g, b); // converting to current OSystem Color - *pixels++ = Graphics::RGBToColor(r, g, b, format); + *pixels++ = format.RGBToColor(r, g, b); } } diff --git a/graphics/video/mpeg_player.cpp b/graphics/video/mpeg_player.cpp index 964f4cd94d..8c017e5bb5 100644 --- a/graphics/video/mpeg_player.cpp +++ b/graphics/video/mpeg_player.cpp @@ -391,9 +391,9 @@ void BaseAnimationState::buildLookup() { // Set up entries 0-255 in rgb-to-pixel value tables. Graphics::PixelFormat format = _sys->getOverlayFormat(); for (i = 0; i < 256; i++) { - r_2_pix_alloc[i + 256] = Graphics::RGBToColor(i, 0, 0, format); - g_2_pix_alloc[i + 256] = Graphics::RGBToColor(0, i, 0, format); - b_2_pix_alloc[i + 256] = Graphics::RGBToColor(0, 0, i, format); + r_2_pix_alloc[i + 256] = format.RGBToColor(i, 0, 0); + g_2_pix_alloc[i + 256] = format.RGBToColor(0, i, 0); + b_2_pix_alloc[i + 256] = format.RGBToColor(0, 0, i); } // Spread out the values we have to the rest of the array so that we do |