A beta tester reported that PackageBuilder failed to load when the OBOS libtranslation.so was used. This was because the OBOS BBitmapStream was missing a protected function. I implemented the protected function (SwapHeader) and changed the class to use it instead of the previous functions that I wrote to provide similar behavior.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2405 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber
2003-01-11 03:19:28 +00:00
parent 5901730132
commit 9f9e1f50fb
+26 -64
View File
@@ -63,7 +63,7 @@ BBitmapStream::BBitmapStream(BBitmap *bitmap)
fDetached = false; fDetached = false;
fPosition = 0; fPosition = 0;
fSize = 0; fSize = 0;
fpBigEndianHeader = NULL; fpBigEndianHeader = new TranslatorBitmap;
// Extract header information if bitmap is available // Extract header information if bitmap is available
if (fBitmap) { if (fBitmap) {
@@ -75,7 +75,10 @@ BBitmapStream::BBitmapStream(BBitmap *bitmap)
((fHeader.bounds.Height() + 1) * fHeader.rowBytes); ((fHeader.bounds.Height() + 1) * fHeader.rowBytes);
fSize = sizeof(TranslatorBitmap) + fHeader.dataSize; fSize = sizeof(TranslatorBitmap) + fHeader.dataSize;
SetBigEndianHeader(); if (B_HOST_IS_BENDIAN)
memcpy(fpBigEndianHeader, &fHeader, sizeof(TranslatorBitmap));
else
SwapHeader(&fHeader, fpBigEndianHeader);
} }
} }
@@ -96,11 +99,10 @@ BBitmapStream::BBitmapStream(BBitmap *bitmap)
// --------------------------------------------------------------- // ---------------------------------------------------------------
BBitmapStream::~BBitmapStream() BBitmapStream::~BBitmapStream()
{ {
if (fBitmap && !fDetached) if (!fDetached)
delete fBitmap; delete fBitmap;
if (fpBigEndianHeader) delete fpBigEndianHeader;
delete fpBigEndianHeader;
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
@@ -213,10 +215,9 @@ BBitmapStream::WriteAt(off_t pos, const void *data, size_t size)
// If we change the header, the rest needs to be reset // If we change the header, the rest needs to be reset
if (pos == sizeof(TranslatorBitmap)) { if (pos == sizeof(TranslatorBitmap)) {
// Setup both host and Big Endian byte order bitmap headers // Setup both host and Big Endian byte order bitmap headers
if (ConvertBEndianToHost(&fHeader) != B_OK) memcpy(fpBigEndianHeader, &fHeader, sizeof(TranslatorBitmap));
return B_ERROR; if (B_HOST_IS_LENDIAN)
if (SetBigEndianHeader() != B_OK) SwapHeader(fpBigEndianHeader, &fHeader);
return B_ERROR;
if (fBitmap && ((fBitmap->Bounds() != fHeader.bounds) || if (fBitmap && ((fBitmap->Bounds() != fHeader.bounds) ||
(fBitmap->ColorSpace() != fHeader.colors) || (fBitmap->ColorSpace() != fHeader.colors) ||
@@ -391,69 +392,30 @@ BBitmapStream::DetachBitmap(BBitmap **outBitmap)
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// ConvertBEndianToHost // SwapHeader
// //
// This static function converts a TranslatorBitmap from Big // Swaps the byte order of source, no matter what the
// Endian byte order to the host byte order. // byte order, and copies the result to destination
// //
// Preconditions: Data pointed to by pheader must be in // Preconditions: both parameters must not be null
// Big Endian byte order
// //
// Parameters: pheader, the TranslatorBitmap structure to convert // Parameters: source, data to be swapped
//
// destination, where the swapped data will
// be copied to
// //
// Postconditions: // Postconditions:
// //
// Returns: B_OK, if the byte swap succeeded // Returns:
// B_BAD_VALUE, if pheader is NULL, //
// or the byte swap failed
// --------------------------------------------------------------- // ---------------------------------------------------------------
status_t void
BBitmapStream::ConvertBEndianToHost(TranslatorBitmap *pheader) BBitmapStream::SwapHeader(const TranslatorBitmap *source,
TranslatorBitmap *destination)
{ {
if (!pheader) memcpy(destination, source, sizeof(TranslatorBitmap));
return B_BAD_VALUE; swap_data(B_UINT32_TYPE, destination, sizeof(TranslatorBitmap),
B_SWAP_ALWAYS);
return swap_data(B_UINT32_TYPE, pheader, sizeof(TranslatorBitmap),
B_SWAP_BENDIAN_TO_HOST);
}
// ---------------------------------------------------------------
// SetBigEndianHeader
//
// Assigns fpBigEndianHeader to the Big Endian byte order version
// of fHeader, the bitmap header information. fpBigEndianHeader is
// used by ReadAt() to send out the bitmap header in the Big
// Endian byte order.
//
// Preconditions: fHeader must be in the host byte order for
// this function to work properly
//
// Parameters:
//
// Postconditions:
//
// Returns: B_OK, if the byte swap succeeded
// B_ERROR, if failed to allocate memory for
// big endian header
// B_BAD_VALUE, if the byte swap failed
// ---------------------------------------------------------------
status_t
BBitmapStream::SetBigEndianHeader()
{
if (!fpBigEndianHeader) {
fpBigEndianHeader = new TranslatorBitmap;
if (!fpBigEndianHeader)
return B_ERROR;
}
fpBigEndianHeader->magic = fHeader.magic;
fpBigEndianHeader->bounds = fHeader.bounds;
fpBigEndianHeader->rowBytes = fHeader.rowBytes;
fpBigEndianHeader->colors = fHeader.colors;
fpBigEndianHeader->dataSize = fHeader.dataSize;
return swap_data(B_UINT32_TYPE, fpBigEndianHeader,
sizeof(TranslatorBitmap), B_SWAP_HOST_TO_BENDIAN);
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------