34 explicit BasePixelPtr(
PIXBYTE*
p =
nullptr ) : mpPixel(
p ) {}
35 void SetRawPtr(
PIXBYTE* pRawPtr ) { mpPixel = pRawPtr; }
36 void AddByteOffset(
int nByteOffset ) { mpPixel += nByteOffset; }
42template <ScanlineFormat PIXFMT>
43class TrueColorPixelPtr :
public BasePixelPtr
62 PIXBYTE GetRed()
const {
return mpPixel[0]; }
63 PIXBYTE GetGreen()
const {
return mpPixel[1]; }
64 PIXBYTE GetBlue()
const {
return mpPixel[2]; }
65 static PIXBYTE GetAlpha() {
return 255; }
66 static void SetAlpha(
PIXBYTE ) {}
82 PIXBYTE GetRed()
const {
return mpPixel[2]; }
83 PIXBYTE GetGreen()
const {
return mpPixel[1]; }
84 PIXBYTE GetBlue()
const {
return mpPixel[0]; }
85 static PIXBYTE GetAlpha() {
return 255; }
86 static void SetAlpha(
PIXBYTE ) {}
102 PIXBYTE GetRed()
const {
return mpPixel[1]; }
103 PIXBYTE GetGreen()
const {
return mpPixel[2]; }
104 PIXBYTE GetBlue()
const {
return mpPixel[3]; }
105 PIXBYTE GetAlpha()
const {
return mpPixel[0]; }
106 void SetAlpha(
PIXBYTE a )
const { mpPixel[0] =
a; }
122 PIXBYTE GetRed()
const {
return mpPixel[3]; }
123 PIXBYTE GetGreen()
const {
return mpPixel[2]; }
124 PIXBYTE GetBlue()
const {
return mpPixel[1]; }
125 PIXBYTE GetAlpha()
const {
return mpPixel[0]; }
126 void SetAlpha(
PIXBYTE a )
const { mpPixel[0] =
a; }
142 PIXBYTE GetRed()
const {
return mpPixel[0]; }
143 PIXBYTE GetGreen()
const {
return mpPixel[1]; }
144 PIXBYTE GetBlue()
const {
return mpPixel[2]; }
145 PIXBYTE GetAlpha()
const {
return mpPixel[3]; }
146 void SetAlpha(
PIXBYTE a )
const{ mpPixel[3] =
a; }
162 PIXBYTE GetRed()
const {
return mpPixel[2]; }
163 PIXBYTE GetGreen()
const {
return mpPixel[1]; }
164 PIXBYTE GetBlue()
const {
return mpPixel[0]; }
165 PIXBYTE GetAlpha()
const {
return mpPixel[3]; }
166 void SetAlpha(
PIXBYTE a )
const{ mpPixel[3] =
a; }
186 PIXBYTE GetRed()
const {
return mpPixel[0]; }
187 PIXBYTE GetGreen()
const {
return mpPixel[0]; }
188 PIXBYTE GetBlue()
const {
return mpPixel[0]; }
189 static PIXBYTE GetAlpha() {
return 255; }
195template <ScanlineFormat SRCFMT, ScanlineFormat DSTFMT>
197 const TrueColorPixelPtr<SRCFMT>& rSrc )
199 rDst.SetColor( rSrc.GetRed(), rSrc.GetGreen(), rSrc.GetBlue() );
200 rDst.SetAlpha( rSrc.GetAlpha() );
203template <ScanlineFormat SRCFMT, ScanlineFormat DSTFMT>
205 const TrueColorPixelPtr<SRCFMT>& rSrc,
int nPixelCount )
207 TrueColorPixelPtr<DSTFMT> aDst( rDst );
208 TrueColorPixelPtr<SRCFMT> aSrc( rSrc );
209 while( --nPixelCount >= 0 )
218template <ScanlineFormat SRCFMT, ScanlineFormat DSTFMT>
220 const TrueColorPixelPtr<SRCFMT>& rSrc,
unsigned nAlphaVal )
222 static const unsigned nAlphaShift = 8;
225 else if( nAlphaVal != ~(~0
U << nAlphaShift) )
227 int nR = rDst.GetRed();
228 int nS = rSrc.GetRed();
229 nR = nS + (((nR - nS) * nAlphaVal) >> nAlphaShift);
231 int nG = rDst.GetGreen();
232 nS = rSrc.GetGreen();
233 nG = nS + (((nG - nS) * nAlphaVal) >> nAlphaShift);
235 int nB = rDst.GetBlue();
237 nB = nS + (((nB - nS) * nAlphaVal) >> nAlphaShift);
239 rDst.SetColor( sal::static_int_cast<PIXBYTE>(nR),
240 sal::static_int_cast<PIXBYTE>(nG),
241 sal::static_int_cast<PIXBYTE>(nB) );
245template <ScanlineFormat MASKFMT, ScanlineFormat SRCFMT, ScanlineFormat DSTFMT>
247 const TrueColorPixelPtr<SRCFMT>& rSrc,
const TrueColorPixelPtr<MASKFMT>& rMsk,
250 TrueColorPixelPtr<MASKFMT> aMsk( rMsk );
251 TrueColorPixelPtr<DSTFMT> aDst( rDst );
252 TrueColorPixelPtr<SRCFMT> aSrc( rSrc );
253 while( --nPixelCount >= 0 )
274 pRawDst += (rSrcBuffer.
mnHeight - 1) * nDstLinestep;
277 else if( nSrcLinestep == nDstLinestep )
279 memcpy( pRawDst, pRawSrc, rSrcBuffer.
mnHeight * nDstLinestep );
283 int nByteWidth = nSrcLinestep;
289 memcpy( pRawDst, pRawSrc, nByteWidth );
290 pRawSrc += nSrcLinestep;
291 pRawDst += nDstLinestep;
297template <ScanlineFormat DSTFMT,ScanlineFormat SRCFMT>
302 SAL_WARN_IF( SRCFMT == DSTFMT,
"vcl.gdi",
"ImplConvertToBitmap into same format");
303 if( SRCFMT == DSTFMT )
309 TrueColorPixelPtr<DSTFMT> aDstLine; aDstLine.SetRawPtr( rDstBuffer.
mpBits );
314 aDstLine.AddByteOffset( (rSrcBuffer.
mnHeight - 1) * nDstLinestep );
315 nDstLinestep = -nDstLinestep;
321 rSrcLine.AddByteOffset( nSrcLinestep );
322 aDstLine.AddByteOffset( nDstLinestep );
328template <ScanlineFormat SRCFMT>
331 TrueColorPixelPtr<SRCFMT> aSrcType; aSrcType.SetRawPtr( rSrc.
mpBits );
346 return ImplConvertToBitmap<ScanlineFormat::N24BitTcBgr>( aSrcType, rDst, rSrc );
348 return ImplConvertToBitmap<ScanlineFormat::N24BitTcRgb>( aSrcType, rDst, rSrc );
351 return ImplConvertToBitmap<ScanlineFormat::N32BitTcAbgr>( aSrcType, rDst, rSrc );
353 return ImplConvertToBitmap<ScanlineFormat::N32BitTcArgb>( aSrcType, rDst, rSrc );
355 return ImplConvertToBitmap<ScanlineFormat::N32BitTcBgra>( aSrcType, rDst, rSrc );
357 return ImplConvertToBitmap<ScanlineFormat::N32BitTcRgba>( aSrcType, rDst, rSrc );
361 static int nNotAccelerated = 0;
364 "ImplConvertFromBitmap for not accelerated case (" << std::hex <<
static_cast<int>(rSrc.
mnFormat) <<
"->" <<
static_cast<int>(rDst.
mnFormat) <<
")" );
410 if( nSrcFormat == nDstFormat )
431 return ImplConvertFromBitmap<ScanlineFormat::N8BitPal>( rDst, rSrc );
435 return ImplConvertFromBitmap<ScanlineFormat::N24BitTcBgr>( rDst, rSrc );
437 return ImplConvertFromBitmap<ScanlineFormat::N24BitTcRgb>( rDst, rSrc );
440 return ImplConvertFromBitmap<ScanlineFormat::N32BitTcAbgr>( rDst, rSrc );
442 return ImplConvertFromBitmap<ScanlineFormat::N32BitTcArgb>( rDst, rSrc );
444 return ImplConvertFromBitmap<ScanlineFormat::N32BitTcBgra>( rDst, rSrc );
446 return ImplConvertFromBitmap<ScanlineFormat::N32BitTcRgba>( rDst, rSrc );
450 static int nNotAccelerated = 0;
453 "ImplFastBitmapConversion for not accelerated case (" << std::hex <<
static_cast<int>(rSrc.
mnFormat) <<
"->" <<
static_cast<int>(rDst.
mnFormat) <<
")" );
471template <ScanlineFormat DSTFMT, ScanlineFormat SRCFMT>
474 TrueColorPixelPtr<DSTFMT> aDstType;
480template <ScanlineFormat SRCFMT>
483 TrueColorPixelPtr<SRCFMT> aSrcType;
484 aSrcType.SetRawPtr(
const_cast<Scanline>( aSrcScanline ));
489 return ImplCopyToScanline<ScanlineFormat::N24BitTcBgr>( nY, rDst, aSrcType, nSrcWidth );
491 return ImplCopyToScanline<ScanlineFormat::N24BitTcRgb>( nY, rDst, aSrcType, nSrcWidth );
494 return ImplCopyToScanline<ScanlineFormat::N32BitTcAbgr>( nY, rDst, aSrcType, nSrcWidth );
496 return ImplCopyToScanline<ScanlineFormat::N32BitTcArgb>( nY, rDst, aSrcType, nSrcWidth );
498 return ImplCopyToScanline<ScanlineFormat::N32BitTcBgra>( nY, rDst, aSrcType, nSrcWidth );
500 return ImplCopyToScanline<ScanlineFormat::N32BitTcRgba>( nY, rDst, aSrcType, nSrcWidth );
518 if( nSrcFormat == nDstFormat )
528 return ImplCopyFromScanline<ScanlineFormat::N24BitTcBgr>( nY, rDst, aSrcScanline, nSrcScanlineSize / 3 );
530 return ImplCopyFromScanline<ScanlineFormat::N24BitTcRgb>( nY, rDst, aSrcScanline, nSrcScanlineSize / 3 );
533 return ImplCopyFromScanline<ScanlineFormat::N32BitTcAbgr>( nY, rDst, aSrcScanline, nSrcScanlineSize / 4 );
535 return ImplCopyFromScanline<ScanlineFormat::N32BitTcArgb>( nY, rDst, aSrcScanline, nSrcScanlineSize / 4 );
537 return ImplCopyFromScanline<ScanlineFormat::N32BitTcBgra>( nY, rDst, aSrcScanline, nSrcScanlineSize / 4 );
539 return ImplCopyFromScanline<ScanlineFormat::N32BitTcRgba>( nY, rDst, aSrcScanline, nSrcScanlineSize / 4 );
555template <ScanlineFormat DSTFMT, ScanlineFormat SRCFMT>
561 "vcl.gdi",
"FastBmp BlendImage: unusual MSKFMT" );
567 TrueColorPixelPtr<ScanlineFormat::N8BitPal> aMskLine; aMskLine.SetRawPtr( rMskBuffer.
mpBits );
568 TrueColorPixelPtr<DSTFMT> aDstLine; aDstLine.SetRawPtr( rDstBuffer.
mpBits );
577 aMskLine.AddByteOffset( (rSrcBuffer.
mnHeight - 1) * nMskLinestep );
578 nMskLinestep = -nMskLinestep;
584 aDstLine.AddByteOffset( (rDstBuffer.
mnHeight - 1) * nDstLinestep );
585 nDstLinestep = -nDstLinestep;
588 assert(rDstBuffer.
mnHeight <= rSrcBuffer.
mnHeight &&
"not sure about that?");
592 aDstLine.AddByteOffset( nDstLinestep );
593 rSrcLine.AddByteOffset( nSrcLinestep );
594 aMskLine.AddByteOffset( nMskLinestep );
602bool ImplBlendToBitmap<ScanlineFormat::N24BitTcBgr,ScanlineFormat::N24BitTcBgr>(
603 TrueColorPixelPtr<ScanlineFormat::N24BitTcBgr>&,
607 TrueColorPixelPtr<ScanlineFormat::N24BitTcRgb> aSrcType; aSrcType.SetRawPtr( rSrcBuffer.
mpBits );
608 return ImplBlendToBitmap<ScanlineFormat::N24BitTcRgb>( aSrcType, rDstBuffer, rSrcBuffer, rMskBuffer );
612bool ImplBlendToBitmap<ScanlineFormat::N32BitTcAbgr,ScanlineFormat::N32BitTcAbgr>(
613 TrueColorPixelPtr<ScanlineFormat::N32BitTcAbgr>&,
617 TrueColorPixelPtr<ScanlineFormat::N32BitTcArgb> aSrcType; aSrcType.SetRawPtr( rSrcBuffer.
mpBits );
618 return ImplBlendToBitmap<ScanlineFormat::N32BitTcArgb>( aSrcType, rDstBuffer, rSrcBuffer, rMskBuffer );
622bool ImplBlendToBitmap<ScanlineFormat::N32BitTcBgra,ScanlineFormat::N32BitTcBgra>(
623 TrueColorPixelPtr<ScanlineFormat::N32BitTcBgra>&,
627 TrueColorPixelPtr<ScanlineFormat::N32BitTcRgba> aSrcType; aSrcType.SetRawPtr( rSrcBuffer.
mpBits );
628 return ImplBlendToBitmap<ScanlineFormat::N32BitTcRgba>( aSrcType, rDstBuffer, rSrcBuffer, rMskBuffer );
631template <ScanlineFormat SRCFMT>
634 TrueColorPixelPtr<SRCFMT> aSrcType; aSrcType.SetRawPtr( rSrc.
mpBits );
649 return ImplBlendToBitmap<ScanlineFormat::N24BitTcBgr>( aSrcType, rDst, rSrc, rMsk );
651 return ImplBlendToBitmap<ScanlineFormat::N24BitTcRgb>( aSrcType, rDst, rSrc, rMsk );
654 return ImplBlendToBitmap<ScanlineFormat::N32BitTcAbgr>( aSrcType, rDst, rSrc, rMsk );
656 return ImplBlendToBitmap<ScanlineFormat::N32BitTcArgb>( aSrcType, rDst, rSrc, rMsk );
658 return ImplBlendToBitmap<ScanlineFormat::N32BitTcBgra>( aSrcType, rDst, rSrc, rMsk );
660 return ImplBlendToBitmap<ScanlineFormat::N32BitTcRgba>( aSrcType, rDst, rSrc, rMsk );
664 static int nNotAccelerated = 0;
667 "ImplBlendFromBitmap for not accelerated case (" << std::hex <<
static_cast<int>(rSrc.
mnFormat) <<
"*" <<
static_cast<int>(rMsk.
mnFormat) <<
"->" <<
static_cast<int>(rDst.
mnFormat) );
712 if( rMskRA.
Height() != 1 )
740 return ImplBlendFromBitmap<ScanlineFormat::N8BitPal>( rDst, rSrc, rMsk );
744 return ImplBlendFromBitmap<ScanlineFormat::N24BitTcBgr>( rDst, rSrc, rMsk );
746 return ImplBlendFromBitmap<ScanlineFormat::N24BitTcRgb>( rDst, rSrc, rMsk );
749 return ImplBlendFromBitmap<ScanlineFormat::N32BitTcAbgr>( rDst, rSrc, rMsk );
751 return ImplBlendFromBitmap<ScanlineFormat::N32BitTcArgb>( rDst, rSrc, rMsk );
753 return ImplBlendFromBitmap<ScanlineFormat::N32BitTcBgra>( rDst, rSrc, rMsk );
755 return ImplBlendFromBitmap<ScanlineFormat::N32BitTcRgba>( rDst, rSrc, rMsk );
759 static int nNotAccelerated = 0;
762 "ImplFastBlend for not accelerated case (" << std::hex <<
static_cast<int>(rSrc.
mnFormat) <<
"*" <<
static_cast<int>(rMsk.
mnFormat) <<
"->" <<
static_cast<int>(rDst.
mnFormat) <<
")" );
772 bool bByteFill =
true;
780 nFillByte =
static_cast<sal_uInt8>( -(nFillByte & 1) );
788 nFillByte = rColor.
GetRed();
789 if( (nFillByte != rColor.
GetGreen())
790 || (nFillByte != rColor.
GetBlue()) )
803 memset( rDst.
mpBits, nFillByte, nByteCount );
const sal_uInt8 * ConstScanline
ScanlineFormat RemoveScanline(ScanlineFormat nFormat)
static bool ImplCopyImage(BitmapBuffer &rDstBuffer, const BitmapBuffer &rSrcBuffer)
bool ImplFastEraseBitmap(BitmapBuffer &rDst, const BitmapColor &rColor)
static bool ImplCopyToScanline(tools::Long nY, BitmapBuffer &rDst, TrueColorPixelPtr< SRCFMT > &rSrcLine, tools::Long nSrcWidth)
static bool ImplCopyFromScanline(tools::Long nY, BitmapBuffer &rDst, ConstScanline aSrcScanline, tools::Long nSrcWidth)
bool ImplFastBitmapBlending(BitmapWriteAccess const &rDstWA, const BitmapReadAccess &rSrcRA, const BitmapReadAccess &rMskRA, const SalTwoRect &rTR)
static void ImplConvertPixel(const TrueColorPixelPtr< DSTFMT > &rDst, const TrueColorPixelPtr< SRCFMT > &rSrc)
static void ImplBlendLines(const TrueColorPixelPtr< DSTFMT > &rDst, const TrueColorPixelPtr< SRCFMT > &rSrc, const TrueColorPixelPtr< MASKFMT > &rMsk, int nPixelCount)
static bool ImplBlendToBitmap(TrueColorPixelPtr< SRCFMT > &rSrcLine, BitmapBuffer &rDstBuffer, const BitmapBuffer &rSrcBuffer, const BitmapBuffer &rMskBuffer)
static bool ImplConvertFromBitmap(BitmapBuffer &rDst, const BitmapBuffer &rSrc)
static bool ImplBlendFromBitmap(BitmapBuffer &rDst, const BitmapBuffer &rSrc, const BitmapBuffer &rMsk)
static void ImplBlendPixels(const TrueColorPixelPtr< DSTFMT > &rDst, const TrueColorPixelPtr< SRCFMT > &rSrc, unsigned nAlphaVal)
bool ImplFastBitmapConversion(BitmapBuffer &rDst, const BitmapBuffer &rSrc, const SalTwoRect &rTR)
static ConstScanline ImplGetScanline(const BitmapBuffer &rBuf, tools::Long nY)
static bool ImplConvertToBitmap(TrueColorPixelPtr< SRCFMT > &rSrcLine, BitmapBuffer &rDstBuffer, const BitmapBuffer &rSrcBuffer)
static void ImplConvertLine(const TrueColorPixelPtr< DSTFMT > &rDst, const TrueColorPixelPtr< SRCFMT > &rSrc, int nPixelCount)
bool ImplFastCopyScanline(tools::Long nY, BitmapBuffer &rDst, ConstScanline aSrcScanline, ScanlineFormat nSrcScanlineFormat, sal_uInt32 nSrcScanlineSize)
sal_uInt8 GetIndex() const
tools::Long Height() const
tools::Long Width() const
bool IsGreyPalette8Bit() const
Returns true if the palette is 8-bit grey palette.
BitmapBuffer * ImplGetBitmapBuffer() const
sal_uInt8 GetBlue() const
sal_uInt8 GetGreen() const
#define SAL_WARN_IF(condition, area, stream)
tools::Long mnScanlineSize