[Scummvm-cvs-logs] SF.net SVN: scummvm:[33319] scummvm/branches/gsoc2008-gui/graphics

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Sun Jul 27 00:58:02 CEST 2008


Revision: 33319
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33319&view=rev
Author:   Tanoku
Date:     2008-07-26 22:58:02 +0000 (Sat, 26 Jul 2008)

Log Message:
-----------
Convolution filters for the vector renderer. Pretty cool.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.cpp
    scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.h

Modified: scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.cpp	2008-07-26 22:06:53 UTC (rev 33318)
+++ scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.cpp	2008-07-26 22:58:02 UTC (rev 33319)
@@ -50,6 +50,15 @@
 	}
 }
 
+const VectorRenderer::ConvolutionDataSet VectorRenderer::_convolutionData[VectorRenderer::kConvolutionMAX] = {
+	{ {{1, 1, 1}, {1, 8, 1}, {1, 1, 1}}, 16, 0 }, // soft blur matrix
+	{ {{2, 2, 2}, {2, 2, 2}, {2, 2, 2}}, 18, 0 }, // hard blur matrix
+	{ {{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}, 16, 0 }, // gaussian blur matrix
+	{ {{2, 0, 0}, {0, -1, 0}, {0, 0, -1}}, 1, 127}, // emboss matrix
+	{ {{-1, -1, -1}, {-1, 9, -1}, {-1, -1, -1}}, 1, 0}, // sharpen matrix
+	{ {{1, 1, 1}, {1, -7, 1}, {1, 1, 1}}, 1, 0} // edge find matrix
+};
+
 /********************************************************************
  * DRAWSTEP handling functions
  ********************************************************************/
@@ -159,6 +168,39 @@
 /********************************************************************
  * MISCELANEOUS functions
  ********************************************************************/
+template <typename PixelType, typename PixelFormat>
+void VectorRendererSpec<PixelType, PixelFormat>::
+areaConvolution(const Common::Rect &area, const int filter[3][3], int filterDiv, int offset) {
+	PixelType *ptr = 0;
+	int newR, newG, newB;
+	uint8 r, g, b;
+	int yVal;
+	
+	for (int y = area.top; y < area.bottom; ++y) {
+		for (int x = area.left; x < area.right; ++x) {
+			for (int j = 0; j < 3; ++j) {
+				yVal = MIN(MAX(y - 1 + j, 0), area.bottom - 1);
+				
+				for (int i = 0; i < 3; ++i) {
+					ptr = (PixelType *)Base::_activeSurface->getBasePtr(MIN(MAX(x - 1 + j, 0), area.right - 1), yVal);
+					colorToRGB<PixelFormat>((uint32)*ptr, r, g, b);
+					
+					newR += r * filter[j][i];
+					newG += g * filter[j][i];
+					newB += b * filter[j][i];
+				}
+			}
+			
+			newR = (newR / filterDiv) + offset;
+			newG = (newG / filterDiv) + offset;
+			newB = (newB / filterDiv) + offset;
+			
+			ptr = (PixelType *)Base::_activeSurface->getBasePtr(x, y);
+			*ptr = RGBToColor<PixelFormat>(CLIP(newR, 0, 255), CLIP(newG, 0, 255), CLIP(newB, 0, 255));
+		}		
+	}
+}
+	
 /** Fixed point SQUARE ROOT **/
 inline uint32 fp_sqroot(uint32 x) {
 	register uint32 root, remHI, remLO, testDIV, count;

Modified: scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.h
===================================================================
--- scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.h	2008-07-26 22:06:53 UTC (rev 33318)
+++ scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.h	2008-07-26 22:58:02 UTC (rev 33319)
@@ -113,6 +113,22 @@
 		kTriangleLeft,
 		kTriangleRight
 	};
+	
+	enum ConvolutionData {
+		kConvolutionSoftBlur,
+		kConvolutionHardBlur,
+		kConvolutionGaussianBlur,
+		kConvolutionEmboss,
+		kConvolutionSharpen,
+		kConvolutionEdgeDetect,
+		kConvolutionMAX
+	};
+	
+	struct ConvolutionDataSet {
+		int matrix[3][3];
+		int divisor;
+		int offset;
+	};
 
 	/**
 	 * Draws a line by considering the special cases for optimization.
@@ -412,6 +428,12 @@
 	
 	virtual void disableShadows() { _disableShadows = true; }
 	virtual void enableShadows() { _disableShadows = false; }
+	
+	virtual void areaConvolution(const Common::Rect &area, const int filter[3][3], int filterDiv, int offset) = 0;
+	
+	virtual void applyConvolutionMatrix(const ConvolutionData id, const Common::Rect &area) {
+		areaConvolution(area, _convolutionData[id].matrix, _convolutionData[id].divisor, _convolutionData[id].offset);
+	}
 
 protected:
 	Surface *_activeSurface; /** Pointer to the surface currently being drawn */
@@ -425,6 +447,8 @@
 
 	int _gradientFactor; /** Multiplication factor of the active gradient */
 	int _gradientBytes[3]; /** Color bytes of the active gradient, used to speed up calculation */
+	
+	static const ConvolutionDataSet _convolutionData[kConvolutionMAX];
 };
 
 /**
@@ -776,6 +800,8 @@
 				} while (--n > 0);
 		}
 	}
+	
+	virtual void areaConvolution(const Common::Rect &area, const int filter[3][3], int filterDiv, int offset);
 
 	PixelType _fgColor; /** Foreground color currently being used to draw on the renderer */
 	PixelType _bgColor; /** Background color currently being used to draw on the renderer */


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list