From d11eb2d5d8183303b95efb42bdef512174b0f39d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 5 Sep 2014 23:10:21 +0200 Subject: [PATCH] HaikuDepot/SharedBitmap: Try load BBitmap via BTranslationUtils --- src/apps/haikudepot/PackageInfo.cpp | 37 +++++++++++++++++++++++------ src/apps/haikudepot/PackageInfo.h | 4 ++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/apps/haikudepot/PackageInfo.cpp b/src/apps/haikudepot/PackageInfo.cpp index dd3908a5c5..3b3c012599 100644 --- a/src/apps/haikudepot/PackageInfo.cpp +++ b/src/apps/haikudepot/PackageInfo.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "support.h" @@ -199,20 +200,42 @@ SharedBitmap::_LoadBitmapFromBuffer(const void* buffer, size_t size) const BMemoryIO stream(buffer, size); // Try to read as an archived bitmap. + BBitmap* bitmap = _LoadArchivedBitmapFromStream(stream); + + if (bitmap == NULL) { + // Try to read as a translator bitmap + stream.Seek(0, SEEK_SET); + bitmap = _LoadTranslatorBitmapFromStream(stream); + } + + if (bitmap != NULL) { + status_t status = bitmap->InitCheck(); + if (status != B_OK) { + delete bitmap; + bitmap = NULL; + } + } + + return bitmap; +} + + +BBitmap* +SharedBitmap::_LoadArchivedBitmapFromStream(BPositionIO& stream) const +{ BMessage archive; status_t status = archive.Unflatten(&stream); if (status != B_OK) return NULL; - BBitmap* bitmap = new BBitmap(&archive); + return new BBitmap(&archive); +} - status = bitmap->InitCheck(); - if (status != B_OK) { - delete bitmap; - bitmap = NULL; - } - return bitmap; +BBitmap* +SharedBitmap::_LoadTranslatorBitmapFromStream(BPositionIO& stream) const +{ + return BTranslationUtils::GetBitmap(&stream); } diff --git a/src/apps/haikudepot/PackageInfo.h b/src/apps/haikudepot/PackageInfo.h index b680c858e4..ddbd988d04 100644 --- a/src/apps/haikudepot/PackageInfo.h +++ b/src/apps/haikudepot/PackageInfo.h @@ -43,6 +43,10 @@ private: BBitmap* _LoadBitmapFromBuffer(const void* buffer, size_t dataSize) const; + BBitmap* _LoadArchivedBitmapFromStream( + BPositionIO& stream) const; + BBitmap* _LoadTranslatorBitmapFromStream( + BPositionIO& stream) const; BBitmap* _LoadIconFromBuffer(const void* buffer, size_t dataSize, int32 size) const;