diff options
author | Jody Northup | 2009-07-03 09:33:58 +0000 |
---|---|---|
committer | Jody Northup | 2009-07-03 09:33:58 +0000 |
commit | c28af8ce941ea92fcf32b726ad03f2f854de342d (patch) | |
tree | 232ff78e9abd9b04512b34e6a210cad5c0865d87 | |
parent | c753e68024d23f1128934c4730fbd4d7bdee8e61 (diff) | |
download | scummvm-rg350-c28af8ce941ea92fcf32b726ad03f2f854de342d.tar.gz scummvm-rg350-c28af8ce941ea92fcf32b726ad03f2f854de342d.tar.bz2 scummvm-rg350-c28af8ce941ea92fcf32b726ad03f2f854de342d.zip |
Provided a virtual method for converting graphics rectangles from screen format to hardware format, for backend developers wanting to provide support for color component orders not directly supported in hardware. (This could probably use a fair bit of looking over, it's ugly and has some fairly arbitrary limitations)
svn-id: r42051
-rw-r--r-- | common/system.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/common/system.h b/common/system.h index 4695ece4a4..be795f971a 100644 --- a/common/system.h +++ b/common/system.h @@ -997,6 +997,80 @@ public: */ virtual Common::WriteStream *createConfigWriteStream() = 0; +#ifdef ENABLE_RGB_COLOR +private: + /** + * Convert a rectangle from the screenformat to the hardwareformat. + * + * @param buf the buffer containing the graphics data source + * @param w the width of the destination rectangle + * @param h the height of the destination rectangle + * @param dest the pixel format currently set in hardware + * @return true if conversion completes successfully, + * false if there is an error. + * + * @note This implementation is slow. Please override this if + * your backend hardware has a better way to deal with this. + * @note This implementation requires the screen pixel format and + * the hardware pixel format to have a matching bytedepth + */ + virtual bool convertRect(byte *buf, int w, int h, + Graphics::PixelFormat dest) { + Graphics::PixelFormat orig = getScreenFormat(); + + // Error out if conversion is impossible + if ((orig.bytesPerPixel != dest.bytesPerPixel) || + (dest.bytesPerPixel == 1) || (!dest.bytesPerPixel)) + return false; + + // Don't perform unnecessary conversion + if (orig == dest) + return true; + + byte *tmp = buf; + byte bytesPerPixel = dest.bytesPerPixel; + // Faster, but larger, to provide optimized handling for each case. + uint32 numpix = w * h; + if (bytesPerPixel == 2) + { + for (uint32 i = 0; i < numpix; i++) { + uint8 r,g,b,a; + uint16 color = *(uint16 *) tmp; + orig.colorToARGB(color, a, r, g, b); + color = dest.ARGBToColor(a, r, g, b); + memcpy(tmp,&color,bytesPerPixel); + tmp += 2; + } + } else if (bytesPerPixel == 3) { + for (uint32 i = 0; i < numpix; i++) { + uint8 r,g,b,a; + uint32 color; + uint8 *col = (uint8 *)&color; +#ifdef SCUMM_BIG_ENDIAN + col++; +#endif + memcpy(col,tmp,bytesPerPixel); + orig.colorToARGB(color, a, r, g, b); + color = dest.ARGBToColor(a, r, g, b); + memcpy(tmp,col,bytesPerPixel); + tmp += 3; + } + } else if (bytesPerPixel == 4) { + for (uint32 i = 0; i < numpix; i++) { + uint8 r,g,b,a; + uint32 color; + memcpy(&color,tmp,bytesPerPixel); + orig.colorToARGB(color, a, r, g, b); + color = dest.ARGBToColor(a, r, g, b); + memcpy(tmp,&color,bytesPerPixel); + tmp += 4; + } + } else { + return false; + } + return true; + }; +#endif // ENABLE_RGB_COLOR //@} }; |