From a7740fb6de17967e0187b606e94d8b7f91951f79 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Wed, 7 Mar 2012 22:00:22 -0500 Subject: GRAPHICS: Add support for converting surfaces from 24bpp --- graphics/surface.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'graphics') diff --git a/graphics/surface.cpp b/graphics/surface.cpp index 0a5b109eb0..fcd702241a 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -20,6 +20,7 @@ */ #include "common/algorithm.h" +#include "common/endian.h" #include "common/util.h" #include "common/rect.h" #include "common/textconsole.h" @@ -281,8 +282,11 @@ Graphics::Surface *Surface::convertTo(const PixelFormat &dstFormat, const byte * return surface; } + if (format.bytesPerPixel == 0 || format.bytesPerPixel > 4) + error("Surface::convertTo(): Can only convert from 1Bpp, 2Bpp, 3Bpp, and 4Bpp"); + if (dstFormat.bytesPerPixel != 2 && dstFormat.bytesPerPixel != 4) - error("Surface::convertTo(): Only 2Bpp and 4Bpp supported"); + error("Surface::convertTo(): Can only convert to 2Bpp and 4Bpp"); surface->create(w, h, dstFormat); @@ -319,9 +323,11 @@ Graphics::Surface *Surface::convertTo(const PixelFormat &dstFormat, const byte * for (int x = 0; x < w; x++) { uint32 srcColor; if (format.bytesPerPixel == 2) - srcColor = *((uint16 *)srcRow); + srcColor = READ_UINT16(srcRow); + else if (format.bytesPerPixel == 3) + srcColor = READ_UINT24(srcRow); else - srcColor = *((uint32 *)srcRow); + srcColor = READ_UINT32(srcRow); srcRow += format.bytesPerPixel; -- cgit v1.2.3