GIFTranslator: Refactor filling out BBitmap
* Remove the NULL check since BBitmaps don't return NULL but check that it IsValid() instead. * Fill out the *out pointer directly instead of creating a temporary bitmap pointer. * Rename err to result. * Return B_OK unconditionally if we get to the end of the function. Thanks again Jérôme
This commit is contained in:
@@ -121,6 +121,7 @@ DetermineType(BPositionIO* source, bool* isGif)
|
|||||||
*isGif = true;
|
*isGif = true;
|
||||||
if (source->Read(header, 6) != 6)
|
if (source->Read(header, 6) != 6)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
header[6] = 0x00;
|
header[6] = 0x00;
|
||||||
|
|
||||||
if (strcmp((char*)header, "GIF87a") != 0
|
if (strcmp((char*)header, "GIF87a") != 0
|
||||||
@@ -152,8 +153,8 @@ status_t
|
|||||||
GetBitmap(BPositionIO* in, BBitmap** out)
|
GetBitmap(BPositionIO* in, BBitmap** out)
|
||||||
{
|
{
|
||||||
TranslatorBitmap header;
|
TranslatorBitmap header;
|
||||||
status_t err = in->Read(&header, sizeof(header));
|
status_t result = in->Read(&header, sizeof(header));
|
||||||
if (err != sizeof(header))
|
if (result != sizeof(header))
|
||||||
return B_IO_ERROR;
|
return B_IO_ERROR;
|
||||||
|
|
||||||
header.magic = B_BENDIAN_TO_HOST_INT32(header.magic);
|
header.magic = B_BENDIAN_TO_HOST_INT32(header.magic);
|
||||||
@@ -166,24 +167,19 @@ GetBitmap(BPositionIO* in, BBitmap** out)
|
|||||||
header.dataSize = B_BENDIAN_TO_HOST_INT32(header.dataSize);
|
header.dataSize = B_BENDIAN_TO_HOST_INT32(header.dataSize);
|
||||||
|
|
||||||
// dump data from stream into a BBitmap
|
// dump data from stream into a BBitmap
|
||||||
BBitmap* bitmap = new BBitmap(header.bounds, header.colors);
|
*out = new BBitmap(header.bounds, header.colors);
|
||||||
*out = bitmap;
|
if (!(*out)->IsValid()) {
|
||||||
if (bitmap == NULL)
|
delete *out;
|
||||||
return B_NO_MEMORY;
|
|
||||||
|
|
||||||
unsigned char* bits = (unsigned char*)bitmap->Bits();
|
|
||||||
if (bits == NULL) {
|
|
||||||
delete bitmap;
|
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = in->Read(bits, header.dataSize);
|
result = in->Read((*out)->Bits(), header.dataSize);
|
||||||
if (err == (status_t)header.dataSize)
|
if (result != (status_t)header.dataSize) {
|
||||||
return B_OK;
|
delete *out;
|
||||||
else {
|
|
||||||
delete bitmap;
|
|
||||||
return B_IO_ERROR;
|
return B_IO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -256,15 +252,15 @@ GIFTranslator::DerivedTranslate(BPositionIO* inSource,
|
|||||||
if (!isGif && inInfo->type != B_TRANSLATOR_BITMAP)
|
if (!isGif && inInfo->type != B_TRANSLATOR_BITMAP)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
status_t err = B_OK;
|
status_t result = B_OK;
|
||||||
bigtime_t now = system_time();
|
bigtime_t now = system_time();
|
||||||
|
|
||||||
if (!isGif) {
|
if (!isGif) {
|
||||||
// BBitmap to GIF
|
// BBitmap to GIF
|
||||||
BBitmap* bitmap;
|
BBitmap* bitmap;
|
||||||
err = GetBitmap(inSource, &bitmap);
|
result = GetBitmap(inSource, &bitmap);
|
||||||
if (err != B_OK)
|
if (result != B_OK)
|
||||||
return err;
|
return result;
|
||||||
|
|
||||||
GIFSave* gifSave = new GIFSave(bitmap, outDestination, fSettings);
|
GIFSave* gifSave = new GIFSave(bitmap, outDestination, fSettings);
|
||||||
if (gifSave->fatalerror) {
|
if (gifSave->fatalerror) {
|
||||||
|
|||||||
Reference in New Issue
Block a user