22#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23#include <com/sun/star/util/Endianness.hpp>
24#include <com/sun/star/rendering/ColorComponentTag.hpp>
25#include <com/sun/star/rendering/ColorSpaceType.hpp>
26#include <com/sun/star/rendering/RenderingIntent.hpp>
29#include <canvasbitmap.hxx>
45 sal_Int32 bitcount( sal_uInt32 val )
47 val = val - ((val >> 1) & 0x55555555);
48 val = (val & 0x33333333) + ((val >> 2) & 0x33333333);
49 val = (val + (val >> 4)) & 0x0F0F0F0F;
50 val = val + (val >> 8);
51 val = val + (val >> 16);
52 return sal_Int32(val & 0x0000003F);
56void VclCanvasBitmap::setComponentInfo( sal_uInt32 redShift, sal_uInt32 greenShift, sal_uInt32 blueShift )
64 if( redShift > greenShift )
66 std::swap(redPos,greenPos);
67 if( redShift > blueShift )
69 std::swap(redPos,bluePos);
70 if( greenShift > blueShift )
71 std::swap(greenPos,bluePos);
76 if( greenShift > blueShift )
78 std::swap(greenPos,bluePos);
79 if( redShift > blueShift )
80 std::swap(redPos,bluePos);
86 pTags[redPos] = rendering::ColorComponentTag::RGB_RED;
87 pTags[greenPos] = rendering::ColorComponentTag::RGB_GREEN;
88 pTags[bluePos] = rendering::ColorComponentTag::RGB_BLUE;
92 pCounts[redPos] = bitcount(redShift);
93 pCounts[greenPos] = bitcount(greenShift);
94 pCounts[bluePos] = bitcount(blueShift);
117 m_aBitmap( rBitmap.GetBitmap() ),
118 m_pBmpAcc( m_aBitmap ),
119 m_nBitsPerInputPixel(0),
120 m_nBitsPerOutputPixel(0),
175 static_cast<sal_uInt32
>(0x00ff00UL),
176 static_cast<sal_uInt32
>(0x0000ffUL) );
184 static_cast<sal_uInt32
>(0x00ff00UL),
185 static_cast<sal_uInt32
>(0xff0000UL) );
195 rendering::ColorComponentTag::RGB_BLUE,
196 rendering::ColorComponentTag::RGB_GREEN,
197 rendering::ColorComponentTag::RGB_RED };
218 rendering::ColorComponentTag::RGB_RED,
219 rendering::ColorComponentTag::RGB_GREEN,
220 rendering::ColorComponentTag::RGB_BLUE };
241 rendering::ColorComponentTag::RGB_GREEN,
242 rendering::ColorComponentTag::RGB_RED,
243 rendering::ColorComponentTag::ALPHA };
264 rendering::ColorComponentTag::RGB_GREEN,
265 rendering::ColorComponentTag::RGB_BLUE,
266 rendering::ColorComponentTag::ALPHA };
290 OSL_FAIL(
"unsupported bitmap format" );
360 return uno::Reference<rendering::XBitmap>(
new VclCanvasBitmap( aNewBmp ) );
365 const geometry::IntegerRectangle2D& rect )
372 if( aRequestedArea.IsEmpty() )
373 return uno::Sequence< sal_Int8 >();
377 throw lang::IndexOutOfBoundsException();
379 throw lang::IndexOutOfBoundsException();
381 if( aRequestedArea.Left() < 0 || aRequestedArea.Top() < 0 ||
385 throw lang::IndexOutOfBoundsException();
388 uno::Sequence< sal_Int8 > aRet;
397 sal_Int8* pOutBuf = aRet.getArray();
400 bitmapLayout.ScanLineBytes =
401 bitmapLayout.ScanLineStride= aRequestedBytes.
getOpenWidth();
403 sal_Int32 nScanlineStride=bitmapLayout.ScanLineStride;
406 pOutBuf += bitmapLayout.ScanLineStride*(aRequestedBytes.
getOpenHeight()-1);
407 nScanlineStride *= -1;
413 OSL_ENSURE(pBmpAcc,
"Invalid bmp read access");
419 memcpy(pOutBuf, pScan+aRequestedBytes.
Left(), aRequestedBytes.
getOpenWidth());
420 pOutBuf += nScanlineStride;
427 OSL_ENSURE(pBmpAcc,
"Invalid bmp read access");
428 OSL_ENSURE(pAlphaAcc,
"Invalid alpha read access");
433 "Transparent bitmap bitcount not integer multiple of 8" );
435 for(
tools::Long y=aRequestedArea.Top();
y<aRequestedArea.Bottom(); ++
y )
442 for(
tools::Long x=aRequestedArea.Left();
x<aRequestedArea.Right(); ++
x )
451 const tools::Long nScanlineOffsetLeft(aRequestedArea.Left()*nNonAlphaBytes);
456 for(
tools::Long x=aRequestedArea.Left();
x<aRequestedArea.Right(); ++
x )
459 *pOutScan++ = *pScan++;
464 pOutBuf += nScanlineStride;
472 const geometry::IntegerPoint2D& pos )
480 throw lang::IndexOutOfBoundsException();
482 throw lang::IndexOutOfBoundsException();
484 if(
pos.X < 0 ||
pos.Y < 0 ||
487 throw lang::IndexOutOfBoundsException();
491 sal_Int8* pOutBuf = aRet.getArray();
494 bitmapLayout.ScanLines = 1;
495 bitmapLayout.ScanLineBytes =
496 bitmapLayout.ScanLineStride= aRet.getLength();
502 assert(pBmpAcc &&
"Invalid bmp read access");
506 memcpy(pOutBuf, pScan+nScanlineLeftOffset, aRet.getLength() );
512 assert(pBmpAcc &&
"Invalid bmp read access");
513 assert(pAlphaAcc &&
"Invalid alpha read access");
518 "Transparent bitmap bitcount not integer multiple of 8" );
532 memcpy(pOutBuf, pScan+nScanlineLeftOffset, nNonAlphaBytes );
533 pOutBuf += nNonAlphaBytes;
545 uno::Reference< XBitmapPalette > aRet;
556 rendering::IntegerBitmapLayout aLayout(
m_aLayout );
562 aLayout.Palette.set(
this );
564 aLayout.ColorSpace.set(
this );
586 if( nIndex < 0 || nIndex >=
nCount )
587 throw lang::IndexOutOfBoundsException(
"Palette index out of range",
588 static_cast<rendering::XBitmapPalette*
>(
this));
592 double* pColor=o_entry.getArray();
593 pColor[0] = aCol.
GetRed();
608 if( nIndex < 0 || nIndex >=
nCount )
609 throw lang::IndexOutOfBoundsException(
"Palette index out of range",
610 static_cast<rendering::XBitmapPalette*
>(
this));
625 return rendering::ColorSpaceType::RGB;
636 return rendering::RenderingIntent::PERCEPTUAL;
641 return uno::Sequence< ::beans::PropertyValue >();
645 const uno::Reference< ::rendering::XColorSpace >& targetColorSpace )
649 uno::Sequence<rendering::ARGBColor> aIntermediate(
651 return targetColorSpace->convertFromARGB(aIntermediate);
658 const std::size_t nLen( deviceColor.getLength() );
661 "number of channels no multiple of pixel element count",
662 static_cast<rendering::XBitmapPalette*
>(
this), 01);
664 uno::Sequence< rendering::RGBColor > aRes(nLen/nComponentsPerPixel);
665 rendering::RGBColor*
pOut( aRes.getArray() );
670 "Invalid color channel indices");
672 "Unable to get BitmapAccess");
674 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
688 "Invalid color channel indices");
690 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
693 *
pOut++ = rendering::RGBColor(
707 const std::size_t nLen( deviceColor.getLength() );
710 "number of channels no multiple of pixel element count",
711 static_cast<rendering::XBitmapPalette*
>(
this), 01);
713 uno::Sequence< rendering::ARGBColor > aRes(nLen/nComponentsPerPixel);
714 rendering::ARGBColor*
pOut( aRes.getArray() );
719 "Invalid color channel indices");
721 "Unable to get BitmapAccess");
723 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
730 *
pOut++ = rendering::ARGBColor(nAlpha,
739 "Invalid color channel indices");
741 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
745 *
pOut++ = rendering::ARGBColor(
760 const std::size_t nLen( deviceColor.getLength() );
763 "number of channels no multiple of pixel element count",
764 static_cast<rendering::XBitmapPalette*
>(
this), 01);
766 uno::Sequence< rendering::ARGBColor > aRes(nLen/nComponentsPerPixel);
767 rendering::ARGBColor*
pOut( aRes.getArray() );
772 "Invalid color channel indices");
774 "Unable to get BitmapAccess");
776 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
783 *
pOut++ = rendering::ARGBColor(nAlpha,
792 "Invalid color channel indices");
794 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
798 *
pOut++ = rendering::ARGBColor(
813 const std::size_t nLen( rgbColor.getLength() );
816 uno::Sequence< double > aRes(nLen*nComponentsPerPixel);
817 double* pColors=aRes.getArray();
821 for(
const auto& rIn : rgbColor )
830 pColors += nComponentsPerPixel;
835 for(
const auto& rIn : rgbColor )
843 pColors += nComponentsPerPixel;
853 const std::size_t nLen( rgbColor.getLength() );
856 uno::Sequence< double > aRes(nLen*nComponentsPerPixel);
857 double* pColors=aRes.getArray();
861 for(
const auto& rIn : rgbColor )
870 pColors += nComponentsPerPixel;
875 for(
const auto& rIn : rgbColor )
883 pColors += nComponentsPerPixel;
893 const std::size_t nLen( rgbColor.getLength() );
896 uno::Sequence< double > aRes(nLen*nComponentsPerPixel);
897 double* pColors=aRes.getArray();
901 for(
const auto& rIn : rgbColor )
903 const double nAlpha( rIn.Alpha );
911 pColors += nComponentsPerPixel;
916 for(
const auto& rIn : rgbColor )
918 const double nAlpha( rIn.Alpha );
925 pColors += nComponentsPerPixel;
945 return util::Endianness::LITTLE;
949 const uno::Reference< ::rendering::XColorSpace >& targetColorSpace )
955 const std::size_t nLen( deviceColor.getLength() );
958 "number of channels no multiple of pixel element count",
959 static_cast<rendering::XBitmapPalette*
>(
this), 01);
961 uno::Sequence<double> aRes(nLen);
962 double*
pOut( aRes.getArray() );
967 "Invalid color channel indices");
969 "Unable to get BitmapAccess");
971 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
987 "Invalid color channel indices");
989 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
1006 uno::Sequence<rendering::ARGBColor> aIntermediate(
1008 return targetColorSpace->convertFromARGB(aIntermediate);
1013 const uno::Reference< ::rendering::XIntegerBitmapColorSpace >& targetColorSpace )
1024 uno::Sequence<rendering::ARGBColor> aIntermediate(
1026 return targetColorSpace->convertIntegerFromARGB(aIntermediate);
1034 const sal_uInt8* pIn(
reinterpret_cast<const sal_uInt8*
>(deviceColor.getConstArray()) );
1035 const std::size_t nLen( deviceColor.getLength() );
1038 uno::Sequence< rendering::RGBColor > aRes(nNumColors);
1039 rendering::RGBColor*
pOut( aRes.getArray() );
1043 "Unable to get BitmapAccess");
1048 for( std::size_t
i=0;
i<nLen;
i+=nBytesPerPixel )
1061 pIn += nBytesPerPixel;
1066 for( sal_Int32
i=0;
i<nNumColors; ++
i )
1087 const sal_uInt8* pIn(
reinterpret_cast<const sal_uInt8*
>(deviceColor.getConstArray()) );
1088 const std::size_t nLen( deviceColor.getLength() );
1091 uno::Sequence< rendering::ARGBColor > aRes(nNumColors);
1092 rendering::ARGBColor*
pOut( aRes.getArray() );
1096 "Unable to get BitmapAccess");
1102 for( std::size_t
i=0;
i<nLen;
i+=nBytesPerPixel )
1115 pIn += nBytesPerPixel;
1120 for( sal_Int32
i=0;
i<nNumColors; ++
i )
1128 *
pOut++ = rendering::ARGBColor(1.0,
1142 const sal_uInt8* pIn(
reinterpret_cast<const sal_uInt8*
>(deviceColor.getConstArray()) );
1143 const std::size_t nLen( deviceColor.getLength() );
1146 uno::Sequence< rendering::ARGBColor > aRes(nNumColors);
1147 rendering::ARGBColor*
pOut( aRes.getArray() );
1151 "Unable to get BitmapAccess");
1157 for( std::size_t
i=0;
i<nLen;
i+=nBytesPerPixel )
1166 const double nAlpha( 1.0 -
toDoubleColor(pIn[nNonAlphaBytes]) );
1167 *
pOut++ = rendering::ARGBColor(nAlpha,
1171 pIn += nBytesPerPixel;
1176 for( sal_Int32
i=0;
i<nNumColors; ++
i )
1184 *
pOut++ = rendering::ARGBColor(1.0,
1198 const std::size_t nLen( rgbColor.getLength() );
1201 uno::Sequence< sal_Int8 > aRes(nNumBytes);
1208 for( std::size_t
i=0;
i<nLen; ++
i )
1220 pColors += nNonAlphaBytes;
1226 for( std::size_t
i=0;
i<nLen; ++
i )
1248 const std::size_t nLen( rgbColor.getLength() );
1251 uno::Sequence< sal_Int8 > aRes(nNumBytes);
1258 for( std::size_t
i=0;
i<nLen; ++
i )
1270 pColors += nNonAlphaBytes;
1276 for( std::size_t
i=0;
i<nLen; ++
i )
1298 const std::size_t nLen( rgbColor.getLength() );
1301 uno::Sequence< sal_Int8 > aRes(nNumBytes);
1308 for( std::size_t
i=0;
i<nLen; ++
i )
1310 const double nAlpha( rgbColor[
i].
Alpha );
1321 pColors += nNonAlphaBytes;
1327 for( std::size_t
i=0;
i<nLen; ++
i )
Bitmap const & GetBitmap() const
sal_uInt8 GetIndex() const
const AlphaMask & GetAlphaMask() const
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
Scale the bitmap.
tools::Long Height() const
tools::Long Width() const
sal_uInt16 GetBestPaletteIndex(const BitmapColor &rBitmapColor) const
ScanlineFormat GetScanlineFormat() const
sal_uInt16 GetPaletteEntryCount() const
sal_uInt16 GetBitCount() const
const ColorMask & GetColorMask() const
const BitmapColor & GetPaletteColor(sal_uInt16 nColor) const
sal_uInt32 GetScanlineSize() const
sal_uInt8 GetPixelIndex(tools::Long nY, tools::Long nX) const
void SetPixelOnData(sal_uInt8 *pData, tools::Long nX, const BitmapColor &rBitmapColor)
BitmapColor GetPixelFromData(const sal_uInt8 *pData, tools::Long nX) const
sal_uInt8 GetIndexFromData(const sal_uInt8 *pData, tools::Long nX) const
Scanline GetScanline(tools::Long nY) const
Size GetSizePixel() const
vcl::ScopedBitmapAccess< BitmapInfoAccess, Bitmap, &Bitmap::AcquireInfoAccess > ScopedInfoAccess
sal_uInt32 GetRedMask() const
sal_uInt32 GetGreenMask() const
sal_uInt32 GetBlueMask() const
sal_uInt8 GetBlue() const
sal_uInt8 GetGreen() const
constexpr tools::Long Width() const
#define ENSURE_ARG_OR_THROW2(c, m, ifc, arg)
#define ENSURE_OR_THROW(c, m)