mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 14:18:37 +00:00
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
This commit is contained in:
parent
c753e68024
commit
c28af8ce94
@ -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
|
||||
//@}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user