From e35b4f20c1041b13361aa2ebc4e758873bb1cee3 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Sun, 7 Aug 2011 14:35:01 +0200 Subject: GRAPHICS: Simplify the interface of Graphics::loadThumbnail(). Now it returns the Surface, so the caller does not need to create one and pass it. --- engines/agi/detection.cpp | 7 +------ engines/cruise/saveload.cpp | 7 ++----- engines/draci/saveload.cpp | 8 ++------ engines/hugo/detection.cpp | 7 +------ engines/kyra/saveload.cpp | 7 +------ engines/saga/detection.cpp | 8 +------- engines/sci/detection.cpp | 8 +------- engines/scumm/saveload.cpp | 7 +------ engines/sword1/detection.cpp | 8 +------- engines/teenagent/detection.cpp | 5 ++--- engines/toon/detection.cpp | 7 +------ engines/tsage/saveload.cpp | 7 ++----- graphics/thumbnail.cpp | 17 +++++++++-------- graphics/thumbnail.h | 2 +- 14 files changed, 26 insertions(+), 79 deletions(-) diff --git a/engines/agi/detection.cpp b/engines/agi/detection.cpp index a0736d0cc3..93fcd2d283 100644 --- a/engines/agi/detection.cpp +++ b/engines/agi/detection.cpp @@ -258,12 +258,7 @@ SaveStateDescriptor AgiMetaEngine::querySaveMetaInfos(const char *target, int sl char saveVersion = in->readByte(); if (saveVersion >= 4) { - Graphics::Surface *thumbnail = new Graphics::Surface(); - assert(thumbnail); - if (!Graphics::loadThumbnail(*in, *thumbnail)) { - delete thumbnail; - thumbnail = 0; - } + Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in); desc.setThumbnail(thumbnail); diff --git a/engines/cruise/saveload.cpp b/engines/cruise/saveload.cpp index 6392009373..c3d1ea6643 100644 --- a/engines/cruise/saveload.cpp +++ b/engines/cruise/saveload.cpp @@ -62,12 +62,9 @@ bool readSavegameHeader(Common::InSaveFile *in, CruiseSavegameHeader &header) { while ((ch = (char)in->readByte()) != '\0') header.saveName += ch; // Get the thumbnail - header.thumbnail = new Graphics::Surface(); - if (!Graphics::loadThumbnail(*in, *header.thumbnail)) { - delete header.thumbnail; - header.thumbnail = NULL; + header.thumbnail = Graphics::loadThumbnail(*in); + if (!header.thumbnail) return false; - } return true; } diff --git a/engines/draci/saveload.cpp b/engines/draci/saveload.cpp index 1479dd3c77..78315d1a97 100644 --- a/engines/draci/saveload.cpp +++ b/engines/draci/saveload.cpp @@ -58,13 +58,9 @@ bool readSavegameHeader(Common::InSaveFile *in, DraciSavegameHeader &header) { header.playtime = in->readUint32LE(); // Get the thumbnail - header.thumbnail = new Graphics::Surface(); - if (!Graphics::loadThumbnail(*in, *header.thumbnail)) { - header.thumbnail->free(); - delete header.thumbnail; - header.thumbnail = NULL; + header.thumbnail = Graphics::loadThumbnail(*in); + if (!header.thumbnail) return false; - } return true; } diff --git a/engines/hugo/detection.cpp b/engines/hugo/detection.cpp index f70a21aa8f..5d972f5658 100644 --- a/engines/hugo/detection.cpp +++ b/engines/hugo/detection.cpp @@ -241,12 +241,7 @@ SaveStateDescriptor HugoMetaEngine::querySaveMetaInfos(const char *target, int s SaveStateDescriptor desc(slot, saveName); - Graphics::Surface *thumbnail = new Graphics::Surface(); - assert(thumbnail); - if (!Graphics::loadThumbnail(*file, *thumbnail)) { - delete thumbnail; - thumbnail = 0; - } + Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*file); desc.setThumbnail(thumbnail); desc.setDeletableFlag(true); diff --git a/engines/kyra/saveload.cpp b/engines/kyra/saveload.cpp index f41cf0c6e3..42c5d3e8a8 100644 --- a/engines/kyra/saveload.cpp +++ b/engines/kyra/saveload.cpp @@ -113,12 +113,7 @@ KyraEngine_v1::kReadSaveHeaderError KyraEngine_v1::readSaveHeader(Common::Seekab if (header.version >= 14) { if (loadThumbnail) { - header.thumbnail = new Graphics::Surface(); - assert(header.thumbnail); - if (!Graphics::loadThumbnail(*in, *header.thumbnail)) { - delete header.thumbnail; - header.thumbnail = 0; - } + header.thumbnail = Graphics::loadThumbnail(*in); } else { Graphics::skipThumbnail(*in); } diff --git a/engines/saga/detection.cpp b/engines/saga/detection.cpp index 2f1b61eed8..091ec8d427 100644 --- a/engines/saga/detection.cpp +++ b/engines/saga/detection.cpp @@ -256,13 +256,7 @@ SaveStateDescriptor SagaMetaEngine::querySaveMetaInfos(const char *target, int s desc.setWriteProtectedFlag(false); if (version >= 6) { - Graphics::Surface *thumbnail = new Graphics::Surface(); - assert(thumbnail); - if (!Graphics::loadThumbnail(*in, *thumbnail)) { - delete thumbnail; - thumbnail = 0; - } - + Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in); desc.setThumbnail(thumbnail); uint32 saveDate = in->readUint32BE(); diff --git a/engines/sci/detection.cpp b/engines/sci/detection.cpp index 82f762e3db..33ca3a6c9c 100644 --- a/engines/sci/detection.cpp +++ b/engines/sci/detection.cpp @@ -676,13 +676,7 @@ SaveStateDescriptor SciMetaEngine::querySaveMetaInfos(const char *target, int sl SaveStateDescriptor desc(slot, meta.name); - Graphics::Surface *thumbnail = new Graphics::Surface(); - assert(thumbnail); - if (!Graphics::loadThumbnail(*in, *thumbnail)) { - delete thumbnail; - thumbnail = 0; - } - + Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in); desc.setThumbnail(thumbnail); desc.setDeletableFlag(true); diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 3cc710c207..870ec8cdf7 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -686,12 +686,7 @@ Graphics::Surface *ScummEngine::loadThumbnailFromSlot(const char *target, int sl Graphics::Surface *thumb = 0; if (Graphics::checkThumbnailHeader(*in)) { - thumb = new Graphics::Surface(); - assert(thumb); - if (!Graphics::loadThumbnail(*in, *thumb)) { - delete thumb; - thumb = 0; - } + thumb = Graphics::loadThumbnail(*in); } delete in; diff --git a/engines/sword1/detection.cpp b/engines/sword1/detection.cpp index 0c1e74082f..4da636bce9 100644 --- a/engines/sword1/detection.cpp +++ b/engines/sword1/detection.cpp @@ -274,13 +274,7 @@ SaveStateDescriptor SwordMetaEngine::querySaveMetaInfos(const char *target, int in->skip(1); if (Graphics::checkThumbnailHeader(*in)) { - Graphics::Surface *thumbnail = new Graphics::Surface(); - assert(thumbnail); - if (!Graphics::loadThumbnail(*in, *thumbnail)) { - delete thumbnail; - thumbnail = 0; - } - + Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in); desc.setThumbnail(thumbnail); } diff --git a/engines/teenagent/detection.cpp b/engines/teenagent/detection.cpp index 72a338664b..fa5a578636 100644 --- a/engines/teenagent/detection.cpp +++ b/engines/teenagent/detection.cpp @@ -177,9 +177,8 @@ public: ssd.setDeletableFlag(true); //checking for the thumbnail - Common::ScopedPtr thumb(new Graphics::Surface); - if (Graphics::loadThumbnail(*in, *thumb)) - ssd.setThumbnail(thumb.release()); + if (Graphics::Surface *const thumb = Graphics::loadThumbnail(*in)) + ssd.setThumbnail(thumb); return ssd; } diff --git a/engines/toon/detection.cpp b/engines/toon/detection.cpp index 810a37720a..ac4caae8b2 100644 --- a/engines/toon/detection.cpp +++ b/engines/toon/detection.cpp @@ -224,12 +224,7 @@ SaveStateDescriptor ToonMetaEngine::querySaveMetaInfos(const char *target, int s SaveStateDescriptor desc(slot, saveName); - Graphics::Surface *thumbnail = new Graphics::Surface(); - assert(thumbnail); - if (!Graphics::loadThumbnail(*file, *thumbnail)) { - delete thumbnail; - thumbnail = 0; - } + Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*file); desc.setThumbnail(thumbnail); desc.setDeletableFlag(true); diff --git a/engines/tsage/saveload.cpp b/engines/tsage/saveload.cpp index 40444cd630..e07964d443 100644 --- a/engines/tsage/saveload.cpp +++ b/engines/tsage/saveload.cpp @@ -249,12 +249,9 @@ bool Saver::readSavegameHeader(Common::InSaveFile *in, tSageSavegameHeader &head while ((ch = (char)in->readByte()) != '\0') header.saveName += ch; // Get the thumbnail - header.thumbnail = new Graphics::Surface(); - if (!Graphics::loadThumbnail(*in, *header.thumbnail)) { - delete header.thumbnail; - header.thumbnail = NULL; + header.thumbnail = Graphics::loadThumbnail(*in); + if (!header.thumbnail) return false; - } // Read in save date/time header.saveYear = in->readSint16LE(); diff --git a/graphics/thumbnail.cpp b/graphics/thumbnail.cpp index e9576efe7a..3684974117 100644 --- a/graphics/thumbnail.cpp +++ b/graphics/thumbnail.cpp @@ -94,23 +94,24 @@ bool skipThumbnail(Common::SeekableReadStream &in) { return true; } -bool loadThumbnail(Common::SeekableReadStream &in, Graphics::Surface &to) { +Graphics::Surface* loadThumbnail(Common::SeekableReadStream &in) { ThumbnailHeader header; if (!loadHeader(in, header, true)) - return false; + return 0; if (header.bpp != 2) { warning("trying to load thumbnail with unsupported bit depth %d", header.bpp); - return false; + return 0; } Graphics::PixelFormat format = g_system->getOverlayFormat(); - to.create(header.width, header.height, format); + Graphics::Surface *const to = new Graphics::Surface(); + to->create(header.width, header.height, format); - OverlayColor *pixels = (OverlayColor *)to.pixels; - for (int y = 0; y < to.h; ++y) { - for (int x = 0; x < to.w; ++x) { + OverlayColor *pixels = (OverlayColor *)to->pixels; + for (int y = 0; y < to->h; ++y) { + for (int x = 0; x < to->w; ++x) { uint8 r, g, b; colorToRGB >(in.readUint16BE(), r, g, b); @@ -119,7 +120,7 @@ bool loadThumbnail(Common::SeekableReadStream &in, Graphics::Surface &to) { } } - return true; + return to; } bool saveThumbnail(Common::WriteStream &out) { diff --git a/graphics/thumbnail.h b/graphics/thumbnail.h index 452125cb47..babc35bd5f 100644 --- a/graphics/thumbnail.h +++ b/graphics/thumbnail.h @@ -53,7 +53,7 @@ bool skipThumbnail(Common::SeekableReadStream &in); * The loaded thumbnail will be automatically converted to the * current overlay pixelformat. */ -bool loadThumbnail(Common::SeekableReadStream &in, Graphics::Surface &to); +Graphics::Surface* loadThumbnail(Common::SeekableReadStream &in); /** * Saves a thumbnail to the given write stream. -- cgit v1.2.3