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();
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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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();

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -177,9 +177,8 @@ public:
ssd.setDeletableFlag(true);
//checking for the thumbnail
Common::ScopedPtr<Graphics::Surface> 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;
}

View File

@ -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);

View File

@ -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();

View File

@ -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<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) {

View File

@ -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.