AlphaMask::AlphaMask( const Bitmap& rBitmap ) :
maBitmap( rBitmap )
{ if ( !rBitmap.IsEmpty() )
maBitmap.Convert( BmpConversion::N8BitNoConversion ); #if HAVE_FEATURE_SKIA // Related tdf#156866 force snapshot of alpha mask when using Skia // In release builds, tdf#156629 and tdf#156630 reappear in many // cases because a BitmapInfoAccess is in a debug block. So, instead // of relying on other code to a create a BitmapInfoAccess instance, // create one here to force the alpha mask to handle any pending // scaling and make the alpha mask immutable. elseif ( SkiaHelper::isVCLSkiaEnabled() )
BitmapInfoAccess aInfoAccess( maBitmap ); #endif
assert( (IsEmpty() || maBitmap.getPixelFormat() == vcl::PixelFormat::N8_BPP) && "alpha bitmap should be 8bpp" );
assert( (IsEmpty() || maBitmap.HasGreyPalette8Bit()) && "alpha bitmap should have greyscale palette" );
}
void AlphaMask::BlendWith(const AlphaMask& rOther)
{
std::shared_ptr<SalBitmap> xImpBmp(ImplGetSVData()->mpDefInst->CreateSalBitmap()); if (xImpBmp->Create(*maBitmap.ImplGetSalBitmap()) && xImpBmp->AlphaBlendWith(*rOther.maBitmap.ImplGetSalBitmap()))
{
maBitmap.ImplSetSalBitmap(xImpBmp);
assert( maBitmap.getPixelFormat() == vcl::PixelFormat::N8_BPP && "alpha bitmap should be 8bpp" );
assert( maBitmap.HasGreyPalette8Bit() && "alpha bitmap should have greyscale palette" ); return;
}
BitmapScopedReadAccess pOtherAcc(rOther);
BitmapScopedWriteAccess pAcc(*this);
assert (pOtherAcc && pAcc && pOtherAcc->GetBitCount() == 8 && pAcc->GetBitCount() == 8 && "cannot BlendWith this combination"); if (!(pOtherAcc && pAcc && pOtherAcc->GetBitCount() == 8 && pAcc->GetBitCount() == 8))
{
SAL_WARN("vcl", "cannot BlendWith this combination"); return;
}
const tools::Long nHeight = std::min(pOtherAcc->Height(), pAcc->Height()); const tools::Long nWidth = std::min(pOtherAcc->Width(), pAcc->Width()); for (tools::Long y = 0; y < nHeight; ++y)
{
Scanline scanline = pAcc->GetScanline( y );
ConstScanline otherScanline = pOtherAcc->GetScanline( y ); for (tools::Long x = 0; x < nWidth; ++x)
{ // Use sal_uInt16 for following multiplication const sal_uInt16 nGrey1 = *scanline; const sal_uInt16 nGrey2 = *otherScanline; // Awkward calculation because the original used transparency, and to replicate // the logic we need to translate into transparency, perform the original logic, // then translate back to alpha. // The original looked like: // auto tmp = nGrey1 + nGrey2 - (nGrey1 * nGrey2 / 255) // which, when converted to using alpha looks like // auto tmp = 255 - ((255 - nGrey1) + (255 - nGrey2) - (255 - nGrey1) * (255 - nGrey2) / 255); // which then simplifies to: auto tmp = nGrey1 * nGrey2 / 255;
*scanline = static_cast<sal_uInt8>(tmp);
++scanline;
++otherScanline;
}
}
pAcc.reset();
assert( maBitmap.getPixelFormat() == vcl::PixelFormat::N8_BPP && "alpha bitmap should be 8bpp" );
assert( maBitmap.HasGreyPalette8Bit() && "alpha bitmap should have greyscale palette" );
}
bool AlphaMask::hasAlpha() const
{ // no content, no alpha if(IsEmpty()) returnfalse;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.