libpgf
6.13.45
PGF - Progressive Graphics File
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Encoder.h
Go to the documentation of this file.
1
/*
2
* The Progressive Graphics File; http://www.libpgf.org
3
*
4
* $Date: 2006-06-04 22:05:59 +0200 (So, 04 Jun 2006) $
5
* $Revision: 229 $
6
*
7
* This file Copyright (C) 2006 xeraina GmbH, Switzerland
8
*
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
11
* as published by the Free Software Foundation; either version 2.1
12
* of the License, or (at your option) any later version.
13
*
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
18
*
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
*/
23
28
29
#ifndef PGF_ENCODER_H
30
#define PGF_ENCODER_H
31
32
#include "
PGFstream.h
"
33
#include "
BitStream.h
"
34
#include "
Subband.h
"
35
#include "
WaveletTransform.h
"
36
38
// Constants
39
#define BufferLen (BufferSize/WordWidth)
40
#define CodeBufferLen BufferSize
41
42
43
44
45
46
class
CEncoder
{
51
class
CMacroBlock
{
52
public
:
56
CMacroBlock
(
CEncoder
*encoder)
57
#pragma warning( suppress : 4351 )
58
:
m_value
()
59
,
m_codeBuffer
()
60
,
m_header
(0)
61
,
m_encoder
(encoder)
62
,
m_sigFlagVector
()
63
{
64
ASSERT(
m_encoder
);
65
Init
(-1);
66
}
67
71
void
Init
(
int
lastLevelIndex) {
// initialize for reusage
72
m_valuePos
= 0;
73
m_maxAbsValue
= 0;
74
m_codePos
= 0;
75
m_lastLevelIndex
= lastLevelIndex;
76
}
77
82
void
BitplaneEncode
();
83
84
DataT
m_value
[
BufferSize
];
85
UINT32
m_codeBuffer
[
CodeBufferLen
];
86
ROIBlockHeader
m_header
;
87
UINT32
m_valuePos
;
88
UINT32
m_maxAbsValue
;
89
UINT32
m_codePos
;
90
int
m_lastLevelIndex
;
91
92
private
:
93
UINT32
RLESigns
(UINT32 codePos, UINT32* signBits, UINT32 signLen);
94
UINT32
DecomposeBitplane
(UINT32 bufferSize, UINT32 planeMask, UINT32 codePos, UINT32* sigBits, UINT32* refBits, UINT32* signBits, UINT32& signLen, UINT32& codeLen);
95
UINT8
NumberOfBitplanes
();
96
bool
GetBitAtPos
(UINT32 pos, UINT32 planeMask)
const
{
return
(abs(
m_value
[pos]) & planeMask) > 0; }
97
98
CEncoder
*
m_encoder
;
// encoder instance
99
bool
m_sigFlagVector
[
BufferSize
+1];
// see paper from Malvar, Fast Progressive Wavelet Coder
100
};
101
102
public
:
112
CEncoder
(
CPGFStream
* stream,
PGFPreHeader
preHeader,
PGFHeader
header,
const
PGFPostHeader
& postHeader,
113
UINT64& userDataPos,
bool
useOMP) THROW_;
// throws IOException
114
117
~CEncoder
();
118
121
void
FavorSpeedOverSize
() {
m_favorSpeed
=
true
; }
122
126
void
Flush
() THROW_;
127
132
void
UpdatePostHeaderSize
(
PGFPreHeader
preHeader) THROW_;
133
139
UINT32
WriteLevelLength
(UINT32*& levelLength) THROW_;
140
145
UINT32
UpdateLevelLength
() THROW_;
146
157
void
Partition
(
CSubband
* band,
int
width,
int
height,
int
startPos,
int
pitch) THROW_;
158
162
void
SetEncodedLevel
(
int
currentLevel) { ASSERT(currentLevel >= 0);
m_currentBlock
->
m_lastLevelIndex
=
m_nLevels
- currentLevel - 1;
m_forceWriting
=
true
; }
163
169
void
WriteValue
(
CSubband
* band,
int
bandPos) THROW_;
170
174
INT64
ComputeHeaderLength
()
const
{
return
m_levelLengthPos
-
m_startPosition
; }
175
179
INT64
ComputeBufferLength
()
const
{
return
m_stream
->
GetPos
() -
m_bufferStartPos
; }
180
184
INT64
ComputeOffset
()
const
{
return
m_stream
->
GetPos
() -
m_levelLengthPos
; }
185
188
void
SetBufferStartPos
() {
m_bufferStartPos
=
m_stream
->
GetPos
(); }
189
190
#ifdef __PGFROISUPPORT__
191
192
193
194
void
EncodeTileBuffer() THROW_ { ASSERT(
m_currentBlock
&&
m_currentBlock
->
m_valuePos
>= 0 &&
m_currentBlock
->
m_valuePos
<=
BufferSize
);
EncodeBuffer
(
ROIBlockHeader
(
m_currentBlock
->
m_valuePos
,
true
)); }
195
198
void
SetROI() { m_roi =
true
; }
199
#endif
200
201
#ifdef TRACE
202
void
DumpBuffer()
const
;
203
#endif
204
205
private
:
206
void
EncodeBuffer
(
ROIBlockHeader
h) THROW_;
// throws IOException
207
void
WriteMacroBlock
(CMacroBlock* block) THROW_;
// throws IOException
208
209
CPGFStream
*
m_stream
;
210
UINT64
m_startPosition
;
211
UINT64
m_levelLengthPos
;
212
UINT64
m_bufferStartPos
;
213
214
CMacroBlock
**
m_macroBlocks
;
215
int
m_macroBlockLen
;
216
int
m_lastMacroBlock
;
217
CMacroBlock
*
m_currentBlock
;
218
219
UINT32*
m_levelLength
;
220
int
m_currLevelIndex
;
221
UINT8
m_nLevels
;
222
bool
m_favorSpeed
;
223
bool
m_forceWriting
;
224
#ifdef __PGFROISUPPORT__
225
bool
m_roi;
226
#endif
227
};
228
229
#endif //PGF_ENCODER
src
Encoder.h
Generated on Tue Nov 12 2013 00:48:40 for libpgf by
1.8.3.1