From fd3c83d5f2414b2bba7b941609b59452a6d5b1e8 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Thu, 7 Jun 2012 21:39:19 +0300 Subject: Add two new 32bpp formats and add helpful comments For Android (and perhaps iOS) we need a 32bpp format with channels in RGBA order. Rename the (basebmp-internal) 32bpp PixelFormatTreats_* typedefs so that the channel order in their names matches the memory order of the channels. Change-Id: Ia8a74f6d44e0a2cffdf66a05ddf8fc7d6ae2a263 --- basebmp/inc/basebmp/rgbmaskpixelformats.hxx | 78 +++++++++++++++++++++++------ basebmp/inc/basebmp/scanlineformats.hxx | 7 ++- basebmp/source/bitmapdevice.cxx | 22 ++++++-- 3 files changed, 86 insertions(+), 21 deletions(-) diff --git a/basebmp/inc/basebmp/rgbmaskpixelformats.hxx b/basebmp/inc/basebmp/rgbmaskpixelformats.hxx index 47f7c2bf6199..b1e65e81028b 100644 --- a/basebmp/inc/basebmp/rgbmaskpixelformats.hxx +++ b/basebmp/inc/basebmp/rgbmaskpixelformats.hxx @@ -231,6 +231,23 @@ template< typename PixelType, //----------------------------------------------------------------------------- +// Hopefully this is an understandable plaintext explanation that matches +// reality... + +// BASEBMP_TRUECOLORMASK_LSB_SWAP means that on a big-endian platform, a pixel +// value when viewed as an integer (16 or 32 bits) has to be byte-swapped for +// the channels to match the masks. Or equivalently (I think), on a big-endian +// platform, the masks need to be byte-swapped to be correct. + +// I.e. on a litte-endian platform the masks work as such. + +// BASEBMP_TRUECOLORMASK_MSB_SWAP means the opposite. The masks work as such +// on big-endian platforms, on little-endian platforms the pixel needs to be +// byte-swapped for the masks to work. + +// So in a sense these two names are "backward". It sounds to me as if +// BASEBMP_TRUECOLORMASK_LSB_SWAP would mean "when on LSB, swap" ;) + #ifdef OSL_LITENDIAN # define BASEBMP_TRUECOLORMASK_LSB_SWAP false # define BASEBMP_TRUECOLORMASK_MSB_SWAP true @@ -265,25 +282,56 @@ typedef PixelFormatTraitsTemplate_RGBMask< BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGB16_565_LSB::getter_type, PixelFormatTraits_RGB16_565_LSB::setter_type); -// 32bpp endian-sensitive RGB + +// 32bpp formats + +// The intent is that the order of channel names in the names of the 32bpp +// format typedefs below correspond to the order of the channel bytes in +// memory, if I understand correctly.... I think the point with the below +// formats is that the channel byte order in memory is the same regardless of +// platform byte order. + +// This one used to be called PixelFormatTraits_RGB32_888. + typedef PixelFormatTraitsTemplate_RGBMask< sal_uInt32, - 0xFF0000, - 0x00FF00, - 0x0000FF, - BASEBMP_TRUECOLORMASK_LSB_SWAP > PixelFormatTraits_RGB32_888; -BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGB32_888::getter_type, - PixelFormatTraits_RGB32_888::setter_type); - -// 32bpp endian-sensitive BGR + 0x00FF0000, + 0x0000FF00, + 0x000000FF, + BASEBMP_TRUECOLORMASK_LSB_SWAP > PixelFormatTraits_BGRX32_8888; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_BGRX32_8888::getter_type, + PixelFormatTraits_BGRX32_8888::setter_type); + +// This one used to be called PixelFormatTraits_BGR32_888. + +typedef PixelFormatTraitsTemplate_RGBMask< + sal_uInt32, + 0x00FF0000, + 0x0000FF00, + 0x000000FF, + BASEBMP_TRUECOLORMASK_MSB_SWAP > PixelFormatTraits_XRGB32_8888; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_XRGB32_8888::getter_type, + PixelFormatTraits_XRGB32_8888::setter_type); + +// The following two ones were added for Android needs and for completeness + +typedef PixelFormatTraitsTemplate_RGBMask< + sal_uInt32, + 0xFF000000, + 0x00FF0000, + 0x0000FF00, + BASEBMP_TRUECOLORMASK_LSB_SWAP > PixelFormatTraits_XBGR32_8888; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_XBGR32_8888::getter_type, + PixelFormatTraits_XBGR32_8888::setter_type); + typedef PixelFormatTraitsTemplate_RGBMask< sal_uInt32, - 0xFF0000, - 0x00FF00, - 0x0000FF, - BASEBMP_TRUECOLORMASK_MSB_SWAP > PixelFormatTraits_BGR32_888; -BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_BGR32_888::getter_type, - PixelFormatTraits_BGR32_888::setter_type); + 0xFF000000, + 0x00FF0000, + 0x0000FF00, + BASEBMP_TRUECOLORMASK_MSB_SWAP > PixelFormatTraits_RGBX32_8888; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGBX32_8888::getter_type, + PixelFormatTraits_RGBX32_8888::setter_type); } // namespace basebmp diff --git a/basebmp/inc/basebmp/scanlineformats.hxx b/basebmp/inc/basebmp/scanlineformats.hxx index ee466f21b5c9..0b713dae7b55 100644 --- a/basebmp/inc/basebmp/scanlineformats.hxx +++ b/basebmp/inc/basebmp/scanlineformats.hxx @@ -50,8 +50,13 @@ namespace basebmp { namespace Format static const sal_Int32 SIXTEEN_BIT_MSB_TC_MASK = (sal_Int32)0x0C; static const sal_Int32 TWENTYFOUR_BIT_TC_MASK = (sal_Int32)0x0D; static const sal_Int32 THIRTYTWO_BIT_TC_MASK = (sal_Int32)0x0E; + // The order of the channels code letters indicates the order of the + // channel bytes in memory, I think + static const sal_Int32 THIRTYTWO_BIT_TC_MASK_BGRA = THIRTYTWO_BIT_TC_MASK; static const sal_Int32 THIRTYTWO_BIT_TC_MASK_ARGB = (sal_Int32)0x0F; - static const sal_Int32 MAX = (sal_Int32)0x0F; + static const sal_Int32 THIRTYTWO_BIT_TC_MASK_ABGR = (sal_Int32)0x10; + static const sal_Int32 THIRTYTWO_BIT_TC_MASK_RGBA = (sal_Int32)0x11; + static const sal_Int32 MAX = (sal_Int32)0x11; } } #endif /* INCLUDED_BASEBMP_SCANLINEFORMATS_HXX */ diff --git a/basebmp/source/bitmapdevice.cxx b/basebmp/source/bitmapdevice.cxx index b3676c603edc..07a36ceeef66 100644 --- a/basebmp/source/bitmapdevice.cxx +++ b/basebmp/source/bitmapdevice.cxx @@ -1862,9 +1862,11 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& 16, // SIXTEEN_BIT_LSB_TC_MASK 16, // SIXTEEN_BIT_MSB_TC_MASK 24, // TWENTYFOUR_BIT_TC_MASK - 32, // THIRTYTWO_BIT_TC_MASK + 32, // THIRTYTWO_BIT_TC_MASK_BGRA 32, // THIRTYTWO_BIT_TC_MASK_ARGB - }; + 32, // THIRTYTWO_BIT_TC_MASK_ABGR + 32, // THIRTYTWO_BIT_TC_MASK_RGBA + }; sal_Int32 nScanlineStride(0); @@ -2004,13 +2006,23 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& // ---------------------------------------------------------------------- // thirtytwo bit formats - case Format::THIRTYTWO_BIT_TC_MASK: - return createRenderer( + case Format::THIRTYTWO_BIT_TC_MASK_BGRA: + return createRenderer( aBounds, nScanlineFormat, nScanlineStride, pFirstScanline, pMem, pPal, rDamage ); case Format::THIRTYTWO_BIT_TC_MASK_ARGB: - return createRenderer( + return createRenderer( + aBounds, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal, rDamage ); + + case Format::THIRTYTWO_BIT_TC_MASK_ABGR: + return createRenderer( + aBounds, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal, rDamage ); + + case Format::THIRTYTWO_BIT_TC_MASK_RGBA: + return createRenderer( aBounds, nScanlineFormat, nScanlineStride, pFirstScanline, pMem, pPal, rDamage ); } -- cgit