LibreOffice Module vcl (master)  1
ccidecom.hxx
Go to the documentation of this file.
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 INCLUDED_FILTER_SOURCE_GRAPHICFILTER_ITIFF_CCIDECOM_HXX
21 #define INCLUDED_FILTER_SOURCE_GRAPHICFILTER_ITIFF_CCIDECOM_HXX
22 
23 #include <sal/types.h>
24 #include <array>
25 #include <memory>
26 
27 #define CCI_OPTION_2D 1 // 2D compression (instead of 1D)
28 #define CCI_OPTION_EOL 2 // There are EOL-Codes at the end of each line.
29 #define CCI_OPTION_BYTEALIGNEOL 4 // Filling bits before each EOL-Code, so that
30  // the end of EOL is bytes aligned
31 #define CCI_OPTION_BYTEALIGNROW 8 // Rows always start byte aligned
32 #define CCI_OPTION_INVERSEBITORDER 16
33 
34 // Entry in the Huffman table:
36  sal_uInt16 nValue; // The data value.
37  sal_uInt16 nCode; // The code through which the data value is represented.
38  sal_uInt16 nCodeBits; // Size of the code in bits.
39 };
40 
41 // Entry in a hash table for daft decoding.
43  sal_uInt16 nValue;
44  sal_uInt16 nCodeBits;
45 };
46 
47 class SvStream;
48 
50 {
51  bool m_bSuccess;
53  DecompressStatus(bool bSuccess, bool bBufferUnchanged)
54  : m_bSuccess(bSuccess), m_bBufferUnchanged(bBufferUnchanged)
55  {
56  }
57 };
58 
60 
61 public:
62 
63  CCIDecompressor( sal_uInt32 nOptions, sal_uInt32 nImageWidth );
65 
66  void StartDecompression( SvStream & rIStream );
67 
68  DecompressStatus DecompressScanline(sal_uInt8 * pTarget, sal_uInt64 nTargetBits, bool bLastLine);
69 
70 private:
71 
72  void MakeLookUp(const CCIHuffmanTableEntry * pHufTab,
73  const CCIHuffmanTableEntry * pHufTabSave,
74  CCILookUpTableEntry * pLookUp,
75  sal_uInt16 nHuffmanTableSize,
76  sal_uInt16 nMaxCodeBits);
77 
78  bool ReadEOL();
79 
80  bool Read2DTag();
81 
83 
84  sal_uInt16 ReadCodeAndDecode(const CCILookUpTableEntry * pLookUp,
85  sal_uInt16 nMaxCodeBits);
86 
87  static void FillBits(sal_uInt8 * pTarget, sal_uInt16 nTargetBits,
88  sal_uInt16 nBitPos, sal_uInt16 nNumBits,
89  sal_uInt8 nBlackOrWhite);
90 
91  static sal_uInt16 CountBits(const sal_uInt8 * pData, sal_uInt16 nDataSizeBits,
92  sal_uInt16 nBitPos, sal_uInt8 nBlackOrWhite);
93 
94  //returns true if pTarget was unmodified
95  bool Read1DScanlineData(sal_uInt8 * pTarget, sal_uInt16 nTargetBits);
96  bool Read2DScanlineData(sal_uInt8 * pTarget, sal_uInt16 nTargetBits);
97 
98  bool bTableBad;
99 
100  bool bStatus;
101 
102  std::unique_ptr<sal_uInt8[]> pByteSwap;
103 
105 
106  sal_uInt32 nEOLCount;
107 
108  sal_uInt32 nWidth;
109 
110  sal_uInt32 nOptions;
111 
112  bool bFirstEOL;
113 
114  std::array<CCILookUpTableEntry, 1<<13> pWhiteLookUp;
115  std::array<CCILookUpTableEntry, 1<<13> pBlackLookUp;
116  std::array<CCILookUpTableEntry, 1<<10> p2DModeLookUp;
117  std::array<CCILookUpTableEntry, 1<<11> pUncompLookUp;
118 
119  sal_uInt32 nInputBitsBuf;
120  sal_uInt16 nInputBitsBufSize;
121 
122  std::unique_ptr<sal_uInt8[]> pLastLine;
123  sal_uInt64 nLastLineSize;
124 };
125 
126 
127 #endif
128 
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< ContentProperties > pData
CCIDecompressor(sal_uInt32 nOptions, sal_uInt32 nImageWidth)
Definition: ccidecom.cxx:567
sal_uInt16 ReadCodeAndDecode(const CCILookUpTableEntry *pLookUp, sal_uInt16 nMaxCodeBits)
Definition: ccidecom.cxx:827
sal_uInt16 nCode
Definition: ccidecom.hxx:37
sal_uInt64 nLastLineSize
Definition: ccidecom.hxx:123
std::unique_ptr< sal_uInt8[]> pByteSwap
Definition: ccidecom.hxx:102
DecompressStatus(bool bSuccess, bool bBufferUnchanged)
Definition: ccidecom.hxx:53
void StartDecompression(SvStream &rIStream)
Definition: ccidecom.cxx:602
std::array< CCILookUpTableEntry, 1<< 13 > pWhiteLookUp
Definition: ccidecom.hxx:114
sal_uInt8 ReadBlackOrWhite()
Definition: ccidecom.cxx:810
std::array< CCILookUpTableEntry, 1<< 11 > pUncompLookUp
Definition: ccidecom.hxx:117
DecompressStatus DecompressScanline(sal_uInt8 *pTarget, sal_uInt64 nTargetBits, bool bLastLine)
Definition: ccidecom.cxx:614
sal_uInt16 nValue
Definition: ccidecom.hxx:43
sal_uInt32 nWidth
Definition: ccidecom.hxx:108
sal_uInt32 nEOLCount
Definition: ccidecom.hxx:106
bool m_bBufferUnchanged
Definition: ccidecom.hxx:52
std::array< CCILookUpTableEntry, 1<< 13 > pBlackLookUp
Definition: ccidecom.hxx:115
void MakeLookUp(const CCIHuffmanTableEntry *pHufTab, const CCIHuffmanTableEntry *pHufTabSave, CCILookUpTableEntry *pLookUp, sal_uInt16 nHuffmanTableSize, sal_uInt16 nMaxCodeBits)
Definition: ccidecom.cxx:709
bool Read2DTag()
Definition: ccidecom.cxx:794
sal_uInt32 nOptions
Definition: ccidecom.hxx:110
sal_uInt32 nInputBitsBuf
Definition: ccidecom.hxx:119
sal_uInt16 nCodeBits
Definition: ccidecom.hxx:44
static void FillBits(sal_uInt8 *pTarget, sal_uInt16 nTargetBits, sal_uInt16 nBitPos, sal_uInt16 nNumBits, sal_uInt8 nBlackOrWhite)
Definition: ccidecom.cxx:849
unsigned char sal_uInt8
bool Read2DScanlineData(sal_uInt8 *pTarget, sal_uInt16 nTargetBits)
Definition: ccidecom.cxx:1002
static sal_uInt16 CountBits(const sal_uInt8 *pData, sal_uInt16 nDataSizeBits, sal_uInt16 nBitPos, sal_uInt8 nBlackOrWhite)
Definition: ccidecom.cxx:873
std::unique_ptr< sal_uInt8[]> pLastLine
Definition: ccidecom.hxx:122
sal_uInt16 nValue
Definition: ccidecom.hxx:36
sal_uInt16 nInputBitsBufSize
Definition: ccidecom.hxx:120
std::array< CCILookUpTableEntry, 1<< 10 > p2DModeLookUp
Definition: ccidecom.hxx:116
bool Read1DScanlineData(sal_uInt8 *pTarget, sal_uInt16 nTargetBits)
Definition: ccidecom.cxx:903
sal_uInt16 nCodeBits
Definition: ccidecom.hxx:38
SvStream * pIStream
Definition: ccidecom.hxx:104