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 #pragma once
21 
22 #include <sal/types.h>
23 #include <array>
24 #include <memory>
25 
26 #define CCI_OPTION_2D 1 // 2D compression (instead of 1D)
27 #define CCI_OPTION_EOL 2 // There are EOL-Codes at the end of each line.
28 #define CCI_OPTION_BYTEALIGNEOL 4 // Filling bits before each EOL-Code, so that
29  // the end of EOL is bytes aligned
30 #define CCI_OPTION_BYTEALIGNROW 8 // Rows always start byte aligned
31 #define CCI_OPTION_INVERSEBITORDER 16
32 
33 // Entry in the Huffman table:
35  sal_uInt16 nValue; // The data value.
36  sal_uInt16 nCode; // The code through which the data value is represented.
37  sal_uInt16 nCodeBits; // Size of the code in bits.
38 };
39 
40 // Entry in a hash table for daft decoding.
42  sal_uInt16 nValue;
43  sal_uInt16 nCodeBits;
44 };
45 
46 class SvStream;
47 
49 {
50  bool m_bSuccess;
52  DecompressStatus(bool bSuccess, bool bBufferUnchanged)
53  : m_bSuccess(bSuccess), m_bBufferUnchanged(bBufferUnchanged)
54  {
55  }
56 };
57 
59 
60 public:
61 
62  CCIDecompressor( sal_uInt32 nOptions, sal_uInt32 nImageWidth );
64 
65  void StartDecompression( SvStream & rIStream );
66 
67  DecompressStatus DecompressScanline(sal_uInt8 * pTarget, sal_uInt64 nTargetBits, bool bLastLine);
68 
69 private:
70 
71  void MakeLookUp(const CCIHuffmanTableEntry * pHufTab,
72  const CCIHuffmanTableEntry * pHufTabSave,
73  CCILookUpTableEntry * pLookUp,
74  sal_uInt16 nHuffmanTableSize,
75  sal_uInt16 nMaxCodeBits);
76 
77  bool ReadEOL();
78 
79  bool Read2DTag();
80 
82 
83  sal_uInt16 ReadCodeAndDecode(const CCILookUpTableEntry * pLookUp,
84  sal_uInt16 nMaxCodeBits);
85 
86  static void FillBits(sal_uInt8 * pTarget, sal_uInt16 nTargetBits,
87  sal_uInt16 nBitPos, sal_uInt16 nNumBits,
88  sal_uInt8 nBlackOrWhite);
89 
90  static sal_uInt16 CountBits(const sal_uInt8 * pData, sal_uInt16 nDataSizeBits,
91  sal_uInt16 nBitPos, sal_uInt8 nBlackOrWhite);
92 
93  //returns true if pTarget was unmodified
94  bool Read1DScanlineData(sal_uInt8 * pTarget, sal_uInt16 nTargetBits);
95  bool Read2DScanlineData(sal_uInt8 * pTarget, sal_uInt16 nTargetBits);
96 
98 
99  bool m_bStatus;
100 
101  std::unique_ptr<sal_uInt8[]> m_pByteSwap;
102 
104 
105  sal_uInt32 m_nEOLCount;
106 
107  sal_uInt32 m_nWidth;
108 
109  sal_uInt32 m_nOptions;
110 
112 
113  std::array<CCILookUpTableEntry, 1<<13> m_pWhiteLookUp;
114  std::array<CCILookUpTableEntry, 1<<13> m_pBlackLookUp;
115  std::array<CCILookUpTableEntry, 1<<10> m_p2DModeLookUp;
116  std::array<CCILookUpTableEntry, 1<<11> m_pUncompLookUp;
117 
118  sal_uInt32 m_nInputBitsBuf;
120 
121  std::unique_ptr<sal_uInt8[]> m_pLastLine;
122  sal_uInt64 m_nLastLineSize;
123 };
124 
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CCIDecompressor(sal_uInt32 nOptions, sal_uInt32 nImageWidth)
Definition: ccidecom.cxx:567
sal_uInt16 ReadCodeAndDecode(const CCILookUpTableEntry *pLookUp, sal_uInt16 nMaxCodeBits)
Definition: ccidecom.cxx:827
std::unique_ptr< sal_Int32[]> pData
sal_uInt16 m_nInputBitsBufSize
Definition: ccidecom.hxx:119
std::array< CCILookUpTableEntry, 1<< 10 > m_p2DModeLookUp
Definition: ccidecom.hxx:115
sal_uInt16 nCode
Definition: ccidecom.hxx:36
std::array< CCILookUpTableEntry, 1<< 13 > m_pBlackLookUp
Definition: ccidecom.hxx:114
sal_uInt32 m_nOptions
Definition: ccidecom.hxx:109
DecompressStatus(bool bSuccess, bool bBufferUnchanged)
Definition: ccidecom.hxx:52
std::array< CCILookUpTableEntry, 1<< 11 > m_pUncompLookUp
Definition: ccidecom.hxx:116
void StartDecompression(SvStream &rIStream)
Definition: ccidecom.cxx:602
sal_uInt8 ReadBlackOrWhite()
Definition: ccidecom.cxx:810
sal_uInt32 m_nEOLCount
Definition: ccidecom.hxx:105
DecompressStatus DecompressScanline(sal_uInt8 *pTarget, sal_uInt64 nTargetBits, bool bLastLine)
Definition: ccidecom.cxx:614
std::unique_ptr< sal_uInt8[]> m_pLastLine
Definition: ccidecom.hxx:121
sal_uInt16 nValue
Definition: ccidecom.hxx:42
std::array< CCILookUpTableEntry, 1<< 13 > m_pWhiteLookUp
Definition: ccidecom.hxx:113
sal_uInt32 m_nWidth
Definition: ccidecom.hxx:107
bool m_bBufferUnchanged
Definition: ccidecom.hxx:51
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_uInt16 nCodeBits
Definition: ccidecom.hxx:43
SvStream * m_pIStream
Definition: ccidecom.hxx:103
sal_uInt32 m_nInputBitsBuf
Definition: ccidecom.hxx:118
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[]> m_pByteSwap
Definition: ccidecom.hxx:101
sal_uInt16 nValue
Definition: ccidecom.hxx:35
bool Read1DScanlineData(sal_uInt8 *pTarget, sal_uInt16 nTargetBits)
Definition: ccidecom.cxx:903
sal_uInt16 nCodeBits
Definition: ccidecom.hxx:37
sal_uInt64 m_nLastLineSize
Definition: ccidecom.hxx:122