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 );
345 return ImplConvertToBitmap<ScanlineFormat::N24BitTcBgr>( aSrcType, rDst, rSrc );
347 return ImplConvertToBitmap<ScanlineFormat::N24BitTcRgb>( aSrcType, rDst, rSrc );
350 return ImplConvertToBitmap<ScanlineFormat::N32BitTcAbgr>( aSrcType, rDst, rSrc );
352 return ImplConvertToBitmap<ScanlineFormat::N32BitTcArgb>( aSrcType, rDst, rSrc );
354 return ImplConvertToBitmap<ScanlineFormat::N32BitTcBgra>( aSrcType, rDst, rSrc );
356 return ImplConvertToBitmap<ScanlineFormat::N32BitTcRgba>( aSrcType, rDst, rSrc );
360 static int nNotAccelerated = 0;
363 "ImplConvertFromBitmap for not accelerated case (" << std::hex <<
static_cast<int>(rSrc.
mnFormat) <<
"->" <<
static_cast<int>(rDst.
mnFormat) <<
")" );
409 if( nSrcFormat == nDstFormat )
429 return ImplConvertFromBitmap<ScanlineFormat::N8BitPal>( rDst, rSrc );
433 return ImplConvertFromBitmap<ScanlineFormat::N24BitTcBgr>( rDst, rSrc );
435 return ImplConvertFromBitmap<ScanlineFormat::N24BitTcRgb>( rDst, rSrc );
438 return ImplConvertFromBitmap<ScanlineFormat::N32BitTcAbgr>( rDst, rSrc );
440 return ImplConvertFromBitmap<ScanlineFormat::N32BitTcArgb>( rDst, rSrc );
442 return ImplConvertFromBitmap<ScanlineFormat::N32BitTcBgra>( rDst, rSrc );
444 return ImplConvertFromBitmap<ScanlineFormat::N32BitTcRgba>( rDst, rSrc );
448 static int nNotAccelerated = 0;
451 "ImplFastBitmapConversion for not accelerated case (" << std::hex <<
static_cast<int>(rSrc.
mnFormat) <<
"->" <<
static_cast<int>(rDst.
mnFormat) <<
")" );
469template <ScanlineFormat DSTFMT, ScanlineFormat SRCFMT>
472 TrueColorPixelPtr<DSTFMT> aDstType;
478template <ScanlineFormat SRCFMT>
481 TrueColorPixelPtr<SRCFMT> aSrcType;
482 aSrcType.SetRawPtr(
const_cast<Scanline>( aSrcScanline ));
487 return ImplCopyToScanline<ScanlineFormat::N24BitTcBgr>( nY, rDst, aSrcType, nSrcWidth );
489 return ImplCopyToScanline<ScanlineFormat::N24BitTcRgb>( nY, rDst, aSrcType, nSrcWidth );
492 return ImplCopyToScanline<ScanlineFormat::N32BitTcAbgr>( nY, rDst, aSrcType, nSrcWidth );
494 return ImplCopyToScanline<ScanlineFormat::N32BitTcArgb>( nY, rDst, aSrcType, nSrcWidth );
496 return ImplCopyToScanline<ScanlineFormat::N32BitTcBgra>( nY, rDst, aSrcType, nSrcWidth );
498 return ImplCopyToScanline<ScanlineFormat::N32BitTcRgba>( nY, rDst, aSrcType, nSrcWidth );
516 if( nSrcFormat == nDstFormat )
526 return ImplCopyFromScanline<ScanlineFormat::N24BitTcBgr>( nY, rDst, aSrcScanline, nSrcScanlineSize / 3 );
528 return ImplCopyFromScanline<ScanlineFormat::N24BitTcRgb>( nY, rDst, aSrcScanline, nSrcScanlineSize / 3 );
531 return ImplCopyFromScanline<ScanlineFormat::N32BitTcAbgr>( nY, rDst, aSrcScanline, nSrcScanlineSize / 4 );
533 return ImplCopyFromScanline<ScanlineFormat::N32BitTcArgb>( nY, rDst, aSrcScanline, nSrcScanlineSize / 4 );
535 return ImplCopyFromScanline<ScanlineFormat::N32BitTcBgra>( nY, rDst, aSrcScanline, nSrcScanlineSize / 4 );
537 return ImplCopyFromScanline<ScanlineFormat::N32BitTcRgba>( nY, rDst, aSrcScanline, nSrcScanlineSize / 4 );
553template <ScanlineFormat DSTFMT, ScanlineFormat SRCFMT>
559 "vcl.gdi",
"FastBmp BlendImage: unusual MSKFMT" );
565 TrueColorPixelPtr<ScanlineFormat::N8BitPal> aMskLine; aMskLine.SetRawPtr( rMskBuffer.
mpBits );
566 TrueColorPixelPtr<DSTFMT> aDstLine; aDstLine.SetRawPtr( rDstBuffer.
mpBits );
575 aMskLine.AddByteOffset( (rSrcBuffer.
mnHeight - 1) * nMskLinestep );
576 nMskLinestep = -nMskLinestep;
582 aDstLine.AddByteOffset( (rDstBuffer.
mnHeight - 1) * nDstLinestep );
583 nDstLinestep = -nDstLinestep;
586 assert(rDstBuffer.
mnHeight <= rSrcBuffer.
mnHeight &&
"not sure about that?");
590 aDstLine.AddByteOffset( nDstLinestep );
591 rSrcLine.AddByteOffset( nSrcLinestep );
592 aMskLine.AddByteOffset( nMskLinestep );
600bool ImplBlendToBitmap<ScanlineFormat::N24BitTcBgr,ScanlineFormat::N24BitTcBgr>(
601 TrueColorPixelPtr<ScanlineFormat::N24BitTcBgr>&,
605 TrueColorPixelPtr<ScanlineFormat::N24BitTcRgb> aSrcType; aSrcType.SetRawPtr( rSrcBuffer.
mpBits );
606 return ImplBlendToBitmap<ScanlineFormat::N24BitTcRgb>( aSrcType, rDstBuffer, rSrcBuffer, rMskBuffer );
610bool ImplBlendToBitmap<ScanlineFormat::N32BitTcAbgr,ScanlineFormat::N32BitTcAbgr>(
611 TrueColorPixelPtr<ScanlineFormat::N32BitTcAbgr>&,
615 TrueColorPixelPtr<ScanlineFormat::N32BitTcArgb> aSrcType; aSrcType.SetRawPtr( rSrcBuffer.
mpBits );
616 return ImplBlendToBitmap<ScanlineFormat::N32BitTcArgb>( aSrcType, rDstBuffer, rSrcBuffer, rMskBuffer );
620bool ImplBlendToBitmap<ScanlineFormat::N32BitTcBgra,ScanlineFormat::N32BitTcBgra>(
621 TrueColorPixelPtr<ScanlineFormat::N32BitTcBgra>&,
625 TrueColorPixelPtr<ScanlineFormat::N32BitTcRgba> aSrcType; aSrcType.SetRawPtr( rSrcBuffer.
mpBits );
626 return ImplBlendToBitmap<ScanlineFormat::N32BitTcRgba>( aSrcType, rDstBuffer, rSrcBuffer, rMskBuffer );
629template <ScanlineFormat SRCFMT>
632 TrueColorPixelPtr<SRCFMT> aSrcType; aSrcType.SetRawPtr( rSrc.
mpBits );
646 return ImplBlendToBitmap<ScanlineFormat::N24BitTcBgr>( aSrcType, rDst, rSrc, rMsk );
648 return ImplBlendToBitmap<ScanlineFormat::N24BitTcRgb>( aSrcType, rDst, rSrc, rMsk );
651 return ImplBlendToBitmap<ScanlineFormat::N32BitTcAbgr>( aSrcType, rDst, rSrc, rMsk );
653 return ImplBlendToBitmap<ScanlineFormat::N32BitTcArgb>( aSrcType, rDst, rSrc, rMsk );
655 return ImplBlendToBitmap<ScanlineFormat::N32BitTcBgra>( aSrcType, rDst, rSrc, rMsk );
657 return ImplBlendToBitmap<ScanlineFormat::N32BitTcRgba>( aSrcType, rDst, rSrc, rMsk );
661 static int nNotAccelerated = 0;
664 "ImplBlendFromBitmap for not accelerated case (" << std::hex <<
static_cast<int>(rSrc.
mnFormat) <<
"*" <<
static_cast<int>(rMsk.
mnFormat) <<
"->" <<
static_cast<int>(rDst.
mnFormat) );
709 if( rMskRA.
Height() != 1 )
736 return ImplBlendFromBitmap<ScanlineFormat::N8BitPal>( rDst, rSrc, rMsk );
740 return ImplBlendFromBitmap<ScanlineFormat::N24BitTcBgr>( rDst, rSrc, rMsk );
742 return ImplBlendFromBitmap<ScanlineFormat::N24BitTcRgb>( rDst, rSrc, rMsk );
745 return ImplBlendFromBitmap<ScanlineFormat::N32BitTcAbgr>( rDst, rSrc, rMsk );
747 return ImplBlendFromBitmap<ScanlineFormat::N32BitTcArgb>( rDst, rSrc, rMsk );
749 return ImplBlendFromBitmap<ScanlineFormat::N32BitTcBgra>( rDst, rSrc, rMsk );
751 return ImplBlendFromBitmap<ScanlineFormat::N32BitTcRgba>( rDst, rSrc, rMsk );
755 static int nNotAccelerated = 0;
758 "ImplFastBlend for not accelerated case (" << std::hex <<
static_cast<int>(rSrc.
mnFormat) <<
"*" <<
static_cast<int>(rMsk.
mnFormat) <<
"->" <<
static_cast<int>(rDst.
mnFormat) <<
")" );
768 bool bByteFill =
true;
775 nFillByte =
static_cast<sal_uInt8>( -(nFillByte & 1) );
783 nFillByte = rColor.
GetRed();
784 if( (nFillByte != rColor.
GetGreen())
785 || (nFillByte != rColor.
GetBlue()) )
798 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