diff options
Diffstat (limited to 'engines/sword25/gfx')
-rw-r--r-- | engines/sword25/gfx/animation.h | 2 | ||||
-rw-r--r-- | engines/sword25/gfx/animationresource.cpp | 6 | ||||
-rw-r--r-- | engines/sword25/gfx/animationtemplateregistry.cpp | 2 | ||||
-rw-r--r-- | engines/sword25/gfx/fontresource.cpp | 2 | ||||
-rw-r--r-- | engines/sword25/gfx/graphicengine.cpp | 4 | ||||
-rw-r--r-- | engines/sword25/gfx/image/art.cpp | 73 | ||||
-rw-r--r-- | engines/sword25/gfx/image/art.h | 5 | ||||
-rw-r--r-- | engines/sword25/gfx/image/renderedimage.cpp | 29 | ||||
-rw-r--r-- | engines/sword25/gfx/image/vectorimage.cpp | 4 | ||||
-rw-r--r-- | engines/sword25/gfx/image/vectorimagerenderer.cpp | 7 | ||||
-rw-r--r-- | engines/sword25/gfx/screenshot.cpp | 6 | ||||
-rw-r--r-- | engines/sword25/gfx/staticbitmap.cpp | 5 | ||||
-rw-r--r-- | engines/sword25/gfx/text.cpp | 2 |
13 files changed, 112 insertions, 35 deletions
diff --git a/engines/sword25/gfx/animation.h b/engines/sword25/gfx/animation.h index 55deacd333..60070be214 100644 --- a/engines/sword25/gfx/animation.h +++ b/engines/sword25/gfx/animation.h @@ -210,7 +210,7 @@ private: AnimationDescription *getAnimationDescription() const; /** - * Initializes a new animation resource from an XML file. + * Initializes a new animation resource from an XML file. */ void initializeAnimationResource(const Common::String &fileName); }; diff --git a/engines/sword25/gfx/animationresource.cpp b/engines/sword25/gfx/animationresource.cpp index b9d70cf87b..621e20ad8c 100644 --- a/engines/sword25/gfx/animationresource.cpp +++ b/engines/sword25/gfx/animationresource.cpp @@ -64,7 +64,7 @@ AnimationResource::AnimationResource(const Common::String &filename) : char *xmlData = _pPackage->getXmlFile(getFileName(), &fileSize); if (!xmlData) { error("Could not read \"%s\".", getFileName().c_str()); - return; + return; } // Parse the contents @@ -118,7 +118,7 @@ bool AnimationResource::parserCallback_animation(ParserNode *node) { // Loop type value const char *loopTypeString = node->values["type"].c_str(); - + if (strcmp(loopTypeString, "oneshot") == 0) { _animationType = Animation::AT_ONESHOT; } else if (strcmp(loopTypeString, "loop") == 0) { @@ -148,7 +148,7 @@ bool AnimationResource::parserCallback_frame(ParserNode *node) { } frame.fileName = _pPackage->getAbsolutePath(fileString); if (frame.fileName.empty()) { - error("Could not create absolute path for file specified in <frame> tag in \"%s\": \"%s\".", + error("Could not create absolute path for file specified in <frame> tag in \"%s\": \"%s\".", getFileName().c_str(), fileString); return false; } diff --git a/engines/sword25/gfx/animationtemplateregistry.cpp b/engines/sword25/gfx/animationtemplateregistry.cpp index 43c099c89d..8184b49eba 100644 --- a/engines/sword25/gfx/animationtemplateregistry.cpp +++ b/engines/sword25/gfx/animationtemplateregistry.cpp @@ -34,7 +34,9 @@ #include "sword25/gfx/animationtemplateregistry.h" #include "sword25/gfx/animationtemplate.h" +namespace Common { DECLARE_SINGLETON(Sword25::AnimationTemplateRegistry); +} namespace Sword25 { diff --git a/engines/sword25/gfx/fontresource.cpp b/engines/sword25/gfx/fontresource.cpp index 7657abb5f2..0aeca7c180 100644 --- a/engines/sword25/gfx/fontresource.cpp +++ b/engines/sword25/gfx/fontresource.cpp @@ -85,7 +85,7 @@ bool FontResource::parserCallback_font(ParserNode *node) { getFileName().c_str(), DEFAULT_GAPWIDTH); _gapWidth = DEFAULT_GAPWIDTH; } - + // Get a reference to the package manager assert(_pKernel); PackageManager *pPackage = _pKernel->getPackage(); diff --git a/engines/sword25/gfx/graphicengine.cpp b/engines/sword25/gfx/graphicengine.cpp index 6b1c2bc514..14ba032107 100644 --- a/engines/sword25/gfx/graphicengine.cpp +++ b/engines/sword25/gfx/graphicengine.cpp @@ -156,7 +156,7 @@ RenderObjectPtr<Panel> GraphicEngine::getMainPanel() { } void GraphicEngine::setVsync(bool vsync) { - warning("STUB: SetVsync(%d)", vsync); + // ScummVM has no concept of VSync } bool GraphicEngine::getVsync() const { @@ -365,7 +365,7 @@ void GraphicEngine::updateLastFrameDuration() { } bool GraphicEngine::saveThumbnailScreenshot(const Common::String &filename) { - // Note: In ScumMVM, rather than saivng the thumbnail to a file, we store it in memory + // Note: In ScumMVM, rather than saivng the thumbnail to a file, we store it in memory // until needed when creating savegame files delete _thumbnail; diff --git a/engines/sword25/gfx/image/art.cpp b/engines/sword25/gfx/image/art.cpp index cd7cfb6b69..2ba102e779 100644 --- a/engines/sword25/gfx/image/art.cpp +++ b/engines/sword25/gfx/image/art.cpp @@ -151,6 +151,8 @@ ArtSVP *art_svp_from_vpath(ArtVpath *vpath) { n_segs_max = 16; svp = (ArtSVP *)malloc(sizeof(ArtSVP) + (n_segs_max - 1) * sizeof(ArtSVPSeg)); + if (!svp) + error("[art_svp_from_vpath] Cannot allocate memory"); dir = 0; n_points = 0; @@ -167,9 +169,14 @@ ArtSVP *art_svp_from_vpath(ArtVpath *vpath) { if (points != NULL && n_points >= 2) { if (n_segs == n_segs_max) { n_segs_max <<= 1; - svp = (ArtSVP *)realloc(svp, sizeof(ArtSVP) + - (n_segs_max - 1) * - sizeof(ArtSVPSeg)); + ArtSVP *tmp = (ArtSVP *)realloc(svp, sizeof(ArtSVP) + + (n_segs_max - 1) * + sizeof(ArtSVPSeg)); + + if (!tmp) + error("Cannot reallocate memory in art_svp_from_vpath()"); + + svp = tmp; } svp->segs[n_segs].n_points = n_points; svp->segs[n_segs].dir = (dir > 0); @@ -204,9 +211,14 @@ ArtSVP *art_svp_from_vpath(ArtVpath *vpath) { y = points[n_points - 1].y; if (n_segs == n_segs_max) { n_segs_max <<= 1; - svp = (ArtSVP *)realloc(svp, sizeof(ArtSVP) + - (n_segs_max - 1) * - sizeof(ArtSVPSeg)); + ArtSVP *tmp = (ArtSVP *)realloc(svp, sizeof(ArtSVP) + + (n_segs_max - 1) * + sizeof(ArtSVPSeg)); + + if (!tmp) + error("Cannot reallocate memory in art_svp_from_vpath()"); + + svp = tmp; } svp->segs[n_segs].n_points = n_points; svp->segs[n_segs].dir = (dir > 0); @@ -246,9 +258,14 @@ ArtSVP *art_svp_from_vpath(ArtVpath *vpath) { if (n_points >= 2) { if (n_segs == n_segs_max) { n_segs_max <<= 1; - svp = (ArtSVP *)realloc(svp, sizeof(ArtSVP) + - (n_segs_max - 1) * - sizeof(ArtSVPSeg)); + ArtSVP *tmp = (ArtSVP *)realloc(svp, sizeof(ArtSVP) + + (n_segs_max - 1) * + sizeof(ArtSVPSeg)); + + if (!tmp) + error("Cannot reallocate memory in art_svp_from_vpath()"); + + svp = tmp; } svp->segs[n_segs].n_points = n_points; svp->segs[n_segs].dir = (dir > 0); @@ -1026,6 +1043,8 @@ struct _ArtPriPoint { static ArtPriQ *art_pri_new(void) { ArtPriQ *result = art_new(ArtPriQ, 1); + if (!result) + error("[art_pri_new] Cannot allocate memory"); result->n_items = 0; result->n_items_max = 16; @@ -1157,8 +1176,13 @@ static int art_svp_writer_rewind_add_segment(ArtSvpWriter *self, int wind_left, (swr->n_segs_max - 1) * sizeof(ArtSVPSeg)); swr->svp = svp; - swr->n_points_max = art_renew(swr->n_points_max, int, - swr->n_segs_max); + int *tmp = art_renew(swr->n_points_max, int, + swr->n_segs_max); + + if (!tmp) + error("Cannot reallocate memory in art_svp_writer_rewind_add_segment()"); + + swr->n_points_max = tmp; } seg = &svp->segs[seg_num]; seg->n_points = 1; @@ -1169,6 +1193,9 @@ static int art_svp_writer_rewind_add_segment(ArtSvpWriter *self, int wind_left, seg->bbox.x1 = x; seg->bbox.y1 = y; seg->points = art_new(ArtPoint, init_n_points_max); + if (!seg->points) + error("[art_svp_writer_rewind_add_segment] Cannot allocate memory"); + seg->points[0].x = x; seg->points[0].y = y; return seg_num; @@ -1213,6 +1240,8 @@ ArtSVP *art_svp_writer_rewind_reap(ArtSvpWriter *self) { ArtSvpWriter *art_svp_writer_rewind_new(ArtWindRule rule) { ArtSvpWriterRewind *result = art_new(ArtSvpWriterRewind, 1); + if (!result) + error("[art_svp_writer_rewind_new] Cannot allocate memory"); result->super.add_segment = art_svp_writer_rewind_add_segment; result->super.add_point = art_svp_writer_rewind_add_point; @@ -1222,6 +1251,9 @@ ArtSvpWriter *art_svp_writer_rewind_new(ArtWindRule rule) { result->n_segs_max = 16; result->svp = (ArtSVP *)malloc(sizeof(ArtSVP) + (result->n_segs_max - 1) * sizeof(ArtSVPSeg)); + if (!result->svp) + error("[art_svp_writer_rewind_new] Cannot allocate memory"); + result->svp->n_segs = 0; result->n_points_max = art_new(int, result->n_segs_max); @@ -1392,6 +1424,9 @@ static void art_svp_intersect_push_pt(ArtIntersectCtx *ctx, ArtActiveSeg *seg, seg->y1 = y; pri_pt = art_new(ArtPriPoint, 1); + if (!pri_pt) + error("[art_svp_intersect_push_pt] Cannot allocate memory"); + pri_pt->x = x; pri_pt->y = y; pri_pt->user_data = seg; @@ -1855,6 +1890,8 @@ static void art_svp_intersect_horiz(ArtIntersectCtx *ctx, ArtActiveSeg *seg, return; hs = art_new(ArtActiveSeg, 1); + if (!hs) + error("[art_svp_intersect_horiz] Cannot allocate memory"); hs->flags = ART_ACTIVE_FLAGS_DEL | (seg->flags & ART_ACTIVE_FLAGS_OUT); if (seg->flags & ART_ACTIVE_FLAGS_OUT) { @@ -1993,10 +2030,11 @@ static void art_svp_intersect_add_seg(ArtIntersectCtx *ctx, const ArtSVPSeg *in_ ArtActiveSeg *seg = art_new(ArtActiveSeg, 1); ArtActiveSeg *test; double x0, y0; - ArtActiveSeg *beg_range; ArtActiveSeg *last = NULL; ArtActiveSeg *left, *right; ArtPriPoint *pri_pt = art_new(ArtPriPoint, 1); + if (!pri_pt) + error("[art_svp_intersect_add_seg] Cannot allocate memory"); seg->flags = 0; seg->in_seg = in_seg; @@ -2019,7 +2057,6 @@ static void art_svp_intersect_add_seg(ArtIntersectCtx *ctx, const ArtSVPSeg *in_ x0 = in_seg->points[0].x; y0 = in_seg->points[0].y; - beg_range = NULL; for (test = ctx->active_head; test != NULL; test = test->right) { double d; int test_bneg = test->flags & ART_ACTIVE_FLAGS_BNEG; @@ -2166,6 +2203,9 @@ void art_svp_intersector(const ArtSVP *in, ArtSvpWriter *out) { return; ctx = art_new(ArtIntersectCtx, 1); + if (!ctx) + error("[art_svp_intersector] Cannot allocate memory"); + ctx->in = in; ctx->out = out; pq = art_pri_new(); @@ -2178,6 +2218,9 @@ void art_svp_intersector(const ArtSVP *in, ArtSvpWriter *out) { ctx->in_curs = 0; first_point = art_new(ArtPriPoint, 1); + if (!first_point) + error("[art_svp_intersector] Cannot allocate memory"); + first_point->x = in->segs[0].points[0].x; first_point->y = in->segs[0].points[0].y; first_point->user_data = NULL; @@ -2319,6 +2362,8 @@ static void art_svp_render_delete_active(int *active_segs, int j, int n_active_s ArtSVPRenderAAIter *art_svp_render_aa_iter(const ArtSVP *svp, int x0, int y0, int x1, int y1) { ArtSVPRenderAAIter *iter = art_new(ArtSVPRenderAAIter, 1); + if (!iter) + error("[art_svp_render_aa_iter] Cannot allocate memory"); iter->svp = svp; iter->y = y0; @@ -2499,7 +2544,7 @@ void art_svp_render_aa_iter_step(ArtSVPRenderAAIter *iter, int *p_start, ADD_STEP(x, xdelta) } if (x < x1) { - this_ = + this_ = (int)(delta * (1 - 0.5 * (x_max - ix_max) * (x_max - ix_max) * rslope)); diff --git a/engines/sword25/gfx/image/art.h b/engines/sword25/gfx/image/art.h index bfeb31cc30..8c9c97bc57 100644 --- a/engines/sword25/gfx/image/art.h +++ b/engines/sword25/gfx/image/art.h @@ -51,10 +51,13 @@ namespace Sword25 { #define art_expand(p, type, max) \ do { \ if(max) {\ - p = art_renew(p, type, max <<= 1); \ + type *tmp = art_renew(p, type, max <<= 1); \ + if (!tmp) error("Cannot reallocate memory for art data"); \ + p = tmp; \ } else { \ max = 1; \ p = art_new(type, 1); \ + if (!p) error("Cannot allocate memory for art data"); \ } \ } while (0) diff --git a/engines/sword25/gfx/image/renderedimage.cpp b/engines/sword25/gfx/image/renderedimage.cpp index a9c9de4f0c..3b29b0333f 100644 --- a/engines/sword25/gfx/image/renderedimage.cpp +++ b/engines/sword25/gfx/image/renderedimage.cpp @@ -72,7 +72,10 @@ static byte *readSavegameThumbnail(const Common::String &filename, uint &fileSiz // Seek to the actual PNG image loadString(*file); // Marker (BS25SAVEGAME) - loadString(*file); // Version + Common::String storedVersionID = loadString(*file); // Version + if (storedVersionID != "SCUMMVM1") + loadString(*file); + loadString(*file); // Description uint32 compressedGamedataSize = atoi(loadString(*file).c_str()); loadString(*file); // Uncompressed game data size @@ -373,17 +376,23 @@ bool RenderedImage::blit(int posX, int posY, int flipping, Common::Rect *pPartRe default: // alpha blending #if defined(SCUMM_LITTLE_ENDIAN) - if (cb != 255) + if (cb == 0) + *out = 0; + else if (cb != 255) *out += ((b - *out) * a * cb) >> 16; else *out += ((b - *out) * a) >> 8; out++; - if (cg != 255) + if (cg == 0) + *out = 0; + else if (cg != 255) *out += ((g - *out) * a * cg) >> 16; else *out += ((g - *out) * a) >> 8; out++; - if (cr != 255) + if (cr == 0) + *out = 0; + else if (cr != 255) *out += ((r - *out) * a * cr) >> 16; else *out += ((r - *out) * a) >> 8; @@ -393,17 +402,23 @@ bool RenderedImage::blit(int posX, int posY, int flipping, Common::Rect *pPartRe #else *out = 255; out++; - if (cr != 255) + if (cr == 0) + *out = 0; + else if (cr != 255) *out += ((r - *out) * a * cr) >> 16; else *out += ((r - *out) * a) >> 8; out++; - if (cg != 255) + if (cg == 0) + *out = 0; + else if (cg != 255) *out += ((g - *out) * a * cg) >> 16; else *out += ((g - *out) * a) >> 8; out++; - if (cb != 255) + if (cb == 0) + *out = 0; + else if (cb != 255) *out += ((b - *out) * a * cb) >> 16; else *out += ((b - *out) * a) >> 8; diff --git a/engines/sword25/gfx/image/vectorimage.cpp b/engines/sword25/gfx/image/vectorimage.cpp index 9235ec2fcf..81f4fc2ad5 100644 --- a/engines/sword25/gfx/image/vectorimage.cpp +++ b/engines/sword25/gfx/image/vectorimage.cpp @@ -248,7 +248,7 @@ VectorImage::VectorImage(const byte *pFileData, uint fileSize, bool &success, co } // readout SWF size - Common::Rect movieRect = flashRectToBSRect(bs); + flashRectToBSRect(bs); // Get frame rate and frame count /* uint32 frameRate = */ @@ -321,6 +321,8 @@ ArtBpath *VectorImage::storeBez(ArtBpath *bez, int lineStyle, int fillStyle0, in bez[*bezNodes].code = ART_END; ArtBpath *bez1 = art_new(ArtBpath, *bezNodes + 1); + if (!bez1) + error("[VectorImage::storeBez] Cannot allocate memory"); for (int i = 0; i <= *bezNodes; i++) bez1[i] = bez[i]; diff --git a/engines/sword25/gfx/image/vectorimagerenderer.cpp b/engines/sword25/gfx/image/vectorimagerenderer.cpp index 97dad3346d..6d4dc213f2 100644 --- a/engines/sword25/gfx/image/vectorimagerenderer.cpp +++ b/engines/sword25/gfx/image/vectorimagerenderer.cpp @@ -270,6 +270,9 @@ ArtVpath *art_vpath_cat(ArtVpath *a, ArtVpath *b) { len_a = art_vpath_len(a); len_b = art_vpath_len(b); dest = art_new(ArtVpath, len_a + len_b + 1); + if (!dest) + error("[art_vpath_cat] Cannot allocate memory"); + p = dest; for (int i = 0; i < len_a; i++) @@ -299,6 +302,8 @@ ArtVpath *art_vpath_reverse(ArtVpath *a) { len = art_vpath_len(a); dest = art_new(ArtVpath, len + 1); + if (!dest) + error("[art_vpath_reverse] Cannot allocate memory"); for (i = 0; i < len; i++) { it = a[len - i - 1]; @@ -371,6 +376,8 @@ void drawBez(ArtBpath *bez1, ArtBpath *bez2, byte *buffer, int width, int height int size = art_vpath_len(vec); ArtVpath *vect = art_new(ArtVpath, size + 1); + if (!vect) + error("[drawBez] Cannot allocate memory"); int k; for (k = 0; k < size; k++) { diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 4f9ba1d3c5..de7b62fba9 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -67,8 +67,8 @@ bool Screenshot::saveToFile(Graphics::Surface *data, Common::WriteStream *stream Common::SeekableReadStream *Screenshot::createThumbnail(Graphics::Surface *data) { // This method takes a screen image with a dimension of 800x600, and creates a screenshot with a dimension of 200x125. - // First 50 pixels are cut off the top and bottom (the interface boards in the game). The remaining image of 800x500 - // will be on a 16th of its size, reduced by being handed out in 4x4 pixel blocks and the average of each block + // First 50 pixels are cut off the top and bottom (the interface boards in the game). The remaining image of 800x500 + // will be on a 16th of its size, reduced by being handed out in 4x4 pixel blocks and the average of each block // generates a pixel of the target image. Finally, the result as a PNG file is stored as a file. // The source image must be 800x600. @@ -84,7 +84,7 @@ Common::SeekableReadStream *Screenshot::createThumbnail(Graphics::Surface *data) // Über das Zielbild iterieren und einen Pixel zur Zeit berechnen. uint x, y; x = y = 0; - + for (byte *pDest = (byte *)thumbnail.pixels; pDest < ((byte *)thumbnail.pixels + thumbnail.pitch * thumbnail.h); ) { // Get an average over a 4x4 pixel block in the source image int alpha, red, green, blue; diff --git a/engines/sword25/gfx/staticbitmap.cpp b/engines/sword25/gfx/staticbitmap.cpp index 60ad94e20f..0ae07b36b5 100644 --- a/engines/sword25/gfx/staticbitmap.cpp +++ b/engines/sword25/gfx/staticbitmap.cpp @@ -170,7 +170,10 @@ bool StaticBitmap::unpersist(InputPersistenceBlock &reader) { result &= Bitmap::unpersist(reader); Common::String resourceFilename; reader.readString(resourceFilename); - result &= initBitmapResource(resourceFilename); + // We may not have saves, and we actually do not need to + // restore them. So do not even try to load them. + if (!resourceFilename.hasPrefix("/saves")) + result &= initBitmapResource(resourceFilename); result &= RenderObject::unpersistChildren(reader); diff --git a/engines/sword25/gfx/text.cpp b/engines/sword25/gfx/text.cpp index 8e18d2936d..82bb7cdff7 100644 --- a/engines/sword25/gfx/text.cpp +++ b/engines/sword25/gfx/text.cpp @@ -61,7 +61,7 @@ Text::Text(InputPersistenceBlock &reader, RenderObjectPtr<RenderObject> parentPt // Temporarily set fields prior to unpersisting actual values _modulationColor(0xffffffff), _autoWrap(false), - _autoWrapThreshold(AUTO_WRAP_THRESHOLD_DEFAULT) { + _autoWrapThreshold(AUTO_WRAP_THRESHOLD_DEFAULT) { // Unpersist the fields _initSuccess = unpersist(reader); |