LCOV - code coverage report
Current view: top level - libreoffice/vcl/headless - svpbmp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 110 161 68.3 %
Date: 2012-12-27 Functions: 10 13 76.9 %
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 "headless/svpbmp.hxx"
      21             : 
      22             : #include <basegfx/vector/b2ivector.hxx>
      23             : #include <basegfx/range/b2ibox.hxx>
      24             : #include <basebmp/scanlineformats.hxx>
      25             : #include <basebmp/color.hxx>
      26             : 
      27             : #include <vcl/salbtype.hxx>
      28             : #include <vcl/bitmap.hxx>
      29             : 
      30             : using namespace basebmp;
      31             : using namespace basegfx;
      32             : 
      33         636 : SvpSalBitmap::~SvpSalBitmap()
      34             : {
      35         636 : }
      36             : 
      37         193 : bool SvpSalBitmap::Create( const Size& rSize,
      38             :                            sal_uInt16 nBitCount,
      39             :                            const BitmapPalette& rPalette )
      40             : {
      41         193 :     sal_uInt32 nFormat = SVP_DEFAULT_BITMAP_FORMAT;
      42         193 :     switch( nBitCount )
      43             :     {
      44          64 :         case 1: nFormat = Format::ONE_BIT_MSB_PAL; break;
      45           2 :         case 4: nFormat = Format::FOUR_BIT_MSB_PAL; break;
      46          90 :         case 8: nFormat = Format::EIGHT_BIT_PAL; break;
      47             : #ifdef OSL_BIGENDIAN
      48             :         case 16: nFormat = Format::SIXTEEN_BIT_MSB_TC_MASK; break;
      49             : #else
      50           0 :         case 16: nFormat = Format::SIXTEEN_BIT_LSB_TC_MASK; break;
      51             : #endif
      52          37 :         case 24: nFormat = Format::TWENTYFOUR_BIT_TC_MASK; break;
      53             : #if defined(ANDROID) || defined(IOS)
      54             :         case 32: nFormat = Format::THIRTYTWO_BIT_TC_MASK_RGBA; break;
      55             : #else
      56           0 :         case 32: nFormat = Format::THIRTYTWO_BIT_TC_MASK; break;
      57             : #endif
      58             :     }
      59         193 :     B2IVector aSize( rSize.Width(), rSize.Height() );
      60         193 :     if( aSize.getX() == 0 )
      61           0 :         aSize.setX( 1 );
      62         193 :     if( aSize.getY() == 0 )
      63           0 :         aSize.setY( 1 );
      64         193 :     if( nBitCount > 8 )
      65          37 :         m_aBitmap = createBitmapDevice( aSize, false, nFormat );
      66             :     else
      67             :     {
      68             :         // prepare palette
      69         156 :         unsigned int nEntries = 1U << nBitCount;
      70             :         std::vector<basebmp::Color>* pPalette =
      71         156 :             new std::vector<basebmp::Color>( nEntries, basebmp::Color(COL_WHITE) );
      72         156 :         unsigned int nColors = rPalette.GetEntryCount();
      73       22828 :         for( unsigned int i = 0; i < nColors; i++ )
      74             :         {
      75       22672 :             const BitmapColor& rCol = rPalette[i];
      76       22672 :             (*pPalette)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
      77             :         }
      78             :         m_aBitmap = createBitmapDevice( aSize, false, nFormat,
      79             :                                         basebmp::RawMemorySharedArray(),
      80             :                                         basebmp::PaletteMemorySharedVector( pPalette )
      81         156 :                                         );
      82             :     }
      83         193 :     return true;
      84             : }
      85             : 
      86           3 : bool SvpSalBitmap::Create( const SalBitmap& rSalBmp )
      87             : {
      88           3 :     const SvpSalBitmap& rSrc = static_cast<const SvpSalBitmap&>(rSalBmp);
      89           3 :     const BitmapDeviceSharedPtr& rSrcBmp = rSrc.getBitmap();
      90           3 :     if( rSrcBmp.get() )
      91             :     {
      92           3 :         B2IVector aSize = rSrcBmp->getSize();
      93           3 :         m_aBitmap = cloneBitmapDevice( aSize, rSrcBmp );
      94           3 :         B2IBox aRect( 0, 0, aSize.getX(), aSize.getY() );
      95           3 :         m_aBitmap->drawBitmap( rSrcBmp, aRect, aRect, DrawMode_PAINT );
      96             :     }
      97             :     else
      98           0 :         m_aBitmap.reset();
      99             : 
     100           3 :     return true;
     101             : }
     102             : 
     103           6 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
     104             :                            SalGraphics* /*pGraphics*/ )
     105             : {
     106           6 :     return false;
     107             : }
     108             : 
     109           3 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
     110             :                            sal_uInt16 /*nNewBitCount*/ )
     111             : {
     112           3 :     return false;
     113             : }
     114             : 
     115           0 : bool SvpSalBitmap::Create( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > /*xBitmapCanvas*/, Size& /*rSize*/, bool /*bMask*/ )
     116             : {
     117           0 :     return false;
     118             : }
     119             : 
     120           0 : void SvpSalBitmap::Destroy()
     121             : {
     122           0 :     m_aBitmap.reset();
     123           0 : }
     124             : 
     125         423 : Size SvpSalBitmap::GetSize() const
     126             : {
     127         423 :     Size aSize;
     128         423 :     if( m_aBitmap.get() )
     129             :     {
     130         423 :         B2IVector aVec( m_aBitmap->getSize() );
     131         423 :         aSize = Size( aVec.getX(), aVec.getY() );
     132             :     }
     133             : 
     134         423 :     return aSize;
     135             : }
     136             : 
     137         311 : sal_uInt16 SvpSalBitmap::GetBitCount() const
     138             : {
     139         311 :     sal_uInt16 nDepth = 0;
     140         311 :     if( m_aBitmap.get() )
     141         308 :         nDepth = getBitCountFromScanlineFormat( m_aBitmap->getScanlineFormat() );
     142         311 :     return nDepth;
     143             : }
     144             : 
     145         392 : BitmapBuffer* SvpSalBitmap::AcquireBuffer( bool )
     146             : {
     147         392 :     BitmapBuffer* pBuf = NULL;
     148         392 :     if( m_aBitmap.get() )
     149             :     {
     150         389 :         pBuf = new BitmapBuffer();
     151         389 :         sal_uInt16 nBitCount = 1;
     152         389 :         switch( m_aBitmap->getScanlineFormat() )
     153             :         {
     154             :             case Format::ONE_BIT_MSB_GREY:
     155             :             case Format::ONE_BIT_MSB_PAL:
     156         112 :                 nBitCount = 1;
     157         112 :                 pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
     158         112 :                 break;
     159             :             case Format::ONE_BIT_LSB_GREY:
     160             :             case Format::ONE_BIT_LSB_PAL:
     161           0 :                 nBitCount = 1;
     162           0 :                 pBuf->mnFormat = BMP_FORMAT_1BIT_LSB_PAL;
     163           0 :                 break;
     164             :             case Format::FOUR_BIT_MSB_GREY:
     165             :             case Format::FOUR_BIT_MSB_PAL:
     166           4 :                 nBitCount = 4;
     167           4 :                 pBuf->mnFormat = BMP_FORMAT_4BIT_MSN_PAL;
     168           4 :                 break;
     169             :             case Format::FOUR_BIT_LSB_GREY:
     170             :             case Format::FOUR_BIT_LSB_PAL:
     171           0 :                 nBitCount = 4;
     172           0 :                 pBuf->mnFormat = BMP_FORMAT_4BIT_LSN_PAL;
     173           0 :                 break;
     174             :             case Format::EIGHT_BIT_PAL:
     175         182 :                 nBitCount = 8;
     176         182 :                 pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
     177         182 :                 break;
     178             :             case Format::EIGHT_BIT_GREY:
     179           0 :                 nBitCount = 8;
     180           0 :                 pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
     181           0 :                 break;
     182             :             case Format::SIXTEEN_BIT_LSB_TC_MASK:
     183           0 :                 nBitCount = 16;
     184           0 :                 pBuf->mnFormat = BMP_FORMAT_16BIT_TC_LSB_MASK;
     185           0 :                 pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
     186           0 :                 break;
     187             :             case Format::SIXTEEN_BIT_MSB_TC_MASK:
     188           0 :                 nBitCount = 16;
     189           0 :                 pBuf->mnFormat = BMP_FORMAT_16BIT_TC_MSB_MASK;
     190           0 :                 pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
     191           0 :                 break;
     192             :             case Format::TWENTYFOUR_BIT_TC_MASK:
     193          91 :                 nBitCount = 24;
     194          91 :                 pBuf->mnFormat = BMP_FORMAT_24BIT_TC_BGR;
     195          91 :                 break;
     196             :             case Format::THIRTYTWO_BIT_TC_MASK_BGRA:
     197           0 :                 nBitCount = 32;
     198           0 :                 pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
     199             : #ifdef OSL_BIGENDIAN
     200             :                 pBuf->maColorMask = ColorMask( 0x0000ff00, 0x00ff0000, 0xff000000 );
     201             : #else
     202           0 :                 pBuf->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff );
     203             : #endif
     204           0 :                 break;
     205             :             case Format::THIRTYTWO_BIT_TC_MASK_ARGB:
     206           0 :                 nBitCount = 32;
     207           0 :                 pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
     208             : #ifdef OSL_BIGENDIAN
     209             :                 pBuf->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff );
     210             : #else
     211           0 :                 pBuf->maColorMask = ColorMask( 0x0000ff00, 0x00ff0000, 0xff000000 );
     212             : #endif
     213           0 :                 break;
     214             :             case Format::THIRTYTWO_BIT_TC_MASK_ABGR:
     215           0 :                 nBitCount = 32;
     216           0 :                 pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
     217             : #ifdef OSL_BIGENDIAN
     218             :                 pBuf->maColorMask = ColorMask( 0x000000ff, 0x0000ff00, 0x00ff0000 );
     219             : #else
     220           0 :                 pBuf->maColorMask = ColorMask( 0xff000000, 0x00ff0000, 0x0000ff00 );
     221             : #endif
     222           0 :                 break;
     223             :             case Format::THIRTYTWO_BIT_TC_MASK_RGBA:
     224           0 :                 nBitCount = 32;
     225           0 :                 pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
     226             : #ifdef OSL_BIGENDIAN
     227             :                 pBuf->maColorMask = ColorMask( 0xff000000, 0x00ff0000, 0x0000ff00 );
     228             : #else
     229           0 :                 pBuf->maColorMask = ColorMask( 0x000000ff, 0x0000ff00, 0x00ff0000 );
     230             : #endif
     231           0 :                 break;
     232             : 
     233             :             default:
     234             :                 // this is an error case !!!!!
     235           0 :                 nBitCount = 1;
     236           0 :                 pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
     237           0 :                 break;
     238             :         }
     239         389 :         if( m_aBitmap->isTopDown() )
     240           0 :             pBuf->mnFormat |= BMP_FORMAT_TOP_DOWN;
     241             : 
     242         389 :         B2IVector aSize = m_aBitmap->getSize();
     243         389 :         pBuf->mnWidth           = aSize.getX();
     244         389 :         pBuf->mnHeight          = aSize.getY();
     245         389 :         pBuf->mnScanlineSize    = m_aBitmap->getScanlineStride();
     246         389 :         pBuf->mnBitCount        = nBitCount;
     247         389 :         pBuf->mpBits            = (sal_uInt8*)m_aBitmap->getBuffer().get();
     248         389 :         if( nBitCount <= 8 )
     249             :         {
     250        1490 :             if( m_aBitmap->getScanlineFormat() == Format::EIGHT_BIT_GREY ||
     251         298 :                 m_aBitmap->getScanlineFormat() == Format::FOUR_BIT_LSB_GREY ||
     252         298 :                 m_aBitmap->getScanlineFormat() == Format::FOUR_BIT_MSB_GREY ||
     253         298 :                 m_aBitmap->getScanlineFormat() == Format::ONE_BIT_LSB_GREY ||
     254         298 :                 m_aBitmap->getScanlineFormat() == Format::ONE_BIT_MSB_GREY
     255             :                 )
     256           0 :                 pBuf->maPalette = Bitmap::GetGreyPalette( 1U << nBitCount );
     257             :             else
     258             :             {
     259         298 :                 basebmp::PaletteMemorySharedVector aPalette = m_aBitmap->getPalette();
     260         298 :                 if( aPalette.get() )
     261             :                 {
     262         298 :                     unsigned int nColors = aPalette->size();
     263         298 :                     if( nColors > 0 )
     264             :                     {
     265         298 :                         pBuf->maPalette.SetEntryCount( nColors );
     266       47178 :                         for( unsigned int i = 0; i < nColors; i++ )
     267             :                         {
     268       46880 :                             const basebmp::Color& rCol = (*aPalette)[i];
     269       46880 :                             pBuf->maPalette[i] = BitmapColor( rCol.getRed(), rCol.getGreen(), rCol.getBlue() );
     270             :                         }
     271             :                     }
     272         298 :                 }
     273             :             }
     274         389 :         }
     275             :     }
     276             : 
     277         392 :     return pBuf;
     278             : }
     279             : 
     280         389 : void SvpSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, bool bReadOnly )
     281             : {
     282         389 :     if( !bReadOnly && pBuffer->maPalette.GetEntryCount() )
     283             :     {
     284             :         // palette might have changed, clone device (but recycle
     285             :         // memory)
     286         221 :         sal_uInt16 nBitCount = 0;
     287         221 :         switch( m_aBitmap->getScanlineFormat() )
     288             :         {
     289             :             case Format::ONE_BIT_MSB_GREY:
     290             :                 // FALLTHROUGH intended
     291             :             case Format::ONE_BIT_MSB_PAL:
     292             :                 // FALLTHROUGH intended
     293             :             case Format::ONE_BIT_LSB_GREY:
     294             :                 // FALLTHROUGH intended
     295             :             case Format::ONE_BIT_LSB_PAL:
     296          70 :                 nBitCount = 1;
     297          70 :                 break;
     298             : 
     299             :             case Format::FOUR_BIT_MSB_GREY:
     300             :                 // FALLTHROUGH intended
     301             :             case Format::FOUR_BIT_MSB_PAL:
     302             :                 // FALLTHROUGH intended
     303             :             case Format::FOUR_BIT_LSB_GREY:
     304             :                 // FALLTHROUGH intended
     305             :             case Format::FOUR_BIT_LSB_PAL:
     306           2 :                 nBitCount = 4;
     307           2 :                 break;
     308             : 
     309             :             case Format::EIGHT_BIT_PAL:
     310             :                 // FALLTHROUGH intended
     311             :             case Format::EIGHT_BIT_GREY:
     312         149 :                 nBitCount = 8;
     313         149 :                 break;
     314             : 
     315             :             default:
     316           0 :                 break;
     317             :         }
     318             : 
     319         221 :         if( nBitCount )
     320             :         {
     321         221 :             sal_uInt32 nEntries = 1U << nBitCount;
     322             : 
     323             :             boost::shared_ptr< std::vector<basebmp::Color> > pPal(
     324             :                 new std::vector<basebmp::Color>( nEntries,
     325         221 :                                                  basebmp::Color(COL_WHITE)));
     326             :             const sal_uInt32 nColors = std::min(
     327         221 :                 (sal_uInt32)pBuffer->maPalette.GetEntryCount(),
     328         221 :                 nEntries);
     329       37489 :             for( sal_uInt32 i = 0; i < nColors; i++ )
     330             :             {
     331       37268 :                 const BitmapColor& rCol = pBuffer->maPalette[i];
     332       37268 :                 (*pPal)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
     333             :             }
     334             : 
     335             :             m_aBitmap = basebmp::createBitmapDevice( m_aBitmap->getSize(),
     336         221 :                                                      m_aBitmap->isTopDown(),
     337             :                                                      m_aBitmap->getScanlineFormat(),
     338             :                                                      m_aBitmap->getBuffer(),
     339         442 :                                                      pPal );
     340             :         }
     341             :     }
     342             : 
     343         389 :     delete pBuffer;
     344         389 : }
     345             : 
     346           0 : bool SvpSalBitmap::GetSystemData( BitmapSystemData& )
     347             : {
     348           0 :     return false;
     349             : }
     350             : 
     351             : 
     352             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10