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),
169 static_cast<sal_uInt32
>(0x00ff00UL),
170 static_cast<sal_uInt32
>(0x0000ffUL) );
178 static_cast<sal_uInt32
>(0x00ff00UL),
179 static_cast<sal_uInt32
>(0xff0000UL) );
189 rendering::ColorComponentTag::RGB_BLUE,
190 rendering::ColorComponentTag::RGB_GREEN,
191 rendering::ColorComponentTag::RGB_RED };
212 rendering::ColorComponentTag::RGB_RED,
213 rendering::ColorComponentTag::RGB_GREEN,
214 rendering::ColorComponentTag::RGB_BLUE };
235 rendering::ColorComponentTag::RGB_GREEN,
236 rendering::ColorComponentTag::RGB_RED,
237 rendering::ColorComponentTag::ALPHA };
258 rendering::ColorComponentTag::RGB_GREEN,
259 rendering::ColorComponentTag::RGB_BLUE,
260 rendering::ColorComponentTag::ALPHA };
284 OSL_FAIL(
"unsupported bitmap format" );
354 return uno::Reference<rendering::XBitmap>(
new VclCanvasBitmap( aNewBmp ) );
359 const geometry::IntegerRectangle2D& rect )
366 if( aRequestedArea.IsEmpty() )
367 return uno::Sequence< sal_Int8 >();
371 throw lang::IndexOutOfBoundsException();
373 throw lang::IndexOutOfBoundsException();
375 if( aRequestedArea.Left() < 0 || aRequestedArea.Top() < 0 ||
379 throw lang::IndexOutOfBoundsException();
382 uno::Sequence< sal_Int8 > aRet;
391 sal_Int8* pOutBuf = aRet.getArray();
394 bitmapLayout.ScanLineBytes =
395 bitmapLayout.ScanLineStride= aRequestedBytes.
getOpenWidth();
397 sal_Int32 nScanlineStride=bitmapLayout.ScanLineStride;
400 pOutBuf += bitmapLayout.ScanLineStride*(aRequestedBytes.
getOpenHeight()-1);
401 nScanlineStride *= -1;
407 OSL_ENSURE(pBmpAcc,
"Invalid bmp read access");
413 memcpy(pOutBuf, pScan+aRequestedBytes.
Left(), aRequestedBytes.
getOpenWidth());
414 pOutBuf += nScanlineStride;
421 OSL_ENSURE(pBmpAcc,
"Invalid bmp read access");
422 OSL_ENSURE(pAlphaAcc,
"Invalid alpha read access");
427 "Transparent bitmap bitcount not integer multiple of 8" );
429 for(
tools::Long y=aRequestedArea.Top();
y<aRequestedArea.Bottom(); ++
y )
436 for(
tools::Long x=aRequestedArea.Left();
x<aRequestedArea.Right(); ++
x )
447 const tools::Long nScanlineOffsetLeft(aRequestedArea.Left()*nNonAlphaBytes);
452 for(
tools::Long x=aRequestedArea.Left();
x<aRequestedArea.Right(); ++
x )
455 *pOutScan++ = *pScan++;
462 pOutBuf += nScanlineStride;
470 const geometry::IntegerPoint2D& pos )
478 throw lang::IndexOutOfBoundsException();
480 throw lang::IndexOutOfBoundsException();
482 if(
pos.X < 0 ||
pos.Y < 0 ||
485 throw lang::IndexOutOfBoundsException();
489 sal_Int8* pOutBuf = aRet.getArray();
492 bitmapLayout.ScanLines = 1;
493 bitmapLayout.ScanLineBytes =
494 bitmapLayout.ScanLineStride= aRet.getLength();
500 assert(pBmpAcc &&
"Invalid bmp read access");
504 memcpy(pOutBuf, pScan+nScanlineLeftOffset, aRet.getLength() );
510 assert(pBmpAcc &&
"Invalid bmp read access");
511 assert(pAlphaAcc &&
"Invalid alpha read access");
516 "Transparent bitmap bitcount not integer multiple of 8" );
532 memcpy(pOutBuf, pScan+nScanlineLeftOffset, nNonAlphaBytes );
533 pOutBuf += nNonAlphaBytes;
547 uno::Reference< XBitmapPalette > aRet;
558 rendering::IntegerBitmapLayout aLayout(
m_aLayout );
564 aLayout.Palette.set(
this );
566 aLayout.ColorSpace.set(
this );
588 if( nIndex < 0 || nIndex >=
nCount )
589 throw lang::IndexOutOfBoundsException(
"Palette index out of range",
590 static_cast<rendering::XBitmapPalette*
>(
this));
594 double* pColor=o_entry.getArray();
595 pColor[0] = aCol.
GetRed();
610 if( nIndex < 0 || nIndex >=
nCount )
611 throw lang::IndexOutOfBoundsException(
"Palette index out of range",
612 static_cast<rendering::XBitmapPalette*
>(
this));
627 return rendering::ColorSpaceType::RGB;
638 return rendering::RenderingIntent::PERCEPTUAL;
643 return uno::Sequence< ::beans::PropertyValue >();
647 const uno::Reference< ::rendering::XColorSpace >& targetColorSpace )
651 uno::Sequence<rendering::ARGBColor> aIntermediate(
653 return targetColorSpace->convertFromARGB(aIntermediate);
660 const std::size_t nLen( deviceColor.getLength() );
663 "number of channels no multiple of pixel element count",
664 static_cast<rendering::XBitmapPalette*
>(
this), 01);
666 uno::Sequence< rendering::RGBColor > aRes(nLen/nComponentsPerPixel);
667 rendering::RGBColor*
pOut( aRes.getArray() );
672 "Invalid color channel indices");
674 "Unable to get BitmapAccess");
676 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
690 "Invalid color channel indices");
692 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
695 *
pOut++ = rendering::RGBColor(
709 const std::size_t nLen( deviceColor.getLength() );
712 "number of channels no multiple of pixel element count",
713 static_cast<rendering::XBitmapPalette*
>(
this), 01);
715 uno::Sequence< rendering::ARGBColor > aRes(nLen/nComponentsPerPixel);
716 rendering::ARGBColor*
pOut( aRes.getArray() );
721 "Invalid color channel indices");
723 "Unable to get BitmapAccess");
725 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
732 *
pOut++ = rendering::ARGBColor(nAlpha,
741 "Invalid color channel indices");
743 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
747 *
pOut++ = rendering::ARGBColor(
762 const std::size_t nLen( deviceColor.getLength() );
765 "number of channels no multiple of pixel element count",
766 static_cast<rendering::XBitmapPalette*
>(
this), 01);
768 uno::Sequence< rendering::ARGBColor > aRes(nLen/nComponentsPerPixel);
769 rendering::ARGBColor*
pOut( aRes.getArray() );
774 "Invalid color channel indices");
776 "Unable to get BitmapAccess");
778 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
785 *
pOut++ = rendering::ARGBColor(nAlpha,
794 "Invalid color channel indices");
796 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
800 *
pOut++ = rendering::ARGBColor(
815 const std::size_t nLen( rgbColor.getLength() );
818 uno::Sequence< double > aRes(nLen*nComponentsPerPixel);
819 double* pColors=aRes.getArray();
823 for(
const auto& rIn : rgbColor )
832 pColors += nComponentsPerPixel;
837 for(
const auto& rIn : rgbColor )
845 pColors += nComponentsPerPixel;
855 const std::size_t nLen( rgbColor.getLength() );
858 uno::Sequence< double > aRes(nLen*nComponentsPerPixel);
859 double* pColors=aRes.getArray();
863 for(
const auto& rIn : rgbColor )
872 pColors += nComponentsPerPixel;
877 for(
const auto& rIn : rgbColor )
885 pColors += nComponentsPerPixel;
895 const std::size_t nLen( rgbColor.getLength() );
898 uno::Sequence< double > aRes(nLen*nComponentsPerPixel);
899 double* pColors=aRes.getArray();
903 for(
const auto& rIn : rgbColor )
905 const double nAlpha( rIn.Alpha );
913 pColors += nComponentsPerPixel;
918 for(
const auto& rIn : rgbColor )
920 const double nAlpha( rIn.Alpha );
927 pColors += nComponentsPerPixel;
947 return util::Endianness::LITTLE;
951 const uno::Reference< ::rendering::XColorSpace >& targetColorSpace )
957 const std::size_t nLen( deviceColor.getLength() );
960 "number of channels no multiple of pixel element count",
961 static_cast<rendering::XBitmapPalette*
>(
this), 01);
963 uno::Sequence<double> aRes(nLen);
964 double*
pOut( aRes.getArray() );
969 "Invalid color channel indices");
971 "Unable to get BitmapAccess");
973 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
989 "Invalid color channel indices");
991 for( std::size_t
i=0;
i<nLen;
i+=nComponentsPerPixel )
1008 uno::Sequence<rendering::ARGBColor> aIntermediate(
1010 return targetColorSpace->convertFromARGB(aIntermediate);
1015 const uno::Reference< ::rendering::XIntegerBitmapColorSpace >& targetColorSpace )
1026 uno::Sequence<rendering::ARGBColor> aIntermediate(
1028 return targetColorSpace->convertIntegerFromARGB(aIntermediate);
1036 const sal_uInt8* pIn(
reinterpret_cast<const sal_uInt8*
>(deviceColor.getConstArray()) );
1037 const std::size_t nLen( deviceColor.getLength() );
1040 uno::Sequence< rendering::RGBColor > aRes(nNumColors);
1041 rendering::RGBColor*
pOut( aRes.getArray() );
1045 "Unable to get BitmapAccess");
1050 for( std::size_t
i=0;
i<nLen;
i+=nBytesPerPixel )
1063 pIn += nBytesPerPixel;
1068 for( sal_Int32
i=0;
i<nNumColors; ++
i )
1089 const sal_uInt8* pIn(
reinterpret_cast<const sal_uInt8*
>(deviceColor.getConstArray()) );
1090 const std::size_t nLen( deviceColor.getLength() );
1093 uno::Sequence< rendering::ARGBColor > aRes(nNumColors);
1094 rendering::ARGBColor*
pOut( aRes.getArray() );
1098 "Unable to get BitmapAccess");
1104 for( std::size_t
i=0;
i<nLen;
i+=nBytesPerPixel )
1117 pIn += nBytesPerPixel;
1122 for( sal_Int32
i=0;
i<nNumColors; ++
i )
1130 *
pOut++ = rendering::ARGBColor(1.0,
1144 const sal_uInt8* pIn(
reinterpret_cast<const sal_uInt8*
>(deviceColor.getConstArray()) );
1145 const std::size_t nLen( deviceColor.getLength() );
1148 uno::Sequence< rendering::ARGBColor > aRes(nNumColors);
1149 rendering::ARGBColor*
pOut( aRes.getArray() );
1153 "Unable to get BitmapAccess");
1159 for( std::size_t
i=0;
i<nLen;
i+=nBytesPerPixel )
1168 const double nAlpha( 1.0 -
toDoubleColor(pIn[nNonAlphaBytes]) );
1169 *
pOut++ = rendering::ARGBColor(nAlpha,
1173 pIn += nBytesPerPixel;
1178 for( sal_Int32
i=0;
i<nNumColors; ++
i )
1186 *
pOut++ = rendering::ARGBColor(1.0,
1200 const std::size_t nLen( rgbColor.getLength() );
1203 uno::Sequence< sal_Int8 > aRes(nNumBytes);
1210 for( std::size_t
i=0;
i<nLen; ++
i )
1222 pColors += nNonAlphaBytes;
1228 for( std::size_t
i=0;
i<nLen; ++
i )
1250 const std::size_t nLen( rgbColor.getLength() );
1253 uno::Sequence< sal_Int8 > aRes(nNumBytes);
1260 for( std::size_t
i=0;
i<nLen; ++
i )
1272 pColors += nNonAlphaBytes;
1278 for( std::size_t
i=0;
i<nLen; ++
i )
1300 const std::size_t nLen( rgbColor.getLength() );
1303 uno::Sequence< sal_Int8 > aRes(nNumBytes);
1310 for( std::size_t
i=0;
i<nLen; ++
i )
1312 const double nAlpha( rgbColor[
i].
Alpha );
1323 pColors += nNonAlphaBytes;
1329 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)