[Scummvm-cvs-logs] SF.net SVN: scummvm:[53314] scummvm/trunk/engines/sword25

sev at users.sourceforge.net sev at users.sourceforge.net
Wed Oct 13 01:34:25 CEST 2010


Revision: 53314
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53314&view=rev
Author:   sev
Date:     2010-10-12 23:34:25 +0000 (Tue, 12 Oct 2010)

Log Message:
-----------
SWORD25: Initial code for vector image rendering. Crashes badly.

Modified Paths:
--------------
    scummvm/trunk/engines/sword25/gfx/image/vectorimage.cpp
    scummvm/trunk/engines/sword25/gfx/image/vectorimage.h
    scummvm/trunk/engines/sword25/gfx/image/vectorimagerenderer.cpp
    scummvm/trunk/engines/sword25/gfx/image/vectorimagerenderer.h
    scummvm/trunk/engines/sword25/gfx/opengl/glimage.cpp
    scummvm/trunk/engines/sword25/gfx/opengl/glimage.h
    scummvm/trunk/engines/sword25/module.mk

Removed Paths:
-------------
    scummvm/trunk/engines/sword25/gfx/opengl/glvectorimageblit.cpp

Modified: scummvm/trunk/engines/sword25/gfx/image/vectorimage.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/image/vectorimage.cpp	2010-10-12 23:33:51 UTC (rev 53313)
+++ scummvm/trunk/engines/sword25/gfx/image/vectorimage.cpp	2010-10-12 23:34:25 UTC (rev 53314)
@@ -43,6 +43,8 @@
 
 #include <libart_lgpl/art_vpath_bpath.h>
 
+#include "sword25/gfx/opengl/glimage.h"
+
 namespace Sword25 {
 
 #define BS_LOG_PREFIX "VECTORIMAGE"
@@ -230,7 +232,7 @@
 // Konstruktion
 // -----------------------------------------------------------------------------
 
-VectorImage::VectorImage(const byte *pFileData, uint fileSize, bool &success) {
+VectorImage::VectorImage(const byte *pFileData, uint fileSize, bool &success) : _pixelData(0) {
 	success = false;
 
 	// Bitstream-Objekt erzeugen
@@ -312,6 +314,9 @@
 		for (int i = _elements[j].getPathCount() - 1; i >= 0; i--)
 			if (_elements[j].getPathInfo(i).getVec())
 				art_free(_elements[j].getPathInfo(i).getVec());
+
+	if (_pixelData)
+		free(_pixelData);
 }
 
 
@@ -591,4 +596,42 @@
 	return 0;
 }
 
+bool VectorImage::blit(int posX, int posY,
+                          int flipping,
+                          Common::Rect *pPartRect,
+                          uint color,
+                          int width, int height) {
+	static VectorImage *oldThis = 0;
+	static int              oldWidth = -2;
+	static int              oldHeight = -2;
+
+	// Falls Breite oder H\xF6he 0 sind, muss nichts dargestellt werden.
+	if (width == 0 || height == 0)
+		return true;
+
+	// Feststellen, ob das alte Bild im Cache nicht wiederbenutzt werden kann und neu Berechnet werden muss
+	if (!(oldThis == this && oldWidth == width && oldHeight == height)) {
+		float ScaleFactorX = (width == - 1) ? 1 : static_cast<float>(width) / static_cast<float>(getWidth());
+		float ScaleFactorY = (height == - 1) ? 1 : static_cast<float>(height) / static_cast<float>(getHeight());
+
+		uint RenderedWidth;
+		uint RenderedHeight;
+
+		render(ScaleFactorX, ScaleFactorY, RenderedWidth, RenderedHeight);
+
+		oldThis = this;
+		oldHeight = height;
+		oldWidth = width;
+	}
+
+	GLImage *rend = new GLImage();
+
+	rend->replaceContent(_pixelData, width, height);
+	rend->blit(posX, posY, flipping, pPartRect, color, width, height);
+
+	delete rend;
+
+	return true;
+}
+
 } // End of namespace Sword25

Modified: scummvm/trunk/engines/sword25/gfx/image/vectorimage.h
===================================================================
--- scummvm/trunk/engines/sword25/gfx/image/vectorimage.h	2010-10-12 23:33:51 UTC (rev 53313)
+++ scummvm/trunk/engines/sword25/gfx/image/vectorimage.h	2010-10-12 23:34:25 UTC (rev 53314)
@@ -181,6 +181,9 @@
 		return GraphicEngine::CF_ARGB32;
 	}
 	virtual bool fill(const Common::Rect *pFillRect = 0, uint color = BS_RGB(0, 0, 0));
+
+	void render(float scaleFactorX, float scaleFactorY, uint &width, uint &height);
+
 	virtual uint getPixel(int x, int y);
 	virtual bool isBlitSource() const {
 		return true;
@@ -219,6 +222,8 @@
 	ArtBpath *storeBez(ArtBpath *bez, int lineStyle, int fillStyle0, int fillStyle1, int *bezNodes, int *bezAllocated);
 	Common::Array<VectorImageElement>    _elements;
 	Common::Rect                         _boundingBox;
+
+	byte *_pixelData;
 };
 
 } // End of namespace Sword25

Modified: scummvm/trunk/engines/sword25/gfx/image/vectorimagerenderer.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/image/vectorimagerenderer.cpp	2010-10-12 23:33:51 UTC (rev 53313)
+++ scummvm/trunk/engines/sword25/gfx/image/vectorimagerenderer.cpp	2010-10-12 23:34:25 UTC (rev 53314)
@@ -32,182 +32,282 @@
  *
  */
 
-// -----------------------------------------------------------------------------
-// Includes
-// -----------------------------------------------------------------------------
+#include <libart_lgpl/art_vpath_bpath.h>
+#include <libart_lgpl/art_svp_vpath.h>
+#include <libart_lgpl/art_svp_vpath_stroke.h>
+#include <libart_lgpl/art_svp_render_aa.h>
+#include <libart_lgpl/art_rgb_svp.h>
+#include <libart_lgpl/art_rgb.h>
 
-#include "sword25/gfx/image/vectorimagerenderer.h"
 #include "sword25/gfx/image/vectorimage.h"
 
-#if 0 // TODO
-#include "agg_conv_curve.h"
-#include "agg_path_storage.h"
-#include "agg_conv_stroke.h"
-#endif
-
 namespace Sword25 {
 
-#if 0 // TODO
-// -----------------------------------------------------------------------------
-// CompoundShape
-// -----------------------------------------------------------------------------
+void
+art_rgb_fill_run1(art_u8 *buf, art_u8 r, art_u8 g, art_u8 b, int n) {
+	int i;
 
-class CompoundShape {
-public:
-	CompoundShape(const BS_VectorImageElement &VectorImageElement) :
-		m_ImageElement(VectorImageElement),
-		m_Path(VectorImageElement.GetPaths()),
-		m_Affine(),
-		m_Curve(m_Path),
-		m_Trans(m_Curve, m_Affine)
-	{}
-
-	unsigned operator [](unsigned i) const {
-		return m_ImageElement.GetPathInfo(i).GetID();
+	if (r == g && g == b && r == 255) {
+		memset(buf, g, n + n + n + n);
+	} else {
+		art_u32 *alt = (art_u32 *)buf;
+		//art_u32 color = (r << 24) | (g << 16) | (b << 8) | 0xff;
+		art_u32 color = (r << 0) | (g << 8) | (b << 16) | (0xff << 24);
+		for (i = 0; i < n; i++)
+			*alt++ = color;
 	}
+}
 
-	unsigned paths() const {
-		return m_ImageElement.GetPathCount();
-	}
+void
+art_rgb_run_alpha1(art_u8 *buf, art_u8 r, art_u8 g, art_u8 b, int alpha, int n) {
+	int i;
+	int v;
 
-	void rewind(unsigned path_id) {
-		m_Trans.rewind(path_id);
+	for (i = 0; i < n; i++) {
+		v = *buf;
+		*buf++ = v + (((r - v) * alpha + 0x80) >> 8);
+		v = *buf;
+		*buf++ = v + (((g - v) * alpha + 0x80) >> 8);
+		v = *buf;
+		*buf++ = v + (((b - v) * alpha + 0x80) >> 8);
+		v = *buf;
+		*buf++ = v + (((alpha - v) * alpha + 0x80) >> 8);
 	}
+}
 
-	unsigned vertex(double *x, double *y) {
-		return m_Trans.vertex(x, y);
-	}
+typedef struct _ArtRgbSVPAlphaData ArtRgbSVPAlphaData;
 
-private:
-	const BS_VectorImageElement                                &m_ImageElement;
-	agg::path_storage                                           m_Path;
-	agg::trans_affine                                           m_Affine;
-	agg::conv_curve<agg::path_storage>                          m_Curve;
-	agg::conv_transform< agg::conv_curve<agg::path_storage> >   m_Trans;
+struct _ArtRgbSVPAlphaData {
+	int alphatab[256];
+	art_u8 r, g, b, alpha;
+	art_u8 *buf;
+	int rowstride;
+	int x0, x1;
 };
 
+static void
+art_rgb_svp_alpha_callback1(void *callback_data, int y,
+                            int start, ArtSVPRenderAAStep *steps, int n_steps) {
+	ArtRgbSVPAlphaData *data = (ArtRgbSVPAlphaData *)callback_data;
+	art_u8 *linebuf;
+	int run_x0, run_x1;
+	art_u32 running_sum = start;
+	int x0, x1;
+	int k;
+	art_u8 r, g, b;
+	int *alphatab;
+	int alpha;
 
-// -----------------------------------------------------------------------------
-// StyleHandler
-// -----------------------------------------------------------------------------
+	linebuf = data->buf;
+	x0 = data->x0;
+	x1 = data->x1;
 
-class StyleHandler {
-public:
-	StyleHandler(const BS_VectorImageElement &VectorImageElement) : m_ImageElement(VectorImageElement) {}
+	r = data->r;
+	g = data->g;
+	b = data->b;
+	alphatab = data->alphatab;
 
-	bool is_solid(uint style) const {
-		return true;
-	}
+	if (n_steps > 0) {
+		run_x1 = steps[0].x;
+		if (run_x1 > x0) {
+			alpha = (running_sum >> 16) & 0xff;
+			if (alpha)
+				art_rgb_run_alpha1(linebuf, r, g, b, alphatab[alpha], run_x1 - x0);
+		}
 
-	const agg::rgba8 &color(unsigned style) const {
-		return m_ImageElement.GetFillStyleColor(style);
+		for (k = 0; k < n_steps - 1; k++) {
+			running_sum += steps[k].delta;
+			run_x0 = run_x1;
+			run_x1 = steps[k + 1].x;
+			if (run_x1 > run_x0) {
+				alpha = (running_sum >> 16) & 0xff;
+				if (alpha)
+					art_rgb_run_alpha1(linebuf + (run_x0 - x0) * 4, r, g, b, alphatab[alpha], run_x1 - run_x0);
+			}
+		}
+		running_sum += steps[k].delta;
+		if (x1 > run_x1) {
+			alpha = (running_sum >> 16) & 0xff;
+			if (alpha)
+				art_rgb_run_alpha1(linebuf + (run_x1 - x0) * 4, r, g, b, alphatab[alpha], x1 - run_x1);
+		}
+	} else {
+		alpha = (running_sum >> 16) & 0xff;
+		if (alpha)
+			art_rgb_run_alpha1(linebuf, r, g, b, alphatab[alpha], x1 - x0);
 	}
 
-	void generate_span(agg::rgba8 *span, int x, int y, unsigned len, unsigned style) {
-		// Wird nicht benutzt
-		return;
-	}
+	data->buf += data->rowstride;
+}
 
-private:
-	const BS_VectorImageElement &m_ImageElement;
-};
+static void
+art_rgb_svp_alpha_opaque_callback1(void *callback_data, int y,
+                                   int start,
+                                   ArtSVPRenderAAStep *steps, int n_steps) {
+	ArtRgbSVPAlphaData *data = (ArtRgbSVPAlphaData *)callback_data;
+	art_u8 *linebuf;
+	int run_x0, run_x1;
+	art_u32 running_sum = start;
+	int x0, x1;
+	int k;
+	art_u8 r, g, b;
+	int *alphatab;
+	int alpha;
 
-BS_VectorImageRenderer::BS_VectorImageRenderer() :
-	PixelFormat(rbuf) {
+	linebuf = data->buf;
+	x0 = data->x0;
+	x1 = data->x1;
 
+	r = data->r;
+	g = data->g;
+	b = data->b;
+	alphatab = data->alphatab;
+
+	if (n_steps > 0) {
+		run_x1 = steps[0].x;
+		if (run_x1 > x0) {
+			alpha = running_sum >> 16;
+			if (alpha) {
+				if (alpha >= 255)
+					art_rgb_fill_run1(linebuf, r, g, b, run_x1 - x0);
+				else
+					art_rgb_run_alpha1(linebuf, r, g, b, alphatab[alpha], run_x1 - x0);
+			}
+		}
+
+		for (k = 0; k < n_steps - 1; k++) {
+			running_sum += steps[k].delta;
+			run_x0 = run_x1;
+			run_x1 = steps[k + 1].x;
+			if (run_x1 > run_x0) {
+				alpha = running_sum >> 16;
+				if (alpha) {
+					if (alpha >= 255)
+						art_rgb_fill_run1(linebuf + (run_x0 - x0) * 4, r, g, b, run_x1 - run_x0);
+					else
+						art_rgb_run_alpha1(linebuf + (run_x0 - x0) * 4, r, g, b, alphatab[alpha], run_x1 - run_x0);
+				}
+			}
+		}
+		running_sum += steps[k].delta;
+		if (x1 > run_x1) {
+			alpha = running_sum >> 16;
+			if (alpha) {
+				if (alpha >= 255)
+					art_rgb_fill_run1(linebuf + (run_x1 - x0) * 4, r, g, b, x1 - run_x1);
+				else
+					art_rgb_run_alpha1(linebuf + (run_x1 - x0) * 4, r, g, b, alphatab[alpha], x1 - run_x1);
+			}
+		}
+	} else {
+		alpha = running_sum >> 16;
+		if (alpha) {
+			if (alpha >= 255)
+				art_rgb_fill_run1(linebuf, r, g, b, x1 - x0);
+			else
+				art_rgb_run_alpha1(linebuf, r, g, b, alphatab[alpha], x1 - x0);
+		}
+	}
+
+	data->buf += data->rowstride;
 }
 
+void
+art_rgb_svp_alpha1(const ArtSVP *svp,
+                   int x0, int y0, int x1, int y1,
+                   art_u32 rgba,
+                   art_u8 *buf, int rowstride,
+                   ArtAlphaGamma *alphagamma) {
+	ArtRgbSVPAlphaData data;
+	int r, g, b, alpha;
+	int i;
+	int a, da;
 
-bool BS_VectorImageRenderer::Render(const BS_VectorImage &VectorImage,
-                                    float ScaleFactorX, float ScaleFactorY,
-                                    uint &Width, uint &Height,
-                                    byte *ImageData,
-                                    float LineScaleFactor,
-                                    bool NoAlphaShapes) {
-	Width = static_cast<uint>(VectorImage.GetWidth() * ScaleFactorX);
-	Height = static_cast<uint>(VectorImage.GetHeight() * ScaleFactorY);
+	r = rgba >> 24;
+	g = (rgba >> 16) & 0xff;
+	b = (rgba >> 8) & 0xff;
+	alpha = rgba & 0xff;
 
-	ImageData.resize(Width * Height * 4);
-	memset(&ImageData[0], 0, ImageData.size());
-	rbuf.attach(reinterpret_cast<agg::int8u *>(&ImageData[0]), Width, Height, Width * 4);
+	data.r = r;
+	data.g = g;
+	data.b = b;
+	data.alpha = alpha;
 
-	BaseRenderer.attach(PixelFormat);
-	ScanlineRenderer.attach(BaseRenderer);
+	a = 0x8000;
+	da = (alpha * 66051 + 0x80) >> 8; /* 66051 equals 2 ^ 32 / (255 * 255) */
 
-	// Die SWF-Shapes sind h\xE4ufig nicht am Ursprung (0, 0) ausgerichtet, daher wird die Shape vor dem Rendern derart verschoben, dass
-	// sich die linke obere Ecke der Bounding-Box im Ursprung befindet. Danach wird die Skalierung angewandt.
-	Scale = agg::trans_affine_translation(- VectorImage.GetBoundingBox().left, - VectorImage.GetBoundingBox().top);
-	Scale *= agg::trans_affine_scaling(ScaleFactorX, ScaleFactorY);
+	for (i = 0; i < 256; i++) {
+		data.alphatab[i] = a >> 16;
+		a += da;
+	}
 
-	for (uint element = 0; element < VectorImage.GetElementCount(); ++element) {
-		const BS_VectorImageElement &CurImageElement = VectorImage.GetElement(element);
+	data.buf = buf;
+	data.rowstride = rowstride;
+	data.x0 = x0;
+	data.x1 = x1;
+	if (alpha == 255)
+		art_svp_render_aa(svp, x0, y0, x1, y1, art_rgb_svp_alpha_opaque_callback1, &data);
+	else
+		art_svp_render_aa(svp, x0, y0, x1, y1, art_rgb_svp_alpha_callback1, &data);
+}
 
-		CompoundShape ImageCompoundShape(CurImageElement);
-		StyleHandler ImageStyleHandler(CurImageElement);
-		agg::conv_transform<CompoundShape> Shape(ImageCompoundShape, Scale);
-		agg::conv_stroke<agg::conv_transform<CompoundShape> > Stroke(Shape);
+void VectorImage::render(float scaleFactorX, float scaleFactorY, uint &width, uint &height) {
+	width = static_cast<uint>(getWidth() * scaleFactorX);
+	height = static_cast<uint>(getHeight() * scaleFactorY);
 
-		// Fill shape
-		//----------------------
-		CompoundRasterizer.clip_box(0, 0, Width, Height);
-		CompoundRasterizer.reset();
-		for (uint i = 0; i < CurImageElement.GetPathCount(); ++i) {
-			uint FillStyle0 = CurImageElement.GetPathInfo(i).GetFillStyle0();
-			uint FillStyle1 = CurImageElement.GetPathInfo(i).GetFillStyle1();
+	if (_pixelData)
+		free(_pixelData);
 
-			if (NoAlphaShapes) {
-				if (FillStyle0 != 0 && CurImageElement.GetFillStyleColor(FillStyle0 - 1).a != 255) FillStyle0 = 0;
-				if (FillStyle1 != 0 && CurImageElement.GetFillStyleColor(FillStyle1 - 1).a != 255) FillStyle1 = 0;
-			}
+	_pixelData = (byte *)malloc(width * height * 4);
+	memset(_pixelData, 0, width * height * 4);
 
-			if (FillStyle0 != 0 || FillStyle1 != 0) {
-				CompoundRasterizer.styles(FillStyle0 - 1, FillStyle1 - 1);
-				CompoundRasterizer.add_path(Shape, CurImageElement.GetPathInfo(i).GetID());
-			}
-		}
-		agg::render_scanlines_compound_layered(CompoundRasterizer, Scanline, BaseRenderer, Alloc, ImageStyleHandler);
+	for (int j = _elements.size() - 1; j >= 0; j--)
+		for (int i = _elements[j].getPathCount() - 1; i >= 0; i--) {
+			if (!_elements[j].getPathInfo(i).getVec())
+				continue;
 
+			bool needfree = false;
+			ArtVpath *vec = _elements[j].getPathInfo(i).getVec();
 
-		// Draw strokes
-		//----------------------
-		Rasterizer.clip_box(0, 0, Width, Height);
-		Stroke.line_join(agg::round_join);
-		Stroke.line_cap(agg::round_cap);
-		for (uint i = 0; i < CurImageElement.GetPathCount(); ++i) {
-			Rasterizer.reset();
+			// Upscale vector
+			if (scaleFactorX != 1.0 || scaleFactorY != 1.0) {
+				ArtVpath *vec1;
+				int size;
 
-			uint CurrentLineStyle = CurImageElement.GetPathInfo(i).GetLineStyle();
-			if (CurrentLineStyle != 0) {
-				Stroke.width(ScaleFactorX * CurImageElement.GetLineStyleWidth(CurrentLineStyle - 1) * LineScaleFactor);
-				Rasterizer.add_path(Stroke, CurImageElement.GetPathInfo(i).GetID());
-				ScanlineRenderer.color(CurImageElement.GetLineStyleColor(CurrentLineStyle - 1));
-				// HACK
-				// Die SWF-Frames enthalten zum Teil Reste von gr\xFCnen Linien, die wohl von Bernd als Umriss benutzt wurden.
-				// Damit diese Reste nicht st\xF6rend auffallen werden gr\xFCne Linien schlichtweg ignoriert.
-				if (!(CurImageElement.GetLineStyleColor(CurrentLineStyle - 1).a == 255 &&
-				        CurImageElement.GetLineStyleColor(CurrentLineStyle - 1).r == 0 &&
-				        CurImageElement.GetLineStyleColor(CurrentLineStyle - 1).g == 255 &&
-				        CurImageElement.GetLineStyleColor(CurrentLineStyle - 1).b == 0))
-					agg::render_scanlines(Rasterizer, Scanline, ScanlineRenderer);
+				for (size = 0; vec[size].code != ART_END; size++);
+
+				vec1 = art_new(ArtVpath, size + 1);
+
+				int k;
+				for (k = 0; k < size; k++) {
+					vec1[k].code = vec[k].code;
+					vec1[k].x = vec[k].x * scaleFactorX;
+					vec1[k].y = vec[k].y * scaleFactorY;
+				}
+
+				vec1[k].code = ART_END;
+
+				vec = vec1;
+				needfree = true;
 			}
-		}
-	}
 
-	return true;
-}
+			ArtSVP *svp1 = art_svp_from_vpath(vec);
 
-#else
+			int penWidth = _elements[j].getLineStyleWidth(_elements[j].getPathInfo(i).getLineStyle());
+			ArtSVP *svp2 = art_svp_vpath_stroke(vec, ART_PATH_STROKE_JOIN_ROUND, ART_PATH_STROKE_CAP_ROUND, penWidth, 1.0, 0.5);
+			if (needfree)
+				art_free(vec);
 
-VectorImageRenderer::VectorImageRenderer() {}
+			int color1 = _elements[j].getFillStyleColor(_elements[j].getPathInfo(i).getFillStyle0());
+			int color2 = _elements[j].getLineStyleColor(_elements[j].getPathInfo(i).getLineStyle());
 
-bool VectorImageRenderer::Render(const VectorImage &VectorImage,
-                                    float ScaleFactorX, float ScaleFactorY,
-                                    uint &Width, uint &Height,
-                                    byte *ImageData,
-                                    float LineScaleFactor,
-                                    bool NoAlphaShapes) {
-	return true;
+			art_rgb_svp_alpha1(svp1, 0, 0, width, height, color1, _pixelData, width * 4, NULL);
+			art_rgb_svp_alpha1(svp2, 0, 0, width, height, color2, _pixelData, width * 4, NULL);
+
+			art_free(svp2);
+			art_free(svp1);
+		}
 }
-#endif
 
+
 } // End of namespace Sword25

Modified: scummvm/trunk/engines/sword25/gfx/image/vectorimagerenderer.h
===================================================================
--- scummvm/trunk/engines/sword25/gfx/image/vectorimagerenderer.h	2010-10-12 23:33:51 UTC (rev 53313)
+++ scummvm/trunk/engines/sword25/gfx/image/vectorimagerenderer.h	2010-10-12 23:34:25 UTC (rev 53314)
@@ -41,18 +41,6 @@
 
 #include "sword25/kernel/common.h"
 
-#if 0 // TODO
-#include "agg_rendering_buffer.h"
-#include "agg_pixfmt_rgba.h"
-#include "agg_renderer_scanline.h"
-#include "agg_rasterizer_scanline_aa.h"
-#include "agg_rasterizer_compound_aa.h"
-#include "agg_scanline_u.h"
-#include "agg_scanline_bin.h"
-#include "agg_trans_affine.h"
-#include "agg_span_allocator.h"
-#endif
-
 namespace Sword25 {
 
 class VectorImage;
@@ -69,9 +57,7 @@
 	bool Render(const VectorImage &VectorImage,
 	            float ScaleFactorX, float ScaleFactorY,
 	            uint &Width, uint &Height,
-	            byte *ImageData,
-	            float LineScaleFactor = 1.0f,
-	            bool NoAlphaShapes = false);
+	            byte *ImageData);
 
 private:
 #if 0

Modified: scummvm/trunk/engines/sword25/gfx/opengl/glimage.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/opengl/glimage.cpp	2010-10-12 23:33:51 UTC (rev 53313)
+++ scummvm/trunk/engines/sword25/gfx/opengl/glimage.cpp	2010-10-12 23:34:25 UTC (rev 53314)
@@ -87,6 +87,8 @@
 	// Dateidaten freigeben
 	delete[] pFileData;
 
+	_doCleanup = true;
+
 	result = true;
 	return;
 }
@@ -96,20 +98,30 @@
 GLImage::GLImage(uint width, uint height, bool &result) :
 	_width(width),
 	_height(height) {
-	result = false;
 
 	_data = new byte[width * height * 4];
 
 	_backSurface = (static_cast<GraphicEngine *>(Kernel::GetInstance()->GetService("gfx")))->getSurface();
 
+	_doCleanup = true;
+
 	result = true;
 	return;
 }
 
+GLImage::GLImage() : _width(0), _height(0), _data(0) {
+	_backSurface = (static_cast<GraphicEngine *>(Kernel::GetInstance()->GetService("gfx")))->getSurface();
+
+	_doCleanup = false;
+
+	return;
+}
+
 // -----------------------------------------------------------------------------
 
 GLImage::~GLImage() {
-	delete[] _data;
+	if (_doCleanup)
+		delete[] _data;
 }
 
 // -----------------------------------------------------------------------------
@@ -140,6 +152,11 @@
 	return true;
 }
 
+void GLImage::replaceContent(byte *pixeldata, int width, int height) {
+	_width = width;
+	_height = height;
+	_data = pixeldata;
+}
 // -----------------------------------------------------------------------------
 
 uint GLImage::getPixel(int x, int y) {

Modified: scummvm/trunk/engines/sword25/gfx/opengl/glimage.h
===================================================================
--- scummvm/trunk/engines/sword25/gfx/opengl/glimage.h	2010-10-12 23:33:51 UTC (rev 53313)
+++ scummvm/trunk/engines/sword25/gfx/opengl/glimage.h	2010-10-12 23:34:25 UTC (rev 53314)
@@ -68,6 +68,8 @@
 	                  d\xFCrfen keine Methoden am Objekt aufgerufen werden und das Objekt ist sofort zu zerst\xF6ren.
 	*/
 	GLImage(uint width, uint height, bool &result);
+	GLImage();
+
 	virtual ~GLImage();
 
 	virtual int getWidth() const {
@@ -87,6 +89,7 @@
 	                  int width = -1, int height = -1);
 	virtual bool fill(const Common::Rect *pFillRect, uint color);
 	virtual bool setContent(const byte *pixeldata, uint size, uint offset = 0, uint stride = 0);
+	void replaceContent(byte *pixeldata, int width, int height);
 	virtual uint getPixel(int x, int y);
 
 	virtual bool isBlitSource() const               {
@@ -114,6 +117,7 @@
 	byte *_data;
 	int  _width;
 	int  _height;
+	bool _doCleanup;
 
 	Graphics::Surface *_backSurface;
 };

Deleted: scummvm/trunk/engines/sword25/gfx/opengl/glvectorimageblit.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/opengl/glvectorimageblit.cpp	2010-10-12 23:33:51 UTC (rev 53313)
+++ scummvm/trunk/engines/sword25/gfx/opengl/glvectorimageblit.cpp	2010-10-12 23:34:25 UTC (rev 53314)
@@ -1,146 +0,0 @@
-/* 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$
- *
- */
-
-/*
- * This code is based on Broken Sword 2.5 engine
- *
- * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
- *
- * Licensed under GNU GPL v2
- *
- */
-
-// -----------------------------------------------------------------------------
-// Includes
-// -----------------------------------------------------------------------------
-
-#include "sword25/gfx/image/vectorimage.h"
-#include "sword25/gfx/image/vectorimagerenderer.h"
-
-namespace Sword25 {
-
-#define BS_LOG_PREFIX "GLVECTORIMAGEBLIT"
-
-// -----------------------------------------------------------------------------
-
-namespace {
-const float LINE_SCALE_FACTOR = 1.0f;
-}
-
-// -----------------------------------------------------------------------------
-
-bool VectorImage::blit(int PosX, int PosY,
-                          int Flipping,
-                          Common::Rect *pPartRect,
-                          uint Color,
-                          int Width, int Height) {
-#if 0
-	static BS_VectorImageRenderer VectorImageRenderer;
-	static byte *PixelData;
-	static GLS_Sprite Sprite = 0;
-	static BS_VectorImage *OldThis = 0;
-	static int              OldWidth;
-	static int              OldHeight;
-	static GLS_Rect         OldSubImage;
-
-	// Falls Breite oder H\xF6he 0 sind, muss nichts dargestellt werden.
-	if (Width == 0 || Height == 0) return true;
-
-	// Sprite erstellen, falls es noch nicht erstellt wurde
-	if (Sprite == 0) {
-		GLS_Result Result = GLS_NewSprite(512, 512, GLS_True, 0, &Sprite);
-		if (Result != GLS_OK) {
-			BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(Result));
-			return false;
-		}
-	}
-
-	// Feststellen, ob das alte Bild im Cache nicht wiederbenutzt werden kann und neu Berechnet werden muss
-	if (!(OldThis == this && OldWidth == Width && OldHeight == Height && Sprite != 0)) {
-		float ScaleFactorX = (Width == - 1) ? 1 : static_cast<float>(Width) / static_cast<float>(GetWidth());
-		float ScaleFactorY = (Height == - 1) ? 1 : static_cast<float>(Height) / static_cast<float>(GetHeight());
-
-		uint RenderedWidth;
-		uint RenderedHeight;
-		if (!VectorImageRenderer.Render(*this, ScaleFactorX, ScaleFactorY, RenderedWidth, RenderedHeight, PixelData, LINE_SCALE_FACTOR)) {
-			BS_LOG_ERRORLN("Call to BS_VectorImageRenderer::Render() failed.");
-			return false;
-		}
-
-		if (RenderedWidth > 512 || RenderedHeight > 512) {
-			BS_LOG_WARNINGLN("Currently the maximum size for scaled vector images is 512x512.");
-			return true;
-		}
-
-		GLS_Result Result = GLS_SetSpriteData(Sprite, RenderedWidth, RenderedHeight, PixelData, 0);
-		if (Result != GLS_OK) {
-			BS_LOG_ERRORLN("Call to GLS_SetSpriteData() failed. Reason: %s", GLS_ResultString(Result));
-			return false;
-		}
-
-		OldThis = this;
-		OldHeight = Height;
-		OldWidth = Width;
-
-		OldSubImage.x1 = 0;
-		OldSubImage.y1 = 0;
-		OldSubImage.x2 = RenderedWidth;
-		OldSubImage.y2 = RenderedHeight;
-	}
-
-	// Rendern
-	// -------
-
-	// pDest wird ignoriert. Es wird einfach angenommen, dass der Backbuffer gemeint ist, da nur auf den Backbuffer gerendert werden kann.
-	// Ebenso werden pPartRect ignoriert. Es wird immer das gesamte Sprite gerendert.
-
-	// Farbe nach GLS_Color konvertieren
-	GLS_Color GLSColor;
-	GLSColor.a = Color >> 24;
-	GLSColor.r = (Color >> 16) & 0xff;
-	GLSColor.g = (Color >> 8) & 0xff;
-	GLSColor.b = Color & 0xff;
-
-	// Rendern
-	// TODO:
-	// Die Bedeutung von FLIP_V und FLIP_H ist vertauscht. Allerdings glaubt der Rest der Engine auch daran, daher war es einfacher diesen Fehler
-	// weiterzuf\xFChren. Bei Gelegenheit ist dieses aber zu \xE4ndern.
-	GLS_Result Result = GLS_Blit(Sprite,
-	                             PosX, PosY,
-	                             &OldSubImage, &GLSColor,
-	                             (Flipping & BS_Image::FLIP_V) ? GLS_True : GLS_False,
-	                             (Flipping & BS_Image::FLIP_H) ? GLS_True : GLS_False,
-	                             1.0f, 1.0f);
-	if (Result != GLS_OK) BS_LOG_ERRORLN("GLS_Blit() failed. Reason: %s", GLS_ResultString(Result));
-#else
-	warning("STUB: BS_VectorImage::Blit()");
-
-	return true;
-#endif
-
-	return true;
-}
-
-} // End of namespace Sword25

Modified: scummvm/trunk/engines/sword25/module.mk
===================================================================
--- scummvm/trunk/engines/sword25/module.mk	2010-10-12 23:33:51 UTC (rev 53313)
+++ scummvm/trunk/engines/sword25/module.mk	2010-10-12 23:34:25 UTC (rev 53314)
@@ -33,7 +33,6 @@
 	gfx/image/vectorimage.o \
 	gfx/image/vectorimagerenderer.o \
 	gfx/opengl/glimage.o \
-	gfx/opengl/glvectorimageblit.o \
 	gfx/opengl/openglgfx.o \
 	gfx/opengl/swimage.o \
 	input/inputengine.o \


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