LCOV - code coverage report
Current view: top level - vcl/headless - svpbmp.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 129 180 71.7 %
Date: 2014-04-11 Functions: 10 14 71.4 %
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             : #ifndef IOS
      21             : 
      22             : #include "headless/svpbmp.hxx"
      23             : 
      24             : #include <basegfx/vector/b2ivector.hxx>
      25             : #include <basegfx/range/b2ibox.hxx>
      26             : #include <basebmp/scanlineformats.hxx>
      27             : #include <basebmp/color.hxx>
      28             : 
      29             : #include <vcl/salbtype.hxx>
      30             : #include <vcl/bitmap.hxx>
      31             : 
      32             : using namespace basebmp;
      33             : using namespace basegfx;
      34             : 
      35      866550 : SvpSalBitmap::~SvpSalBitmap()
      36             : {
      37      866550 : }
      38             : 
      39       49337 : bool SvpSalBitmap::Create( const Size& rSize,
      40             :                            sal_uInt16 nBitCount,
      41             :                            const BitmapPalette& rPalette )
      42             : {
      43       49337 :     basebmp::Format nFormat = SVP_DEFAULT_BITMAP_FORMAT;
      44             :     SAL_INFO( "vcl.headless", "SvpSalBitmap::Create(" << rSize.Width() << "," << rSize.Height() << "," << nBitCount << ")" );
      45       49337 :     switch( nBitCount )
      46             :     {
      47         803 :         case 1: nFormat = FORMAT_ONE_BIT_MSB_PAL; break;
      48         212 :         case 4: nFormat = FORMAT_FOUR_BIT_MSB_PAL; break;
      49       32930 :         case 8: nFormat = FORMAT_EIGHT_BIT_PAL; break;
      50             : #ifdef OSL_BIGENDIAN
      51             :         case 16: nFormat = FORMAT_SIXTEEN_BIT_MSB_TC_MASK; break;
      52             : #else
      53           1 :         case 16: nFormat = FORMAT_SIXTEEN_BIT_LSB_TC_MASK; break;
      54             : #endif
      55       15391 :         case 24: nFormat = FORMAT_TWENTYFOUR_BIT_TC_MASK; break;
      56             : #ifdef ANDROID
      57             :         case 32: nFormat = FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA; break;
      58             : #else
      59           0 :         case 32: nFormat = FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA; break;
      60             : #endif
      61             :     }
      62       49337 :     B2IVector aSize( rSize.Width(), rSize.Height() );
      63       49337 :     if( aSize.getX() == 0 )
      64           0 :         aSize.setX( 1 );
      65       49337 :     if( aSize.getY() == 0 )
      66           0 :         aSize.setY( 1 );
      67       49337 :     if( nBitCount > 8 )
      68       15392 :         m_aBitmap = createBitmapDevice( aSize, false, nFormat );
      69             :     else
      70             :     {
      71             :         // prepare palette
      72       33945 :         unsigned int nEntries = 1U << nBitCount;
      73             :         std::vector<basebmp::Color>* pPalette =
      74       33945 :             new std::vector<basebmp::Color>( nEntries, basebmp::Color(COL_WHITE) );
      75       33945 :         unsigned int nColors = rPalette.GetEntryCount();
      76     8345292 :         for( unsigned int i = 0; i < nColors; i++ )
      77             :         {
      78     8311347 :             const BitmapColor& rCol = rPalette[i];
      79     8311347 :             (*pPalette)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
      80             :         }
      81       67890 :         m_aBitmap = createBitmapDevice( aSize, false, nFormat,
      82             :                                         basebmp::RawMemorySharedArray(),
      83             :                                         basebmp::PaletteMemorySharedVector( pPalette )
      84       33945 :                                         );
      85             :     }
      86       49337 :     return true;
      87             : }
      88             : 
      89      119450 : bool SvpSalBitmap::Create( const SalBitmap& rSalBmp )
      90             : {
      91      119450 :     const SvpSalBitmap& rSrc = static_cast<const SvpSalBitmap&>(rSalBmp);
      92      119450 :     const BitmapDeviceSharedPtr& rSrcBmp = rSrc.getBitmap();
      93      119450 :     if( rSrcBmp.get() )
      94             :     {
      95      119450 :         B2IVector aSize = rSrcBmp->getSize();
      96      119450 :         m_aBitmap = cloneBitmapDevice( aSize, rSrcBmp );
      97      119450 :         B2IBox aRect( 0, 0, aSize.getX(), aSize.getY() );
      98      119450 :         m_aBitmap->drawBitmap( rSrcBmp, aRect, aRect, DrawMode_PAINT );
      99             :     }
     100             :     else
     101           0 :         m_aBitmap.reset();
     102             : 
     103      119450 :     return true;
     104             : }
     105             : 
     106           0 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
     107             :                            SalGraphics* /*pGraphics*/ )
     108             : {
     109           0 :     return false;
     110             : }
     111             : 
     112           4 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
     113             :                            sal_uInt16 /*nNewBitCount*/ )
     114             : {
     115           4 :     return false;
     116             : }
     117             : 
     118           0 : bool SvpSalBitmap::Create( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > /*xBitmapCanvas*/, Size& /*rSize*/, bool /*bMask*/ )
     119             : {
     120           0 :     return false;
     121             : }
     122             : 
     123           0 : void SvpSalBitmap::Destroy()
     124             : {
     125           0 :     m_aBitmap.reset();
     126           0 : }
     127             : 
     128      632766 : Size SvpSalBitmap::GetSize() const
     129             : {
     130      632766 :     Size aSize;
     131      632766 :     if( m_aBitmap.get() )
     132             :     {
     133      632766 :         B2IVector aVec( m_aBitmap->getSize() );
     134      632766 :         aSize = Size( aVec.getX(), aVec.getY() );
     135             :     }
     136             : 
     137      632766 :     return aSize;
     138             : }
     139             : 
     140      253609 : sal_uInt16 SvpSalBitmap::GetBitCount() const
     141             : {
     142      253609 :     sal_uInt16 nDepth = 0;
     143      253609 :     if( m_aBitmap.get() )
     144      253605 :         nDepth = getBitCountFromScanlineFormat( m_aBitmap->getScanlineFormat() );
     145      253609 :     return nDepth;
     146             : }
     147             : 
     148      553288 : BitmapBuffer* SvpSalBitmap::AcquireBuffer( bool )
     149             : {
     150      553288 :     BitmapBuffer* pBuf = NULL;
     151      553288 :     if( m_aBitmap.get() )
     152             :     {
     153      553284 :         pBuf = new BitmapBuffer();
     154      553284 :         sal_uInt16 nBitCount = 1;
     155      553284 :         switch( m_aBitmap->getScanlineFormat() )
     156             :         {
     157             :             case FORMAT_ONE_BIT_MSB_GREY:
     158             :             case FORMAT_ONE_BIT_MSB_PAL:
     159        5656 :                 nBitCount = 1;
     160        5656 :                 pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
     161        5656 :                 break;
     162             :             case FORMAT_ONE_BIT_LSB_GREY:
     163             :             case FORMAT_ONE_BIT_LSB_PAL:
     164           0 :                 nBitCount = 1;
     165           0 :                 pBuf->mnFormat = BMP_FORMAT_1BIT_LSB_PAL;
     166           0 :                 break;
     167             :             case FORMAT_FOUR_BIT_MSB_GREY:
     168             :             case FORMAT_FOUR_BIT_MSB_PAL:
     169         397 :                 nBitCount = 4;
     170         397 :                 pBuf->mnFormat = BMP_FORMAT_4BIT_MSN_PAL;
     171         397 :                 break;
     172             :             case FORMAT_FOUR_BIT_LSB_GREY:
     173             :             case FORMAT_FOUR_BIT_LSB_PAL:
     174           0 :                 nBitCount = 4;
     175           0 :                 pBuf->mnFormat = BMP_FORMAT_4BIT_LSN_PAL;
     176           0 :                 break;
     177             :             case FORMAT_EIGHT_BIT_PAL:
     178      311691 :                 nBitCount = 8;
     179      311691 :                 pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
     180      311691 :                 break;
     181             :             case FORMAT_EIGHT_BIT_GREY:
     182           0 :                 nBitCount = 8;
     183           0 :                 pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
     184           0 :                 break;
     185             :             case FORMAT_SIXTEEN_BIT_LSB_TC_MASK:
     186          11 :                 nBitCount = 16;
     187          11 :                 pBuf->mnFormat = BMP_FORMAT_16BIT_TC_LSB_MASK;
     188          11 :                 pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
     189          11 :                 break;
     190             :             case FORMAT_SIXTEEN_BIT_MSB_TC_MASK:
     191           0 :                 nBitCount = 16;
     192           0 :                 pBuf->mnFormat = BMP_FORMAT_16BIT_TC_MSB_MASK;
     193           0 :                 pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
     194           0 :                 break;
     195             :             case FORMAT_TWENTYFOUR_BIT_TC_MASK:
     196      235529 :                 nBitCount = 24;
     197      235529 :                 pBuf->mnFormat = BMP_FORMAT_24BIT_TC_BGR;
     198      235529 :                 break;
     199             :             case FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA:
     200           0 :                 nBitCount = 32;
     201           0 :                 pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
     202             : #ifdef OSL_BIGENDIAN
     203             :                 pBuf->maColorMask = ColorMask( 0x0000ff00, 0x00ff0000, 0xff000000 );
     204             : #else
     205           0 :                 pBuf->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff );
     206             : #endif
     207           0 :                 break;
     208             :             case FORMAT_THIRTYTWO_BIT_TC_MASK_ARGB:
     209           0 :                 nBitCount = 32;
     210           0 :                 pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
     211             : #ifdef OSL_BIGENDIAN
     212             :                 pBuf->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff );
     213             : #else
     214           0 :                 pBuf->maColorMask = ColorMask( 0x0000ff00, 0x00ff0000, 0xff000000 );
     215             : #endif
     216           0 :                 break;
     217             :             case FORMAT_THIRTYTWO_BIT_TC_MASK_ABGR:
     218           0 :                 nBitCount = 32;
     219           0 :                 pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
     220             : #ifdef OSL_BIGENDIAN
     221             :                 pBuf->maColorMask = ColorMask( 0x000000ff, 0x0000ff00, 0x00ff0000 );
     222             : #else
     223           0 :                 pBuf->maColorMask = ColorMask( 0xff000000, 0x00ff0000, 0x0000ff00 );
     224             : #endif
     225           0 :                 break;
     226             :             case FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA:
     227           0 :                 nBitCount = 32;
     228           0 :                 pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
     229             : #ifdef OSL_BIGENDIAN
     230             :                 pBuf->maColorMask = ColorMask( 0xff000000, 0x00ff0000, 0x0000ff00 );
     231             : #else
     232           0 :                 pBuf->maColorMask = ColorMask( 0x000000ff, 0x0000ff00, 0x00ff0000 );
     233             : #endif
     234           0 :                 break;
     235             : 
     236             :             default:
     237             :                 // this is an error case !!!!!
     238           0 :                 nBitCount = 1;
     239           0 :                 pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
     240           0 :                 break;
     241             :         }
     242      553284 :         if( m_aBitmap->isTopDown() )
     243           0 :             pBuf->mnFormat |= BMP_FORMAT_TOP_DOWN;
     244             : 
     245      553284 :         B2IVector aSize = m_aBitmap->getSize();
     246      553284 :         pBuf->mnWidth           = aSize.getX();
     247      553284 :         pBuf->mnHeight          = aSize.getY();
     248      553284 :         pBuf->mnScanlineSize    = m_aBitmap->getScanlineStride();
     249      553284 :         pBuf->mnBitCount        = nBitCount;
     250      553284 :         pBuf->mpBits            = (sal_uInt8*)m_aBitmap->getBuffer().get();
     251      553284 :         if( nBitCount <= 8 )
     252             :         {
     253      953232 :             if( m_aBitmap->getScanlineFormat() == FORMAT_EIGHT_BIT_GREY ||
     254      635488 :                 m_aBitmap->getScanlineFormat() == FORMAT_FOUR_BIT_LSB_GREY ||
     255      635488 :                 m_aBitmap->getScanlineFormat() == FORMAT_FOUR_BIT_MSB_GREY ||
     256      953232 :                 m_aBitmap->getScanlineFormat() == FORMAT_ONE_BIT_LSB_GREY ||
     257      317744 :                 m_aBitmap->getScanlineFormat() == FORMAT_ONE_BIT_MSB_GREY
     258             :                 )
     259           0 :                 pBuf->maPalette = Bitmap::GetGreyPalette( 1U << nBitCount );
     260             :             else
     261             :             {
     262      317744 :                 basebmp::PaletteMemorySharedVector aPalette = m_aBitmap->getPalette();
     263      317744 :                 if( aPalette.get() )
     264             :                 {
     265      317744 :                     unsigned int nColors = aPalette->size();
     266      317744 :                     if( nColors > 0 )
     267             :                     {
     268      317744 :                         pBuf->maPalette.SetEntryCount( nColors );
     269    80128304 :                         for( unsigned int i = 0; i < nColors; i++ )
     270             :                         {
     271    79810560 :                             const basebmp::Color& rCol = (*aPalette)[i];
     272    79810560 :                             pBuf->maPalette[i] = BitmapColor( rCol.getRed(), rCol.getGreen(), rCol.getBlue() );
     273             :                         }
     274             :                     }
     275      317744 :                 }
     276             :             }
     277      553284 :         }
     278             :     }
     279             : 
     280      553288 :     return pBuf;
     281             : }
     282             : 
     283      553284 : void SvpSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, bool bReadOnly )
     284             : {
     285      553284 :     if( !bReadOnly && pBuffer->maPalette.GetEntryCount() )
     286             :     {
     287             :         // palette might have changed, clone device (but recycle
     288             :         // memory)
     289       51193 :         sal_uInt16 nBitCount = 0;
     290       51193 :         switch( m_aBitmap->getScanlineFormat() )
     291             :         {
     292             :             case FORMAT_ONE_BIT_MSB_GREY:
     293             :                 // FALLTHROUGH intended
     294             :             case FORMAT_ONE_BIT_MSB_PAL:
     295             :                 // FALLTHROUGH intended
     296             :             case FORMAT_ONE_BIT_LSB_GREY:
     297             :                 // FALLTHROUGH intended
     298             :             case FORMAT_ONE_BIT_LSB_PAL:
     299         820 :                 nBitCount = 1;
     300         820 :                 break;
     301             : 
     302             :             case FORMAT_FOUR_BIT_MSB_GREY:
     303             :                 // FALLTHROUGH intended
     304             :             case FORMAT_FOUR_BIT_MSB_PAL:
     305             :                 // FALLTHROUGH intended
     306             :             case FORMAT_FOUR_BIT_LSB_GREY:
     307             :                 // FALLTHROUGH intended
     308             :             case FORMAT_FOUR_BIT_LSB_PAL:
     309         225 :                 nBitCount = 4;
     310         225 :                 break;
     311             : 
     312             :             case FORMAT_EIGHT_BIT_PAL:
     313             :                 // FALLTHROUGH intended
     314             :             case FORMAT_EIGHT_BIT_GREY:
     315       50148 :                 nBitCount = 8;
     316       50148 :                 break;
     317             : 
     318             :             default:
     319           0 :                 break;
     320             :         }
     321             : 
     322       51193 :         if( nBitCount )
     323             :         {
     324       51193 :             sal_uInt32 nEntries = 1U << nBitCount;
     325             : 
     326             :             boost::shared_ptr< std::vector<basebmp::Color> > pPal(
     327             :                 new std::vector<basebmp::Color>( nEntries,
     328       51193 :                                                  basebmp::Color(COL_WHITE)));
     329             :             const sal_uInt32 nColors = std::min(
     330       51193 :                 (sal_uInt32)pBuffer->maPalette.GetEntryCount(),
     331       51193 :                 nEntries);
     332    12813809 :             for( sal_uInt32 i = 0; i < nColors; i++ )
     333             :             {
     334    12762616 :                 const BitmapColor& rCol = pBuffer->maPalette[i];
     335    12762616 :                 (*pPal)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
     336             :             }
     337             : 
     338      153579 :             m_aBitmap = basebmp::createBitmapDevice( m_aBitmap->getSize(),
     339       51193 :                                                      m_aBitmap->isTopDown(),
     340             :                                                      m_aBitmap->getScanlineFormat(),
     341             :                                                      m_aBitmap->getBuffer(),
     342      102386 :                                                      pPal );
     343             :         }
     344             :     }
     345             : 
     346      553284 :     delete pBuffer;
     347      553284 : }
     348             : 
     349           0 : bool SvpSalBitmap::GetSystemData( BitmapSystemData& )
     350             : {
     351           0 :     return false;
     352             : }
     353             : 
     354      427457 : sal_uInt32 SvpSalBitmap::getBitCountFromScanlineFormat( basebmp::Format nFormat )
     355             : {
     356      427457 :     sal_uInt32 nBitCount = 1;
     357      427457 :     switch( nFormat )
     358             :     {
     359             :         case FORMAT_ONE_BIT_MSB_GREY:
     360             :         case FORMAT_ONE_BIT_LSB_GREY:
     361             :         case FORMAT_ONE_BIT_MSB_PAL:
     362             :         case FORMAT_ONE_BIT_LSB_PAL:
     363        5399 :             nBitCount = 1;
     364        5399 :             break;
     365             :         case FORMAT_FOUR_BIT_MSB_GREY:
     366             :         case FORMAT_FOUR_BIT_LSB_GREY:
     367             :         case FORMAT_FOUR_BIT_MSB_PAL:
     368             :         case FORMAT_FOUR_BIT_LSB_PAL:
     369         444 :             nBitCount = 4;
     370         444 :             break;
     371             :         case FORMAT_EIGHT_BIT_PAL:
     372             :         case FORMAT_EIGHT_BIT_GREY:
     373      184156 :             nBitCount = 8;
     374      184156 :             break;
     375             :         case FORMAT_SIXTEEN_BIT_LSB_TC_MASK:
     376             :         case FORMAT_SIXTEEN_BIT_MSB_TC_MASK:
     377           4 :             nBitCount = 16;
     378           4 :             break;
     379             :         case FORMAT_TWENTYFOUR_BIT_TC_MASK:
     380      237454 :             nBitCount = 24;
     381      237454 :             break;
     382             :         case FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA:
     383             :         case FORMAT_THIRTYTWO_BIT_TC_MASK_ARGB:
     384             :         case FORMAT_THIRTYTWO_BIT_TC_MASK_ABGR:
     385             :         case FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA:
     386           0 :             nBitCount = 32;
     387           0 :             break;
     388             :         default:
     389             :         OSL_FAIL( "unsupported basebmp format" );
     390           0 :         break;
     391             :     }
     392      427457 :     return nBitCount;
     393             : }
     394             : 
     395             : #endif
     396             : 
     397             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10