diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2015-11-23 13:19:29 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2015-11-23 13:59:25 +0100 |
commit | a4fc2b364f47d3e8ada841381283dd49bfe9d5a0 (patch) | |
tree | d37fe0c706c88b91dfe9401e2933edcc21ab8d1c /vcl | |
parent | 49b0711dade7a926ba03309d376133be3f60bbf0 (diff) |
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
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vcl.mk | 2 | ||||
-rw-r--r-- | vcl/inc/image.h | 66 | ||||
-rw-r--r-- | vcl/source/image/Image.cxx | 129 | ||||
-rw-r--r-- | vcl/source/image/ImplImage.cxx | 15 | ||||
-rw-r--r-- | vcl/source/image/ImplImageBmp.cxx | 287 | ||||
-rw-r--r-- | vcl/source/image/ImplImageData.cxx | 48 | ||||
-rw-r--r-- | vcl/source/outdev/bitmap.cxx | 89 |
7 files changed, 91 insertions, 545 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index c2699a0c7636..e9db8fea26b7 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 9ddfadba9608..ba49ac084275 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 cc1f46714ce3..33a5018891ba 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 9272cf07b4e1..4b9fba12666d 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 cb83cc3ae4ea..000000000000 --- 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 6fc0747b2874..000000000000 --- 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 c48f653c8526..6225e79356d7 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); } } |