LCOV - code coverage report
Current view: top level - filter/source/graphicfilter/icgm - bitmap.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 194 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 7 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             : 
      21             : #include "main.hxx"
      22             : 
      23             : 
      24             : 
      25           0 : CGMBitmap::CGMBitmap( CGM& rCGM ) :
      26             :     mpCGM                           ( &rCGM ),
      27           0 :     pCGMBitmapDescriptor            ( new CGMBitmapDescriptor )
      28             : {
      29           0 :     ImplGetBitmap( *pCGMBitmapDescriptor );
      30           0 : };
      31             : 
      32             : 
      33             : 
      34           0 : CGMBitmap::~CGMBitmap()
      35             : {
      36           0 :     delete pCGMBitmapDescriptor;
      37           0 : }
      38             : 
      39             : 
      40             : 
      41           0 : void CGMBitmap::ImplGetBitmap( CGMBitmapDescriptor& rDesc )
      42             : {
      43           0 :     rDesc.mbStatus = true;
      44             : 
      45           0 :     if ( ImplGetDimensions( rDesc ) && rDesc.mpBuf )
      46             :     {
      47           0 :         rDesc.mpBitmap = new Bitmap( Size( rDesc.mnX, rDesc.mnY ), (sal_uInt16)rDesc.mnDstBitsPerPixel );
      48           0 :         if ( ( rDesc.mpAcc = rDesc.mpBitmap->AcquireWriteAccess() ) != NULL )
      49             :         {
      50             : 
      51             :             // the picture may either be read from left to right or right to left, from top to bottom ...
      52             : 
      53           0 :             long nxCount = rDesc.mnX + 1;   // +1 because we are using prefix decreasing
      54           0 :             long nyCount = rDesc.mnY + 1;
      55             :             long    nx, ny, nxC;
      56             : 
      57           0 :             switch ( rDesc.mnDstBitsPerPixel )
      58             :             {
      59             :                 case 1 :
      60             :                 {
      61           0 :                     if ( rDesc.mnLocalColorPrecision == 1 )
      62           0 :                         ImplSetCurrentPalette( rDesc );
      63             :                     else
      64             :                     {
      65           0 :                         rDesc.mpAcc->SetPaletteEntryCount( 2 );
      66           0 :                         rDesc.mpAcc->SetPaletteColor( 0, BMCOL( mpCGM->pElement->nBackGroundColor ) );
      67             :                         rDesc.mpAcc->SetPaletteColor( 1,
      68           0 :                             ( mpCGM->pElement->nAspectSourceFlags & ASF_FILLINTERIORSTYLE )
      69           0 :                                 ? BMCOL( mpCGM->pElement->pFillBundle->GetColor() )
      70           0 :                                     : BMCOL( mpCGM->pElement->aFillBundle.GetColor() ) ) ;
      71             :                     }
      72           0 :                     for ( ny = 0; --nyCount ; ny++, rDesc.mpBuf += rDesc.mnScanSize )
      73             :                     {
      74           0 :                         nxC = nxCount;
      75           0 :                         for ( nx = 0; --nxC; nx++ )
      76             :                         {   // this is not fast, but a one bit/pixel format is rarely used
      77           0 :                             rDesc.mpAcc->SetPixelIndex( ny, nx, static_cast<sal_uInt8>( (*( rDesc.mpBuf + (nx >> 3)) >> ((nx & 7)^7))) & 1 );
      78             :                         }
      79             :                     }
      80             :                 }
      81           0 :                 break;
      82             : 
      83             :                 case 2 :
      84             :                 {
      85           0 :                     ImplSetCurrentPalette( rDesc );
      86           0 :                     for ( ny = 0; --nyCount; ny++, rDesc.mpBuf += rDesc.mnScanSize )
      87             :                     {
      88           0 :                         nxC = nxCount;
      89           0 :                         for ( nx = 0; --nxC; nx++ )
      90             :                         {   // this is not fast, but a two bits/pixel format is rarely used
      91           0 :                             rDesc.mpAcc->SetPixelIndex( ny, nx, static_cast<sal_uInt8>( (*(rDesc.mpBuf + (nx >> 2)) >> (((nx & 3)^3) << 1))) & 3 );
      92             :                         }
      93             :                     }
      94             :                 }
      95           0 :                 break;
      96             : 
      97             :                 case 4 :
      98             :                 {
      99           0 :                     ImplSetCurrentPalette( rDesc );
     100           0 :                     for ( ny = 0; --nyCount; ny++, rDesc.mpBuf += rDesc.mnScanSize )
     101             :                     {
     102           0 :                         nxC = nxCount;
     103             :                         sal_Int8  nDat;
     104           0 :                         sal_uInt8* pTemp = rDesc.mpBuf;
     105           0 :                         for ( nx = 0; --nxC; nx++ )
     106             :                         {
     107           0 :                             nDat = *pTemp++;
     108           0 :                             rDesc.mpAcc->SetPixelIndex( ny, nx, static_cast<sal_uInt8>(nDat >> 4) );
     109           0 :                             if ( --nxC )
     110             :                             {
     111           0 :                                 nx ++;
     112           0 :                                 rDesc.mpAcc->SetPixelIndex( ny, nx, static_cast<sal_uInt8>(nDat & 15) );
     113             :                             }
     114             :                             else
     115           0 :                                 break;
     116             :                         }
     117             :                     }
     118             :                 }
     119           0 :                 break;
     120             : 
     121             :                 case 8 :
     122             :                 {
     123           0 :                     ImplSetCurrentPalette( rDesc );
     124           0 :                     for ( ny = 0; --nyCount; ny++, rDesc.mpBuf += rDesc.mnScanSize )
     125             :                     {
     126           0 :                         sal_uInt8* pTemp = rDesc.mpBuf;
     127           0 :                         nxC = nxCount;
     128           0 :                         for ( nx = 0; --nxC; nx++ )
     129             :                         {
     130           0 :                             rDesc.mpAcc->SetPixelIndex( ny, nx, *(pTemp++) );
     131             :                         }
     132             :                     }
     133             :                 }
     134           0 :                 break;
     135             : 
     136             :                 case 24 :
     137             :                 {
     138             :                     {
     139           0 :                         BitmapColor aBitmapColor;
     140           0 :                         for ( ny = 0; --nyCount; ny++, rDesc.mpBuf += rDesc.mnScanSize )
     141             :                         {
     142           0 :                             sal_uInt8* pTemp = rDesc.mpBuf;
     143           0 :                             nxC = nxCount;
     144           0 :                             for ( nx = 0; --nxC; nx++ )
     145             :                             {
     146           0 :                                 aBitmapColor.SetRed( *pTemp++ );
     147           0 :                                 aBitmapColor.SetGreen( *pTemp++ );
     148           0 :                                 aBitmapColor.SetBlue( *pTemp++ );
     149           0 :                                 rDesc.mpAcc->SetPixel( ny, nx, aBitmapColor );
     150             :                             }
     151           0 :                         }
     152             :                     }
     153             :                 }
     154           0 :                 break;
     155             :             }
     156           0 :             double nX = rDesc.mnR.X - rDesc.mnQ.X;
     157           0 :             double nY = rDesc.mnR.Y - rDesc.mnQ.Y;
     158             : 
     159           0 :             rDesc.mndy = sqrt( nX * nX + nY * nY );
     160             : 
     161           0 :             nX = rDesc.mnR.X - rDesc.mnP.X;
     162           0 :             nY = rDesc.mnR.Y - rDesc.mnP.Y;
     163             : 
     164           0 :             rDesc.mndx = sqrt( nX * nX + nY * nY );
     165             : 
     166           0 :             nX = rDesc.mnR.X - rDesc.mnP.X;
     167           0 :             nY = rDesc.mnR.Y - rDesc.mnP.Y;
     168             : 
     169           0 :             rDesc.mnOrientation = acos( nX / sqrt( nX * nX + nY * nY ) ) * 57.29577951308;
     170           0 :             if ( nY > 0 )
     171           0 :                 rDesc.mnOrientation = 360 - rDesc.mnOrientation;
     172             : 
     173           0 :             nX = rDesc.mnQ.X - rDesc.mnR.X;
     174           0 :             nY = rDesc.mnQ.Y - rDesc.mnR.Y;
     175             : 
     176           0 :             double fAngle = 0.01745329251994 * ( 360 - rDesc.mnOrientation );
     177           0 :             double fSin = sin(fAngle);
     178           0 :             double fCos = cos(fAngle);
     179           0 :             nX = fCos * nX + fSin * nY;
     180           0 :             nY = -( fSin * nX - fCos * nY );
     181             : 
     182           0 :             fAngle = acos( nX / sqrt( nX * nX + nY * nY ) ) * 57.29577951308;
     183           0 :             if ( nY > 0 )
     184           0 :                 fAngle = 360 - fAngle;
     185             : 
     186           0 :             if ( fAngle > 180 )                 // is the picture build upwards or downwards ?
     187             :             {
     188           0 :                 rDesc.mnOrigin = rDesc.mnP;
     189             :             }
     190             :             else
     191             :             {
     192           0 :                 rDesc.mbVMirror = true;
     193           0 :                 rDesc.mnOrigin = rDesc.mnP;
     194           0 :                 rDesc.mnOrigin.X += rDesc.mnQ.X - rDesc.mnR.X;
     195           0 :                 rDesc.mnOrigin.Y += rDesc.mnQ.Y - rDesc.mnR.Y;
     196             :             }
     197             :         }
     198             :         else
     199           0 :             rDesc.mbStatus = false;
     200             :     }
     201             :     else
     202           0 :         rDesc.mbStatus = false;
     203             : 
     204           0 :     if ( rDesc.mpAcc )
     205             :     {
     206           0 :         Bitmap::ReleaseAccess( rDesc.mpAcc );
     207           0 :         rDesc.mpAcc = NULL;
     208             :     }
     209           0 :     if ( !rDesc.mbStatus )
     210             :     {
     211           0 :         if ( rDesc.mpBitmap )
     212             :         {
     213           0 :             delete rDesc.mpBitmap;
     214           0 :             rDesc.mpBitmap = NULL;
     215             :         }
     216             :     }
     217           0 : }
     218             : 
     219             : 
     220             : 
     221           0 : void CGMBitmap::ImplSetCurrentPalette( CGMBitmapDescriptor& rDesc )
     222             : {
     223             :     sal_uInt16 nColors = sal::static_int_cast< sal_uInt16 >(
     224           0 :         1 << rDesc.mnDstBitsPerPixel);
     225           0 :     rDesc.mpAcc->SetPaletteEntryCount( nColors );
     226           0 :     for ( sal_uInt16 i = 0; i < nColors; i++ )
     227             :     {
     228           0 :         rDesc.mpAcc->SetPaletteColor( i, BMCOL( mpCGM->pElement->aLatestColorTable[ i ] ) );
     229             :     }
     230           0 : }
     231             : 
     232             : 
     233             : 
     234           0 : bool CGMBitmap::ImplGetDimensions( CGMBitmapDescriptor& rDesc )
     235             : {
     236           0 :     mpCGM->ImplGetPoint( rDesc.mnP );           // parallelogram    p < - > r
     237           0 :     mpCGM->ImplGetPoint( rDesc.mnQ );           //                          |
     238           0 :     mpCGM->ImplGetPoint( rDesc.mnR );           //                          q
     239           0 :     sal_uInt32 nPrecision = mpCGM->pElement->nIntegerPrecision;
     240           0 :     rDesc.mnX = mpCGM->ImplGetUI( nPrecision );
     241           0 :     rDesc.mnY = mpCGM->ImplGetUI( nPrecision );
     242           0 :     rDesc.mnLocalColorPrecision = mpCGM->ImplGetI( nPrecision );
     243           0 :     rDesc.mnScanSize = 0;
     244           0 :     switch( rDesc.mnLocalColorPrecision )
     245             :     {
     246             :         case long(0x80000001) :                 // monochrome ( bit = 0->backgroundcolor )
     247             :         case 0 :                                //              bit = 1->fillcolor
     248           0 :             rDesc.mnDstBitsPerPixel = 1;
     249           0 :             break;
     250             :         case 1 :                                // 2 color indexed ( monochrome )
     251             :         case -1 :
     252           0 :             rDesc.mnDstBitsPerPixel = 1;
     253           0 :             break;
     254             :         case 2 :                                // 4 color indexed
     255             :         case -2 :
     256           0 :             rDesc.mnDstBitsPerPixel = 2;
     257           0 :             break;
     258             :         case 4 :                                // 16 color indexed
     259             :         case -4 :
     260           0 :             rDesc.mnDstBitsPerPixel = 4;
     261           0 :             break;
     262             :         case 8 :                                // 256 color indexed
     263             :         case -8 :
     264           0 :             rDesc.mnDstBitsPerPixel = 8;
     265           0 :             rDesc.mnScanSize = rDesc.mnX;
     266           0 :             break;
     267             :         case 16 :                               // NS
     268             :         case -16 :
     269           0 :             rDesc.mbStatus = false;
     270           0 :             break;
     271             :         case 24 :                               // 24 bit directColor ( 8 bits each component )
     272             :         case -24 :
     273           0 :             rDesc.mnDstBitsPerPixel = 24;
     274           0 :             break;
     275             :         case 32 :                               // NS
     276             :         case -32 :
     277           0 :             rDesc.mbStatus = false;
     278           0 :             break;
     279             : 
     280             :     }
     281             :     // mnCompressionMode == 0 : CCOMP_RUNLENGTH
     282             :     //                   == 1 : CCOMP_PACKED ( no compression. each row starts on a 4 byte boundary )
     283           0 :     if ( ( rDesc.mnCompressionMode = mpCGM->ImplGetUI16() ) != 1 )
     284           0 :         rDesc.mbStatus = false;
     285             : 
     286           0 :     if ( !( rDesc.mnX || rDesc.mnY ) )
     287           0 :         rDesc.mbStatus = false;
     288             : 
     289           0 :     sal_uInt32 nHeaderSize = 2 + 3 * nPrecision + 3 * mpCGM->ImplGetPointSize();
     290           0 :     rDesc.mnScanSize = ( ( rDesc.mnX * rDesc.mnDstBitsPerPixel + 7 ) >> 3 );
     291             : 
     292             :     sal_uInt32  nScanSize;
     293           0 :     nScanSize = rDesc.mnScanSize;
     294           0 :     if ( ( nScanSize * rDesc.mnY + nHeaderSize ) != mpCGM->mnElementSize )  // try a scansize without dw alignment
     295             :     {
     296           0 :         nScanSize = ( rDesc.mnScanSize + 1 ) & ~1;
     297           0 :         if ( ( nScanSize * rDesc.mnY + nHeaderSize ) != mpCGM->mnElementSize )  // then we'll try word alignment
     298             :         {
     299           0 :             nScanSize = ( rDesc.mnScanSize + 3 ) & ~3;
     300           0 :             if ( ( nScanSize * rDesc.mnY + nHeaderSize ) != mpCGM->mnElementSize )  // and last we'll try dword alignment
     301             :             {
     302           0 :                 nScanSize = ( rDesc.mnScanSize + 1 ) & ~1;          // and LAST BUT NOT LEAST we'll try word alignment without aligning the last line
     303           0 :                 if ( ( nScanSize * ( rDesc.mnY - 1 ) + rDesc.mnScanSize + nHeaderSize ) != mpCGM->mnElementSize )
     304             :                 {
     305           0 :                     nScanSize = ( rDesc.mnScanSize + 3 ) & ~3;
     306           0 :                     if ( ( nScanSize * ( rDesc.mnY - 1 ) + rDesc.mnScanSize + nHeaderSize ) != mpCGM->mnElementSize )
     307             :                     {
     308           0 :                         mpCGM->mnParaSize = 0;                              // this format is corrupt
     309           0 :                         rDesc.mbStatus = false;
     310             :                     }
     311             :                 }
     312             :             }
     313             :         }
     314             :     }
     315           0 :     rDesc.mnScanSize = nScanSize;
     316           0 :     if ( rDesc.mbStatus )
     317             :     {
     318           0 :         rDesc.mpBuf = mpCGM->mpSource + mpCGM->mnParaSize;  // mpBuf now points to the first scanline
     319           0 :         mpCGM->mnParaSize += rDesc.mnScanSize * rDesc.mnY;
     320             :     }
     321           0 :     return rDesc.mbStatus;
     322             : }
     323             : 
     324             : 
     325             : 
     326           0 : void CGMBitmap::ImplInsert( CGMBitmapDescriptor& rSource, CGMBitmapDescriptor& rDest )
     327             : {
     328           0 :     if ( ( rSource.mnR.Y == rDest.mnQ.Y ) && ( rSource.mnR.X == rDest.mnQ.X ) )
     329             :     {   // Insert on Bottom
     330           0 :         if ( mpCGM->mnVDCYmul == -1 )
     331           0 :             rDest.mnOrigin = rSource.mnOrigin;          // new origin
     332           0 :         rDest.mpBitmap->Expand( 0, rSource.mnY );
     333             :         rDest.mpBitmap->CopyPixel( Rectangle( Point( 0, rDest.mnY ), Size( rSource.mnX, rSource.mnY ) ),
     334           0 :             Rectangle( Point( 0, 0 ), Size( rSource.mnX, rSource.mnY ) ), rSource.mpBitmap );
     335           0 :         FloatPoint aFloatPoint;
     336           0 :         aFloatPoint.X = rSource.mnQ.X - rSource.mnR.X;
     337           0 :         aFloatPoint.Y = rSource.mnQ.Y - rSource.mnR.Y;
     338           0 :         rDest.mnQ.X += aFloatPoint.X;
     339           0 :         rDest.mnQ.Y += aFloatPoint.Y;
     340           0 :         rDest.mnP = rSource.mnP;
     341           0 :         rDest.mnR = rSource.mnR;
     342             :     }
     343             :     else
     344             :     {   // Insert on Top
     345           0 :         if ( mpCGM->mnVDCYmul == 1 )
     346           0 :             rDest.mnOrigin = rSource.mnOrigin;          // new origin
     347           0 :         rDest.mpBitmap->Expand( 0, rSource.mnY );
     348             :         rDest.mpBitmap->CopyPixel( Rectangle( Point( 0, rDest.mnY ), Size( rSource.mnX, rSource.mnY ) ),
     349           0 :             Rectangle( Point( 0, 0 ), Size( rSource.mnX, rSource.mnY ) ), rSource.mpBitmap );
     350           0 :         rDest.mnP = rSource.mnP;
     351           0 :         rDest.mnR = rSource.mnR;
     352             :     }
     353           0 :     rDest.mnY += rSource.mnY;
     354           0 :     rDest.mndy += rSource.mndy;
     355           0 : };
     356             : 
     357           0 : CGMBitmap* CGMBitmap::GetNext()
     358             : {
     359           0 :     if ( pCGMBitmapDescriptor->mpBitmap && pCGMBitmapDescriptor->mbStatus )
     360             :     {
     361           0 :         CGMBitmap* pCGMTempBitmap = new CGMBitmap( *mpCGM );
     362           0 :         if ( ( (long)pCGMTempBitmap->pCGMBitmapDescriptor->mnOrientation == (long)pCGMBitmapDescriptor->mnOrientation ) &&
     363           0 :             ( ( ( pCGMTempBitmap->pCGMBitmapDescriptor->mnR.X == pCGMBitmapDescriptor->mnQ.X ) &&
     364           0 :                     ( pCGMTempBitmap->pCGMBitmapDescriptor->mnR.Y == pCGMBitmapDescriptor->mnQ.Y ) ) ||
     365           0 :             ( ( pCGMTempBitmap->pCGMBitmapDescriptor->mnQ.X == pCGMBitmapDescriptor->mnR.X ) &&
     366           0 :                     ( pCGMTempBitmap->pCGMBitmapDescriptor->mnQ.Y == pCGMBitmapDescriptor->mnR.Y ) ) ) )
     367             :         {
     368           0 :             ImplInsert( *(pCGMTempBitmap->pCGMBitmapDescriptor), *(pCGMBitmapDescriptor) );
     369           0 :             delete pCGMTempBitmap;
     370           0 :             return NULL;
     371             :         }
     372             : 
     373           0 :         CGMBitmapDescriptor* pTempBD = pCGMBitmapDescriptor;
     374           0 :         pCGMBitmapDescriptor = pCGMTempBitmap->pCGMBitmapDescriptor;
     375           0 :         pCGMTempBitmap->pCGMBitmapDescriptor = pTempBD;
     376           0 :         return pCGMTempBitmap;
     377             :     }
     378             :     else
     379           0 :         return NULL;
     380             : }
     381             : 
     382             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11