update emoji autocorrect entries from po-files
[LibreOffice.git] / vcl / source / gdi / alpha.cxx
blobad1b5cc744e1664dc88a3ebc0fd075b09fb4e056
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/debug.hxx>
21 #include <vcl/bmpacc.hxx>
22 #include <tools/color.hxx>
23 #include <vcl/alpha.hxx>
25 AlphaMask::AlphaMask()
29 AlphaMask::AlphaMask( const Bitmap& rBitmap ) :
30 Bitmap( rBitmap )
32 if( !!rBitmap )
33 Bitmap::Convert( BMP_CONVERSION_8BIT_GREYS );
36 AlphaMask::AlphaMask( const AlphaMask& rAlphaMask ) :
37 Bitmap( rAlphaMask )
41 AlphaMask::AlphaMask( const Size& rSizePixel, sal_uInt8* pEraseTransparency ) :
42 Bitmap( rSizePixel, 8, &Bitmap::GetGreyPalette( 256 ) )
44 if( pEraseTransparency )
45 Bitmap::Erase( Color( *pEraseTransparency, *pEraseTransparency, *pEraseTransparency ) );
48 AlphaMask::~AlphaMask()
52 AlphaMask& AlphaMask::operator=( const Bitmap& rBitmap )
54 *(Bitmap*) this = rBitmap;
56 if( !!rBitmap )
57 Bitmap::Convert( BMP_CONVERSION_8BIT_GREYS );
59 return *this;
62 const Bitmap& AlphaMask::ImplGetBitmap() const
64 return( (const Bitmap&) *this );
67 void AlphaMask::ImplSetBitmap( const Bitmap& rBitmap )
69 SAL_WARN_IF( 8 != rBitmap.GetBitCount(), "vcl.gdi", "Bitmap should be 8bpp, not " << rBitmap.GetBitCount() << "bpp" );
70 SAL_WARN_IF( !rBitmap.HasGreyPalette(), "vcl.gdi", "Bitmap isn't greyscale" );
71 *(Bitmap*) this = rBitmap;
74 Bitmap AlphaMask::GetBitmap() const
76 return ImplGetBitmap();
79 bool AlphaMask::Erase( sal_uInt8 cTransparency )
81 return Bitmap::Erase( Color( cTransparency, cTransparency, cTransparency ) );
84 bool AlphaMask::Replace( const Bitmap& rMask, sal_uInt8 cReplaceTransparency )
86 BitmapReadAccess* pMaskAcc = ( (Bitmap&) rMask ).AcquireReadAccess();
87 BitmapWriteAccess* pAcc = AcquireWriteAccess();
88 bool bRet = false;
90 if( pMaskAcc && pAcc )
92 const BitmapColor aReplace( cReplaceTransparency );
93 const long nWidth = std::min( pMaskAcc->Width(), pAcc->Width() );
94 const long nHeight = std::min( pMaskAcc->Height(), pAcc->Height() );
95 const BitmapColor aMaskWhite( pMaskAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
97 for( long nY = 0L; nY < nHeight; nY++ )
98 for( long nX = 0L; nX < nWidth; nX++ )
99 if( pMaskAcc->GetPixel( nY, nX ) == aMaskWhite )
100 pAcc->SetPixel( nY, nX, aReplace );
103 Bitmap::ReleaseAccess( pMaskAcc );
104 ReleaseAccess( pAcc );
106 return bRet;
109 bool AlphaMask::Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransparency, sal_uLong
110 #ifdef DBG_UTIL
111 nTol
112 #endif
115 BitmapWriteAccess* pAcc = AcquireWriteAccess();
116 bool bRet = false;
118 DBG_ASSERT( !nTol, "AlphaMask::Replace: nTol not used yet" );
120 if( pAcc && pAcc->GetBitCount() == 8 )
122 const long nWidth = pAcc->Width(), nHeight = pAcc->Height();
124 if( pAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL )
126 for( long nY = 0L; nY < nHeight; nY++ )
128 Scanline pScan = pAcc->GetScanline( nY );
130 for( long nX = 0L; nX < nWidth; nX++, pScan++ )
132 if( *pScan == cSearchTransparency )
133 *pScan = cReplaceTransparency;
137 else
139 BitmapColor aReplace( cReplaceTransparency );
141 for( long nY = 0L; nY < nHeight; nY++ )
143 for( long nX = 0L; nX < nWidth; nX++ )
145 if( pAcc->GetPixel( nY, nX ).GetIndex() == cSearchTransparency )
146 pAcc->SetPixel( nY, nX, aReplace );
151 bRet = true;
154 if( pAcc )
155 ReleaseAccess( pAcc );
157 return bRet;
160 void AlphaMask::ReleaseAccess( BitmapReadAccess* pAccess )
162 if( pAccess )
164 Bitmap::ReleaseAccess( pAccess );
165 Bitmap::Convert( BMP_CONVERSION_8BIT_GREYS );
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */