diff --git a/headers/private/interface/InterfacePrivate.h b/headers/private/interface/InterfacePrivate.h index da37bb5e58..2ad2251d1c 100644 --- a/headers/private/interface/InterfacePrivate.h +++ b/headers/private/interface/InterfacePrivate.h @@ -9,6 +9,7 @@ #define _INTERFACE_PRIVATE_H +#include #include @@ -17,6 +18,11 @@ namespace BPrivate { bool get_mode_parameter(uint32 mode, int32& width, int32& height, uint32& colorSpace); + +int32 get_bytes_per_row(color_space colorSpace, int32 width); + + + } // namespace BPrivate diff --git a/src/kits/interface/Bitmap.cpp b/src/kits/interface/Bitmap.cpp index ad07b6b1d6..95435a69db 100644 --- a/src/kits/interface/Bitmap.cpp +++ b/src/kits/interface/Bitmap.cpp @@ -106,7 +106,6 @@ get_raw_bytes_per_row(color_space colorSpace, int32 width) \return The number of bytes per row needed to store data for a row, or 0, if the color space is not supported. */ -static inline int32 get_bytes_per_row(color_space colorSpace, int32 width) { @@ -361,7 +360,7 @@ BBitmap::Archive(BMessage *data, bool deep) const break; } } - // Note: R5 does not archive the data if B_BITMAP_IS_CONTIGNUOUS is + // Note: R5 does not archive the data if B_BITMAP_IS_CONTIGUOUS is // true and it does save all formats as B_RAW_TYPE and it does save // the data even if B_BITMAP_ACCEPTS_VIEWS is set (as opposed to // the BeBook) diff --git a/src/servers/app/ServerBitmap.cpp b/src/servers/app/ServerBitmap.cpp index 84af4c6ea1..cabac8d539 100644 --- a/src/servers/app/ServerBitmap.cpp +++ b/src/servers/app/ServerBitmap.cpp @@ -18,9 +18,11 @@ #include "ClientMemoryAllocator.h" #include "ColorConversion.h" #include "HWInterface.h" +#include "InterfacePrivate.h" #include "Overlay.h" using std::nothrow; +using namespace BPrivate; /*! A word about memory housekeeping and why it's implemented this way: @@ -71,7 +73,9 @@ ServerBitmap::ServerBitmap(BRect rect, color_space space, uint32 flags, fOwner(NULL) // fToken is initialized (if used) by the BitmapManager { - _HandleSpace(space, bytesPerRow); + int32 minBytesPerRow = get_bytes_per_row(space, fWidth); + + fBytesPerRow = max_c(bytesPerRow, minBytesPerRow); } @@ -148,110 +152,6 @@ ServerBitmap::_AllocateBuffer(void) } -/*! - \brief Internal function used to translate color space values to appropriate internal - values. - \param space Color space for the bitmap. - \param bytesPerRow Number of bytes per row to be used as an override. -*/ -void -ServerBitmap::_HandleSpace(color_space space, int32 bytesPerRow) -{ - // TODO: Code duplication here, reuse functions in Bitmap.cpp - // and GraphicsDefs.cpp - - // calculate the minimum bytes per row - int32 minBPR = 0; - switch(space) { - // 32-bit - case B_RGB32: - case B_RGBA32: - case B_RGB32_BIG: - case B_RGBA32_BIG: - case B_UVL32: - case B_UVLA32: - case B_LAB32: - case B_LABA32: - case B_HSI32: - case B_HSIA32: - case B_HSV32: - case B_HSVA32: - case B_HLS32: - case B_HLSA32: - case B_CMY32: - case B_CMYA32: - case B_CMYK32: - minBPR = fWidth * 4; - break; - - // 24-bit - case B_RGB24_BIG: - case B_RGB24: - case B_LAB24: - case B_UVL24: - case B_HSI24: - case B_HSV24: - case B_HLS24: - case B_CMY24: - // TODO: These last two are calculated - // (width + 3) / 4 * 12 - // in Bitmap.cpp, I don't understand why though. - case B_YCbCr444: - case B_YUV444: - minBPR = fWidth * 3; - break; - - // 16-bit - case B_YUV9: - case B_YUV12: - case B_RGB15: - case B_RGBA15: - case B_RGB16: - case B_RGB16_BIG: - case B_RGB15_BIG: - case B_RGBA15_BIG: - minBPR = fWidth * 2; - break; - - case B_YCbCr422: - case B_YUV422: - minBPR = (fWidth + 3) / 4 * 8; - // TODO: huh? why not simply fWidth * 2 ?!? - break; - - // 8-bit - case B_CMAP8: - case B_GRAY8: - minBPR = fWidth; - break; - - // 1-bit - case B_GRAY1: - minBPR = (fWidth + 7) / 8; - break; - - // TODO: ??? get a clue what these mean - case B_YCbCr411: - case B_YUV411: - case B_YUV420: - case B_YCbCr420: - minBPR = (fWidth + 3) / 4 * 6; - break; - - case B_NO_COLOR_SPACE: - default: - break; - } - if (minBPR > 0 || bytesPerRow > 0) { - // add the padding or use the provided bytesPerRow if sufficient - if (bytesPerRow >= minBPR) - fBytesPerRow = bytesPerRow; - else - fBytesPerRow = ((minBPR + 3) / 4) * 4; - } -} - - status_t ServerBitmap::ImportBits(const void *bits, int32 bitsLength, int32 bytesPerRow, color_space colorSpace) diff --git a/src/servers/app/ServerBitmap.h b/src/servers/app/ServerBitmap.h index 6ef437cdb0..6eed5af0ef 100644 --- a/src/servers/app/ServerBitmap.h +++ b/src/servers/app/ServerBitmap.h @@ -98,8 +98,6 @@ protected: void _AllocateBuffer(); - void _HandleSpace(color_space space, - int32 bytesperline = -1); ClientMemoryAllocator* fAllocator; void* fAllocationCookie;