LCOV - code coverage report
Current view: top level - filter/source/graphicfilter/etiff - etiff.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 257 0.0 %
Date: 2014-11-03 Functions: 0 16 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 <vcl/graph.hxx>
      22             : #include <vcl/svapp.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : #include <vcl/bmpacc.hxx>
      25             : #include <svl/solar.hrc>
      26             : #include <vcl/fltcall.hxx>
      27             : #include <vcl/FilterConfigItem.hxx>
      28             : 
      29             : #define NewSubfileType              254
      30             : #define ImageWidth                  256
      31             : #define ImageLength                 257
      32             : #define BitsPerSample               258
      33             : #define Compression                 259
      34             : #define PhotometricInterpretation   262
      35             : #define StripOffsets                273
      36             : #define SamplesPerPixel             277
      37             : #define RowsPerStrip                278
      38             : #define StripByteCounts             279
      39             : #define XResolution                 282
      40             : #define YResolution                 283
      41             : #define PlanarConfiguration         284
      42             : #define ResolutionUnit              296
      43             : #define ColorMap                    320
      44             : 
      45             : 
      46             : // - TIFFWriter -
      47             : 
      48             : 
      49             : struct TIFFLZWCTreeNode
      50             : {
      51             : 
      52             :     TIFFLZWCTreeNode*       pBrother;       // next node with the same father
      53             :     TIFFLZWCTreeNode*       pFirstChild;    // first son
      54             :     sal_uInt16              nCode;          // The code for the string of pixel values, which arises if... <missing comment>
      55             :     sal_uInt16              nValue;         // pixel value
      56             : };
      57             : 
      58             : class TIFFWriter
      59             : {
      60             : private:
      61             : 
      62             :     SvStream& m_rOStm;
      63             :     sal_uInt32              mnStreamOfs;
      64             : 
      65             :     bool                mbStatus;
      66             :     BitmapReadAccess*       mpAcc;
      67             : 
      68             :     sal_uInt32              mnWidth, mnHeight, mnColors;
      69             :     sal_uInt32              mnCurAllPictHeight;
      70             :     sal_uInt32              mnSumOfAllPictHeight;
      71             :     sal_uInt32              mnBitsPerPixel;
      72             :     sal_uInt32              mnLastPercent;
      73             : 
      74             :     sal_uInt32              mnLatestIfdPos;
      75             :     sal_uInt16              mnTagCount;                 // number of tags already written
      76             :     sal_uInt32              mnCurrentTagCountPos;       // offset to the position where the current
      77             :                                                         // tag count is to insert
      78             : 
      79             :     sal_uInt32              mnXResPos;                  // if != 0 this DWORDs stores the
      80             :     sal_uInt32              mnYResPos;                  // actual streamposition of the
      81             :     sal_uInt32              mnPalPos;                   // Tag Entry
      82             :     sal_uInt32              mnBitmapPos;
      83             :     sal_uInt32              mnStripByteCountPos;
      84             : 
      85             :     TIFFLZWCTreeNode*       pTable;
      86             :     TIFFLZWCTreeNode*       pPrefix;
      87             :     sal_uInt16              nDataSize;
      88             :     sal_uInt16              nClearCode;
      89             :     sal_uInt16              nEOICode;
      90             :     sal_uInt16              nTableSize;
      91             :     sal_uInt16              nCodeSize;
      92             :     sal_uInt32              nOffset;
      93             :     sal_uInt32              dwShift;
      94             : 
      95             :     com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator;
      96             : 
      97             :     void                ImplCallback( sal_uInt32 nPercent );
      98             :     bool            ImplWriteHeader( bool bMultiPage );
      99             :     void                ImplWritePalette();
     100             :     bool            ImplWriteBody();
     101             :     void                ImplWriteTag( sal_uInt16 TagID, sal_uInt16 DataType, sal_uInt32 NumberOfItems, sal_uInt32 Value);
     102             :     void                ImplWriteResolution( sal_uLong nStreamPos, sal_uInt32 nResolutionUnit );
     103             :     void                StartCompression();
     104             :     void                Compress( sal_uInt8 nSrc );
     105             :     void                EndCompression();
     106             :     inline void         WriteBits( sal_uInt16 nCode, sal_uInt16 nCodeLen );
     107             : 
     108             : public:
     109             : 
     110             :     TIFFWriter(SvStream &rStream);
     111             :     ~TIFFWriter();
     112             : 
     113             :     bool WriteTIFF( const Graphic& rGraphic, FilterConfigItem* pFilterConfigItem );
     114             : };
     115             : 
     116             : 
     117             : 
     118           0 : TIFFWriter::TIFFWriter(SvStream &rStream)
     119             :     : m_rOStm(rStream)
     120             :     , mnStreamOfs(0)
     121             :     , mbStatus(true)
     122             :     , mpAcc(NULL)
     123             :     , mnWidth(0)
     124             :     , mnHeight(0)
     125             :     , mnColors(0)
     126             :     , mnCurAllPictHeight(0)
     127             :     , mnSumOfAllPictHeight(0)
     128             :     , mnBitsPerPixel(0)
     129             :     , mnLastPercent(0)
     130             :     , mnLatestIfdPos(0)
     131             :     , mnTagCount(0)
     132             :     , mnCurrentTagCountPos(0)
     133             :     , mnXResPos(0)
     134             :     , mnYResPos(0)
     135             :     , mnPalPos(0)
     136             :     , mnBitmapPos(0)
     137             :     , mnStripByteCountPos(0)
     138             :     , pTable(NULL)
     139             :     , pPrefix(NULL)
     140             :     , nDataSize(0)
     141             :     , nClearCode(0)
     142             :     , nEOICode(0)
     143             :     , nTableSize(0)
     144             :     , nCodeSize(0)
     145             :     , nOffset(0)
     146           0 :     , dwShift(0)
     147             : {
     148           0 : }
     149             : 
     150           0 : TIFFWriter::~TIFFWriter()
     151             : {
     152           0 : }
     153             : 
     154           0 : bool TIFFWriter::WriteTIFF( const Graphic& rGraphic, FilterConfigItem* pFilterConfigItem)
     155             : {
     156           0 :     if ( pFilterConfigItem )
     157             :     {
     158           0 :         xStatusIndicator = pFilterConfigItem->GetStatusIndicator();
     159           0 :         if ( xStatusIndicator.is() )
     160             :         {
     161           0 :             OUString aMsg;
     162           0 :             xStatusIndicator->start( aMsg, 100 );
     163             :         }
     164             :     }
     165             : 
     166           0 :     const sal_uInt16    nOldFormat = m_rOStm.GetNumberFormatInt();
     167           0 :     mnStreamOfs = m_rOStm.Tell();
     168             : 
     169             :     // we will use the BIG Endian Mode
     170             :     // TIFF header
     171           0 :     m_rOStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
     172           0 :     m_rOStm.WriteUInt32( 0x4d4d002a );      // TIFF identifier
     173           0 :     mnLatestIfdPos = m_rOStm.Tell();
     174           0 :     m_rOStm.WriteUInt32( 0 );
     175             : 
     176           0 :     Animation   aAnimation;
     177           0 :     Bitmap      aBmp;
     178             : 
     179           0 :     if( mbStatus )
     180             :     {
     181           0 :         if ( rGraphic.IsAnimated() )
     182           0 :             aAnimation = rGraphic.GetAnimation();
     183             :         else
     184             :         {
     185           0 :             AnimationBitmap aAnimationBitmap( rGraphic.GetBitmap(), Point(), Size() );
     186           0 :             aAnimation.Insert( aAnimationBitmap );
     187             :         }
     188             : 
     189             :         sal_uInt16 i;
     190           0 :         for ( i = 0; i < aAnimation.Count(); i++ )
     191           0 :             mnSumOfAllPictHeight += aAnimation.Get( i ).aBmpEx.GetSizePixel().Height();
     192             : 
     193           0 :         for ( i = 0; mbStatus && ( i < aAnimation.Count() ); i++ )
     194             :         {
     195           0 :             mnPalPos = 0;
     196           0 :             const AnimationBitmap& rAnimationBitmap = aAnimation.Get( i );
     197           0 :             aBmp = rAnimationBitmap.aBmpEx.GetBitmap();
     198           0 :             mpAcc = aBmp.AcquireReadAccess();
     199           0 :             if ( mpAcc )
     200             :             {
     201           0 :                 mnBitsPerPixel = aBmp.GetBitCount();
     202             : 
     203             :                 // export code below only handles four discrete cases
     204             :                 mnBitsPerPixel =
     205           0 :                     mnBitsPerPixel <= 1 ? 1 : mnBitsPerPixel <= 4 ? 4 : mnBitsPerPixel <= 8 ? 8 : 24;
     206             : 
     207           0 :                 if ( ImplWriteHeader( ( aAnimation.Count() > 0 ) ) )
     208             :                 {
     209           0 :                     Size aDestMapSize( 300, 300 );
     210           0 :                     const MapMode aMapMode( aBmp.GetPrefMapMode() );
     211           0 :                     if ( aMapMode.GetMapUnit() != MAP_PIXEL )
     212             :                     {
     213           0 :                         const Size aPrefSize( rGraphic.GetPrefSize() );
     214           0 :                         aDestMapSize = OutputDevice::LogicToLogic( aPrefSize, aMapMode, MAP_INCH );
     215             :                     }
     216           0 :                     ImplWriteResolution( mnXResPos, aDestMapSize.Width() );
     217           0 :                     ImplWriteResolution( mnYResPos, aDestMapSize.Height() );
     218           0 :                     if  ( mnPalPos )
     219           0 :                         ImplWritePalette();
     220           0 :                     ImplWriteBody();
     221             :                 }
     222           0 :                 sal_uInt32 nCurPos = m_rOStm.Tell();
     223           0 :                 m_rOStm.Seek( mnCurrentTagCountPos );
     224           0 :                 m_rOStm.WriteUInt16( mnTagCount );
     225           0 :                 m_rOStm.Seek( nCurPos );
     226             : 
     227           0 :                 aBmp.ReleaseAccess( mpAcc );
     228             :             }
     229             :             else
     230           0 :                 mbStatus = false;
     231             :         }
     232             :     }
     233           0 :     m_rOStm.SetNumberFormatInt( nOldFormat );
     234             : 
     235           0 :     if ( xStatusIndicator.is() )
     236           0 :         xStatusIndicator->end();
     237             : 
     238           0 :     return mbStatus;
     239             : }
     240             : 
     241             : 
     242             : 
     243           0 : void TIFFWriter::ImplCallback( sal_uInt32 nPercent )
     244             : {
     245           0 :     if ( xStatusIndicator.is() )
     246             :     {
     247           0 :         if( nPercent >= mnLastPercent + 3 )
     248             :         {
     249           0 :             mnLastPercent = nPercent;
     250           0 :             if ( nPercent <= 100 )
     251           0 :                 xStatusIndicator->setValue( nPercent );
     252             :         }
     253             :     }
     254           0 : }
     255             : 
     256             : 
     257             : 
     258             : 
     259           0 : bool TIFFWriter::ImplWriteHeader( bool bMultiPage )
     260             : {
     261           0 :     mnTagCount = 0;
     262           0 :     mnWidth = mpAcc->Width();
     263           0 :     mnHeight = mpAcc->Height();
     264             : 
     265           0 :     if ( mnWidth && mnHeight && mnBitsPerPixel && mbStatus )
     266             :     {
     267           0 :         sal_uInt32 nCurrentPos = m_rOStm.Tell();
     268           0 :         m_rOStm.Seek( mnLatestIfdPos );
     269           0 :         m_rOStm.WriteUInt32( ( nCurrentPos - mnStreamOfs ) );   // offset to the IFD
     270           0 :         m_rOStm.Seek( nCurrentPos );
     271             : 
     272             :         // (OFS8) TIFF image file directory (IFD)
     273           0 :         mnCurrentTagCountPos = m_rOStm.Tell();
     274           0 :         m_rOStm.WriteUInt16( 0 );               // the number of tagentrys is to insert later
     275             : 
     276           0 :         sal_uInt32 nSubFileFlags = 0;
     277           0 :         if ( bMultiPage )
     278           0 :             nSubFileFlags |= 2;
     279           0 :         ImplWriteTag( NewSubfileType, 4, 1, nSubFileFlags );
     280           0 :         ImplWriteTag( ImageWidth, 4, 1, mnWidth );
     281           0 :         ImplWriteTag( ImageLength, 4, 1, mnHeight);
     282           0 :         ImplWriteTag( BitsPerSample, 3, 1, ( mnBitsPerPixel == 24 ) ? 8 : mnBitsPerPixel );
     283           0 :         ImplWriteTag( Compression, 3, 1, 5 );
     284             :         sal_uInt8 nTemp;
     285           0 :         switch ( mnBitsPerPixel )
     286             :         {
     287             :             case 1 :
     288           0 :                 nTemp = 1;
     289           0 :                 break;
     290             :             case 4 :
     291             :             case 8 :
     292           0 :                 nTemp = 3;
     293           0 :                 break;
     294             :             case 24:
     295           0 :                 nTemp = 2;
     296           0 :                 break;
     297             :             default:
     298           0 :                 nTemp = 0;  // -Wall set a default...
     299           0 :                 break;
     300             :         }
     301           0 :         ImplWriteTag( PhotometricInterpretation, 3, 1, nTemp );
     302           0 :         mnBitmapPos = m_rOStm.Tell();
     303           0 :         ImplWriteTag( StripOffsets, 4, 1, 0 );
     304           0 :         ImplWriteTag( SamplesPerPixel, 3, 1, ( mnBitsPerPixel == 24 ) ? 3 : 1 );
     305           0 :         ImplWriteTag( RowsPerStrip, 4, 1, mnHeight );   //0xffffffff );
     306           0 :         mnStripByteCountPos = m_rOStm.Tell();
     307           0 :         ImplWriteTag( StripByteCounts, 4, 1, ( ( mnWidth * mnBitsPerPixel * mnHeight ) + 7 ) >> 3 );
     308           0 :         mnXResPos = m_rOStm.Tell();
     309           0 :         ImplWriteTag( XResolution, 5, 1, 0 );
     310           0 :         mnYResPos = m_rOStm.Tell();
     311           0 :         ImplWriteTag( YResolution, 5, 1, 0 );
     312           0 :         if ( mnBitsPerPixel != 1 )
     313           0 :             ImplWriteTag( PlanarConfiguration, 3, 1, 1 );   //  ( RGB ORDER )
     314           0 :         ImplWriteTag( ResolutionUnit, 3, 1, 2);             // Resolution Unit is Inch
     315           0 :         if ( ( mnBitsPerPixel == 4 ) || ( mnBitsPerPixel == 8 ) )
     316             :         {
     317           0 :             mnColors = mpAcc->GetPaletteEntryCount();
     318           0 :             mnPalPos = m_rOStm.Tell();
     319           0 :             ImplWriteTag( ColorMap, 3, 3 * mnColors, 0 );
     320             :         }
     321             : 
     322             :         // and last we write zero to close the num dir entries list
     323           0 :         mnLatestIfdPos = m_rOStm.Tell();
     324           0 :         m_rOStm.WriteUInt32( 0 );               // there are no more IFD
     325             :     }
     326             :     else
     327           0 :         mbStatus = false;
     328             : 
     329           0 :     return mbStatus;
     330             : }
     331             : 
     332             : 
     333             : 
     334           0 : void TIFFWriter::ImplWritePalette()
     335             : {
     336             :     sal_uInt16 i;
     337           0 :     sal_uLong nCurrentPos = m_rOStm.Tell();
     338           0 :     m_rOStm.Seek( mnPalPos + 8 );           // the palette tag entry needs the offset
     339           0 :     m_rOStm.WriteUInt32( nCurrentPos - mnStreamOfs );  // to the palette colors
     340           0 :     m_rOStm.Seek( nCurrentPos );
     341             : 
     342           0 :     for ( i = 0; i < mnColors; i++ )
     343             :     {
     344           0 :         const BitmapColor& rColor = mpAcc->GetPaletteColor( i );
     345           0 :         m_rOStm.WriteUInt16( ( rColor.GetRed() << 8 ) );
     346             :     }
     347           0 :     for ( i = 0; i < mnColors; i++ )
     348             :     {
     349           0 :         const BitmapColor& rColor = mpAcc->GetPaletteColor( i );
     350           0 :         m_rOStm.WriteUInt16( ( rColor.GetGreen() << 8 ) );
     351             :     }
     352           0 :     for ( i = 0; i < mnColors; i++ )
     353             :     {
     354           0 :         const BitmapColor& rColor = mpAcc->GetPaletteColor( i );
     355           0 :         m_rOStm.WriteUInt16( ( rColor.GetBlue() << 8 ) );
     356             :     }
     357           0 : }
     358             : 
     359             : 
     360             : 
     361           0 : bool TIFFWriter::ImplWriteBody()
     362             : {
     363           0 :     sal_uInt8   nTemp = 0;
     364             :     sal_uInt8    nShift;
     365             :     sal_uLong   j, x, y;
     366             : 
     367           0 :     sal_uLong nGfxBegin = m_rOStm.Tell();
     368           0 :     m_rOStm.Seek( mnBitmapPos + 8 );        // the strip offset tag entry needs the offset
     369           0 :     m_rOStm.WriteUInt32( nGfxBegin - mnStreamOfs );        // to the bitmap data
     370           0 :     m_rOStm.Seek( nGfxBegin );
     371             : 
     372           0 :     StartCompression();
     373             : 
     374           0 :     switch( mnBitsPerPixel )
     375             :     {
     376             :         case 24 :
     377             :         {
     378           0 :             for ( y = 0; y < mnHeight; y++, mnCurAllPictHeight++ )
     379             :             {
     380           0 :                 ImplCallback( 100 * mnCurAllPictHeight / mnSumOfAllPictHeight );
     381           0 :                 for ( x = 0; x < mnWidth; x++ )
     382             :                 {
     383           0 :                     const BitmapColor& rColor = mpAcc->GetPixel( y, x );
     384           0 :                     Compress( rColor.GetRed() );
     385           0 :                     Compress( rColor.GetGreen() );
     386           0 :                     Compress( rColor.GetBlue() );
     387           0 :                 }
     388             :             }
     389             :         }
     390           0 :         break;
     391             : 
     392             :         case 8 :
     393             :         {
     394           0 :             for ( y = 0; y < mnHeight; y++, mnCurAllPictHeight++ )
     395             :             {
     396           0 :                 ImplCallback( 100 * mnCurAllPictHeight / mnSumOfAllPictHeight );
     397           0 :                 for ( x = 0; x < mnWidth; x++ )
     398             :                 {
     399           0 :                     Compress( mpAcc->GetPixelIndex( y, x ) );
     400             :                 }
     401             :             }
     402             :         }
     403           0 :         break;
     404             : 
     405             :         case 4 :
     406             :         {
     407           0 :             for ( nShift = 0, y = 0; y < mnHeight; y++, mnCurAllPictHeight++ )
     408             :             {
     409           0 :                 ImplCallback( 100 * mnCurAllPictHeight / mnSumOfAllPictHeight );
     410           0 :                 for ( x = 0; x < mnWidth; x++, nShift++ )
     411             :                 {
     412           0 :                     if (!( nShift & 1 ))
     413           0 :                         nTemp = ( mpAcc->GetPixelIndex( y, x ) << 4 );
     414             :                     else
     415           0 :                         Compress( (sal_uInt8)( nTemp | ( mpAcc->GetPixelIndex( y, x ) & 0xf ) ) );
     416             :                 }
     417           0 :                 if ( nShift & 1 )
     418           0 :                     Compress( nTemp );
     419             :             }
     420             :         }
     421           0 :         break;
     422             : 
     423             :         case 1 :
     424             :         {
     425           0 :             j = 1;
     426           0 :             for ( y = 0; y < mnHeight; y++, mnCurAllPictHeight++ )
     427             :             {
     428           0 :                 ImplCallback( 100 * mnCurAllPictHeight / mnSumOfAllPictHeight );
     429           0 :                 for ( x = 0; x < mnWidth; x++)
     430             :                 {
     431           0 :                     j <<= 1;
     432           0 :                     j |= ( ( ~mpAcc->GetPixelIndex( y, x ) ) & 1 );
     433           0 :                     if ( j & 0x100 )
     434             :                     {
     435           0 :                         Compress( (sal_uInt8)j );
     436           0 :                         j = 1;
     437             :                     }
     438             :                 }
     439           0 :                 if ( j != 1 )
     440             :                 {
     441           0 :                     Compress( (sal_uInt8)(j << ( ( ( x & 7) ^ 7 ) + 1 ) ) );
     442           0 :                     j = 1;
     443             :                 }
     444             :             }
     445             :         }
     446           0 :         break;
     447             : 
     448             :         default:
     449             :         {
     450           0 :             mbStatus = false;
     451             :         }
     452           0 :         break;
     453             :     }
     454             : 
     455           0 :     EndCompression();
     456             : 
     457           0 :     if ( mnStripByteCountPos && mbStatus )
     458             :     {
     459           0 :         sal_uLong nGfxEnd = m_rOStm.Tell();
     460           0 :         m_rOStm.Seek( mnStripByteCountPos + 8 );
     461           0 :         m_rOStm.WriteUInt32( nGfxEnd - nGfxBegin );      // mnStripByteCountPos needs the size of the compression data
     462           0 :         m_rOStm.Seek( nGfxEnd );
     463             :     }
     464           0 :     return mbStatus;
     465             : }
     466             : 
     467             : 
     468             : 
     469           0 : void TIFFWriter::ImplWriteResolution( sal_uLong nStreamPos, sal_uInt32 nResolutionUnit )
     470             : {
     471           0 :     sal_uLong nCurrentPos = m_rOStm.Tell();
     472           0 :     m_rOStm.Seek( nStreamPos + 8 );
     473           0 :     m_rOStm.WriteUInt32( nCurrentPos - mnStreamOfs );
     474           0 :     m_rOStm.Seek( nCurrentPos );
     475           0 :     m_rOStm.WriteUInt32( 1 );
     476           0 :     m_rOStm.WriteUInt32( nResolutionUnit );
     477           0 : }
     478             : 
     479             : 
     480             : 
     481           0 : void TIFFWriter::ImplWriteTag( sal_uInt16 nTagID, sal_uInt16 nDataType, sal_uInt32 nNumberOfItems, sal_uInt32 nValue)
     482             : {
     483           0 :         mnTagCount++;
     484             : 
     485           0 :         m_rOStm.WriteUInt16( nTagID );
     486           0 :         m_rOStm.WriteUInt16( nDataType );
     487           0 :         m_rOStm.WriteUInt32( nNumberOfItems );
     488           0 :         if ( nDataType == 3 )
     489           0 :             nValue <<=16;           // in Big Endian Mode WORDS needed to be shifted to a DWORD
     490           0 :         m_rOStm.WriteUInt32( nValue );
     491           0 : }
     492             : 
     493             : 
     494             : 
     495           0 : inline void TIFFWriter::WriteBits( sal_uInt16 nCode, sal_uInt16 nCodeLen )
     496             : {
     497           0 :     dwShift |= ( nCode << ( nOffset - nCodeLen ) );
     498           0 :     nOffset -= nCodeLen;
     499           0 :     while ( nOffset < 24 )
     500             :     {
     501           0 :         m_rOStm.WriteUChar( ( dwShift >> 24 ) );
     502           0 :         dwShift <<= 8;
     503           0 :         nOffset += 8;
     504             :     }
     505           0 :     if ( nCode == 257 && nOffset != 32 )
     506             :     {
     507           0 :         m_rOStm.WriteUChar( ( dwShift >> 24 ) );
     508             :     }
     509           0 : }
     510             : 
     511             : 
     512             : 
     513           0 : void TIFFWriter::StartCompression()
     514             : {
     515             :     sal_uInt16 i;
     516           0 :     nDataSize = 8;
     517             : 
     518           0 :     nClearCode = 1 << nDataSize;
     519           0 :     nEOICode = nClearCode + 1;
     520           0 :     nTableSize = nEOICode + 1;
     521           0 :     nCodeSize = nDataSize + 1;
     522             : 
     523           0 :     nOffset = 32;                       // number of free bits in dwShift
     524           0 :     dwShift = 0;
     525             : 
     526           0 :     pTable = new TIFFLZWCTreeNode[ 4096 ];
     527             : 
     528           0 :     for ( i = 0; i < 4096; i++)
     529             :     {
     530           0 :         pTable[ i ].pBrother = pTable[ i ].pFirstChild = NULL;
     531           0 :         pTable[ i ].nValue = (sal_uInt8)( pTable[ i ].nCode = i );
     532             :     }
     533             : 
     534           0 :     pPrefix = NULL;
     535           0 :     WriteBits( nClearCode, nCodeSize );
     536           0 : }
     537             : 
     538             : 
     539             : 
     540           0 : void TIFFWriter::Compress( sal_uInt8 nCompThis )
     541             : {
     542             :     TIFFLZWCTreeNode*    p;
     543             :     sal_uInt16              i;
     544             :     sal_uInt8               nV;
     545             : 
     546           0 :     if( !pPrefix )
     547             :     {
     548           0 :         pPrefix = pTable + nCompThis;
     549             :     }
     550             :     else
     551             :     {
     552           0 :         nV = nCompThis;
     553           0 :         for( p = pPrefix->pFirstChild; p != NULL; p = p->pBrother )
     554             :         {
     555           0 :             if ( p->nValue == nV )
     556           0 :                 break;
     557             :         }
     558             : 
     559           0 :         if( p )
     560           0 :             pPrefix = p;
     561             :         else
     562             :         {
     563           0 :             WriteBits( pPrefix->nCode, nCodeSize );
     564             : 
     565           0 :             if ( nTableSize == 409 )
     566             :             {
     567           0 :                 WriteBits( nClearCode, nCodeSize );
     568             : 
     569           0 :                 for ( i = 0; i < nClearCode; i++ )
     570           0 :                     pTable[ i ].pFirstChild = NULL;
     571             : 
     572           0 :                 nCodeSize = nDataSize + 1;
     573           0 :                 nTableSize = nEOICode + 1;
     574             :             }
     575             :             else
     576             :             {
     577           0 :                 if( nTableSize == (sal_uInt16)( ( 1 << nCodeSize ) - 1 ) )
     578           0 :                     nCodeSize++;
     579             : 
     580           0 :                 p = pTable + ( nTableSize++ );
     581           0 :                 p->pBrother = pPrefix->pFirstChild;
     582           0 :                 pPrefix->pFirstChild = p;
     583           0 :                 p->nValue = nV;
     584           0 :                 p->pFirstChild = NULL;
     585             :             }
     586             : 
     587           0 :             pPrefix = pTable + nV;
     588             :         }
     589             :     }
     590           0 : }
     591             : 
     592             : 
     593             : 
     594           0 : void TIFFWriter::EndCompression()
     595             : {
     596           0 :     if( pPrefix )
     597           0 :         WriteBits( pPrefix->nCode, nCodeSize );
     598             : 
     599           0 :     WriteBits( nEOICode, nCodeSize );
     600           0 :     delete[] pTable;
     601           0 : }
     602             : 
     603             : 
     604             : 
     605             : // this needs to be kept in sync with
     606             : // ImpFilterLibCacheEntry::GetImportFunction() from
     607             : // vcl/source/filter/graphicfilter.cxx
     608             : #if defined(DISABLE_DYNLOADING)
     609             : #define GraphicExport etiGraphicExport
     610             : #endif
     611             : 
     612             : extern "C" SAL_DLLPUBLIC_EXPORT bool SAL_CALL
     613           0 : GraphicExport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pFilterConfigItem )
     614             : {
     615           0 :     TIFFWriter aWriter(rStream);
     616           0 :     return aWriter.WriteTIFF( rGraphic, pFilterConfigItem );
     617           0 : }
     618             : 
     619             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10