diff options
-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 //@} }; |