diff options
author | Jody Northup | 2009-07-03 11:46:09 +0000 |
---|---|---|
committer | Jody Northup | 2009-07-03 11:46:09 +0000 |
commit | c37f1d9d5e5ee2e2745c75f99189fb197c605c63 (patch) | |
tree | ab508099f93cf50c7abb6ca730b699bfb1f462b4 | |
parent | c28af8ce941ea92fcf32b726ad03f2f854de342d (diff) | |
download | scummvm-rg350-c37f1d9d5e5ee2e2745c75f99189fb197c605c63.tar.gz scummvm-rg350-c37f1d9d5e5ee2e2745c75f99189fb197c605c63.tar.bz2 scummvm-rg350-c37f1d9d5e5ee2e2745c75f99189fb197c605c63.zip |
Cleaned up system.h, renamed OSystem::convertRect to OSystem::convertScreenRect (still not very descriptive). Added graphics/conversion.h and graphics/conversion.cpp with Graphics::crossBlit function created from extending original contents of OSystem::convertRect
svn-id: r42057
-rw-r--r-- | common/system.h | 74 | ||||
-rw-r--r-- | dists/msvc8/scummvm.vcproj | 8 | ||||
-rw-r--r-- | graphics/conversion.cpp | 138 | ||||
-rw-r--r-- | graphics/conversion.h | 56 |
4 files changed, 216 insertions, 60 deletions
diff --git a/common/system.h b/common/system.h index be795f971a..46e14589ab 100644 --- a/common/system.h +++ b/common/system.h @@ -31,6 +31,9 @@ #include "common/rect.h" #include "graphics/pixelformat.h" +#ifdef ENABLE_RGB_COLOR +#include "graphics/conversion.h" +#endif namespace Audio { class Mixer; @@ -1000,12 +1003,15 @@ public: #ifdef ENABLE_RGB_COLOR private: /** - * Convert a rectangle from the screenformat to the hardwareformat. + * Convert a rectangle from the screen format to the hardware format. * - * @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 + * @param dstbuf the buffer which will recieve the converted graphics data + * @param srcbuf the buffer containing the original graphics data + * @param dstpitch width in bytes of one full line of the dest buffer + * @param srcpitch width in bytes of one full line of the source buffer + * @param w the width of the graphics data + * @param h the height of the graphics data + * @param hwFmt the pixel format currently set in hardware * @return true if conversion completes successfully, * false if there is an error. * @@ -1014,61 +1020,9 @@ private: * @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; + virtual bool convertScreenRect(byte *dstbuf, const byte *srcbuf, int dstpitch, int srcpitch, + int w, int h, Graphics::PixelFormat hwFmt) { + return Graphics::crossBlit(dstbuf,srcbuf,dstpitch,srcpitch,w,h,hwFmt,getScreenFormat()); }; #endif // ENABLE_RGB_COLOR //@} diff --git a/dists/msvc8/scummvm.vcproj b/dists/msvc8/scummvm.vcproj index 78c6755ebd..5b75747cbf 100644 --- a/dists/msvc8/scummvm.vcproj +++ b/dists/msvc8/scummvm.vcproj @@ -1431,6 +1431,14 @@ > </File> <File + RelativePath="..\..\graphics\conversion.cpp" + > + </File> + <File + RelativePath="..\..\graphics\conversion.h" + > + </File> + <File RelativePath="..\..\graphics\cursorman.cpp" > </File> diff --git a/graphics/conversion.cpp b/graphics/conversion.cpp new file mode 100644 index 0000000000..3db0bee33c --- /dev/null +++ b/graphics/conversion.cpp @@ -0,0 +1,138 @@ +/* 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$ + */ + +#include "graphics/conversion.h" +#include "common/scummsys.h" +namespace Graphics { +// TODO: YUV to RGB conversion function + +// Function to blit a rect from one color format to another +bool crossBlit(byte *dst, const byte *src, int dstpitch, int srcpitch, + int w, int h, Graphics::PixelFormat dstFmt, Graphics::PixelFormat srcFmt) { + // Error out if conversion is impossible + if ((srcFmt.bytesPerPixel == 1) || (dstFmt.bytesPerPixel == 1) + || (!srcFmt.bytesPerPixel) || (!dstFmt.bytesPerPixel) + || (srcFmt.bytesPerPixel > dstFmt.bytesPerPixel)) + return false; + + // Don't perform unnecessary conversion + if (srcFmt == dstFmt) + return true; + + // Faster, but larger, to provide optimized handling for each case. + int srcDelta,dstDelta; + srcDelta = (srcpitch - w * srcFmt.bytesPerPixel); + dstDelta = (dstpitch - w * dstFmt.bytesPerPixel); + + // TODO: optimized cases for dstDelta of 0 + uint8 r,g,b,a; + if (dstFmt.bytesPerPixel == 2) + { + uint16 color; + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++, src += 2, dst += 2) { + color = *(uint16 *) src; + srcFmt.colorToARGB(color, a, r, g, b); + color = dstFmt.ARGBToColor(a, r, g, b); + *(uint16 *) dst = color; + } + src += srcDelta; + dst += dstDelta; + } + } else if (dstFmt.bytesPerPixel == 3) { + uint32 color; + uint8 *col = (uint8 *) &color; +#ifdef SCUMM_BIG_ENDIAN + col++; +#endif + if (srcFmt.bytesPerPixel == 2) { + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++, src += 2, dst += 3) { + color = *(uint16 *) src; + srcFmt.colorToARGB(color, a, r, g, b); + color = dstFmt.ARGBToColor(a, r, g, b); + memcpy(dst,col,3); + } + src += srcDelta; + dst += dstDelta; + } + } else { + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++, src += 3, dst += 3) { + uint8 r,g,b,a; + memcpy(col,src,3); + srcFmt.colorToARGB(color, a, r, g, b); + color = dstFmt.ARGBToColor(a, r, g, b); + memcpy(dst,col,3); + } + src += srcDelta; + dst += dstDelta; + } + } + } else if (dstFmt.bytesPerPixel == 4) { + uint32 color; + if (srcFmt.bytesPerPixel == 2) { + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++, src += 2, dst += 4) { + color = *(uint16 *) src; + srcFmt.colorToARGB(color, a, r, g, b); + color = dstFmt.ARGBToColor(a, r, g, b); + *(uint32 *) dst = color; + } + src += srcDelta; + dst += dstDelta; + } + } else if (srcFmt.bytesPerPixel == 3) { + uint8 *col = (uint8 *)&color; +#ifdef SCUMM_BIG_ENDIAN + col++; +#endif + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++, src += 2, dst += 4) { + memcpy(col,src,3); + srcFmt.colorToARGB(color, a, r, g, b); + color = dstFmt.ARGBToColor(a, r, g, b); + *(uint32 *) dst = color; + } + src += srcDelta; + dst += dstDelta; + } + } else { + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++, src += 4, dst += 4) { + color = *(uint32 *) src; + srcFmt.colorToARGB(color, a, r, g, b); + color = dstFmt.ARGBToColor(a, r, g, b); + *(uint32 *) dst = color; + } + src += srcDelta; + dst += dstDelta; + } + } + } else { + return false; + } + return true; +} +} // end of namespace Graphics
\ No newline at end of file diff --git a/graphics/conversion.h b/graphics/conversion.h new file mode 100644 index 0000000000..12015c498e --- /dev/null +++ b/graphics/conversion.h @@ -0,0 +1,56 @@ +/* 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_CONVERSION_H +#define GRAPHICS_CONVERSION_H + +#include "common/scummsys.h" +#include "graphics/pixelformat.h" +namespace Graphics { + +// TODO: generic YUV to RGB pixel conversion +// TODO: generic YUV to RGB blit + +/** + * Convert a rectangle from the one format to another, and blits it. + * + * @param dstbuf the buffer which will recieve the converted graphics data + * @param srcbuf the buffer containing the original graphics data + * @param dstpitch width in bytes of one full line of the dest buffer + * @param srcpitch width in bytes of one full line of the source buffer + * @param w the width of the graphics data + * @param h the height of the graphics data + * @param dstFmt the desired pixel format + * @param srcFmt the original pixel format + * @return true if conversion completes successfully, + * false if there is an error. + * + * @note This implementation currently requires the destination's + * format have at least as high a bitdepth as the source's. + * + */ +bool crossBlit(byte *dst, const byte *src, int dstpitch, int srcpitch, + int w, int h, Graphics::PixelFormat dstFmt, Graphics::PixelFormat srcFmt); +} // end of namespace Graphics +#endif //GRAPHICS_CONVERSION_H
\ No newline at end of file |