diff options
author | Eugene Sandulenko | 2010-09-03 23:02:00 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2010-10-12 23:34:25 +0000 |
commit | 7032c209a7e8bbd77bc7638f1a173a992bdb5e81 (patch) | |
tree | 7657c701d1edd8e218f233546f8ed4cac950e079 | |
parent | 5f83fd19540c3072f50edff0acddf1cb6a072b78 (diff) | |
download | scummvm-rg350-7032c209a7e8bbd77bc7638f1a173a992bdb5e81.tar.gz scummvm-rg350-7032c209a7e8bbd77bc7638f1a173a992bdb5e81.tar.bz2 scummvm-rg350-7032c209a7e8bbd77bc7638f1a173a992bdb5e81.zip |
SWORD25: Initial code for vector image rendering. Crashes badly.
svn-id: r53314
-rw-r--r-- | engines/sword25/gfx/image/vectorimage.cpp | 45 | ||||
-rw-r--r-- | engines/sword25/gfx/image/vectorimage.h | 5 | ||||
-rw-r--r-- | engines/sword25/gfx/image/vectorimagerenderer.cpp | 392 | ||||
-rw-r--r-- | engines/sword25/gfx/image/vectorimagerenderer.h | 16 | ||||
-rw-r--r-- | engines/sword25/gfx/opengl/glimage.cpp | 21 | ||||
-rw-r--r-- | engines/sword25/gfx/opengl/glimage.h | 4 | ||||
-rw-r--r-- | engines/sword25/gfx/opengl/glvectorimageblit.cpp | 146 | ||||
-rw-r--r-- | engines/sword25/module.mk | 1 |
8 files changed, 319 insertions, 311 deletions
diff --git a/engines/sword25/gfx/image/vectorimage.cpp b/engines/sword25/gfx/image/vectorimage.cpp index 45e81b6f71..42cac1aaa1 100644 --- a/engines/sword25/gfx/image/vectorimage.cpp +++ b/engines/sword25/gfx/image/vectorimage.cpp @@ -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 @@ Common::Rect CalculateBoundingBox(const VectorImageElement &vectorImageElement) // 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 @@ VectorImage::~VectorImage() { 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 @@ bool VectorImage::setContent(const byte *pixeldata, uint size, uint offset, uint 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öhe 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 diff --git a/engines/sword25/gfx/image/vectorimage.h b/engines/sword25/gfx/image/vectorimage.h index e5688078ee..d4cbfece7c 100644 --- a/engines/sword25/gfx/image/vectorimage.h +++ b/engines/sword25/gfx/image/vectorimage.h @@ -181,6 +181,9 @@ public: 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 @@ private: 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 diff --git a/engines/sword25/gfx/image/vectorimagerenderer.cpp b/engines/sword25/gfx/image/vectorimagerenderer.cpp index de34302908..5031123b3c 100644 --- a/engines/sword25/gfx/image/vectorimagerenderer.cpp +++ b/engines/sword25/gfx/image/vectorimagerenderer.cpp @@ -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 -// ----------------------------------------------------------------------------- - -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(); - } - - unsigned paths() const { - return m_ImageElement.GetPathCount(); +void +art_rgb_fill_run1(art_u8 *buf, art_u8 r, art_u8 g, art_u8 b, int n) { + int i; + + 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; } +} - void rewind(unsigned path_id) { - m_Trans.rewind(path_id); +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; + + 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; + + 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) & 0xff; + if (alpha) + art_rgb_run_alpha1(linebuf, r, g, b, alphatab[alpha], run_x1 - x0); + } -// ----------------------------------------------------------------------------- -// StyleHandler -// ----------------------------------------------------------------------------- + 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); + } -class StyleHandler { -public: - StyleHandler(const BS_VectorImageElement &VectorImageElement) : m_ImageElement(VectorImageElement) {} + data->buf += data->rowstride; +} - bool is_solid(uint style) const { - return true; - } +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; + + 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); + } + } - 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; + 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); + } } - void generate_span(agg::rgba8 *span, int x, int y, unsigned len, unsigned style) { - // Wird nicht benutzt - return; + 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; + + r = rgba >> 24; + g = (rgba >> 16) & 0xff; + b = (rgba >> 8) & 0xff; + alpha = rgba & 0xff; + + data.r = r; + data.g = g; + data.b = b; + data.alpha = alpha; + + a = 0x8000; + da = (alpha * 66051 + 0x80) >> 8; /* 66051 equals 2 ^ 32 / (255 * 255) */ + + for (i = 0; i < 256; i++) { + data.alphatab[i] = a >> 16; + a += da; } -private: - const BS_VectorImageElement &m_ImageElement; -}; + 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); +} -BS_VectorImageRenderer::BS_VectorImageRenderer() : - PixelFormat(rbuf) { +void VectorImage::render(float scaleFactorX, float scaleFactorY, uint &width, uint &height) { + width = static_cast<uint>(getWidth() * scaleFactorX); + height = static_cast<uint>(getHeight() * scaleFactorY); -} + if (_pixelData) + free(_pixelData); + _pixelData = (byte *)malloc(width * height * 4); + memset(_pixelData, 0, width * height * 4); -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); - - ImageData.resize(Width * Height * 4); - memset(&ImageData[0], 0, ImageData.size()); - rbuf.attach(reinterpret_cast<agg::int8u *>(&ImageData[0]), Width, Height, Width * 4); - - BaseRenderer.attach(PixelFormat); - ScanlineRenderer.attach(BaseRenderer); - - // Die SWF-Shapes sind häufig 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 (uint element = 0; element < VectorImage.GetElementCount(); ++element) { - const BS_VectorImageElement &CurImageElement = VectorImage.GetElement(element); - - CompoundShape ImageCompoundShape(CurImageElement); - StyleHandler ImageStyleHandler(CurImageElement); - agg::conv_transform<CompoundShape> Shape(ImageCompoundShape, Scale); - agg::conv_stroke<agg::conv_transform<CompoundShape> > Stroke(Shape); - - // 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 (NoAlphaShapes) { - if (FillStyle0 != 0 && CurImageElement.GetFillStyleColor(FillStyle0 - 1).a != 255) FillStyle0 = 0; - if (FillStyle1 != 0 && CurImageElement.GetFillStyleColor(FillStyle1 - 1).a != 255) FillStyle1 = 0; - } + 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; - 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); - - - // 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(); - - 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ünen Linien, die wohl von Bernd als Umriss benutzt wurden. - // Damit diese Reste nicht störend auffallen werden grüne 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); + bool needfree = false; + ArtVpath *vec = _elements[j].getPathInfo(i).getVec(); + + // Upscale vector + if (scaleFactorX != 1.0 || scaleFactorY != 1.0) { + ArtVpath *vec1; + int size; + + 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); + + 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); -#else + int color1 = _elements[j].getFillStyleColor(_elements[j].getPathInfo(i).getFillStyle0()); + int color2 = _elements[j].getLineStyleColor(_elements[j].getPathInfo(i).getLineStyle()); -VectorImageRenderer::VectorImageRenderer() {} + 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); -bool VectorImageRenderer::Render(const VectorImage &VectorImage, - float ScaleFactorX, float ScaleFactorY, - uint &Width, uint &Height, - byte *ImageData, - float LineScaleFactor, - bool NoAlphaShapes) { - return true; + art_free(svp2); + art_free(svp1); + } } -#endif + } // End of namespace Sword25 diff --git a/engines/sword25/gfx/image/vectorimagerenderer.h b/engines/sword25/gfx/image/vectorimagerenderer.h index 2b1f63fdb6..b266c8a457 100644 --- a/engines/sword25/gfx/image/vectorimagerenderer.h +++ b/engines/sword25/gfx/image/vectorimagerenderer.h @@ -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 @@ public: 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 diff --git a/engines/sword25/gfx/opengl/glimage.cpp b/engines/sword25/gfx/opengl/glimage.cpp index bccd18660d..cf8b294ea7 100644 --- a/engines/sword25/gfx/opengl/glimage.cpp +++ b/engines/sword25/gfx/opengl/glimage.cpp @@ -87,6 +87,8 @@ GLImage::GLImage(const Common::String &filename, bool &result) : // Dateidaten freigeben delete[] pFileData; + _doCleanup = true; + result = true; return; } @@ -96,20 +98,30 @@ GLImage::GLImage(const Common::String &filename, bool &result) : 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 @@ bool GLImage::setContent(const byte *pixeldata, uint size, uint offset, uint str return true; } +void GLImage::replaceContent(byte *pixeldata, int width, int height) { + _width = width; + _height = height; + _data = pixeldata; +} // ----------------------------------------------------------------------------- uint GLImage::getPixel(int x, int y) { diff --git a/engines/sword25/gfx/opengl/glimage.h b/engines/sword25/gfx/opengl/glimage.h index 5f019d2bc0..bcc6bf8e20 100644 --- a/engines/sword25/gfx/opengl/glimage.h +++ b/engines/sword25/gfx/opengl/glimage.h @@ -68,6 +68,8 @@ public: dürfen keine Methoden am Objekt aufgerufen werden und das Objekt ist sofort zu zerstören. */ GLImage(uint width, uint height, bool &result); + GLImage(); + virtual ~GLImage(); virtual int getWidth() const { @@ -87,6 +89,7 @@ public: 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 @@ private: byte *_data; int _width; int _height; + bool _doCleanup; Graphics::Surface *_backSurface; }; diff --git a/engines/sword25/gfx/opengl/glvectorimageblit.cpp b/engines/sword25/gfx/opengl/glvectorimageblit.cpp deleted file mode 100644 index 664d9c16b0..0000000000 --- a/engines/sword25/gfx/opengl/glvectorimageblit.cpp +++ /dev/null @@ -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öhe 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ühren. Bei Gelegenheit ist dieses aber zu ändern. - 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 diff --git a/engines/sword25/module.mk b/engines/sword25/module.mk index 40be7fad24..4eb113a0e9 100644 --- a/engines/sword25/module.mk +++ b/engines/sword25/module.mk @@ -33,7 +33,6 @@ MODULE_OBJS := \ 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 \ |