LCOV - code coverage report
Current view: top level - vcl/source/gdi - alpha.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 31 73 42.5 %
Date: 2014-11-03 Functions: 13 16 81.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <tools/debug.hxx>
      21             : #include <vcl/bmpacc.hxx>
      22             : #include <tools/color.hxx>
      23             : #include <vcl/alpha.hxx>
      24             : 
      25      311811 : AlphaMask::AlphaMask()
      26             : {
      27      311811 : }
      28             : 
      29       15751 : AlphaMask::AlphaMask( const Bitmap& rBitmap ) :
      30       15751 :     Bitmap( rBitmap )
      31             : {
      32       15751 :     if( !!rBitmap )
      33       15713 :         Bitmap::Convert( BMP_CONVERSION_8BIT_GREYS );
      34       15751 : }
      35             : 
      36      311799 : AlphaMask::AlphaMask( const AlphaMask& rAlphaMask ) :
      37      311799 :     Bitmap( rAlphaMask )
      38             : {
      39      311799 : }
      40             : 
      41       44606 : AlphaMask::AlphaMask( const Size& rSizePixel, sal_uInt8* pEraseTransparency ) :
      42       44606 :     Bitmap( rSizePixel, 8, &Bitmap::GetGreyPalette( 256 ) )
      43             : {
      44       44606 :     if( pEraseTransparency )
      45       11205 :         Bitmap::Erase( Color( *pEraseTransparency, *pEraseTransparency, *pEraseTransparency ) );
      46       44606 : }
      47             : 
      48      710881 : AlphaMask::~AlphaMask()
      49             : {
      50      710881 : }
      51             : 
      52           0 : AlphaMask& AlphaMask::operator=( const Bitmap& rBitmap )
      53             : {
      54           0 :     *(Bitmap*) this = rBitmap;
      55             : 
      56           0 :     if( !!rBitmap )
      57           0 :         Bitmap::Convert( BMP_CONVERSION_8BIT_GREYS );
      58             : 
      59           0 :     return *this;
      60             : }
      61             : 
      62       76221 : const Bitmap& AlphaMask::ImplGetBitmap() const
      63             : {
      64       76221 :     return( (const Bitmap&) *this );
      65             : }
      66             : 
      67      311811 : void AlphaMask::ImplSetBitmap( const Bitmap& rBitmap )
      68             : {
      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      311811 :     *(Bitmap*) this = rBitmap;
      72      311811 : }
      73             : 
      74        7804 : Bitmap AlphaMask::GetBitmap() const
      75             : {
      76        7804 :     return ImplGetBitmap();
      77             : }
      78             : 
      79       18984 : bool AlphaMask::Erase( sal_uInt8 cTransparency )
      80             : {
      81       18984 :     return Bitmap::Erase( Color( cTransparency, cTransparency, cTransparency ) );
      82             : }
      83             : 
      84           0 : bool AlphaMask::Replace( const Bitmap& rMask, sal_uInt8 cReplaceTransparency )
      85             : {
      86           0 :     BitmapReadAccess*   pMaskAcc = ( (Bitmap&) rMask ).AcquireReadAccess();
      87           0 :     BitmapWriteAccess*  pAcc = AcquireWriteAccess();
      88           0 :     bool                bRet = false;
      89             : 
      90           0 :     if( pMaskAcc && pAcc )
      91             :     {
      92           0 :         const BitmapColor   aReplace( cReplaceTransparency );
      93           0 :         const long          nWidth = std::min( pMaskAcc->Width(), pAcc->Width() );
      94           0 :         const long          nHeight = std::min( pMaskAcc->Height(), pAcc->Height() );
      95           0 :         const BitmapColor   aMaskWhite( pMaskAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
      96             : 
      97           0 :         for( long nY = 0L; nY < nHeight; nY++ )
      98           0 :             for( long nX = 0L; nX < nWidth; nX++ )
      99           0 :                 if( pMaskAcc->GetPixel( nY, nX ) == aMaskWhite )
     100           0 :                     pAcc->SetPixel( nY, nX, aReplace );
     101             :     }
     102             : 
     103           0 :     ( (Bitmap&) rMask ).ReleaseAccess( pMaskAcc );
     104           0 :     ReleaseAccess( pAcc );
     105             : 
     106           0 :     return bRet;
     107             : }
     108             : 
     109           0 : bool AlphaMask::Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransparency, sal_uLong
     110             : #ifdef DBG_UTIL
     111             : nTol
     112             : #endif
     113             : )
     114             : {
     115           0 :     BitmapWriteAccess*  pAcc = AcquireWriteAccess();
     116           0 :     bool                bRet = false;
     117             : 
     118             :     DBG_ASSERT( !nTol, "AlphaMask::Replace: nTol not used yet" );
     119             : 
     120           0 :     if( pAcc && pAcc->GetBitCount() == 8 )
     121             :     {
     122           0 :         const long nWidth = pAcc->Width(), nHeight = pAcc->Height();
     123             : 
     124           0 :         if( pAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL )
     125             :         {
     126           0 :             for( long nY = 0L; nY < nHeight; nY++ )
     127             :             {
     128           0 :                 Scanline pScan = pAcc->GetScanline( nY );
     129             : 
     130           0 :                 for( long nX = 0L; nX < nWidth; nX++, pScan++ )
     131             :                 {
     132           0 :                     if( *pScan == cSearchTransparency )
     133           0 :                         *pScan = cReplaceTransparency;
     134             :                 }
     135             :             }
     136             :         }
     137             :         else
     138             :         {
     139           0 :             BitmapColor aReplace( cReplaceTransparency );
     140             : 
     141           0 :             for( long nY = 0L; nY < nHeight; nY++ )
     142             :             {
     143           0 :                 for( long nX = 0L; nX < nWidth; nX++ )
     144             :                 {
     145           0 :                     if( pAcc->GetPixel( nY, nX ).GetIndex() == cSearchTransparency )
     146           0 :                         pAcc->SetPixel( nY, nX, aReplace );
     147             :                 }
     148           0 :             }
     149             :         }
     150             : 
     151           0 :         bRet = true;
     152             :     }
     153             : 
     154           0 :     if( pAcc )
     155           0 :         ReleaseAccess( pAcc );
     156             : 
     157           0 :     return bRet;
     158             : }
     159             : 
     160      251321 : void AlphaMask::ReleaseAccess( BitmapReadAccess* pAccess )
     161             : {
     162      251321 :     if( pAccess )
     163             :     {
     164      251321 :         Bitmap::ReleaseAccess( pAccess );
     165      251321 :         Bitmap::Convert( BMP_CONVERSION_8BIT_GREYS );
     166             :     }
     167      252554 : }
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10