[Scummvm-cvs-logs] scummvm master -> b2de2cf85582fe62b96fcf36006816e16d023511

clone2727 clone2727 at gmail.com
Tue Apr 17 03:38:14 CEST 2012


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:
b2de2cf855 GRAPHICS: Improve the YUV410 conversion code speed some more


Commit: b2de2cf85582fe62b96fcf36006816e16d023511
    https://github.com/scummvm/scummvm/commit/b2de2cf85582fe62b96fcf36006816e16d023511
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2012-04-16T18:34:13-07:00

Commit Message:
GRAPHICS: Improve the YUV410 conversion code speed some more

Changed paths:
    graphics/yuv_to_rgb.cpp



diff --git a/graphics/yuv_to_rgb.cpp b/graphics/yuv_to_rgb.cpp
index 0abebf9..78903d0 100644
--- a/graphics/yuv_to_rgb.cpp
+++ b/graphics/yuv_to_rgb.cpp
@@ -300,6 +300,30 @@ void convertYUV420ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uS
 		convertYUV420ToRGB<uint32>((byte *)dst->pixels, dst->pitch, lookup, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch);
 }
 
+#define READ_QUAD(ptr, prefix) \
+	byte prefix##A = ptr[index]; \
+	byte prefix##B = ptr[index + 1]; \
+	byte prefix##C = ptr[index + uvPitch]; \
+	byte prefix##D = ptr[index + uvPitch + 1]
+
+#define DO_INTERPOLATION(out) \
+	out = (out##A * (4 - xDiff) * (4 - yDiff) + out##B * xDiff * (4 - yDiff) + \
+			out##C * yDiff * (4 - xDiff) + out##D * xDiff * yDiff) >> 4
+
+#define DO_YUV410_PIXEL() \
+	DO_INTERPOLATION(u); \
+	DO_INTERPOLATION(v); \
+	\
+	cr_r  = Cr_r_tab[v]; \
+	crb_g = Cr_g_tab[v] + Cb_g_tab[u]; \
+	cb_b  = Cb_b_tab[u]; \
+	\
+	PUT_PIXEL(*ySrc, dstPtr); \
+	dstPtr += sizeof(PixelInt); \
+	\
+	ySrc++; \
+	xDiff++
+
 template<typename PixelInt>
 void convertYUV410ToRGB(byte *dstPtr, int dstPitch, const YUVToRGBLookup *lookup, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch) {
 	// Keep the tables in pointers here to avoid a dereference on each pixel
@@ -309,47 +333,41 @@ void convertYUV410ToRGB(byte *dstPtr, int dstPitch, const YUVToRGBLookup *lookup
 	const int16 *Cb_b_tab = Cb_g_tab + 256;
 	const uint32 *rgbToPix = lookup->_rgbToPix;
 
+	int quarterWidth = yWidth >> 2;
+
 	for (int y = 0; y < yHeight; y++) {
-		for (int x = 0; x < yWidth; x++) {
+		for (int x = 0; x < quarterWidth; x++) {
 			// Perform bilinear interpolation on the the chroma values
 			// Based on the algorithm found here: http://tech-algorithm.com/articles/bilinear-image-scaling/
 			// Feel free to optimize further
-			int targetX = x >> 2;
 			int targetY = y >> 2;
-			int xDiff = x & 3;
+			int xDiff = 0;
 			int yDiff = y & 3;
-			int index = targetY * uvPitch + targetX;
-
-			byte a = uSrc[index];
-			byte b = uSrc[index + 1];
-			byte c = uSrc[index + uvPitch];
-			byte d = uSrc[index + uvPitch + 1];
-
-			byte u = (a * (4 - xDiff) * (4 - yDiff) + b * xDiff * (4 - yDiff) +
-					c * yDiff * (4 - xDiff) + d * xDiff * yDiff) >> 4;
-
-			a = vSrc[index];
-			b = vSrc[index + 1];
-			c = vSrc[index + uvPitch];
-			d = vSrc[index + uvPitch + 1];
+			int index = targetY * uvPitch + x;
 
-			byte v = (a * (4 - xDiff) * (4 - yDiff) + b * xDiff * (4 - yDiff) +
-					c * yDiff * (4 - xDiff) + d * xDiff * yDiff) >> 4;
+			// Declare some variables for the following macros
+			byte u, v;
+			int16 cr_r, crb_g, cb_b;
+			register const uint32 *L;
 
-			int16 cr_r  = Cr_r_tab[v];
-			int16 crb_g = Cr_g_tab[v] + Cb_g_tab[u];
-			int16 cb_b  = Cb_b_tab[u];
-			const uint32 *L;
+			READ_QUAD(uSrc, u);
+			READ_QUAD(vSrc, v);
 
-			PUT_PIXEL(ySrc[x], dstPtr);
-			dstPtr += sizeof(PixelInt);
+			DO_YUV410_PIXEL();
+			DO_YUV410_PIXEL();
+			DO_YUV410_PIXEL();
+			DO_YUV410_PIXEL();
 		}
 
 		dstPtr += dstPitch - yWidth * sizeof(PixelInt);
-		ySrc += yPitch;
+		ySrc += yPitch - yWidth;
 	}
 }
 
+#undef READ_QUAD
+#undef DO_INTERPOLATION
+#undef DO_YUV410_PIXEL
+
 void convertYUV410ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch) {
 	// Sanity checks
 	assert(dst && dst->pixels);






More information about the Scummvm-git-logs mailing list