[Scummvm-git-logs] scummvm master -> 7f2d9fd0fd72cfb70694727b0ee5bd949f47fd62

sev- noreply at scummvm.org
Thu Dec 22 22:45:17 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
7f2d9fd0fd GRAPHICS: Split conversion.cpp into multiple files


Commit: 7f2d9fd0fd72cfb70694727b0ee5bd949f47fd62
    https://github.com/scummvm/scummvm/commit/7f2d9fd0fd72cfb70694727b0ee5bd949f47fd62
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2022-12-22T23:45:14+01:00

Commit Message:
GRAPHICS: Split conversion.cpp into multiple files

Changed paths:
  A graphics/blit-scale.cpp
  A graphics/blit.cpp
  A graphics/blit.h
  R graphics/conversion.cpp
    backends/graphics/android/android-graphics.cpp
    backends/graphics/opengl/opengl-graphics.cpp
    backends/graphics/opengl/texture.cpp
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp
    backends/graphics3d/android/android-graphics3d.cpp
    backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
    backends/platform/3ds/osystem-graphics.cpp
    backends/platform/dc/display.cpp
    backends/platform/ds/ds-graphics.cpp
    backends/platform/ios7/ios7_osys_video.mm
    backends/platform/iphone/osys_video.mm
    backends/platform/n64/osys_n64_base.cpp
    backends/platform/wii/osystem_gfx.cpp
    engines/cryo/eden_graphics.cpp
    engines/myst3/myst3.cpp
    graphics/conversion.h
    graphics/module.mk
    graphics/surface.cpp
    graphics/transparent_surface.cpp
    gui/ThemeEngine.cpp


diff --git a/backends/graphics/android/android-graphics.cpp b/backends/graphics/android/android-graphics.cpp
index df7b083db03..06e85eba9b2 100644
--- a/backends/graphics/android/android-graphics.cpp
+++ b/backends/graphics/android/android-graphics.cpp
@@ -36,7 +36,7 @@
 // for the Android port
 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
 
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 
 #include "backends/graphics/opengl/pipelines/pipeline.h"
 
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index e269cbd6b5c..d2ceae90172 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -44,7 +44,7 @@
 #endif
 #endif
 
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #ifdef USE_OSD
 #include "graphics/fontman.h"
 #include "graphics/font.h"
diff --git a/backends/graphics/opengl/texture.cpp b/backends/graphics/opengl/texture.cpp
index d8da9fa9526..eb9d96a85d6 100644
--- a/backends/graphics/opengl/texture.cpp
+++ b/backends/graphics/opengl/texture.cpp
@@ -31,7 +31,7 @@
 #include "common/rect.h"
 #include "common/textconsole.h"
 
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 
 #ifdef USE_SCALERS
 #include "graphics/scalerplugin.h"
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index 72fe3f8681e..28b5a044bac 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -34,7 +34,7 @@
 #ifdef USE_RGB_COLOR
 #include "common/list.h"
 #endif
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "graphics/font.h"
 #include "graphics/fontman.h"
 #include "graphics/scaler.h"
diff --git a/backends/graphics3d/android/android-graphics3d.cpp b/backends/graphics3d/android/android-graphics3d.cpp
index bb90ad2bee3..89c2b26cd8e 100644
--- a/backends/graphics3d/android/android-graphics3d.cpp
+++ b/backends/graphics3d/android/android-graphics3d.cpp
@@ -37,7 +37,7 @@
 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
 
 #include "common/tokenizer.h"
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "graphics/opengl/shader.h"
 #include "graphics/opengl/context.h"
 
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
index 353ea86128a..573a2b44151 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
@@ -36,7 +36,7 @@
 
 #include "engines/engine.h"
 
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "graphics/opengl/context.h"
 #include "graphics/opengl/system_headers.h"
 
diff --git a/backends/platform/3ds/osystem-graphics.cpp b/backends/platform/3ds/osystem-graphics.cpp
index c7af866acb0..7a187229248 100644
--- a/backends/platform/3ds/osystem-graphics.cpp
+++ b/backends/platform/3ds/osystem-graphics.cpp
@@ -26,7 +26,7 @@
 #include "backends/platform/3ds/options-dialog.h"
 #include "backends/platform/3ds/config.h"
 #include "common/rect.h"
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "graphics/fontman.h"
 #include "gui/gui-manager.h"
 
diff --git a/backends/platform/dc/display.cpp b/backends/platform/dc/display.cpp
index 708b1ccd550..1a18f522e56 100644
--- a/backends/platform/dc/display.cpp
+++ b/backends/platform/dc/display.cpp
@@ -22,7 +22,7 @@
 #define RONIN_TIMER_ACCESS
 
 #include "common/scummsys.h"
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "graphics/surface.h"
 #include "dc.h"
 
diff --git a/backends/platform/ds/ds-graphics.cpp b/backends/platform/ds/ds-graphics.cpp
index a1b2a4f6353..b875e749538 100644
--- a/backends/platform/ds/ds-graphics.cpp
+++ b/backends/platform/ds/ds-graphics.cpp
@@ -26,7 +26,7 @@
 
 #include "common/translation.h"
 
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 
 namespace DS {
 
diff --git a/backends/platform/ios7/ios7_osys_video.mm b/backends/platform/ios7/ios7_osys_video.mm
index c2eccc3e010..3b010161bcf 100644
--- a/backends/platform/ios7/ios7_osys_video.mm
+++ b/backends/platform/ios7/ios7_osys_video.mm
@@ -25,7 +25,7 @@
 #include "backends/platform/ios7/ios7_osys_main.h"
 #include "backends/platform/ios7/ios7_video.h"
 
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "backends/platform/ios7/ios7_app_delegate.h"
 
 @interface iOS7AlertHandler : NSObject<UIAlertViewDelegate>
diff --git a/backends/platform/iphone/osys_video.mm b/backends/platform/iphone/osys_video.mm
index 7a404a189ce..795755453a5 100644
--- a/backends/platform/iphone/osys_video.mm
+++ b/backends/platform/iphone/osys_video.mm
@@ -25,7 +25,7 @@
 #include "backends/platform/iphone/osys_main.h"
 #include "backends/platform/iphone/iphone_video.h"
 
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 
 void OSystem_IPHONE::engineInit() {
 	EventsBaseBackend::engineInit();
diff --git a/backends/platform/n64/osys_n64_base.cpp b/backends/platform/n64/osys_n64_base.cpp
index 1d3b01492cc..4642edd09c1 100644
--- a/backends/platform/n64/osys_n64_base.cpp
+++ b/backends/platform/n64/osys_n64_base.cpp
@@ -32,7 +32,7 @@
 #include "backends/mutex/null/null-mutex.h"
 #include "backends/saves/default/default-saves.h"
 #include "backends/timer/default/default-timer.h"
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 
 typedef unsigned long long uint64;
 
diff --git a/backends/platform/wii/osystem_gfx.cpp b/backends/platform/wii/osystem_gfx.cpp
index 4e9c6990fe4..dab644218ca 100644
--- a/backends/platform/wii/osystem_gfx.cpp
+++ b/backends/platform/wii/osystem_gfx.cpp
@@ -27,7 +27,7 @@
 #include <gxflux/gfx_con.h>
 
 #include "common/config-manager.h"
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "backends/fs/wii/wii-fs-factory.h"
 
 #include "osystem.h"
diff --git a/engines/cryo/eden_graphics.cpp b/engines/cryo/eden_graphics.cpp
index 8cb6161d4cd..40f727a5233 100644
--- a/engines/cryo/eden_graphics.cpp
+++ b/engines/cryo/eden_graphics.cpp
@@ -25,7 +25,7 @@
 #include "cryo/eden.h"
 #include "cryo/eden_graphics.h"
 
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "graphics/palette.h"
 #include "video/hnm_decoder.h"
 
diff --git a/engines/myst3/myst3.cpp b/engines/myst3/myst3.cpp
index 0aa797eb3f1..c694a5c8d5f 100644
--- a/engines/myst3/myst3.cpp
+++ b/engines/myst3/myst3.cpp
@@ -53,7 +53,6 @@
 
 #include "image/jpeg.h"
 
-#include "graphics/conversion.h"
 #include "graphics/renderer.h"
 #include "graphics/yuv_to_rgb.h"
 #include "graphics/framelimiter.h"
diff --git a/graphics/conversion.cpp b/graphics/blit-scale.cpp
similarity index 52%
rename from graphics/conversion.cpp
rename to graphics/blit-scale.cpp
index ebc0be4ad54..d4c279cc402 100644
--- a/graphics/conversion.cpp
+++ b/graphics/blit-scale.cpp
@@ -24,380 +24,15 @@
  *
  */
 
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "graphics/pixelformat.h"
 #include "graphics/transform_struct.h"
 
-#include "common/endian.h"
 #include "common/math.h"
 #include "common/rect.h"
 
 namespace Graphics {
 
-// TODO: YUV to RGB conversion function
-
-// Function to blit a rect
-void copyBlit(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const uint bytesPerPixel) {
-	if (dst == src)
-		return;
-
-	if (dstPitch == srcPitch && ((w * bytesPerPixel) == dstPitch)) {
-		memcpy(dst, src, dstPitch * h);
-	} else {
-		for (uint i = 0; i < h; ++i) {
-			memcpy(dst, src, w * bytesPerPixel);
-			dst += dstPitch;
-			src += srcPitch;
-		}
-	}
-}
-
-namespace {
-
-template<typename Size>
-inline void keyBlitLogic(byte *dst, const byte *src, const uint w, const uint h,
-						 const uint srcDelta, const uint dstDelta, const uint32 key) {
-	for (uint y = 0; y < h; ++y) {
-		for (uint x = 0; x < w; ++x) {
-			uint32 color = *(const Size *)src;
-			if (color != key)
-				*(Size *)dst = color;
-
-			src += sizeof(Size);
-			dst += sizeof(Size);
-		}
-
-		src += srcDelta;
-		dst += dstDelta;
-	}
-}
-
-} // End of anonymous namespace
-
-// Function to blit a rect with a transparent color key
-bool keyBlit(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const uint bytesPerPixel, const uint32 key) {
-	if (dst == src)
-		return true;
-
-	// Faster, but larger, to provide optimized handling for each case.
-	const uint srcDelta = (srcPitch - w * bytesPerPixel);
-	const uint dstDelta = (dstPitch - w * bytesPerPixel);
-
-	if (bytesPerPixel == 1) {
-		keyBlitLogic<uint8>(dst, src, w, h, srcDelta, dstDelta, key);
-	} else if (bytesPerPixel == 2) {
-		keyBlitLogic<uint16>(dst, src, w, h, srcDelta, dstDelta, key);
-	} else if (bytesPerPixel == 4) {
-		keyBlitLogic<uint32>(dst, src, w, h, srcDelta, dstDelta, key);
-	} else {
-		return false;
-	}
-
-	return true;
-}
-
-namespace {
-
-template<typename SrcColor, typename DstColor, bool backward, bool hasKey>
-inline void crossBlitLogic(byte *dst, const byte *src, const uint w, const uint h,
-						   const PixelFormat &srcFmt, const PixelFormat &dstFmt,
-						   const uint srcDelta, const uint dstDelta, const uint32 key) {
-	for (uint y = 0; y < h; ++y) {
-		for (uint x = 0; x < w; ++x) {
-			const uint32 color = *(const SrcColor *)src;
-			if (!hasKey || color != key) {
-				byte a, r, g, b;
-				srcFmt.colorToARGB(color, a, r, g, b);
-				*(DstColor *)dst = dstFmt.ARGBToColor(a, r, g, b);
-			}
-
-			if (backward) {
-				src -= sizeof(SrcColor);
-				dst -= sizeof(DstColor);
-			} else {
-				src += sizeof(SrcColor);
-				dst += sizeof(DstColor);
-			}
-		}
-
-		if (backward) {
-			src -= srcDelta;
-			dst -= dstDelta;
-		} else {
-			src += srcDelta;
-			dst += dstDelta;
-		}
-	}
-}
-
-template<typename DstColor, bool backward, bool hasKey>
-inline void crossBlitLogic1BppSource(byte *dst, const byte *src, const uint w, const uint h,
-									 const uint srcDelta, const uint dstDelta, const uint32 *map, const uint32 key) {
-	for (uint y = 0; y < h; ++y) {
-		for (uint x = 0; x < w; ++x) {
-			const byte color = *src;
-			if (!hasKey || color != key) {
-				*(DstColor *)dst = map[color];
-			}
-
-			if (backward) {
-				src -= 1;
-				dst -= sizeof(DstColor);
-			} else {
-				src += 1;
-				dst += sizeof(DstColor);
-			}
-		}
-
-		if (backward) {
-			src -= srcDelta;
-			dst -= dstDelta;
-		} else {
-			src += srcDelta;
-			dst += dstDelta;
-		}
-	}
-}
-
-template<typename DstColor, bool backward, bool hasKey>
-inline void crossBlitLogic3BppSource(byte *dst, const byte *src, const uint w, const uint h,
-									 const PixelFormat &srcFmt, const PixelFormat &dstFmt,
-									 const uint srcDelta, const uint dstDelta, const uint32 key) {
-	uint32 color;
-	byte r, g, b, a;
-	uint8 *col = (uint8 *)&color;
-#ifdef SCUMM_BIG_ENDIAN
-	col++;
-#endif
-	for (uint y = 0; y < h; ++y) {
-		for (uint x = 0; x < w; ++x) {
-			memcpy(col, src, 3);
-			if (!hasKey || color != key) {
-				srcFmt.colorToARGB(color, a, r, g, b);
-				*(DstColor *)dst = dstFmt.ARGBToColor(a, r, g, b);
-			}
-
-			if (backward) {
-				src -= 3;
-				dst -= sizeof(DstColor);
-			} else {
-				src += 3;
-				dst += sizeof(DstColor);
-			}
-		}
-
-		if (backward) {
-			src -= srcDelta;
-			dst -= dstDelta;
-		} else {
-			src += srcDelta;
-			dst += dstDelta;
-		}
-	}
-}
-
-} // End of anonymous namespace
-
-// Function to blit a rect from one color format to another
-bool crossBlit(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt) {
-	// Error out if conversion is impossible
-	if ((srcFmt.bytesPerPixel == 1) || (dstFmt.bytesPerPixel == 1)
-			 || (dstFmt.bytesPerPixel == 3)
-			 || (!srcFmt.bytesPerPixel) || (!dstFmt.bytesPerPixel))
-		return false;
-
-	// Don't perform unnecessary conversion
-	if (srcFmt == dstFmt) {
-		copyBlit(dst, src, dstPitch, srcPitch, w, h, dstFmt.bytesPerPixel);
-		return true;
-	}
-
-	// Faster, but larger, to provide optimized handling for each case.
-	const uint srcDelta = (srcPitch - w * srcFmt.bytesPerPixel);
-	const uint dstDelta = (dstPitch - w * dstFmt.bytesPerPixel);
-
-	// TODO: optimized cases for dstDelta of 0
-	if (dstFmt.bytesPerPixel == 2) {
-		if (srcFmt.bytesPerPixel == 2) {
-			crossBlitLogic<uint16, uint16, false, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
-		} else if (srcFmt.bytesPerPixel == 3) {
-			crossBlitLogic3BppSource<uint16, false, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
-		} else {
-			crossBlitLogic<uint32, uint16, false, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
-		}
-	} else if (dstFmt.bytesPerPixel == 4) {
-		if (srcFmt.bytesPerPixel == 2) {
-			// We need to blit the surface from bottom right to top left here.
-			// This is neeeded, because when we convert to the same memory
-			// buffer copying the surface from top left to bottom right would
-			// overwrite the source, since we have more bits per destination
-			// color than per source color.
-			dst += h * dstPitch - dstDelta - dstFmt.bytesPerPixel;
-			src += h * srcPitch - srcDelta - srcFmt.bytesPerPixel;
-			crossBlitLogic<uint16, uint32, true, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
-		} else if (srcFmt.bytesPerPixel == 3) {
-			// We need to blit the surface from bottom right to top left here.
-			// This is neeeded, because when we convert to the same memory
-			// buffer copying the surface from top left to bottom right would
-			// overwrite the source, since we have more bits per destination
-			// color than per source color.
-			dst += h * dstPitch - dstDelta - dstFmt.bytesPerPixel;
-			src += h * srcPitch - srcDelta - srcFmt.bytesPerPixel;
-			crossBlitLogic3BppSource<uint32, true, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
-		} else {
-			crossBlitLogic<uint32, uint32, false, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
-		}
-	} else {
-		return false;
-	}
-	return true;
-}
-
-// Function to blit a rect from one color format to another with a transparent color key
-bool crossKeyBlit(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt, const uint32 key) {
-	// Error out if conversion is impossible
-	if ((srcFmt.bytesPerPixel == 1) || (dstFmt.bytesPerPixel == 1)
-			 || (dstFmt.bytesPerPixel == 3)
-			 || (!srcFmt.bytesPerPixel) || (!dstFmt.bytesPerPixel))
-		return false;
-
-	// Don't perform unnecessary conversion
-	if (srcFmt == dstFmt) {
-		keyBlit(dst, src, dstPitch, srcPitch, w, h, dstFmt.bytesPerPixel, key);
-		return true;
-	}
-
-	// Faster, but larger, to provide optimized handling for each case.
-	const uint srcDelta = (srcPitch - w * srcFmt.bytesPerPixel);
-	const uint dstDelta = (dstPitch - w * dstFmt.bytesPerPixel);
-
-	// TODO: optimized cases for dstDelta of 0
-	if (dstFmt.bytesPerPixel == 2) {
-		if (srcFmt.bytesPerPixel == 2) {
-			crossBlitLogic<uint16, uint16, false, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
-		} else if (srcFmt.bytesPerPixel == 3) {
-			crossBlitLogic3BppSource<uint16, false, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
-		} else {
-			crossBlitLogic<uint32, uint16, false, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
-		}
-	} else if (dstFmt.bytesPerPixel == 4) {
-		if (srcFmt.bytesPerPixel == 2) {
-			// We need to blit the surface from bottom right to top left here.
-			// This is neeeded, because when we convert to the same memory
-			// buffer copying the surface from top left to bottom right would
-			// overwrite the source, since we have more bits per destination
-			// color than per source color.
-			dst += h * dstPitch - dstDelta - dstFmt.bytesPerPixel;
-			src += h * srcPitch - srcDelta - srcFmt.bytesPerPixel;
-			crossBlitLogic<uint16, uint32, true, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
-		} else if (srcFmt.bytesPerPixel == 3) {
-			// We need to blit the surface from bottom right to top left here.
-			// This is neeeded, because when we convert to the same memory
-			// buffer copying the surface from top left to bottom right would
-			// overwrite the source, since we have more bits per destination
-			// color than per source color.
-			dst += h * dstPitch - dstDelta - dstFmt.bytesPerPixel;
-			src += h * srcPitch - srcDelta - srcFmt.bytesPerPixel;
-			crossBlitLogic3BppSource<uint32, true, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
-		} else {
-			crossBlitLogic<uint32, uint32, false, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
-		}
-	} else {
-		return false;
-	}
-	return true;
-}
-
-// Function to blit a rect from one color format to another using a map
-bool crossBlitMap(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const uint bytesPerPixel, const uint32 *map) {
-	// Error out if conversion is impossible
-	if ((bytesPerPixel == 3) || (!bytesPerPixel))
-		return false;
-
-	// Faster, but larger, to provide optimized handling for each case.
-	const uint srcDelta = (srcPitch - w);
-	const uint dstDelta = (dstPitch - w * bytesPerPixel);
-
-	if (bytesPerPixel == 1) {
-		crossBlitLogic1BppSource<uint8, false, false>(dst, src, w, h, srcDelta, dstDelta, map, 0);
-	} else if (bytesPerPixel == 2) {
-		// We need to blit the surface from bottom right to top left here.
-		// This is neeeded, because when we convert to the same memory
-		// buffer copying the surface from top left to bottom right would
-		// overwrite the source, since we have more bits per destination
-		// color than per source color.
-		dst += h * dstPitch - dstDelta - bytesPerPixel;
-		src += h * srcPitch - srcDelta - 1;
-		crossBlitLogic1BppSource<uint16, true, false>(dst, src, w, h, srcDelta, dstDelta, map, 0);
-	} else if (bytesPerPixel == 4) {
-		// We need to blit the surface from bottom right to top left here.
-		// This is neeeded, because when we convert to the same memory
-		// buffer copying the surface from top left to bottom right would
-		// overwrite the source, since we have more bits per destination
-		// color than per source color.
-		dst += h * dstPitch - dstDelta - bytesPerPixel;
-		src += h * srcPitch - srcDelta - 1;
-		crossBlitLogic1BppSource<uint32, true, false>(dst, src, w, h, srcDelta, dstDelta, map, 0);
-	} else {
-		return false;
-	}
-	return true;
-}
-
-// Function to blit a rect from one color format to another using a map with a transparent color key
-bool crossKeyBlitMap(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const uint bytesPerPixel, const uint32 *map, const uint32 key) {
-	// Error out if conversion is impossible
-	if ((bytesPerPixel == 3) || (!bytesPerPixel))
-		return false;
-
-	// Faster, but larger, to provide optimized handling for each case.
-	const uint srcDelta = (srcPitch - w);
-	const uint dstDelta = (dstPitch - w * bytesPerPixel);
-
-	if (bytesPerPixel == 1) {
-		crossBlitLogic1BppSource<uint8, false, true>(dst, src, w, h, srcDelta, dstDelta, map, key);
-	} else if (bytesPerPixel == 2) {
-		// We need to blit the surface from bottom right to top left here.
-		// This is neeeded, because when we convert to the same memory
-		// buffer copying the surface from top left to bottom right would
-		// overwrite the source, since we have more bits per destination
-		// color than per source color.
-		dst += h * dstPitch - dstDelta - bytesPerPixel;
-		src += h * srcPitch - srcDelta - 1;
-		crossBlitLogic1BppSource<uint16, true, true>(dst, src, w, h, srcDelta, dstDelta, map, key);
-	} else if (bytesPerPixel == 4) {
-		// We need to blit the surface from bottom right to top left here.
-		// This is neeeded, because when we convert to the same memory
-		// buffer copying the surface from top left to bottom right would
-		// overwrite the source, since we have more bits per destination
-		// color than per source color.
-		dst += h * dstPitch - dstDelta - bytesPerPixel;
-		src += h * srcPitch - srcDelta - 1;
-		crossBlitLogic1BppSource<uint32, true, true>(dst, src, w, h, srcDelta, dstDelta, map, key);
-	} else {
-		return false;
-	}
-	return true;
-}
-
 namespace {
 
 template <typename Size>
diff --git a/graphics/blit.cpp b/graphics/blit.cpp
new file mode 100644
index 00000000000..2cb90a6ff55
--- /dev/null
+++ b/graphics/blit.cpp
@@ -0,0 +1,389 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "graphics/blit.h"
+#include "graphics/pixelformat.h"
+
+namespace Graphics {
+
+// Function to blit a rect
+void copyBlit(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const uint bytesPerPixel) {
+	if (dst == src)
+		return;
+
+	if (dstPitch == srcPitch && ((w * bytesPerPixel) == dstPitch)) {
+		memcpy(dst, src, dstPitch * h);
+	} else {
+		for (uint i = 0; i < h; ++i) {
+			memcpy(dst, src, w * bytesPerPixel);
+			dst += dstPitch;
+			src += srcPitch;
+		}
+	}
+}
+
+namespace {
+
+template<typename Size>
+inline void keyBlitLogic(byte *dst, const byte *src, const uint w, const uint h,
+						 const uint srcDelta, const uint dstDelta, const uint32 key) {
+	for (uint y = 0; y < h; ++y) {
+		for (uint x = 0; x < w; ++x) {
+			uint32 color = *(const Size *)src;
+			if (color != key)
+				*(Size *)dst = color;
+
+			src += sizeof(Size);
+			dst += sizeof(Size);
+		}
+
+		src += srcDelta;
+		dst += dstDelta;
+	}
+}
+
+} // End of anonymous namespace
+
+// Function to blit a rect with a transparent color key
+bool keyBlit(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const uint bytesPerPixel, const uint32 key) {
+	if (dst == src)
+		return true;
+
+	// Faster, but larger, to provide optimized handling for each case.
+	const uint srcDelta = (srcPitch - w * bytesPerPixel);
+	const uint dstDelta = (dstPitch - w * bytesPerPixel);
+
+	if (bytesPerPixel == 1) {
+		keyBlitLogic<uint8>(dst, src, w, h, srcDelta, dstDelta, key);
+	} else if (bytesPerPixel == 2) {
+		keyBlitLogic<uint16>(dst, src, w, h, srcDelta, dstDelta, key);
+	} else if (bytesPerPixel == 4) {
+		keyBlitLogic<uint32>(dst, src, w, h, srcDelta, dstDelta, key);
+	} else {
+		return false;
+	}
+
+	return true;
+}
+
+namespace {
+
+template<typename SrcColor, typename DstColor, bool backward, bool hasKey>
+inline void crossBlitLogic(byte *dst, const byte *src, const uint w, const uint h,
+						   const PixelFormat &srcFmt, const PixelFormat &dstFmt,
+						   const uint srcDelta, const uint dstDelta, const uint32 key) {
+	for (uint y = 0; y < h; ++y) {
+		for (uint x = 0; x < w; ++x) {
+			const uint32 color = *(const SrcColor *)src;
+			if (!hasKey || color != key) {
+				byte a, r, g, b;
+				srcFmt.colorToARGB(color, a, r, g, b);
+				*(DstColor *)dst = dstFmt.ARGBToColor(a, r, g, b);
+			}
+
+			if (backward) {
+				src -= sizeof(SrcColor);
+				dst -= sizeof(DstColor);
+			} else {
+				src += sizeof(SrcColor);
+				dst += sizeof(DstColor);
+			}
+		}
+
+		if (backward) {
+			src -= srcDelta;
+			dst -= dstDelta;
+		} else {
+			src += srcDelta;
+			dst += dstDelta;
+		}
+	}
+}
+
+template<typename DstColor, bool backward, bool hasKey>
+inline void crossBlitLogic1BppSource(byte *dst, const byte *src, const uint w, const uint h,
+									 const uint srcDelta, const uint dstDelta, const uint32 *map, const uint32 key) {
+	for (uint y = 0; y < h; ++y) {
+		for (uint x = 0; x < w; ++x) {
+			const byte color = *src;
+			if (!hasKey || color != key) {
+				*(DstColor *)dst = map[color];
+			}
+
+			if (backward) {
+				src -= 1;
+				dst -= sizeof(DstColor);
+			} else {
+				src += 1;
+				dst += sizeof(DstColor);
+			}
+		}
+
+		if (backward) {
+			src -= srcDelta;
+			dst -= dstDelta;
+		} else {
+			src += srcDelta;
+			dst += dstDelta;
+		}
+	}
+}
+
+template<typename DstColor, bool backward, bool hasKey>
+inline void crossBlitLogic3BppSource(byte *dst, const byte *src, const uint w, const uint h,
+									 const PixelFormat &srcFmt, const PixelFormat &dstFmt,
+									 const uint srcDelta, const uint dstDelta, const uint32 key) {
+	uint32 color;
+	byte r, g, b, a;
+	uint8 *col = (uint8 *)&color;
+#ifdef SCUMM_BIG_ENDIAN
+	col++;
+#endif
+	for (uint y = 0; y < h; ++y) {
+		for (uint x = 0; x < w; ++x) {
+			memcpy(col, src, 3);
+			if (!hasKey || color != key) {
+				srcFmt.colorToARGB(color, a, r, g, b);
+				*(DstColor *)dst = dstFmt.ARGBToColor(a, r, g, b);
+			}
+
+			if (backward) {
+				src -= 3;
+				dst -= sizeof(DstColor);
+			} else {
+				src += 3;
+				dst += sizeof(DstColor);
+			}
+		}
+
+		if (backward) {
+			src -= srcDelta;
+			dst -= dstDelta;
+		} else {
+			src += srcDelta;
+			dst += dstDelta;
+		}
+	}
+}
+
+} // End of anonymous namespace
+
+// Function to blit a rect from one color format to another
+bool crossBlit(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt) {
+	// Error out if conversion is impossible
+	if ((srcFmt.bytesPerPixel == 1) || (dstFmt.bytesPerPixel == 1)
+			 || (dstFmt.bytesPerPixel == 3)
+			 || (!srcFmt.bytesPerPixel) || (!dstFmt.bytesPerPixel))
+		return false;
+
+	// Don't perform unnecessary conversion
+	if (srcFmt == dstFmt) {
+		copyBlit(dst, src, dstPitch, srcPitch, w, h, dstFmt.bytesPerPixel);
+		return true;
+	}
+
+	// Faster, but larger, to provide optimized handling for each case.
+	const uint srcDelta = (srcPitch - w * srcFmt.bytesPerPixel);
+	const uint dstDelta = (dstPitch - w * dstFmt.bytesPerPixel);
+
+	// TODO: optimized cases for dstDelta of 0
+	if (dstFmt.bytesPerPixel == 2) {
+		if (srcFmt.bytesPerPixel == 2) {
+			crossBlitLogic<uint16, uint16, false, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
+		} else if (srcFmt.bytesPerPixel == 3) {
+			crossBlitLogic3BppSource<uint16, false, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
+		} else {
+			crossBlitLogic<uint32, uint16, false, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
+		}
+	} else if (dstFmt.bytesPerPixel == 4) {
+		if (srcFmt.bytesPerPixel == 2) {
+			// We need to blit the surface from bottom right to top left here.
+			// This is neeeded, because when we convert to the same memory
+			// buffer copying the surface from top left to bottom right would
+			// overwrite the source, since we have more bits per destination
+			// color than per source color.
+			dst += h * dstPitch - dstDelta - dstFmt.bytesPerPixel;
+			src += h * srcPitch - srcDelta - srcFmt.bytesPerPixel;
+			crossBlitLogic<uint16, uint32, true, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
+		} else if (srcFmt.bytesPerPixel == 3) {
+			// We need to blit the surface from bottom right to top left here.
+			// This is neeeded, because when we convert to the same memory
+			// buffer copying the surface from top left to bottom right would
+			// overwrite the source, since we have more bits per destination
+			// color than per source color.
+			dst += h * dstPitch - dstDelta - dstFmt.bytesPerPixel;
+			src += h * srcPitch - srcDelta - srcFmt.bytesPerPixel;
+			crossBlitLogic3BppSource<uint32, true, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
+		} else {
+			crossBlitLogic<uint32, uint32, false, false>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, 0);
+		}
+	} else {
+		return false;
+	}
+	return true;
+}
+
+// Function to blit a rect from one color format to another with a transparent color key
+bool crossKeyBlit(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt, const uint32 key) {
+	// Error out if conversion is impossible
+	if ((srcFmt.bytesPerPixel == 1) || (dstFmt.bytesPerPixel == 1)
+			 || (dstFmt.bytesPerPixel == 3)
+			 || (!srcFmt.bytesPerPixel) || (!dstFmt.bytesPerPixel))
+		return false;
+
+	// Don't perform unnecessary conversion
+	if (srcFmt == dstFmt) {
+		keyBlit(dst, src, dstPitch, srcPitch, w, h, dstFmt.bytesPerPixel, key);
+		return true;
+	}
+
+	// Faster, but larger, to provide optimized handling for each case.
+	const uint srcDelta = (srcPitch - w * srcFmt.bytesPerPixel);
+	const uint dstDelta = (dstPitch - w * dstFmt.bytesPerPixel);
+
+	// TODO: optimized cases for dstDelta of 0
+	if (dstFmt.bytesPerPixel == 2) {
+		if (srcFmt.bytesPerPixel == 2) {
+			crossBlitLogic<uint16, uint16, false, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
+		} else if (srcFmt.bytesPerPixel == 3) {
+			crossBlitLogic3BppSource<uint16, false, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
+		} else {
+			crossBlitLogic<uint32, uint16, false, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
+		}
+	} else if (dstFmt.bytesPerPixel == 4) {
+		if (srcFmt.bytesPerPixel == 2) {
+			// We need to blit the surface from bottom right to top left here.
+			// This is neeeded, because when we convert to the same memory
+			// buffer copying the surface from top left to bottom right would
+			// overwrite the source, since we have more bits per destination
+			// color than per source color.
+			dst += h * dstPitch - dstDelta - dstFmt.bytesPerPixel;
+			src += h * srcPitch - srcDelta - srcFmt.bytesPerPixel;
+			crossBlitLogic<uint16, uint32, true, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
+		} else if (srcFmt.bytesPerPixel == 3) {
+			// We need to blit the surface from bottom right to top left here.
+			// This is neeeded, because when we convert to the same memory
+			// buffer copying the surface from top left to bottom right would
+			// overwrite the source, since we have more bits per destination
+			// color than per source color.
+			dst += h * dstPitch - dstDelta - dstFmt.bytesPerPixel;
+			src += h * srcPitch - srcDelta - srcFmt.bytesPerPixel;
+			crossBlitLogic3BppSource<uint32, true, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
+		} else {
+			crossBlitLogic<uint32, uint32, false, true>(dst, src, w, h, srcFmt, dstFmt, srcDelta, dstDelta, key);
+		}
+	} else {
+		return false;
+	}
+	return true;
+}
+
+// Function to blit a rect from one color format to another using a map
+bool crossBlitMap(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const uint bytesPerPixel, const uint32 *map) {
+	// Error out if conversion is impossible
+	if ((bytesPerPixel == 3) || (!bytesPerPixel))
+		return false;
+
+	// Faster, but larger, to provide optimized handling for each case.
+	const uint srcDelta = (srcPitch - w);
+	const uint dstDelta = (dstPitch - w * bytesPerPixel);
+
+	if (bytesPerPixel == 1) {
+		crossBlitLogic1BppSource<uint8, false, false>(dst, src, w, h, srcDelta, dstDelta, map, 0);
+	} else if (bytesPerPixel == 2) {
+		// We need to blit the surface from bottom right to top left here.
+		// This is neeeded, because when we convert to the same memory
+		// buffer copying the surface from top left to bottom right would
+		// overwrite the source, since we have more bits per destination
+		// color than per source color.
+		dst += h * dstPitch - dstDelta - bytesPerPixel;
+		src += h * srcPitch - srcDelta - 1;
+		crossBlitLogic1BppSource<uint16, true, false>(dst, src, w, h, srcDelta, dstDelta, map, 0);
+	} else if (bytesPerPixel == 4) {
+		// We need to blit the surface from bottom right to top left here.
+		// This is neeeded, because when we convert to the same memory
+		// buffer copying the surface from top left to bottom right would
+		// overwrite the source, since we have more bits per destination
+		// color than per source color.
+		dst += h * dstPitch - dstDelta - bytesPerPixel;
+		src += h * srcPitch - srcDelta - 1;
+		crossBlitLogic1BppSource<uint32, true, false>(dst, src, w, h, srcDelta, dstDelta, map, 0);
+	} else {
+		return false;
+	}
+	return true;
+}
+
+// Function to blit a rect from one color format to another using a map with a transparent color key
+bool crossKeyBlitMap(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const uint bytesPerPixel, const uint32 *map, const uint32 key) {
+	// Error out if conversion is impossible
+	if ((bytesPerPixel == 3) || (!bytesPerPixel))
+		return false;
+
+	// Faster, but larger, to provide optimized handling for each case.
+	const uint srcDelta = (srcPitch - w);
+	const uint dstDelta = (dstPitch - w * bytesPerPixel);
+
+	if (bytesPerPixel == 1) {
+		crossBlitLogic1BppSource<uint8, false, true>(dst, src, w, h, srcDelta, dstDelta, map, key);
+	} else if (bytesPerPixel == 2) {
+		// We need to blit the surface from bottom right to top left here.
+		// This is neeeded, because when we convert to the same memory
+		// buffer copying the surface from top left to bottom right would
+		// overwrite the source, since we have more bits per destination
+		// color than per source color.
+		dst += h * dstPitch - dstDelta - bytesPerPixel;
+		src += h * srcPitch - srcDelta - 1;
+		crossBlitLogic1BppSource<uint16, true, true>(dst, src, w, h, srcDelta, dstDelta, map, key);
+	} else if (bytesPerPixel == 4) {
+		// We need to blit the surface from bottom right to top left here.
+		// This is neeeded, because when we convert to the same memory
+		// buffer copying the surface from top left to bottom right would
+		// overwrite the source, since we have more bits per destination
+		// color than per source color.
+		dst += h * dstPitch - dstDelta - bytesPerPixel;
+		src += h * srcPitch - srcDelta - 1;
+		crossBlitLogic1BppSource<uint32, true, true>(dst, src, w, h, srcDelta, dstDelta, map, key);
+	} else {
+		return false;
+	}
+	return true;
+}
+
+} // End of namespace Graphics
diff --git a/graphics/blit.h b/graphics/blit.h
new file mode 100644
index 00000000000..cf09ded2160
--- /dev/null
+++ b/graphics/blit.h
@@ -0,0 +1,180 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef GRAPHICS_BLIT_H
+#define GRAPHICS_BLIT_H
+
+#include "graphics/pixelformat.h"
+
+namespace Common {
+struct Point;
+}
+
+namespace Graphics {
+
+/**
+ * @defgroup graphics_blit Blitting
+ * @ingroup graphics
+ *
+ * @brief Graphics blitting operations.
+ *
+ * @{
+ */
+
+struct TransformStruct;
+
+/** Converting a palette for use with crossBlitMap(). */
+inline static void convertPaletteToMap(uint32 *dst, const byte *src, uint colors, const Graphics::PixelFormat &format) {
+	while (colors-- > 0) {
+		*dst++ = format.RGBToColor(src[0], src[1], src[2]);
+		src += 3;
+	}
+}
+
+/**
+ * Blits a rectangle.
+ *
+ * @param dst			the buffer which will receive the converted graphics data
+ * @param src			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 bytesPerPixel	the number of bytes per pixel
+ */
+void copyBlit(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const uint bytesPerPixel);
+
+/**
+ * Blits a rectangle with a transparent color key.
+ *
+ * @param dst			the buffer which will receive the converted graphics data
+ * @param src			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 bytesPerPixel	the number of bytes per pixel
+ * @param key			the transparent color key
+ */
+bool keyBlit(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const uint bytesPerPixel, const uint32 key);
+
+/**
+ * Blits a rectangle from one graphical format to another.
+ *
+ * @param dst		the buffer which will receive the converted graphics data
+ * @param src		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 Blitting to a 3Bpp destination is not supported
+ * @note This can convert a surface in place, regardless of the
+ *       source and destination format, as long as there is enough
+ *       space for the destination. The dstPitch / srcPitch ratio
+ *       must at least equal the dstBpp / srcBpp ratio for
+ *       dstPitch >= srcPitch and at most dstBpp / srcBpp for
+ *       dstPitch < srcPitch though.
+ */
+bool crossBlit(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt);
+
+/**
+ * Blits a rectangle from one graphical format to another with a transparent color key.
+ *
+ * @param dst		the buffer which will receive the converted graphics data
+ * @param src		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
+ * @param key			the transparent color key in the original pixel format
+ * @return			true if conversion completes successfully,
+ *					false if there is an error.
+ *
+ * @note Blitting to a 3Bpp destination is not supported
+ * @note This can convert a surface in place, regardless of the
+ *       source and destination format, as long as there is enough
+ *       space for the destination. The dstPitch / srcPitch ratio
+ *       must at least equal the dstBpp / srcBpp ratio for
+ *       dstPitch >= srcPitch and at most dstBpp / srcBpp for
+ *       dstPitch < srcPitch though.
+ */
+bool crossKeyBlit(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt, const uint32 key);
+
+bool crossBlitMap(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const uint bytesPerPixel, const uint32 *map);
+
+bool crossKeyBlitMap(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint w, const uint h,
+			   const uint bytesPerPixel, const uint32 *map, const uint32 key);
+
+bool scaleBlit(byte *dst, const byte *src,
+			   const uint dstPitch, const uint srcPitch,
+			   const uint dstW, const uint dstH,
+			   const uint srcW, const uint srcH,
+			   const Graphics::PixelFormat &fmt);
+
+bool scaleBlitBilinear(byte *dst, const byte *src,
+					   const uint dstPitch, const uint srcPitch,
+					   const uint dstW, const uint dstH,
+					   const uint srcW, const uint srcH,
+					   const Graphics::PixelFormat &fmt);
+
+bool rotoscaleBlit(byte *dst, const byte *src,
+				   const uint dstPitch, const uint srcPitch,
+				   const uint dstW, const uint dstH,
+				   const uint srcW, const uint srcH,
+				   const Graphics::PixelFormat &fmt,
+				   const TransformStruct &transform,
+				   const Common::Point &newHotspot);
+
+bool rotoscaleBlitBilinear(byte *dst, const byte *src,
+						   const uint dstPitch, const uint srcPitch,
+						   const uint dstW, const uint dstH,
+						   const uint srcW, const uint srcH,
+						   const Graphics::PixelFormat &fmt,
+						   const TransformStruct &transform,
+						   const Common::Point &newHotspot);
+/** @} */
+} // End of namespace Graphics
+
+#endif // GRAPHICS_BLIT_H
diff --git a/graphics/conversion.h b/graphics/conversion.h
index 4381ca1ed84..76ed9c58f7e 100644
--- a/graphics/conversion.h
+++ b/graphics/conversion.h
@@ -24,12 +24,6 @@
 
 #include "common/util.h"
 
-#include "graphics/pixelformat.h"
-
-namespace Common {
-struct Point;
-}
-
 namespace Graphics {
 
 /**
@@ -41,8 +35,6 @@ namespace Graphics {
  * @{
  */
 
-struct TransformStruct;
-
 /** Converting a color from YUV to RGB colorspace. */
 inline static void YUV2RGB(byte y, byte u, byte v, byte &r, byte &g, byte &b) {
 	r = CLIP<int>(y + ((1357 * (v - 128)) >> 10), 0, 255);
@@ -57,141 +49,6 @@ inline static void RGB2YUV(byte r, byte g, byte b, byte &y, byte &u, byte &v) {
 	v = CLIP<int>( ((r * 512) >> 10) - ((g * 429) >> 10) - ((b *  83) >> 10) + 128, 0, 255);
 }
 
-/** Converting a palette for use with crossBlitMap(). */
-inline static void convertPaletteToMap(uint32 *dst, const byte *src, uint colors, const Graphics::PixelFormat &format) {
-	while (colors-- > 0) {
-		*dst++ = format.RGBToColor(src[0], src[1], src[2]);
-		src += 3;
-	}
-}
-
-// TODO: generic YUV to RGB blit
-
-/**
- * Blits a rectangle.
- *
- * @param dst			the buffer which will receive the converted graphics data
- * @param src			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 bytesPerPixel	the number of bytes per pixel
- */
-void copyBlit(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const uint bytesPerPixel);
-
-/**
- * Blits a rectangle with a transparent color key.
- *
- * @param dst			the buffer which will receive the converted graphics data
- * @param src			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 bytesPerPixel	the number of bytes per pixel
- * @param key			the transparent color key
- */
-bool keyBlit(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const uint bytesPerPixel, const uint32 key);
-
-/**
- * Blits a rectangle from one graphical format to another.
- *
- * @param dst		the buffer which will receive the converted graphics data
- * @param src		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 Blitting to a 3Bpp destination is not supported
- * @note This can convert a surface in place, regardless of the
- *       source and destination format, as long as there is enough
- *       space for the destination. The dstPitch / srcPitch ratio
- *       must at least equal the dstBpp / srcBpp ratio for
- *       dstPitch >= srcPitch and at most dstBpp / srcBpp for
- *       dstPitch < srcPitch though.
- */
-bool crossBlit(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt);
-
-/**
- * Blits a rectangle from one graphical format to another with a transparent color key.
- *
- * @param dst		the buffer which will receive the converted graphics data
- * @param src		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
- * @param key			the transparent color key in the original pixel format
- * @return			true if conversion completes successfully,
- *					false if there is an error.
- *
- * @note Blitting to a 3Bpp destination is not supported
- * @note This can convert a surface in place, regardless of the
- *       source and destination format, as long as there is enough
- *       space for the destination. The dstPitch / srcPitch ratio
- *       must at least equal the dstBpp / srcBpp ratio for
- *       dstPitch >= srcPitch and at most dstBpp / srcBpp for
- *       dstPitch < srcPitch though.
- */
-bool crossKeyBlit(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt, const uint32 key);
-
-bool crossBlitMap(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const uint bytesPerPixel, const uint32 *map);
-
-bool crossKeyBlitMap(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint w, const uint h,
-			   const uint bytesPerPixel, const uint32 *map, const uint32 key);
-
-bool scaleBlit(byte *dst, const byte *src,
-			   const uint dstPitch, const uint srcPitch,
-			   const uint dstW, const uint dstH,
-			   const uint srcW, const uint srcH,
-			   const Graphics::PixelFormat &fmt);
-
-bool scaleBlitBilinear(byte *dst, const byte *src,
-					   const uint dstPitch, const uint srcPitch,
-					   const uint dstW, const uint dstH,
-					   const uint srcW, const uint srcH,
-					   const Graphics::PixelFormat &fmt);
-
-bool rotoscaleBlit(byte *dst, const byte *src,
-				   const uint dstPitch, const uint srcPitch,
-				   const uint dstW, const uint dstH,
-				   const uint srcW, const uint srcH,
-				   const Graphics::PixelFormat &fmt,
-				   const TransformStruct &transform,
-				   const Common::Point &newHotspot);
-
-bool rotoscaleBlitBilinear(byte *dst, const byte *src,
-						   const uint dstPitch, const uint srcPitch,
-						   const uint dstW, const uint dstH,
-						   const uint srcW, const uint srcH,
-						   const Graphics::PixelFormat &fmt,
-						   const TransformStruct &transform,
-						   const Common::Point &newHotspot);
 /** @} */
 } // End of namespace Graphics
 
diff --git a/graphics/module.mk b/graphics/module.mk
index 9b7dd5abc14..a70118797bb 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -1,7 +1,8 @@
 MODULE := graphics
 
 MODULE_OBJS := \
-	conversion.o \
+	blit.o \
+	blit-scale.o \
 	cursorman.o \
 	font.o \
 	fontman.o \
diff --git a/graphics/surface.cpp b/graphics/surface.cpp
index e78cd59f6f9..88a06af1275 100644
--- a/graphics/surface.cpp
+++ b/graphics/surface.cpp
@@ -27,7 +27,7 @@
 #include "graphics/palette.h"
 #include "graphics/primitives.h"
 #include "graphics/surface.h"
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "graphics/transform_tools.h"
 
 namespace Graphics {
diff --git a/graphics/transparent_surface.cpp b/graphics/transparent_surface.cpp
index f94effffa5d..ef4c3292163 100644
--- a/graphics/transparent_surface.cpp
+++ b/graphics/transparent_surface.cpp
@@ -27,7 +27,7 @@
 #include "common/rect.h"
 #include "common/math.h"
 #include "common/textconsole.h"
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "graphics/primitives.h"
 #include "graphics/transparent_surface.h"
 #include "graphics/transform_tools.h"
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index 32720db22fd..eb7998ba2a8 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -28,7 +28,7 @@
 #include "common/translation.h"
 #include "common/unicode-bidi.h"
 
-#include "graphics/conversion.h"
+#include "graphics/blit.h"
 #include "graphics/cursorman.h"
 #include "graphics/fontman.h"
 #include "graphics/surface.h"




More information about the Scummvm-git-logs mailing list