Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
JBig2_HtrdProc.cpp
Go to the documentation of this file.
1
// Copyright 2015 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7
#
include
"core/fxcodec/jbig2/JBig2_HtrdProc.h"
8
9
#
include
<
algorithm
>
10
#
include
<
utility
>
11
12
#
include
"core/fxcodec/jbig2/JBig2_BitStream.h"
13
#
include
"core/fxcodec/jbig2/JBig2_GrdProc.h"
14
#
include
"core/fxcodec/jbig2/JBig2_Image.h"
15
16
CJBig2_HTRDProc
::
CJBig2_HTRDProc
() =
default
;
17
18
CJBig2_HTRDProc
::~
CJBig2_HTRDProc
() =
default
;
19
20
std
::
unique_ptr
<
CJBig2_Image
>
CJBig2_HTRDProc
::
DecodeArith
(
21
CJBig2_ArithDecoder
* pArithDecoder,
22
pdfium::span<JBig2ArithCtx> gbContexts,
23
PauseIndicatorIface
* pPause) {
24
std::unique_ptr<CJBig2_Image> HSKIP;
25
if
(
HENABLESKIP
== 1) {
26
HSKIP =
std
::make_unique<
CJBig2_Image
>(
HGW
,
HGH
);
27
for
(uint32_t mg = 0; mg <
HGH
; ++mg) {
28
for
(uint32_t ng = 0; ng <
HGW
; ++ng) {
29
int32_t x = (
HGX
+ mg *
HRY
+ ng *
HRX
) >> 8;
30
int32_t y = (
HGY
+ mg *
HRX
- ng *
HRY
) >> 8;
31
if
((x +
HPW
<= 0) | (x >=
static_cast
<int32_t>(
HBW
)) | (y +
HPH
<= 0) |
32
(y >=
static_cast
<int32_t>(
HPH
))) {
33
HSKIP->SetPixel(ng, mg, 1);
34
}
else
{
35
HSKIP->SetPixel(ng, mg, 0);
36
}
37
}
38
}
39
}
40
uint32_t HBPP = 1;
41
while
(
static_cast
<uint32_t>(1 << HBPP) <
HNUMPATS
)
42
++HBPP;
43
44
CJBig2_GRDProc
GRD;
45
GRD
.
MMR
=
HMMR
;
46
GRD
.
GBW
=
HGW
;
47
GRD
.
GBH
=
HGH
;
48
GRD
.
GBTEMPLATE
=
HTEMPLATE
;
49
GRD
.
TPGDON
=
false
;
50
GRD
.
USESKIP
=
HENABLESKIP
;
51
GRD.SKIP = HSKIP.get();
52
if
(
HTEMPLATE
<= 1)
53
GRD.GBAT[0] = 3;
54
else
55
GRD.GBAT[0] = 2;
56
GRD.GBAT[1] = -1;
57
if
(GRD
.
GBTEMPLATE
== 0) {
58
GRD.GBAT[2] = -3;
59
GRD.GBAT[3] = -1;
60
GRD.GBAT[4] = 2;
61
GRD.GBAT[5] = -2;
62
GRD.GBAT[6] = -2;
63
GRD.GBAT[7] = -2;
64
}
65
66
uint8_t GSBPP =
static_cast
<uint8_t>(HBPP);
67
std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP);
68
for
(int32_t i = GSBPP - 1; i >= 0; --i) {
69
std::unique_ptr<CJBig2_Image> pImage;
70
CJBig2_GRDProc
::
ProgressiveArithDecodeState
state;
71
state.pImage = &pImage;
72
state.pArithDecoder = pArithDecoder;
73
state.gbContexts = gbContexts;
74
state.pPause =
nullptr
;
75
FXCODEC_STATUS
status = GRD
.
StartDecodeArith
(
&state
)
;
76
state.pPause = pPause;
77
while
(status ==
FXCODEC_STATUS
::
kDecodeToBeContinued
)
78
status = GRD
.
ContinueDecode
(
&state
)
;
79
if
(!pImage)
80
return
nullptr
;
81
82
GSPLANES[i] =
std
::move(pImage);
83
if
(i < GSBPP - 1)
84
GSPLANES[i]->ComposeFrom(0, 0, GSPLANES[i + 1].get(),
JBIG2_COMPOSE_XOR
);
85
}
86
return
DecodeImage(GSPLANES);
87
}
88
89
std
::
unique_ptr
<
CJBig2_Image
>
CJBig2_HTRDProc
::
DecodeMMR
(
90
CJBig2_BitStream
* pStream) {
91
uint32_t HBPP = 1;
92
while
(
static_cast
<uint32_t>(1 << HBPP) <
HNUMPATS
)
93
++HBPP;
94
95
CJBig2_GRDProc
GRD;
96
GRD
.
MMR
=
HMMR
;
97
GRD
.
GBW
=
HGW
;
98
GRD
.
GBH
=
HGH
;
99
100
uint8_t GSBPP =
static_cast
<uint8_t>(HBPP);
101
std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP);
102
GRD.StartDecodeMMR(&GSPLANES[GSBPP - 1], pStream);
103
if
(!GSPLANES[GSBPP - 1])
104
return
nullptr
;
105
106
pStream
->
alignByte
(
)
;
107
pStream
->
addOffset
(
3
)
;
108
for
(int32_t J = GSBPP - 2; J >= 0; --J) {
109
GRD.StartDecodeMMR(&GSPLANES[J], pStream);
110
if
(!GSPLANES[J])
111
return
nullptr
;
112
113
pStream
->
alignByte
(
)
;
114
pStream
->
addOffset
(
3
)
;
115
GSPLANES[J]->ComposeFrom(0, 0, GSPLANES[J + 1].get(),
JBIG2_COMPOSE_XOR
);
116
}
117
return
DecodeImage(GSPLANES);
118
}
119
120
std::unique_ptr<CJBig2_Image>
CJBig2_HTRDProc
::DecodeImage(
121
const
std::vector<std::unique_ptr<CJBig2_Image>>& GSPLANES) {
122
auto
HTREG =
std
::make_unique<
CJBig2_Image
>(
HBW
,
HBH
);
123
if
(!HTREG->data())
124
return
nullptr
;
125
126
HTREG->Fill(
HDEFPIXEL
);
127
for
(uint32_t y = 0; y <
HGH
; ++y) {
128
for
(uint32_t x = 0; x <
HGW
; ++x) {
129
uint32_t gsval = 0;
130
for
(uint8_t i = 0; i < GSPLANES.size(); ++i)
131
gsval |= GSPLANES[i]->GetPixel(x, y) << i;
132
uint32_t pat_index =
std
::min(gsval,
HNUMPATS
- 1);
133
int32_t out_x = (
HGX
+ y *
HRY
+ x *
HRX
) >> 8;
134
int32_t out_y = (
HGY
+ y *
HRX
- x *
HRY
) >> 8;
135
(*HPATS)[pat_index]->ComposeTo(HTREG.get(), out_x, out_y, HCOMBOP);
136
}
137
}
138
return
HTREG;
139
}
JBIG2_COMPOSE_XOR
@ JBIG2_COMPOSE_XOR
Definition
JBig2_Image.h:25
CJBig2_ArithDecoder
Definition
JBig2_ArithDecoder.h:41
CJBig2_BitStream
Definition
JBig2_BitStream.h:14
CJBig2_BitStream::alignByte
void alignByte()
Definition
JBig2_BitStream.cpp:120
CJBig2_BitStream::addOffset
void addOffset(uint32_t dwDelta)
Definition
JBig2_BitStream.cpp:152
CJBig2_GRDProc::ProgressiveArithDecodeState
Definition
JBig2_GrdProc.h:29
CJBig2_GRDProc
Definition
JBig2_GrdProc.h:27
CJBig2_GRDProc::GBW
uint32_t GBW
Definition
JBig2_GrdProc.h:57
CJBig2_GRDProc::GBTEMPLATE
uint8_t GBTEMPLATE
Definition
JBig2_GrdProc.h:56
CJBig2_GRDProc::GBH
uint32_t GBH
Definition
JBig2_GrdProc.h:58
CJBig2_GRDProc::MMR
bool MMR
Definition
JBig2_GrdProc.h:53
CJBig2_GRDProc::TPGDON
bool TPGDON
Definition
JBig2_GrdProc.h:54
CJBig2_GRDProc::USESKIP
bool USESKIP
Definition
JBig2_GrdProc.h:55
CJBig2_GRDProc::ContinueDecode
FXCODEC_STATUS ContinueDecode(ProgressiveArithDecodeState *pState)
Definition
JBig2_GrdProc.cpp:496
CJBig2_GRDProc::StartDecodeArith
FXCODEC_STATUS StartDecodeArith(ProgressiveArithDecodeState *pState)
Definition
JBig2_GrdProc.cpp:411
CJBig2_HTRDProc
Definition
JBig2_HtrdProc.h:24
CJBig2_HTRDProc::HRX
uint16_t HRX
Definition
JBig2_HtrdProc.h:50
CJBig2_HTRDProc::HBW
uint32_t HBW
Definition
JBig2_HtrdProc.h:37
CJBig2_HTRDProc::HPH
uint8_t HPH
Definition
JBig2_HtrdProc.h:53
CJBig2_HTRDProc::DecodeMMR
std::unique_ptr< CJBig2_Image > DecodeMMR(CJBig2_BitStream *pStream)
Definition
JBig2_HtrdProc.cpp:89
CJBig2_HTRDProc::HGX
int32_t HGX
Definition
JBig2_HtrdProc.h:48
CJBig2_HTRDProc::~CJBig2_HTRDProc
~CJBig2_HTRDProc()
CJBig2_HTRDProc::HENABLESKIP
bool HENABLESKIP
Definition
JBig2_HtrdProc.h:45
CJBig2_HTRDProc::HMMR
bool HMMR
Definition
JBig2_HtrdProc.h:39
CJBig2_HTRDProc::HPW
uint8_t HPW
Definition
JBig2_HtrdProc.h:52
CJBig2_HTRDProc::HGY
int32_t HGY
Definition
JBig2_HtrdProc.h:49
CJBig2_HTRDProc::HRY
uint16_t HRY
Definition
JBig2_HtrdProc.h:51
CJBig2_HTRDProc::HBH
uint32_t HBH
Definition
JBig2_HtrdProc.h:38
CJBig2_HTRDProc::DecodeArith
std::unique_ptr< CJBig2_Image > DecodeArith(CJBig2_ArithDecoder *pArithDecoder, pdfium::span< JBig2ArithCtx > gbContexts, PauseIndicatorIface *pPause)
Definition
JBig2_HtrdProc.cpp:20
CJBig2_HTRDProc::CJBig2_HTRDProc
CJBig2_HTRDProc()
CJBig2_HTRDProc::HTEMPLATE
uint8_t HTEMPLATE
Definition
JBig2_HtrdProc.h:40
CJBig2_HTRDProc::HGW
uint32_t HGW
Definition
JBig2_HtrdProc.h:46
CJBig2_HTRDProc::HDEFPIXEL
bool HDEFPIXEL
Definition
JBig2_HtrdProc.h:43
CJBig2_HTRDProc::HGH
uint32_t HGH
Definition
JBig2_HtrdProc.h:47
CJBig2_HTRDProc::HNUMPATS
uint32_t HNUMPATS
Definition
JBig2_HtrdProc.h:41
CJBig2_Image
Definition
JBig2_Image.h:30
PauseIndicatorIface
Definition
pauseindicator_iface.h:10
FXCODEC_STATUS
FXCODEC_STATUS
Definition
fx_codec_def.h:10
FXCODEC_STATUS::kDecodeToBeContinued
@ kDecodeToBeContinued
Definition
fx_codec_def.h:15
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxcodec
jbig2
JBig2_HtrdProc.cpp
Generated on
for Qt by
1.18.0