include/vcl/BitmapTools.hxx | 1 include/vcl/GraphicObject.hxx | 9 +++++ include/vcl/bitmap.hxx | 7 +++ include/vcl/dibtools.hxx | 4 ++ include/vcl/graph.hxx | 1 vcl/source/app/settings.cxx | 2 - vcl/source/bitmap/BitmapTools.cxx | 5 ++ vcl/source/bitmap/bitmap.cxx | 64 ++++++++++++++++++++++++++++++++++++ vcl/source/bitmap/dibtools.cxx | 8 ++++ vcl/source/filter/bmp/BmpWriter.cxx | 6 +-- vcl/source/gdi/TypeSerializer.cxx | 2 - vcl/source/gdi/graph.cxx | 5 ++ vcl/source/gdi/pdfextoutdevdata.cxx | 2 - vcl/source/gdi/pdfwriter_impl.cxx | 4 +- 14 files changed, 112 insertions(+), 8 deletions(-)
New commits: commit 4151265850bdbf94a7b1385fdaaffb037cfd4240 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Aug 13 14:04:45 2025 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Aug 13 16:44:15 2025 +0200 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.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx index f6b17e0f3ff8..b3eb65725b7d 100644 --- a/include/vcl/BitmapTools.hxx +++ b/include/vcl/BitmapTools.hxx @@ -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 diff --git a/include/vcl/GraphicObject.hxx b/include/vcl/GraphicObject.hxx index 309b86295dbc..40bc2221cb40 100644 --- a/include/vcl/GraphicObject.hxx +++ b/include/vcl/GraphicObject.hxx @@ -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(); diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx index e21c5bc519b4..87949802b326 100644 --- a/include/vcl/bitmap.hxx +++ b/include/vcl/bitmap.hxx @@ -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'), diff --git a/include/vcl/dibtools.hxx b/include/vcl/dibtools.hxx index e3d6b89ec29b..4e2b24f96370 100644 --- a/include/vcl/dibtools.hxx +++ b/include/vcl/dibtools.hxx @@ -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, diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx index 647336a1a3b9..626648b8b8b9 100644 --- a/include/vcl/graph.hxx +++ b/include/vcl/graph.hxx @@ -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; diff --git a/vcl/source/app/settings.cxx b/vcl/source/app/settings.cxx index 6add26b29d3d..b809187d3f3a 100644 --- a/vcl/source/app/settings.cxx +++ b/vcl/source/app/settings.cxx @@ -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) diff --git a/vcl/source/bitmap/BitmapTools.cxx b/vcl/source/bitmap/BitmapTools.cxx index ada2948ac570..cc09187b7c99 100644 --- a/vcl/source/bitmap/BitmapTools.cxx +++ b/vcl/source/bitmap/BitmapTools.cxx @@ -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; diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx index 635a738e5d4b..d51cfa93e69d 100644 --- a/vcl/source/bitmap/bitmap.cxx +++ b/vcl/source/bitmap/bitmap.cxx @@ -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: */ diff --git a/vcl/source/bitmap/dibtools.cxx b/vcl/source/bitmap/dibtools.cxx index 0eb415627299..d5e63c9138cf 100644 --- a/vcl/source/bitmap/dibtools.cxx +++ b/vcl/source/bitmap/dibtools.cxx @@ -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) diff --git a/vcl/source/filter/bmp/BmpWriter.cxx b/vcl/source/filter/bmp/BmpWriter.cxx index 7768259a5392..3d940d661ac7 100644 --- a/vcl/source/filter/bmp/BmpWriter.cxx +++ b/vcl/source/filter/bmp/BmpWriter.cxx @@ -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(); } diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx index 6c1ae34e9de2..9ceaa7debfd9 100644 --- a/vcl/source/gdi/TypeSerializer.cxx +++ b/vcl/source/gdi/TypeSerializer.cxx @@ -398,7 +398,7 @@ void TypeSerializer::writeGraphic(const Graphic& rGraphic) } else { - WriteDIBBitmapEx(aGraphic.GetBitmapEx(), mrStream); + WriteDIBBitmapEx(aGraphic.GetBitmap(), mrStream); } } break; diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx index dc83b8e81870..3575a7929c36 100644 --- a/vcl/source/gdi/graph.cxx +++ b/vcl/source/gdi/graph.cxx @@ -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(); diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx index 76560578f4ff..d385db8c9cae 100644 --- a/vcl/source/gdi/pdfextoutdevdata.cxx +++ b/vcl/source/gdi/pdfextoutdevdata.cxx @@ -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); } diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 2b491fb87e93..2eae76b667f2 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -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; }