LCOV - code coverage report
Current view: top level - vcl/headless - svpbmp.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 180 0.0 %
Date: 2014-04-14 Functions: 0 14 0.0 %
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           0 : SvpSalBitmap::~SvpSalBitmap()
      36             : {
      37           0 : }
      38             : 
      39           0 : bool SvpSalBitmap::Create( const Size& rSize,
      40             :                            sal_uInt16 nBitCount,
      41             :                            const BitmapPalette& rPalette )
      42             : {
      43           0 :     basebmp::Format nFormat = SVP_DEFAULT_BITMAP_FORMAT;
      44             :     SAL_INFO( "vcl.headless", "SvpSalBitmap::Create(" << rSize.Width() << "," << rSize.Height() << "," << nBitCount << ")" );
      45           0 :     switch( nBitCount )
      46             :     {
      47           0 :         case 1: nFormat = FORMAT_ONE_BIT_MSB_PAL; break;
      48           0 :         case 4: nFormat = FORMAT_FOUR_BIT_MSB_PAL; break;
      49           0 :         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           0 :         case 16: nFormat = FORMAT_SIXTEEN_BIT_LSB_TC_MASK; break;
      54             : #endif
      55           0 :         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           0 :     B2IVector aSize( rSize.Width(), rSize.Height() );
      63           0 :     if( aSize.getX() == 0 )
      64           0 :         aSize.setX( 1 );
      65           0 :     if( aSize.getY() == 0 )
      66           0 :         aSize.setY( 1 );
      67           0 :     if( nBitCount > 8 )
      68           0 :         m_aBitmap = createBitmapDevice( aSize, false, nFormat );
      69             :     else
      70             :     {
      71             :         // prepare palette
      72           0 :         unsigned int nEntries = 1U << nBitCount;
      73             :         std::vector<basebmp::Color>* pPalette =
      74           0 :             new std::vector<basebmp::Color>( nEntries, basebmp::Color(COL_WHITE) );
      75           0 :         unsigned int nColors = rPalette.GetEntryCount();
      76           0 :         for( unsigned int i = 0; i < nColors; i++ )
      77             :         {
      78           0 :             const BitmapColor& rCol = rPalette[i];
      79           0 :             (*pPalette)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
      80             :         }
      81           0 :         m_aBitmap = createBitmapDevice( aSize, false, nFormat,
      82             :                                         basebmp::RawMemorySharedArray(),
      83             :                                         basebmp::PaletteMemorySharedVector( pPalette )
      84           0 :                                         );
      85             :     }
      86           0 :     return true;
      87             : }
      88             : 
      89           0 : bool SvpSalBitmap::Create( const SalBitmap& rSalBmp )
      90             : {
      91           0 :     const SvpSalBitmap& rSrc = static_cast<const SvpSalBitmap&>(rSalBmp);
      92           0 :     const BitmapDeviceSharedPtr& rSrcBmp = rSrc.getBitmap();
      93           0 :     if( rSrcBmp.get() )
      94             :     {
      95           0 :         B2IVector aSize = rSrcBmp->getSize();
      96           0 :         m_aBitmap = cloneBitmapDevice( aSize, rSrcBmp );
      97           0 :         B2IBox aRect( 0, 0, aSize.getX(), aSize.getY() );
      98           0 :         m_aBitmap->drawBitmap( rSrcBmp, aRect, aRect, DrawMode_PAINT );
      99             :     }
     100             :     else
     101           0 :         m_aBitmap.reset();
     102             : 
     103           0 :     return true;
     104             : }
     105             : 
     106           0 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
     107             :                            SalGraphics* /*pGraphics*/ )
     108             : {
     109           0 :     return false;
     110             : }
     111             : 
     112           0 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
     113             :                            sal_uInt16 /*nNewBitCount*/ )
     114             : {
     115           0 :     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           0 : Size SvpSalBitmap::GetSize() const
     129             : {
     130           0 :     Size aSize;
     131           0 :     if( m_aBitmap.get() )
     132             :     {
     133           0 :         B2IVector aVec( m_aBitmap->getSize() );
     134           0 :         aSize = Size( aVec.getX(), aVec.getY() );
     135             :     }
     136             : 
     137           0 :     return aSize;
     138             : }
     139             : 
     140           0 : sal_uInt16 SvpSalBitmap::GetBitCount() const
     141             : {
     142           0 :     sal_uInt16 nDepth = 0;
     143           0 :     if( m_aBitmap.get() )
     144           0 :         nDepth = getBitCountFromScanlineFormat( m_aBitmap->getScanlineFormat() );
     145           0 :     return nDepth;
     146             : }
     147             : 
     148           0 : BitmapBuffer* SvpSalBitmap::AcquireBuffer( bool )
     149             : {
     150           0 :     BitmapBuffer* pBuf = NULL;
     151           0 :     if( m_aBitmap.get() )
     152             :     {
     153           0 :         pBuf = new BitmapBuffer();
     154           0 :         sal_uInt16 nBitCount = 1;
     155           0 :         switch( m_aBitmap->getScanlineFormat() )
     156             :         {
     157             :             case FORMAT_ONE_BIT_MSB_GREY:
     158             :             case FORMAT_ONE_BIT_MSB_PAL:
     159           0 :                 nBitCount = 1;
     160           0 :                 pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
     161           0 :                 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           0 :                 nBitCount = 4;
     170           0 :                 pBuf->mnFormat = BMP_FORMAT_4BIT_MSN_PAL;
     171           0 :                 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           0 :                 nBitCount = 8;
     179           0 :                 pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
     180           0 :                 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           0 :                 nBitCount = 16;
     187           0 :                 pBuf->mnFormat = BMP_FORMAT_16BIT_TC_LSB_MASK;
     188           0 :                 pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
     189           0 :                 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           0 :                 nBitCount = 24;
     197           0 :                 pBuf->mnFormat = BMP_FORMAT_24BIT_TC_BGR;
     198           0 :                 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           0 :         if( m_aBitmap->isTopDown() )
     243           0 :             pBuf->mnFormat |= BMP_FORMAT_TOP_DOWN;
     244             : 
     245           0 :         B2IVector aSize = m_aBitmap->getSize();
     246           0 :         pBuf->mnWidth           = aSize.getX();
     247           0 :         pBuf->mnHeight          = aSize.getY();
     248           0 :         pBuf->mnScanlineSize    = m_aBitmap->getScanlineStride();
     249           0 :         pBuf->mnBitCount        = nBitCount;
     250           0 :         pBuf->mpBits            = (sal_uInt8*)m_aBitmap->getBuffer().get();
     251           0 :         if( nBitCount <= 8 )
     252             :         {
     253           0 :             if( m_aBitmap->getScanlineFormat() == FORMAT_EIGHT_BIT_GREY ||
     254           0 :                 m_aBitmap->getScanlineFormat() == FORMAT_FOUR_BIT_LSB_GREY ||
     255           0 :                 m_aBitmap->getScanlineFormat() == FORMAT_FOUR_BIT_MSB_GREY ||
     256           0 :                 m_aBitmap->getScanlineFormat() == FORMAT_ONE_BIT_LSB_GREY ||
     257           0 :                 m_aBitmap->getScanlineFormat() == FORMAT_ONE_BIT_MSB_GREY
     258             :                 )
     259           0 :                 pBuf->maPalette = Bitmap::GetGreyPalette( 1U << nBitCount );
     260             :             else
     261             :             {
     262           0 :                 basebmp::PaletteMemorySharedVector aPalette = m_aBitmap->getPalette();
     263           0 :                 if( aPalette.get() )
     264             :                 {
     265           0 :                     unsigned int nColors = aPalette->size();
     266           0 :                     if( nColors > 0 )
     267             :                     {
     268           0 :                         pBuf->maPalette.SetEntryCount( nColors );
     269           0 :                         for( unsigned int i = 0; i < nColors; i++ )
     270             :                         {
     271           0 :                             const basebmp::Color& rCol = (*aPalette)[i];
     272           0 :                             pBuf->maPalette[i] = BitmapColor( rCol.getRed(), rCol.getGreen(), rCol.getBlue() );
     273             :                         }
     274             :                     }
     275           0 :                 }
     276             :             }
     277           0 :         }
     278             :     }
     279             : 
     280           0 :     return pBuf;
     281             : }
     282             : 
     283           0 : void SvpSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, bool bReadOnly )
     284             : {
     285           0 :     if( !bReadOnly && pBuffer->maPalette.GetEntryCount() )
     286             :     {
     287             :         // palette might have changed, clone device (but recycle
     288             :         // memory)
     289           0 :         sal_uInt16 nBitCount = 0;
     290           0 :         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           0 :                 nBitCount = 1;
     300           0 :                 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           0 :                 nBitCount = 4;
     310           0 :                 break;
     311             : 
     312             :             case FORMAT_EIGHT_BIT_PAL:
     313             :                 // FALLTHROUGH intended
     314             :             case FORMAT_EIGHT_BIT_GREY:
     315           0 :                 nBitCount = 8;
     316           0 :                 break;
     317             : 
     318             :             default:
     319           0 :                 break;
     320             :         }
     321             : 
     322           0 :         if( nBitCount )
     323             :         {
     324           0 :             sal_uInt32 nEntries = 1U << nBitCount;
     325             : 
     326             :             boost::shared_ptr< std::vector<basebmp::Color> > pPal(
     327             :                 new std::vector<basebmp::Color>( nEntries,
     328           0 :                                                  basebmp::Color(COL_WHITE)));
     329             :             const sal_uInt32 nColors = std::min(
     330           0 :                 (sal_uInt32)pBuffer->maPalette.GetEntryCount(),
     331           0 :                 nEntries);
     332           0 :             for( sal_uInt32 i = 0; i < nColors; i++ )
     333             :             {
     334           0 :                 const BitmapColor& rCol = pBuffer->maPalette[i];
     335           0 :                 (*pPal)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
     336             :             }
     337             : 
     338           0 :             m_aBitmap = basebmp::createBitmapDevice( m_aBitmap->getSize(),
     339           0 :                                                      m_aBitmap->isTopDown(),
     340             :                                                      m_aBitmap->getScanlineFormat(),
     341             :                                                      m_aBitmap->getBuffer(),
     342           0 :                                                      pPal );
     343             :         }
     344             :     }
     345             : 
     346           0 :     delete pBuffer;
     347           0 : }
     348             : 
     349           0 : bool SvpSalBitmap::GetSystemData( BitmapSystemData& )
     350             : {
     351           0 :     return false;
     352             : }
     353             : 
     354           0 : sal_uInt32 SvpSalBitmap::getBitCountFromScanlineFormat( basebmp::Format nFormat )
     355             : {
     356           0 :     sal_uInt32 nBitCount = 1;
     357           0 :     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           0 :             nBitCount = 1;
     364           0 :             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           0 :             nBitCount = 4;
     370           0 :             break;
     371             :         case FORMAT_EIGHT_BIT_PAL:
     372             :         case FORMAT_EIGHT_BIT_GREY:
     373           0 :             nBitCount = 8;
     374           0 :             break;
     375             :         case FORMAT_SIXTEEN_BIT_LSB_TC_MASK:
     376             :         case FORMAT_SIXTEEN_BIT_MSB_TC_MASK:
     377           0 :             nBitCount = 16;
     378           0 :             break;
     379             :         case FORMAT_TWENTYFOUR_BIT_TC_MASK:
     380           0 :             nBitCount = 24;
     381           0 :             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           0 :     return nBitCount;
     393             : }
     394             : 
     395             : #endif
     396             : 
     397             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10