[Libreoffice-commits] core.git: 5 commits - include/vcl vcl/inc vcl/Library_vcl.mk vcl/source

Tomaž Vajngerl tomaz.vajngerl at collabora.com
Mon Nov 23 04:59:59 PST 2015


 include/vcl/BitmapProcessor.hxx       |    2 
 include/vcl/image.hxx                 |    9 -
 vcl/Library_vcl.mk                    |    2 
 vcl/inc/image.h                       |   77 +--------
 vcl/source/bitmap/BitmapProcessor.cxx |  141 ++++++++++++++++
 vcl/source/image/Image.cxx            |  129 ++++++++-------
 vcl/source/image/ImageList.cxx        |    3 
 vcl/source/image/ImplImage.cxx        |   15 -
 vcl/source/image/ImplImageBmp.cxx     |  287 ----------------------------------
 vcl/source/image/ImplImageData.cxx    |   48 -----
 vcl/source/outdev/bitmap.cxx          |   89 ----------
 11 files changed, 241 insertions(+), 561 deletions(-)

New commits:
commit a4fc2b364f47d3e8ada841381283dd49bfe9d5a0
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Nov 23 13:19:29 2015 +0100

    vcl: simplify Image internals
    
    Image could be of 2 types - BITMAP or IMAGE, where BITMAP used to
    store the content in a Bitmap and IMAGE in a ImplImageData, which
    contained a BitmapEx. This was refactored with this commit to
    always store the content in a BitmapEx and there are no distinct
    image types anymore. This greatly simplfies the code.
    
    Drawing of the image in case of type IMAGE was done in the class
    ImplImageBmp which also modified the image according to
    DrawImageFlags (for example to create a "disabled" image). This
    was moved to ImplImage and the bitmap manipulation code was moved
    to BitmapProcessor (done in previous commits).
    
    Change-Id: Iec9f63a7c05618c457d8465f1ec60ed4f16bd579

diff --git a/include/vcl/image.hxx b/include/vcl/image.hxx
index 696e7cd..e5c045f 100644
--- a/include/vcl/image.hxx
+++ b/include/vcl/image.hxx
@@ -25,6 +25,8 @@
 #include <tools/resid.hxx>
 #include <tools/solar.h>
 #include <vcl/bitmapex.hxx>
+#include <vcl/outdev.hxx>
+
 #include <com/sun/star/uno/Reference.hxx>
 
 #include <vector>
@@ -71,6 +73,8 @@ public:
     bool            operator==( const Image& rImage ) const;
     bool            operator!=( const Image& rImage ) const { return !(Image::operator==( rImage )); }
 
+    void Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle, const Size* pSize = nullptr);
+
 private:
 
     ImplImage*             mpImplData;
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index c2699a0..e9db8fe 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -330,8 +330,6 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/image/ImageList \
     vcl/source/image/ImageRepository \
     vcl/source/image/ImplImage \
-    vcl/source/image/ImplImageBmp \
-    vcl/source/image/ImplImageData \
     vcl/source/image/ImplImageList \
     vcl/source/image/ImplImageTree \
     vcl/source/helper/canvasbitmap \
diff --git a/vcl/inc/image.h b/vcl/inc/image.h
index 9ddfadb..ba49ac0 100644
--- a/vcl/inc/image.h
+++ b/vcl/inc/image.h
@@ -24,41 +24,6 @@
 
 #include <unordered_map>
 
-// - ImplImageBmp -
-
-class ImplImageBmp
-{
-public:
-
-                ImplImageBmp();
-                ~ImplImageBmp();
-
-    void        Create( const BitmapEx& rBmpEx, long nItemWidth, long nItemHeight,sal_uInt16 nInitSize );
-    void        Draw( OutputDevice* pDev, const Point& rPos, DrawImageFlags nStyle, const Size* pSize = NULL );
-
-private:
-
-    BitmapEx    maBmpEx;
-    BitmapChecksum maBitmapChecksum;
-
-    BitmapEx    maDisabledBmpEx;
-    BitmapEx*   mpDisplayBmp;
-    Size        maSize;
-    sal_uInt8*      mpInfoAry;
-    sal_uInt16      mnSize;
-
-    void        ImplUpdateDisplayBmp( OutputDevice* pOutDev );
-    void        ImplUpdateDisabledBmpEx();
-
-private:
-    ImplImageBmp( const ImplImageBmp& ) = delete;
-    void operator=( const ImplImageBmp& ) = delete;
-};
-
-// - ImageTypes -
-
-enum ImageType { IMAGETYPE_BITMAP, IMAGETYPE_IMAGE };
-
 // - ImplImageList -
 
 struct ImageAryData
@@ -100,34 +65,23 @@ struct ImplImageList
     void RemoveImage( sal_uInt16 nPos );
 };
 
-// - ImpImageData -
-
-struct ImplImageData
-{
-    ImplImageBmp*   mpImageBitmap;
-    BitmapEx        maBmpEx;
-
-                    ImplImageData( const BitmapEx& rBmpEx );
-                    ~ImplImageData();
-
-    bool            IsEqual( const ImplImageData& rData );
-};
-
 // - ImplImage -
 
 struct ImplImage
 {
-    sal_uIntPtr         mnRefCount;
-    // TODO: use inheritance to get rid of meType+mpData
-    void*           mpData;
-    ImageType       meType;
+    sal_uIntPtr mnRefCount;
+
+    BitmapChecksum maBitmapChecksum;
+
+    std::unique_ptr<BitmapEx> mpBitmapEx;
+    BitmapEx maDisabledBitmapEx;
 
-                    ImplImage();
-                    ~ImplImage();
+    ImplImage();
+    ~ImplImage();
 
 private:
-            ImplImage( const ImplImage&) = delete;
-    void    operator=( const ImplImage&) = delete;
+    ImplImage(const ImplImage&) = delete;
+    void operator=(const ImplImage&) = delete;
 };
 
 #endif // INCLUDED_VCL_INC_IMAGE_H
diff --git a/vcl/source/image/Image.cxx b/vcl/source/image/Image.cxx
index cc1f467..33a5018 100644
--- a/vcl/source/image/Image.cxx
+++ b/vcl/source/image/Image.cxx
@@ -33,6 +33,8 @@
 #include <vcl/implimagetree.hxx>
 #include <image.h>
 
+#include <vcl/BitmapProcessor.hxx>
+
 #if OSL_DEBUG_LEVEL > 0
 #include <rtl/strbuf.hxx>
 #endif
@@ -153,47 +155,26 @@ Image::Image( const OUString &rFileUrl ) :
 
 Image::~Image()
 {
-
     if( mpImplData && ( 0 == --mpImplData->mnRefCount ) )
         delete mpImplData;
 }
 
-void Image::ImplInit( const BitmapEx& rBmpEx )
+void Image::ImplInit(const BitmapEx& rBitmapEx)
 {
-    if( !rBmpEx.IsEmpty() )
+    if (!rBitmapEx.IsEmpty())
     {
         mpImplData = new ImplImage;
-
-        if( rBmpEx.GetTransparentType() == TRANSPARENT_NONE )
-        {
-            mpImplData->meType = IMAGETYPE_BITMAP;
-            mpImplData->mpData = new Bitmap( rBmpEx.GetBitmap() );
-        }
-        else
-        {
-            mpImplData->meType = IMAGETYPE_IMAGE;
-            mpImplData->mpData = new ImplImageData( rBmpEx );
-        }
+        mpImplData->mpBitmapEx.reset(new BitmapEx(rBitmapEx));
     }
 }
 
 Size Image::GetSizePixel() const
 {
-
     Size aRet;
 
-    if( mpImplData )
+    if (mpImplData && mpImplData->mpBitmapEx)
     {
-        switch( mpImplData->meType )
-        {
-            case IMAGETYPE_BITMAP:
-                aRet = static_cast< Bitmap* >( mpImplData->mpData )->GetSizePixel();
-            break;
-
-            case IMAGETYPE_IMAGE:
-                aRet = static_cast< ImplImageData* >( mpImplData->mpData )->maBmpEx.GetSizePixel();
-            break;
-        }
+        aRet = mpImplData->mpBitmapEx->GetSizePixel();
     }
 
     return aRet;
@@ -201,21 +182,11 @@ Size Image::GetSizePixel() const
 
 BitmapEx Image::GetBitmapEx() const
 {
-
     BitmapEx aRet;
 
-    if( mpImplData )
+    if (mpImplData && mpImplData->mpBitmapEx)
     {
-        switch( mpImplData->meType )
-        {
-            case IMAGETYPE_BITMAP:
-                aRet = *static_cast< Bitmap* >( mpImplData->mpData );
-            break;
-
-            case IMAGETYPE_IMAGE:
-                aRet = static_cast< ImplImageData* >( mpImplData->mpData )->maBmpEx;
-            break;
-        }
+        aRet = BitmapEx(*mpImplData->mpBitmapEx);
     }
 
     return aRet;
@@ -242,36 +213,80 @@ Image& Image::operator=( const Image& rImage )
     return *this;
 }
 
-bool Image::operator==( const Image& rImage ) const
+bool Image::operator==(const Image& rImage) const
 {
-
     bool bRet = false;
 
-    if( rImage.mpImplData == mpImplData )
+    if (rImage.mpImplData == mpImplData)
         bRet = true;
-    else if( !rImage.mpImplData || !mpImplData )
+    else if (!rImage.mpImplData || !mpImplData)
         bRet = false;
-    else if( rImage.mpImplData->mpData == mpImplData->mpData )
-        bRet = true;
-    else if( rImage.mpImplData->meType == mpImplData->meType )
+    else if (rImage.mpImplData->mpBitmapEx == mpImplData->mpBitmapEx)
+        bRet = (rImage.mpImplData->mpBitmapEx == mpImplData->mpBitmapEx);
+
+    return bRet;
+}
+
+void Image::Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle, const Size* pSize)
+{
+    if (mpImplData == nullptr || !mpImplData->mpBitmapEx || !pOutDev->IsDeviceOutputNecessary())
+        return;
+
+    const Point aSrcPos(0, 0);
+    Size aBitmapSizePixel = mpImplData->mpBitmapEx->GetSizePixel();
+
+    Size aOutSize = pSize ? *pSize : pOutDev->PixelToLogic(aBitmapSizePixel);
+
+    if (nStyle & DrawImageFlags::Disable)
+    {
+        BitmapChecksum aChecksum = mpImplData->mpBitmapEx->GetChecksum();
+        if (mpImplData->maBitmapChecksum != aChecksum)
+        {
+            mpImplData->maBitmapChecksum = aChecksum;
+            mpImplData->maDisabledBitmapEx = BitmapProcessor::createDisabledImage(*mpImplData->mpBitmapEx);
+        }
+        pOutDev->DrawBitmapEx(rPos, aOutSize, aSrcPos, aBitmapSizePixel, mpImplData->maDisabledBitmapEx);
+    }
+    else
     {
-        switch( mpImplData->meType )
+        if (nStyle & (DrawImageFlags::ColorTransform | DrawImageFlags::Highlight |
+                      DrawImageFlags::Deactive | DrawImageFlags::SemiTransparent))
         {
-            case IMAGETYPE_BITMAP:
-                bRet = ( *static_cast< Bitmap* >( rImage.mpImplData->mpData ) == *static_cast< Bitmap* >( mpImplData->mpData ) );
-            break;
+            BitmapEx aTempBitmapEx(*mpImplData->mpBitmapEx);
 
-            case IMAGETYPE_IMAGE:
-                bRet = static_cast< ImplImageData* >( rImage.mpImplData->mpData )->IsEqual( *static_cast< ImplImageData* >( mpImplData->mpData ) );
-            break;
+            if (nStyle & (DrawImageFlags::Highlight | DrawImageFlags::Deactive))
+            {
+                const StyleSettings& rSettings = pOutDev->GetSettings().GetStyleSettings();
+                Color aColor;
+                if (nStyle & DrawImageFlags::Highlight)
+                    aColor = rSettings.GetHighlightColor();
+                else
+                    aColor = rSettings.GetDeactiveColor();
+
+                BitmapProcessor::colorizeImage(aTempBitmapEx, aColor);
+            }
 
-            default:
-                bRet = false;
-            break;
+            if (nStyle & DrawImageFlags::SemiTransparent)
+            {
+                if (aTempBitmapEx.IsTransparent())
+                {
+                    Bitmap aAlphaBmp(aTempBitmapEx.GetAlpha().GetBitmap());
+                    aAlphaBmp.Adjust(50);
+                    aTempBitmapEx = BitmapEx(aTempBitmapEx.GetBitmap(), AlphaMask(aAlphaBmp));
+                }
+                else
+                {
+                    sal_uInt8 cErase = 128;
+                    aTempBitmapEx = BitmapEx(aTempBitmapEx.GetBitmap(), AlphaMask(aTempBitmapEx.GetSizePixel(), &cErase));
+                }
+            }
+            pOutDev->DrawBitmapEx(rPos, aOutSize, aSrcPos, aTempBitmapEx.GetSizePixel(), aTempBitmapEx);
+        }
+        else
+        {
+            pOutDev->DrawBitmapEx(rPos, aOutSize, aSrcPos, mpImplData->mpBitmapEx->GetSizePixel(), *mpImplData->mpBitmapEx);
         }
     }
-
-    return bRet;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/image/ImplImage.cxx b/vcl/source/image/ImplImage.cxx
index 9272cf0..4b9fba1 100644
--- a/vcl/source/image/ImplImage.cxx
+++ b/vcl/source/image/ImplImage.cxx
@@ -31,23 +31,14 @@
 
 ImplImage::ImplImage()
     : mnRefCount(1)
-    , mpData(nullptr)
-    , meType(IMAGETYPE_BITMAP)
+    , maBitmapChecksum(0)
+    , mpBitmapEx()
+    , maDisabledBitmapEx()
 {
 }
 
 ImplImage::~ImplImage()
 {
-    switch( meType )
-    {
-        case IMAGETYPE_BITMAP:
-            delete static_cast< Bitmap* >( mpData );
-        break;
-
-        case IMAGETYPE_IMAGE:
-            delete static_cast< ImplImageData* >( mpData );
-        break;
-    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/image/ImplImageBmp.cxx b/vcl/source/image/ImplImageBmp.cxx
deleted file mode 100644
index cb83cc3..0000000
--- a/vcl/source/image/ImplImageBmp.cxx
+++ /dev/null
@@ -1,287 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <vcl/outdev.hxx>
-#include <vcl/bitmapex.hxx>
-#include <vcl/alpha.hxx>
-#include <vcl/window.hxx>
-#include <vcl/bmpacc.hxx>
-#include <vcl/virdev.hxx>
-#include <vcl/image.hxx>
-#include <vcl/settings.hxx>
-
-#include <image.h>
-#include <memory>
-
-#define IMPSYSIMAGEITEM_MASK        ( 0x01 )
-#define IMPSYSIMAGEITEM_ALPHA       ( 0x02 )
-
-ImplImageBmp::ImplImageBmp()
-    : maBitmapChecksum(0)
-    , mpDisplayBmp(nullptr)
-    , mpInfoAry(nullptr)
-    , mnSize(0)
-{
-}
-
-ImplImageBmp::~ImplImageBmp()
-{
-    delete[] mpInfoAry;
-    delete mpDisplayBmp;
-}
-
-void ImplImageBmp::Create( const BitmapEx& rBmpEx, long nItemWidth, long nItemHeight, sal_uInt16 nInitSize )
-{
-    maBmpEx = rBmpEx;
-    maDisabledBmpEx.SetEmpty();
-
-    delete mpDisplayBmp;
-    mpDisplayBmp = nullptr;
-
-    maSize = Size( nItemWidth, nItemHeight );
-    mnSize = nInitSize;
-
-    delete[] mpInfoAry;
-    mpInfoAry = new sal_uInt8[ mnSize ];
-    memset( mpInfoAry,
-            rBmpEx.IsAlpha() ? IMPSYSIMAGEITEM_ALPHA : ( rBmpEx.IsTransparent() ? IMPSYSIMAGEITEM_MASK : 0 ),
-            mnSize );
-}
-
-void ImplImageBmp::Draw( OutputDevice* pOutDev,
-                         const Point& rPos, DrawImageFlags nStyle,
-                         const Size* pSize )
-{
-    if( pOutDev->IsDeviceOutputNecessary() )
-    {
-        const Point aSrcPos(0, 0);
-        Size        aOutSize;
-
-        aOutSize = ( pSize ? *pSize : pOutDev->PixelToLogic( maSize ) );
-
-        if( nStyle & DrawImageFlags::Disable )
-        {
-            BitmapChecksum aChecksum = maBmpEx.GetChecksum();
-            if (maBitmapChecksum != aChecksum)
-            {
-                maBitmapChecksum = aChecksum;
-                ImplUpdateDisabledBmpEx();
-            }
-            pOutDev->DrawBitmapEx( rPos, aOutSize, aSrcPos, maSize, maDisabledBmpEx );
-        }
-        else
-        {
-            if( nStyle & ( DrawImageFlags::ColorTransform |
-                           DrawImageFlags::Highlight | DrawImageFlags::Deactive | DrawImageFlags::SemiTransparent ) )
-            {
-                BitmapEx        aTmpBmpEx;
-                const Rectangle aCropRect( aSrcPos, maSize );
-
-                if( mpInfoAry[0] & ( IMPSYSIMAGEITEM_MASK | IMPSYSIMAGEITEM_ALPHA ) )
-                    aTmpBmpEx = maBmpEx;
-                else
-                    aTmpBmpEx = maBmpEx.GetBitmap();
-
-                aTmpBmpEx.Crop( aCropRect );
-
-                Bitmap aTmpBmp( aTmpBmpEx.GetBitmap() );
-
-                if( nStyle & ( DrawImageFlags::Highlight | DrawImageFlags::Deactive ) )
-                {
-                    BitmapWriteAccess* pAcc = aTmpBmp.AcquireWriteAccess();
-
-                    if( pAcc )
-                    {
-                        const StyleSettings&    rSettings = pOutDev->GetSettings().GetStyleSettings();
-                        Color                   aColor;
-                        BitmapColor             aCol;
-                        const long              nW = pAcc->Width();
-                        const long              nH = pAcc->Height();
-                        std::unique_ptr<sal_uInt8[]> pMapR(new sal_uInt8[ 256 ]);
-                        std::unique_ptr<sal_uInt8[]> pMapG(new sal_uInt8[ 256 ]);
-                        std::unique_ptr<sal_uInt8[]> pMapB(new sal_uInt8[ 256 ]);
-                        long                    nX, nY;
-
-                        if( nStyle & DrawImageFlags::Highlight )
-                            aColor = rSettings.GetHighlightColor();
-                        else
-                            aColor = rSettings.GetDeactiveColor();
-
-                        const sal_uInt8 cR = aColor.GetRed();
-                        const sal_uInt8 cG = aColor.GetGreen();
-                        const sal_uInt8 cB = aColor.GetBlue();
-
-                        for( nX = 0L; nX < 256L; nX++ )
-                        {
-                            pMapR[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cR ) >> 1 ) > 255 ) ? 255 : nY );
-                            pMapG[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cG ) >> 1 ) > 255 ) ? 255 : nY );
-                            pMapB[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cB ) >> 1 ) > 255 ) ? 255 : nY );
-                        }
-
-                        if( pAcc->HasPalette() )
-                        {
-                            for( sal_uInt16 i = 0, nCount = pAcc->GetPaletteEntryCount(); i < nCount; i++ )
-                            {
-                                const BitmapColor& rCol = pAcc->GetPaletteColor( i );
-                                aCol.SetRed( pMapR[ rCol.GetRed() ] );
-                                aCol.SetGreen( pMapG[ rCol.GetGreen() ] );
-                                aCol.SetBlue( pMapB[ rCol.GetBlue() ] );
-                                pAcc->SetPaletteColor( i, aCol );
-                            }
-                        }
-                        else if( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_BGR )
-                        {
-                            for( nY = 0L; nY < nH; nY++ )
-                            {
-                                Scanline pScan = pAcc->GetScanline( nY );
-
-                                for( nX = 0L; nX < nW; nX++ )
-                                {
-                                    *pScan = pMapB[ *pScan ]; pScan++;
-                                    *pScan = pMapG[ *pScan ]; pScan++;
-                                    *pScan = pMapR[ *pScan ]; pScan++;
-                                }
-                            }
-                        }
-                        else
-                        {
-                            for( nY = 0L; nY < nH; nY++ )
-                            {
-                                for( nX = 0L; nX < nW; nX++ )
-                                {
-                                    aCol = pAcc->GetPixel( nY, nX );
-                                    aCol.SetRed( pMapR[ aCol.GetRed() ] );
-                                    aCol.SetGreen( pMapG[ aCol.GetGreen() ] );
-                                    aCol.SetBlue( pMapB[ aCol.GetBlue() ] );
-                                    pAcc->SetPixel( nY, nX, aCol );
-                                }
-                            }
-                        }
-
-                        Bitmap::ReleaseAccess( pAcc );
-                    }
-                }
-
-                if( nStyle & DrawImageFlags::SemiTransparent )
-                {
-                    if( aTmpBmpEx.IsTransparent()  )
-                    {
-                        Bitmap aAlphaBmp( aTmpBmpEx.GetAlpha().GetBitmap() );
-
-                        aAlphaBmp.Adjust( 50 );
-                        aTmpBmpEx = BitmapEx( aTmpBmp, AlphaMask( aAlphaBmp ) );
-                    }
-                    else
-                    {
-                        sal_uInt8 cErase = 128;
-                        aTmpBmpEx = BitmapEx( aTmpBmp, AlphaMask( aTmpBmp.GetSizePixel(),  &cErase ) );
-                    }
-                }
-                else
-                {
-                    if( aTmpBmpEx.IsAlpha() )
-                        aTmpBmpEx = BitmapEx( aTmpBmp, aTmpBmpEx.GetAlpha() );
-                    else if( aTmpBmpEx.IsTransparent() )
-                        aTmpBmpEx = BitmapEx( aTmpBmp, aTmpBmpEx.GetMask() );
-                }
-
-                pOutDev->DrawBitmapEx( rPos, aOutSize, aTmpBmpEx );
-            }
-            else
-            {
-                const BitmapEx* pOutputBmp;
-
-                if( pOutDev->GetOutDevType() == OUTDEV_WINDOW )
-                {
-                    ImplUpdateDisplayBmp( pOutDev );
-                    pOutputBmp = mpDisplayBmp;
-                }
-                else
-                    pOutputBmp = &maBmpEx;
-
-                if( pOutputBmp )
-                    pOutDev->DrawBitmapEx( rPos, aOutSize, aSrcPos, maSize, *pOutputBmp );
-            }
-        }
-    }
-}
-
-void ImplImageBmp::ImplUpdateDisplayBmp(OutputDevice*)
-{
-    if (!mpDisplayBmp && !maBmpEx.IsEmpty())
-    {
-        mpDisplayBmp = new BitmapEx(maBmpEx);
-    }
-}
-
-void ImplImageBmp::ImplUpdateDisabledBmpEx()
-{
-    const Size aTotalSize( maBmpEx.GetSizePixel() );
-
-    if( maDisabledBmpEx.IsEmpty() )
-    {
-        Bitmap      aGrey( aTotalSize, 8, &Bitmap::GetGreyPalette( 256 ) );
-        AlphaMask   aGreyAlphaMask( aTotalSize );
-
-        maDisabledBmpEx = BitmapEx( aGrey, aGreyAlphaMask );
-    }
-
-    Bitmap              aBmp( maBmpEx.GetBitmap() );
-    BitmapReadAccess*   pBmp( aBmp.AcquireReadAccess() );
-    AlphaMask           aBmpAlphaMask( maBmpEx.GetAlpha() );
-    BitmapReadAccess*   pBmpAlphaMask( aBmpAlphaMask.AcquireReadAccess() );
-    Bitmap              aGrey( maDisabledBmpEx.GetBitmap() );
-    BitmapWriteAccess*  pGrey( aGrey.AcquireWriteAccess() );
-    AlphaMask           aGreyAlphaMask( maDisabledBmpEx.GetAlpha() );
-    BitmapWriteAccess*  pGreyAlphaMask( aGreyAlphaMask.AcquireWriteAccess() );
-
-    if( pBmp && pBmpAlphaMask && pGrey && pGreyAlphaMask )
-    {
-        BitmapColor aGreyVal( 0 );
-        BitmapColor aGreyAlphaMaskVal( 0 );
-
-        const int nLeft = 0;
-        const int nRight = nLeft + maSize.Width();
-        const int nTop = 0;
-        const int nBottom = nTop + maSize.Height();
-
-        for( int nY = nTop; nY < nBottom; ++nY )
-        {
-            for( int nX = nLeft; nX < nRight; ++nX )
-            {
-                aGreyVal.SetIndex( pBmp->GetLuminance( nY, nX ) );
-                pGrey->SetPixel( nY, nX, aGreyVal );
-
-                const BitmapColor aBmpAlphaMaskVal( pBmpAlphaMask->GetPixel( nY, nX ) );
-
-                aGreyAlphaMaskVal.SetIndex( static_cast< sal_uInt8 >( ::std::min( aBmpAlphaMaskVal.GetIndex() + 178ul, 255ul ) ) );
-                pGreyAlphaMask->SetPixel( nY, nX, aGreyAlphaMaskVal );
-            }
-        }
-    }
-
-    Bitmap::ReleaseAccess( pBmp );
-    aBmpAlphaMask.ReleaseAccess( pBmpAlphaMask );
-    Bitmap::ReleaseAccess( pGrey );
-    aGreyAlphaMask.ReleaseAccess( pGreyAlphaMask );
-
-    maDisabledBmpEx = BitmapEx( aGrey, aGreyAlphaMask );
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/image/ImplImageData.cxx b/vcl/source/image/ImplImageData.cxx
deleted file mode 100644
index 6fc0747..0000000
--- a/vcl/source/image/ImplImageData.cxx
+++ /dev/null
@@ -1,48 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <vcl/outdev.hxx>
-#include <vcl/bitmapex.hxx>
-#include <vcl/alpha.hxx>
-#include <vcl/window.hxx>
-#include <vcl/bmpacc.hxx>
-#include <vcl/virdev.hxx>
-#include <vcl/image.hxx>
-#include <vcl/settings.hxx>
-
-#include <image.h>
-#include <memory>
-
-ImplImageData::ImplImageData( const BitmapEx& rBmpEx ) :
-    mpImageBitmap( nullptr ),
-    maBmpEx( rBmpEx )
-{
-}
-
-ImplImageData::~ImplImageData()
-{
-    delete mpImageBitmap;
-}
-
-bool ImplImageData::IsEqual( const ImplImageData& rData )
-{
-    return( maBmpEx == rData.maBmpEx );
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index c48f653..6225e79 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -1297,44 +1297,6 @@ void OutputDevice::DrawTransformedBitmapEx(
     }
 }
 
-namespace
-{
-    BitmapEx makeDisabledBitmap(const Bitmap &rBitmap)
-    {
-        const Size aTotalSize( rBitmap.GetSizePixel() );
-        Bitmap aGrey( aTotalSize, 8, &Bitmap::GetGreyPalette( 256 ) );
-        AlphaMask aGreyAlphaMask( aTotalSize );
-        BitmapReadAccess*  pBmp = const_cast<Bitmap&>(rBitmap).AcquireReadAccess();
-        BitmapWriteAccess* pGrey = aGrey.AcquireWriteAccess();
-        BitmapWriteAccess* pGreyAlphaMask = aGreyAlphaMask.AcquireWriteAccess();
-
-        if( pBmp && pGrey && pGreyAlphaMask )
-        {
-            BitmapColor aGreyVal( 0 );
-            BitmapColor aGreyAlphaMaskVal( 0 );
-            const int nLeft = 0, nRight = aTotalSize.Width();
-            const int nTop = 0, nBottom = nTop + aTotalSize.Height();
-
-            for( int nY = nTop; nY < nBottom; ++nY )
-            {
-                for( int nX = nLeft; nX < nRight; ++nX )
-                {
-                    aGreyVal.SetIndex( pBmp->GetLuminance( nY, nX ) );
-                    pGrey->SetPixel( nY, nX, aGreyVal );
-
-                    aGreyAlphaMaskVal.SetIndex( static_cast< sal_uInt8 >( 128ul ) );
-                    pGreyAlphaMask->SetPixel( nY, nX, aGreyAlphaMaskVal );
-                }
-            }
-        }
-
-        Bitmap::ReleaseAccess( pBmp );
-        Bitmap::ReleaseAccess( pGrey );
-        Bitmap::ReleaseAccess( pGreyAlphaMask );
-        return BitmapEx( aGrey, aGreyAlphaMask );
-    }
-}
-
 void OutputDevice::DrawImage( const Point& rPos, const Image& rImage, DrawImageFlags nStyle )
 {
     assert(!is_double_buffered_window());
@@ -1349,52 +1311,13 @@ void OutputDevice::DrawImage( const Point& rPos, const Size& rSize,
 
     bool bIsSizeValid = rSize.getWidth() != 0 && rSize.getHeight() != 0;
 
-    if( rImage.mpImplData && !ImplIsRecordLayout() )
+    if (!ImplIsRecordLayout())
     {
-        switch( rImage.mpImplData->meType )
-        {
-            case IMAGETYPE_BITMAP:
-            {
-                const Bitmap &rBitmap = *static_cast< Bitmap* >( rImage.mpImplData->mpData );
-                if( nStyle & DrawImageFlags::Disable )
-                {
-                    if ( bIsSizeValid )
-                        DrawBitmapEx( rPos, rSize, makeDisabledBitmap(rBitmap) );
-                    else
-                        DrawBitmapEx( rPos, makeDisabledBitmap(rBitmap) );
-                }
-                else
-                {
-                    if ( bIsSizeValid )
-                        DrawBitmap( rPos, rSize, rBitmap );
-                    else
-                        DrawBitmap( rPos, rBitmap );
-                }
-            }
-            break;
-
-            case IMAGETYPE_IMAGE:
-            {
-                ImplImageData* pData = static_cast< ImplImageData* >( rImage.mpImplData->mpData );
-
-                if ( !pData->mpImageBitmap )
-                {
-                    const Size aSize( pData->maBmpEx.GetSizePixel() );
-
-                    pData->mpImageBitmap = new ImplImageBmp;
-                    pData->mpImageBitmap->Create( pData->maBmpEx, aSize.Width(), aSize.Height(), 1 );
-                }
-
-                if ( bIsSizeValid )
-                    pData->mpImageBitmap->Draw( this, rPos, nStyle, &rSize );
-                else
-                    pData->mpImageBitmap->Draw( this, rPos, nStyle );
-            }
-            break;
-
-            default:
-            break;
-        }
+        Image& rNonConstImage = const_cast<Image&>(rImage);
+        if (bIsSizeValid)
+            rNonConstImage.Draw(this, rPos, nStyle, &rSize);
+        else
+            rNonConstImage.Draw(this, rPos, nStyle);
     }
 }
 
commit 49b0711dade7a926ba03309d376133be3f60bbf0
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Nov 23 13:16:26 2015 +0100

    vcl: add colorizeImage to BitmapProcessor
    
    Change-Id: Ic90368e83d7f9a187eb8404d8aaec4380ff5bcb1

diff --git a/include/vcl/BitmapProcessor.hxx b/include/vcl/BitmapProcessor.hxx
index 3d7397f..0f0f138 100644
--- a/include/vcl/BitmapProcessor.hxx
+++ b/include/vcl/BitmapProcessor.hxx
@@ -17,6 +17,7 @@ class BitmapProcessor
 public:
     static BitmapEx createLightImage(const BitmapEx& rBitmapEx);
     static BitmapEx createDisabledImage(const BitmapEx& rBitmapEx);
+    static void colorizeImage(BitmapEx& rBitmapEx, Color aColor);
 };
 
 #endif // INCLUDED_VCL_BITMAP_PROCESSOR_HXX
diff --git a/vcl/source/bitmap/BitmapProcessor.cxx b/vcl/source/bitmap/BitmapProcessor.cxx
index 5ac4680..20f8121 100644
--- a/vcl/source/bitmap/BitmapProcessor.cxx
+++ b/vcl/source/bitmap/BitmapProcessor.cxx
@@ -127,4 +127,73 @@ BitmapEx BitmapProcessor::createDisabledImage(const BitmapEx& rBitmapEx)
     return aReturnBitmap;
 }
 
+void BitmapProcessor::colorizeImage(BitmapEx& rBitmapEx, Color aColor)
+{
+    Bitmap aBitmap = rBitmapEx.GetBitmap();
+    Bitmap::ScopedWriteAccess pWriteAccess(aBitmap);
+
+    if (pWriteAccess)
+    {
+        BitmapColor aBitmapColor;
+        const long nW = pWriteAccess->Width();
+        const long nH = pWriteAccess->Height();
+        std::vector<sal_uInt8> pMapR(256);
+        std::vector<sal_uInt8> pMapG(256);
+        std::vector<sal_uInt8> pMapB(256);
+        long nX;
+        long nY;
+
+        const sal_uInt8 cR = aColor.GetRed();
+        const sal_uInt8 cG = aColor.GetGreen();
+        const sal_uInt8 cB = aColor.GetBlue();
+
+        for (nX = 0; nX < 256; ++nX)
+        {
+            pMapR[nX] = MinMax((nX + cR) / 2, 0, 255);
+            pMapG[nX] = MinMax((nX + cG) / 2, 0, 255);
+            pMapB[nX] = MinMax((nX + cB) / 2, 0, 255);
+        }
+
+        if (pWriteAccess->HasPalette())
+        {
+            for (sal_uInt16 i = 0, nCount = pWriteAccess->GetPaletteEntryCount(); i < nCount; i++)
+            {
+                const BitmapColor& rCol = pWriteAccess->GetPaletteColor(i);
+                aBitmapColor.SetRed(pMapR[rCol.GetRed()]);
+                aBitmapColor.SetGreen(pMapG[rCol.GetGreen()]);
+                aBitmapColor.SetBlue(pMapB[rCol.GetBlue()]);
+                pWriteAccess->SetPaletteColor(i, aBitmapColor);
+            }
+        }
+        else if (pWriteAccess->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_BGR)
+        {
+            for (nY = 0; nY < nH; ++nY)
+            {
+                Scanline pScan = pWriteAccess->GetScanline(nY);
+
+                for (nX = 0; nX < nW; ++nX)
+                {
+                    *pScan = pMapB[*pScan]; pScan++;
+                    *pScan = pMapG[*pScan]; pScan++;
+                    *pScan = pMapR[*pScan]; pScan++;
+                }
+            }
+        }
+        else
+        {
+            for (nY = 0; nY < nH; ++nY)
+            {
+                for (nX = 0; nX < nW; ++nX)
+                {
+                    aBitmapColor = pWriteAccess->GetPixel(nY, nX);
+                    aBitmapColor.SetRed(pMapR[aBitmapColor.GetRed()]);
+                    aBitmapColor.SetGreen(pMapG[aBitmapColor.GetGreen()]);
+                    aBitmapColor.SetBlue(pMapB[aBitmapColor.GetBlue()]);
+                    pWriteAccess->SetPixel(nY, nX, aBitmapColor);
+                }
+            }
+        }
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 15f66df8602b0920266ff2be86873246da4fda31
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Sun Nov 22 17:55:39 2015 +0100

    vcl: Bitmap processor to create a disabled image
    
    Change-Id: Iba5d86988736fa28329e1ba2783dfb15e37815a8

diff --git a/include/vcl/BitmapProcessor.hxx b/include/vcl/BitmapProcessor.hxx
index 73f0001..3d7397f 100644
--- a/include/vcl/BitmapProcessor.hxx
+++ b/include/vcl/BitmapProcessor.hxx
@@ -16,6 +16,7 @@ class BitmapProcessor
 {
 public:
     static BitmapEx createLightImage(const BitmapEx& rBitmapEx);
+    static BitmapEx createDisabledImage(const BitmapEx& rBitmapEx);
 };
 
 #endif // INCLUDED_VCL_BITMAP_PROCESSOR_HXX
diff --git a/vcl/source/bitmap/BitmapProcessor.cxx b/vcl/source/bitmap/BitmapProcessor.cxx
index a82e350..5ac4680 100644
--- a/vcl/source/bitmap/BitmapProcessor.cxx
+++ b/vcl/source/bitmap/BitmapProcessor.cxx
@@ -55,4 +55,76 @@ BitmapEx BitmapProcessor::createLightImage(const BitmapEx& rBitmapEx)
     return BitmapEx(aDarkBitmap, rBitmapEx.GetAlpha());
 }
 
+BitmapEx BitmapProcessor::createDisabledImage(const BitmapEx& rBitmapEx)
+{
+    const Size aSize(rBitmapEx.GetSizePixel());
+
+    Bitmap aGrey(aSize, 8, &Bitmap::GetGreyPalette(256));
+    AlphaMask aGreyAlpha(aSize);
+
+    Bitmap aBitmap(rBitmapEx.GetBitmap());
+    BitmapReadAccess* pRead(aBitmap.AcquireReadAccess());
+
+    BitmapWriteAccess* pGrey(aGrey.AcquireWriteAccess());
+    BitmapWriteAccess* pGreyAlpha(aGreyAlpha.AcquireWriteAccess());
+
+    BitmapEx aReturnBitmap;
+
+    if (rBitmapEx.IsTransparent())
+    {
+        AlphaMask aBitmapAlpha(rBitmapEx.GetAlpha());
+        BitmapReadAccess* pReadAlpha(aBitmapAlpha.AcquireReadAccess());
+
+        if (pRead && pReadAlpha && pGrey && pGreyAlpha)
+        {
+            BitmapColor aGreyValue(0);
+            BitmapColor aGreyAlphaValue(0);
+
+            for (int nY = 0; nY < aSize.Height(); ++nY)
+            {
+                for (int nX = 0; nX < aSize.Width(); ++nX)
+                {
+                    aGreyValue.SetIndex(pRead->GetLuminance(nY, nX));
+                    pGrey->SetPixel(nY, nX, aGreyValue);
+
+                    const BitmapColor aBitmapAlphaValue(pReadAlpha->GetPixel(nY, nX));
+
+                    aGreyAlphaValue.SetIndex(sal_uInt8(std::min(aBitmapAlphaValue.GetIndex() + 178ul, 255ul)));
+                    pGreyAlpha->SetPixel(nY, nX, aGreyAlphaValue);
+                }
+            }
+        }
+        aBitmapAlpha.ReleaseAccess(pReadAlpha);
+        aReturnBitmap = BitmapEx(aGrey, aGreyAlpha);
+    }
+    else
+    {
+        if (pRead && pGrey && pGreyAlpha)
+        {
+            BitmapColor aGreyValue(0);
+            BitmapColor aGreyAlphaValue(0);
+
+            for (int nY = 0; nY < aSize.Height(); ++nY)
+            {
+                for (int nX = 0; nX < aSize.Width(); ++nX)
+                {
+                    aGreyValue.SetIndex(pRead->GetLuminance(nY, nX));
+                    pGrey->SetPixel(nY, nX, aGreyValue);
+
+                    aGreyAlphaValue.SetIndex(128);
+                    pGreyAlpha->SetPixel(nY, nX, aGreyAlphaValue);
+                }
+            }
+        }
+        aReturnBitmap = BitmapEx(aGrey);
+    }
+
+    Bitmap::ReleaseAccess(pRead);
+
+    Bitmap::ReleaseAccess(pGrey);
+    aGreyAlpha.ReleaseAccess(pGreyAlpha);
+
+    return aReturnBitmap;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit f1592d3821a2ab69d2ddd27095696a39082bc24d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Sun Nov 22 16:44:06 2015 +0100

    ImplImageRefData is not used anywhere anymore
    
    Change-Id: I578cc029815aaf7c2a36ad127d90cf833b5646c4

diff --git a/vcl/inc/image.h b/vcl/inc/image.h
index 1315db1..9ddfadb 100644
--- a/vcl/inc/image.h
+++ b/vcl/inc/image.h
@@ -100,17 +100,6 @@ struct ImplImageList
     void RemoveImage( sal_uInt16 nPos );
 };
 
-// - ImplImageRefData -
-
-struct ImplImageRefData
-{
-    ImplImageList*  mpImplData;
-    sal_uInt16          mnIndex;
-
-                    ImplImageRefData() {}    // Um Warning zu umgehen
-                    ~ImplImageRefData();
-};
-
 // - ImpImageData -
 
 struct ImplImageData
commit d95a715dd84564502c85503a0e8ccd28b6799798
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Sat Nov 21 23:48:04 2015 +0100

    remove unused constructor parameter
    
    Change-Id: Ia2d1a8d7d43ceac36b6bce87f5a733d6bce3bd6f

diff --git a/include/vcl/image.hxx b/include/vcl/image.hxx
index 35b30c0..696e7cd 100644
--- a/include/vcl/image.hxx
+++ b/include/vcl/image.hxx
@@ -83,9 +83,8 @@ class VCL_DLLPUBLIC ImageList
 public:
                     explicit ImageList( sal_uInt16 nInit = 8, sal_uInt16 nGrow = 4 );
                     explicit ImageList( const ResId& rResId );
-                    ImageList( const ::std::vector< OUString >& rNameVector,
-                               const OUString& rPrefix,
-                               const Color* pMaskColor = nullptr );
+                    ImageList( const std::vector<OUString>& rNameVector,
+                               const OUString& rPrefix);
                     ImageList( const ImageList& rImageList );
                     ~ImageList();
 
diff --git a/vcl/source/image/ImageList.cxx b/vcl/source/image/ImageList.cxx
index 6c2dff9..80806ec 100644
--- a/vcl/source/image/ImageList.cxx
+++ b/vcl/source/image/ImageList.cxx
@@ -93,8 +93,7 @@ ImageList::ImageList( const ResId& rResId ) :
 }
 
 ImageList::ImageList( const ::std::vector< OUString >& rNameVector,
-                      const OUString& rPrefix,
-                      const Color* ) :
+                      const OUString& rPrefix) :
     mpImplData( nullptr ),
     mnInitSize( 1 ),
     mnGrowSize( 4 )


More information about the Libreoffice-commits mailing list