From ee918f63650b748bf4e744ce317e7ecceb96a7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 24 Jun 2011 16:48:05 +0000 Subject: [PATCH] * This fixes the BitmapStream issues identified by #7740; the actual problem persists to be debugged further. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42297 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/translation/BitmapStream.cpp | 30 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/kits/translation/BitmapStream.cpp b/src/kits/translation/BitmapStream.cpp index f2af83d77c..05a4b80e6b 100644 --- a/src/kits/translation/BitmapStream.cpp +++ b/src/kits/translation/BitmapStream.cpp @@ -32,7 +32,7 @@ BBitmapStream::BBitmapStream(BBitmap* bitmap) fBigEndianHeader = new TranslatorBitmap; // Extract header information if bitmap is available - if (fBitmap != NULL) { + if (fBitmap != NULL && fBitmap->InitCheck() == B_OK) { fHeader.magic = B_TRANSLATOR_BITMAP; fHeader.bounds = fBitmap->Bounds(); fHeader.rowBytes = fBitmap->BytesPerRow(); @@ -45,7 +45,8 @@ BBitmapStream::BBitmapStream(BBitmap* bitmap) memcpy(fBigEndianHeader, &fHeader, sizeof(TranslatorBitmap)); else SwapHeader(&fHeader, fBigEndianHeader); - } + } else + fBitmap = NULL; } @@ -71,8 +72,8 @@ BBitmapStream::~BBitmapStream() ssize_t BBitmapStream::ReadAt(off_t pos, void* buffer, size_t size) { - if (!fBitmap) - return B_ERROR; + if (fBitmap == NULL) + return B_NO_INIT; if (size == 0) return B_OK; if (pos >= fSize || pos < 0 || buffer == NULL) @@ -113,8 +114,8 @@ BBitmapStream::ReadAt(off_t pos, void* buffer, size_t size) ssize_t BBitmapStream::WriteAt(off_t pos, const void* data, size_t size) { - if (!size) - return B_NO_ERROR; + if (size == 0) + return B_OK; if (!data || pos < 0 || pos > fSize) return B_BAD_VALUE; @@ -128,6 +129,9 @@ BBitmapStream::WriteAt(off_t pos, const void* data, size_t size) toWrite = sizeof(TranslatorBitmap) - pos; dest = (reinterpret_cast (&fHeader)) + pos; } else { + if (fBitmap == NULL || !fBitmap->IsValid()) + return B_ERROR; + toWrite = fHeader.dataSize - pos + sizeof(TranslatorBitmap); dest = (reinterpret_cast (fBitmap->Bits())) + pos - sizeof(TranslatorBitmap); @@ -152,7 +156,7 @@ BBitmapStream::WriteAt(off_t pos, const void* data, size_t size) if (B_HOST_IS_LENDIAN) SwapHeader(fBigEndianHeader, &fHeader); - if (fBitmap + if (fBitmap != NULL && (fBitmap->Bounds() != fHeader.bounds || fBitmap->ColorSpace() != fHeader.colors || (uint32)fBitmap->BytesPerRow() != fHeader.rowBytes)) { @@ -161,19 +165,25 @@ BBitmapStream::WriteAt(off_t pos, const void* data, size_t size) delete fBitmap; fBitmap = NULL; } - if (!fBitmap) { + if (fBitmap == NULL) { if (fHeader.bounds.left > 0.0 || fHeader.bounds.top > 0.0) DEBUGGER("non-origin bounds!"); fBitmap = new BBitmap(fHeader.bounds, fHeader.colors); - if (!fBitmap) + if (fBitmap == NULL) return B_ERROR; + if (!fBitmap->IsValid()) { + status_t error = fBitmap->InitCheck(); + delete fBitmap; + fBitmap = NULL; + return error; + } if ((uint32)fBitmap->BytesPerRow() != fHeader.rowBytes) { fprintf(stderr, "BitmapStream %ld %ld\n", fBitmap->BytesPerRow(), fHeader.rowBytes); return B_MISMATCHED_VALUES; } } - if (fBitmap) + if (fBitmap != NULL) fSize = sizeof(TranslatorBitmap) + fBitmap->BitsLength(); } }