GRAPHICS: Simplify the interface of Graphics::loadThumbnail().

Now it returns the Surface, so the caller does not need to create one and pass it.
This commit is contained in:
Christoph Mallon 2011-08-07 14:35:01 +02:00
parent b4b6ce0954
commit e35b4f20c1
14 changed files with 26 additions and 79 deletions

View file

@ -258,12 +258,7 @@ SaveStateDescriptor AgiMetaEngine::querySaveMetaInfos(const char *target, int sl
char saveVersion = in->readByte(); char saveVersion = in->readByte();
if (saveVersion >= 4) { if (saveVersion >= 4) {
Graphics::Surface *thumbnail = new Graphics::Surface(); Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in);
assert(thumbnail);
if (!Graphics::loadThumbnail(*in, *thumbnail)) {
delete thumbnail;
thumbnail = 0;
}
desc.setThumbnail(thumbnail); desc.setThumbnail(thumbnail);

View file

@ -62,12 +62,9 @@ bool readSavegameHeader(Common::InSaveFile *in, CruiseSavegameHeader &header) {
while ((ch = (char)in->readByte()) != '\0') header.saveName += ch; while ((ch = (char)in->readByte()) != '\0') header.saveName += ch;
// Get the thumbnail // Get the thumbnail
header.thumbnail = new Graphics::Surface(); header.thumbnail = Graphics::loadThumbnail(*in);
if (!Graphics::loadThumbnail(*in, *header.thumbnail)) { if (!header.thumbnail)
delete header.thumbnail;
header.thumbnail = NULL;
return false; return false;
}
return true; return true;
} }

View file

@ -58,13 +58,9 @@ bool readSavegameHeader(Common::InSaveFile *in, DraciSavegameHeader &header) {
header.playtime = in->readUint32LE(); header.playtime = in->readUint32LE();
// Get the thumbnail // Get the thumbnail
header.thumbnail = new Graphics::Surface(); header.thumbnail = Graphics::loadThumbnail(*in);
if (!Graphics::loadThumbnail(*in, *header.thumbnail)) { if (!header.thumbnail)
header.thumbnail->free();
delete header.thumbnail;
header.thumbnail = NULL;
return false; return false;
}
return true; return true;
} }

View file

@ -241,12 +241,7 @@ SaveStateDescriptor HugoMetaEngine::querySaveMetaInfos(const char *target, int s
SaveStateDescriptor desc(slot, saveName); SaveStateDescriptor desc(slot, saveName);
Graphics::Surface *thumbnail = new Graphics::Surface(); Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*file);
assert(thumbnail);
if (!Graphics::loadThumbnail(*file, *thumbnail)) {
delete thumbnail;
thumbnail = 0;
}
desc.setThumbnail(thumbnail); desc.setThumbnail(thumbnail);
desc.setDeletableFlag(true); desc.setDeletableFlag(true);

View file

@ -113,12 +113,7 @@ KyraEngine_v1::kReadSaveHeaderError KyraEngine_v1::readSaveHeader(Common::Seekab
if (header.version >= 14) { if (header.version >= 14) {
if (loadThumbnail) { if (loadThumbnail) {
header.thumbnail = new Graphics::Surface(); header.thumbnail = Graphics::loadThumbnail(*in);
assert(header.thumbnail);
if (!Graphics::loadThumbnail(*in, *header.thumbnail)) {
delete header.thumbnail;
header.thumbnail = 0;
}
} else { } else {
Graphics::skipThumbnail(*in); Graphics::skipThumbnail(*in);
} }

View file

@ -256,13 +256,7 @@ SaveStateDescriptor SagaMetaEngine::querySaveMetaInfos(const char *target, int s
desc.setWriteProtectedFlag(false); desc.setWriteProtectedFlag(false);
if (version >= 6) { if (version >= 6) {
Graphics::Surface *thumbnail = new Graphics::Surface(); Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in);
assert(thumbnail);
if (!Graphics::loadThumbnail(*in, *thumbnail)) {
delete thumbnail;
thumbnail = 0;
}
desc.setThumbnail(thumbnail); desc.setThumbnail(thumbnail);
uint32 saveDate = in->readUint32BE(); uint32 saveDate = in->readUint32BE();

View file

@ -676,13 +676,7 @@ SaveStateDescriptor SciMetaEngine::querySaveMetaInfos(const char *target, int sl
SaveStateDescriptor desc(slot, meta.name); SaveStateDescriptor desc(slot, meta.name);
Graphics::Surface *thumbnail = new Graphics::Surface(); Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in);
assert(thumbnail);
if (!Graphics::loadThumbnail(*in, *thumbnail)) {
delete thumbnail;
thumbnail = 0;
}
desc.setThumbnail(thumbnail); desc.setThumbnail(thumbnail);
desc.setDeletableFlag(true); desc.setDeletableFlag(true);

View file

@ -686,12 +686,7 @@ Graphics::Surface *ScummEngine::loadThumbnailFromSlot(const char *target, int sl
Graphics::Surface *thumb = 0; Graphics::Surface *thumb = 0;
if (Graphics::checkThumbnailHeader(*in)) { if (Graphics::checkThumbnailHeader(*in)) {
thumb = new Graphics::Surface(); thumb = Graphics::loadThumbnail(*in);
assert(thumb);
if (!Graphics::loadThumbnail(*in, *thumb)) {
delete thumb;
thumb = 0;
}
} }
delete in; delete in;

View file

@ -274,13 +274,7 @@ SaveStateDescriptor SwordMetaEngine::querySaveMetaInfos(const char *target, int
in->skip(1); in->skip(1);
if (Graphics::checkThumbnailHeader(*in)) { if (Graphics::checkThumbnailHeader(*in)) {
Graphics::Surface *thumbnail = new Graphics::Surface(); Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*in);
assert(thumbnail);
if (!Graphics::loadThumbnail(*in, *thumbnail)) {
delete thumbnail;
thumbnail = 0;
}
desc.setThumbnail(thumbnail); desc.setThumbnail(thumbnail);
} }

View file

@ -177,9 +177,8 @@ public:
ssd.setDeletableFlag(true); ssd.setDeletableFlag(true);
//checking for the thumbnail //checking for the thumbnail
Common::ScopedPtr<Graphics::Surface> thumb(new Graphics::Surface); if (Graphics::Surface *const thumb = Graphics::loadThumbnail(*in))
if (Graphics::loadThumbnail(*in, *thumb)) ssd.setThumbnail(thumb);
ssd.setThumbnail(thumb.release());
return ssd; return ssd;
} }

View file

@ -224,12 +224,7 @@ SaveStateDescriptor ToonMetaEngine::querySaveMetaInfos(const char *target, int s
SaveStateDescriptor desc(slot, saveName); SaveStateDescriptor desc(slot, saveName);
Graphics::Surface *thumbnail = new Graphics::Surface(); Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*file);
assert(thumbnail);
if (!Graphics::loadThumbnail(*file, *thumbnail)) {
delete thumbnail;
thumbnail = 0;
}
desc.setThumbnail(thumbnail); desc.setThumbnail(thumbnail);
desc.setDeletableFlag(true); desc.setDeletableFlag(true);

View file

@ -249,12 +249,9 @@ bool Saver::readSavegameHeader(Common::InSaveFile *in, tSageSavegameHeader &head
while ((ch = (char)in->readByte()) != '\0') header.saveName += ch; while ((ch = (char)in->readByte()) != '\0') header.saveName += ch;
// Get the thumbnail // Get the thumbnail
header.thumbnail = new Graphics::Surface(); header.thumbnail = Graphics::loadThumbnail(*in);
if (!Graphics::loadThumbnail(*in, *header.thumbnail)) { if (!header.thumbnail)
delete header.thumbnail;
header.thumbnail = NULL;
return false; return false;
}
// Read in save date/time // Read in save date/time
header.saveYear = in->readSint16LE(); header.saveYear = in->readSint16LE();

View file

@ -94,23 +94,24 @@ bool skipThumbnail(Common::SeekableReadStream &in) {
return true; return true;
} }
bool loadThumbnail(Common::SeekableReadStream &in, Graphics::Surface &to) { Graphics::Surface* loadThumbnail(Common::SeekableReadStream &in) {
ThumbnailHeader header; ThumbnailHeader header;
if (!loadHeader(in, header, true)) if (!loadHeader(in, header, true))
return false; return 0;
if (header.bpp != 2) { if (header.bpp != 2) {
warning("trying to load thumbnail with unsupported bit depth %d", header.bpp); warning("trying to load thumbnail with unsupported bit depth %d", header.bpp);
return false; return 0;
} }
Graphics::PixelFormat format = g_system->getOverlayFormat(); 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; OverlayColor *pixels = (OverlayColor *)to->pixels;
for (int y = 0; y < to.h; ++y) { for (int y = 0; y < to->h; ++y) {
for (int x = 0; x < to.w; ++x) { for (int x = 0; x < to->w; ++x) {
uint8 r, g, b; uint8 r, g, b;
colorToRGB<ColorMasks<565> >(in.readUint16BE(), r, g, b); colorToRGB<ColorMasks<565> >(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) { bool saveThumbnail(Common::WriteStream &out) {

View file

@ -53,7 +53,7 @@ bool skipThumbnail(Common::SeekableReadStream &in);
* The loaded thumbnail will be automatically converted to the * The loaded thumbnail will be automatically converted to the
* current overlay pixelformat. * 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. * Saves a thumbnail to the given write stream.