BitmapEx->Bitmap in Graphic

add a new method on Graphic to return a Bitmap and convert a small selection of callers.

Change-Id: I9c6596e6f5c781fe4e77702333792ae0e3a6fd58
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189510
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
This commit is contained in:
Noel Grandin
2025-08-13 16:44:15 +02:00
parent 7e3950902f
commit 4151265850
14 changed files with 112 additions and 8 deletions
+1
View File
@@ -73,6 +73,7 @@ VCL_DLLPUBLIC void DrawAlphaBitmapAndAlphaGradient(Bitmap & rBitmap, bool bFixed
VCL_DLLPUBLIC void DrawAndClipBitmap(const Point& rPos, const Size& rSize, const BitmapEx& rBitmap, BitmapEx & aBmpEx, basegfx::B2DPolyPolygon const & rClipPath);
VCL_DLLPUBLIC css::uno::Sequence< sal_Int8 > GetMaskDIB(BitmapEx const & aBmpEx);
VCL_DLLPUBLIC css::uno::Sequence< sal_Int8 > GetMaskDIB(Bitmap const & aBmp);
/**
* @param data will be filled with alpha data, if xBitmap is alpha/transparent image
+9
View File
@@ -155,6 +155,15 @@ private:
const Size& rDstSize,
bool bEnlarge
) const;
void SAL_DLLPRIVATE ImplTransformBitmap(
Bitmap& rBmp,
const GraphicAttr& rAttr,
const Size& rCropLeftTop,
const Size& rCropRightBottom,
const tools::Rectangle& rCropRect,
const Size& rDstSize,
bool bEnlarge
) const;
public:
GraphicObject();
+7
View File
@@ -572,6 +572,13 @@ public:
bool bInvert = false,
bool msoBrightness = false );
SAL_DLLPRIVATE void ChangeColorAlpha( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo );
/**
* Adds a constant value to the alpha layer
*/
SAL_DLLPRIVATE void AdjustTransparency( sal_uInt8 cTrans );
/** Remove existing blending against COL_WHITE based on given AlphaMask
Inside convertToBitmapEx the content gets rendered to RGB target (no 'A'),
+4
View File
@@ -85,6 +85,10 @@ bool VCL_DLLPUBLIC WriteDIB(
const BitmapEx& rSource,
SvStream& rOStm,
bool bCompressed = true);
bool VCL_DLLPUBLIC WriteDIB(
const Bitmap& rSource,
SvStream& rOStm,
bool bCompressed = true);
bool VCL_DLLPUBLIC WriteDIBBitmapEx(
const BitmapEx& rSource,
+1
View File
@@ -126,6 +126,7 @@ public:
// MetaFile when played. Defaults will use a no-AAed, not snapped conversion as
// before.
BitmapEx GetBitmapEx(const GraphicConversionParameters& rParameters = GraphicConversionParameters()) const;
Bitmap GetBitmap(const GraphicConversionParameters& rParameters = GraphicConversionParameters()) const;
/// Gives direct access to the contained BitmapEx.
const Bitmap& GetBitmapRef() const;
+1 -1
View File
@@ -1962,7 +1962,7 @@ static Bitmap readBitmap(const OUString& rPath)
Graphic aGraphic;
if (GraphicFilter::LoadGraphic(aPath, OUString(), aGraphic) != ERRCODE_NONE)
return Bitmap();
return Bitmap(aGraphic.GetBitmapEx());
return aGraphic.GetBitmap();
}
static void setupAppBackgroundBitmap(OUString& rAppBackBitmapFileName, Bitmap& rAppBackBitmap)
+5
View File
@@ -651,6 +651,11 @@ css::uno::Sequence< sal_Int8 > GetMaskDIB(BitmapEx const & aBmpEx)
return css::uno::Sequence< sal_Int8 >();
}
css::uno::Sequence< sal_Int8 > GetMaskDIB(Bitmap const & rBmp)
{
return GetMaskDIB(BitmapEx(rBmp));
}
static bool readAlpha( BitmapReadAccess const * pAlphaReadAcc, tools::Long nY, const tools::Long nWidth, unsigned char* data, tools::Long nOff )
{
bool bIsAlpha = false;
+64
View File
@@ -2128,4 +2128,68 @@ Bitmap Bitmap::CreateColorBitmap() const
return BitmapEx(*this).GetBitmap();
}
void Bitmap::ChangeColorAlpha( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo )
{
assert(HasAlpha());
if (!HasAlpha())
return;
BitmapScopedWriteAccess pAccess(*this);
assert( pAccess );
if ( !pAccess )
return;
for ( tools::Long nY = 0, nHeight = pAccess->Height(); nY < nHeight; nY++ )
{
Scanline pScanline = pAccess->GetScanline( nY );
for ( tools::Long nX = 0, nWidth = pAccess->Width(); nX < nWidth; nX++ )
{
BitmapColor aCol = pAccess->GetPixelFromData( pScanline, nX );
const sal_uInt8 cIndex = aCol.GetAlpha();
if ( cIndex == cIndexFrom )
{
aCol.SetAlpha(nAlphaTo);
pAccess->SetPixelOnData( pScanline, nX, aCol );
}
}
}
}
void Bitmap::AdjustTransparency(sal_uInt8 cTrans)
{
if (!HasAlpha())
{
AlphaMask aAlpha(GetSizePixel(), &cTrans);
BitmapEx aNew( *this, aAlpha );
*this = Bitmap(aNew);
}
else
{
BitmapScopedWriteAccess pA(*this);
assert(pA);
if( !pA )
return;
sal_uLong nTrans = cTrans;
const tools::Long nWidth = pA->Width(), nHeight = pA->Height();
BitmapColor aAlphaValue( 0 );
for( tools::Long nY = 0; nY < nHeight; nY++ )
{
Scanline pScanline = pA->GetScanline( nY );
for( tools::Long nX = 0; nX < nWidth; nX++ )
{
BitmapColor aCol = pA->GetPixelFromData( pScanline, nX );
sal_uLong nNewTrans = nTrans + (255 - aCol.GetAlpha());
// clamp to 255
nNewTrans = ( nNewTrans & 0xffffff00 ) ? 255 : nNewTrans;
// convert back to alpha
aCol.SetAlpha( static_cast<sal_uInt8>(255 - nNewTrans) );
pA->SetPixelOnData( pScanline, nX, aCol );
}
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+8
View File
@@ -1822,6 +1822,14 @@ bool WriteDIB(
return ImplWriteDIB(rSource.GetBitmap(), rOStm, bCompressed, /*bFileHeader*/true);
}
bool WriteDIB(
const Bitmap& rSource,
SvStream& rOStm,
bool bCompressed)
{
return ImplWriteDIB(rSource.CreateColorBitmap(), rOStm, bCompressed, /*bFileHeader*/true);
}
bool WriteDIBBitmapEx(
const BitmapEx& rSource,
SvStream& rOStm)
+3 -3
View File
@@ -22,17 +22,17 @@
bool BmpWriter(SvStream& rStream, const Graphic& rGraphic, FilterConfigItem* pFilterConfigItem)
{
BitmapEx aBitmap = rGraphic.GetBitmapEx();
Bitmap aBitmap = rGraphic.GetBitmap();
sal_Int32 nColor = pFilterConfigItem->ReadInt32(u"Color"_ustr, 0);
auto nColorRes = static_cast<BmpConversion>(nColor);
if (nColorRes != BmpConversion::NNONE && nColorRes <= BmpConversion::N24Bit)
{
if (!aBitmap.Convert(nColorRes))
aBitmap = rGraphic.GetBitmapEx();
aBitmap = rGraphic.GetBitmap();
}
bool bRleCoding = pFilterConfigItem->ReadBool(u"RLE_Coding"_ustr, true);
WriteDIB(aBitmap, rStream, bRleCoding);
WriteDIB(BitmapEx(aBitmap), rStream, bRleCoding);
return rStream.good();
}
+1 -1
View File
@@ -398,7 +398,7 @@ void TypeSerializer::writeGraphic(const Graphic& rGraphic)
}
else
{
WriteDIBBitmapEx(aGraphic.GetBitmapEx(), mrStream);
WriteDIBBitmapEx(aGraphic.GetBitmap(), mrStream);
}
}
break;
+5
View File
@@ -338,6 +338,11 @@ BitmapEx Graphic::GetBitmapEx(const GraphicConversionParameters& rParameters) co
return mxImpGraphic->getBitmapEx(rParameters);
}
Bitmap Graphic::GetBitmap(const GraphicConversionParameters& rParameters) const
{
return mxImpGraphic->getBitmap(rParameters);
}
Animation Graphic::GetAnimation() const
{
return mxImpGraphic->getAnimation();
+1 -1
View File
@@ -501,7 +501,7 @@ bool PageSyncData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAc
aOutputRect.SetSize(pA->GetSize());
}
}
auto ePixelFormat = aGraphic.GetBitmapEx().getPixelFormat();
auto ePixelFormat = aGraphic.GetBitmap().getPixelFormat();
rWriter.DrawJPGBitmap(aTmp, ePixelFormat > vcl::PixelFormat::N8_BPP, aGraphic.GetSizePixel(), aOutputRect, aAlphaMask, aGraphic);
}
+2 -2
View File
@@ -9936,12 +9936,12 @@ void PDFWriterImpl::drawJPGBitmap( SvStream& rDCTData, bool bIsTrueColor, const
GraphicConverter::Import( rDCTData, aGraphic, ConvertDataFormat::JPG );
if( !rAlphaMask.IsEmpty() && rAlphaMask.GetSizePixel() == aGraphic.GetSizePixel() )
{
Bitmap aBmp( aGraphic.GetBitmapEx().GetBitmap() );
Bitmap aBmp( aGraphic.GetBitmap().CreateColorBitmap() );
BitmapEx aBmpEx( aBmp, rAlphaMask );
drawBitmap( rTargetArea.TopLeft(), rTargetArea.GetSize(), Bitmap(aBmpEx) );
}
else
drawBitmap( rTargetArea.TopLeft(), rTargetArea.GetSize(), Bitmap(aGraphic.GetBitmapEx()) );
drawBitmap( rTargetArea.TopLeft(), rTargetArea.GetSize(), aGraphic.GetBitmap() );
return;
}