Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: core/fxcodec/codec/fx_codec.cpp

Issue 2477443002: Remove FX_BOOL from core (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxcodec/codec/ccodec_scanlinedecoder.h ('k') | core/fxcodec/codec/fx_codec_bmp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fxcodec/fx_codec.h" 7 #include "core/fxcodec/fx_codec.h"
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <memory> 10 #include <memory>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 while (m_NextLine < line) { 67 while (m_NextLine < line) {
68 ReadNextLine(); 68 ReadNextLine();
69 m_NextLine++; 69 m_NextLine++;
70 } 70 }
71 m_pLastScanline = ReadNextLine(); 71 m_pLastScanline = ReadNextLine();
72 m_NextLine++; 72 m_NextLine++;
73 return m_pLastScanline; 73 return m_pLastScanline;
74 } 74 }
75 75
76 FX_BOOL CCodec_ScanlineDecoder::SkipToScanline(int line, IFX_Pause* pPause) { 76 bool CCodec_ScanlineDecoder::SkipToScanline(int line, IFX_Pause* pPause) {
77 if (m_NextLine == line || m_NextLine == line + 1) 77 if (m_NextLine == line || m_NextLine == line + 1)
78 return FALSE; 78 return false;
79 79
80 if (m_NextLine < 0 || m_NextLine > line) { 80 if (m_NextLine < 0 || m_NextLine > line) {
81 v_Rewind(); 81 v_Rewind();
82 m_NextLine = 0; 82 m_NextLine = 0;
83 } 83 }
84 m_pLastScanline = nullptr; 84 m_pLastScanline = nullptr;
85 while (m_NextLine < line) { 85 while (m_NextLine < line) {
86 m_pLastScanline = ReadNextLine(); 86 m_pLastScanline = ReadNextLine();
87 m_NextLine++; 87 m_NextLine++;
88 if (pPause && pPause->NeedToPauseNow()) { 88 if (pPause && pPause->NeedToPauseNow()) {
89 return TRUE; 89 return true;
90 } 90 }
91 } 91 }
92 return FALSE; 92 return false;
93 } 93 }
94 94
95 uint8_t* CCodec_ScanlineDecoder::ReadNextLine() { 95 uint8_t* CCodec_ScanlineDecoder::ReadNextLine() {
96 return v_GetNextLine(); 96 return v_GetNextLine();
97 } 97 }
98 98
99 #ifdef PDF_ENABLE_XFA 99 #ifdef PDF_ENABLE_XFA
100 CFX_DIBAttribute::CFX_DIBAttribute() 100 CFX_DIBAttribute::CFX_DIBAttribute()
101 : m_nXDPI(-1), 101 : m_nXDPI(-1),
102 m_nYDPI(-1), 102 m_nYDPI(-1),
(...skipping 10 matching lines...) Expand all
113 for (const auto& pair : m_Exif) 113 for (const auto& pair : m_Exif)
114 FX_Free(pair.second); 114 FX_Free(pair.second);
115 } 115 }
116 #endif // PDF_ENABLE_XFA 116 #endif // PDF_ENABLE_XFA
117 117
118 class CCodec_RLScanlineDecoder : public CCodec_ScanlineDecoder { 118 class CCodec_RLScanlineDecoder : public CCodec_ScanlineDecoder {
119 public: 119 public:
120 CCodec_RLScanlineDecoder(); 120 CCodec_RLScanlineDecoder();
121 ~CCodec_RLScanlineDecoder() override; 121 ~CCodec_RLScanlineDecoder() override;
122 122
123 FX_BOOL Create(const uint8_t* src_buf, 123 bool Create(const uint8_t* src_buf,
124 uint32_t src_size, 124 uint32_t src_size,
125 int width, 125 int width,
126 int height, 126 int height,
127 int nComps, 127 int nComps,
128 int bpc); 128 int bpc);
129 129
130 // CCodec_ScanlineDecoder 130 // CCodec_ScanlineDecoder
131 FX_BOOL v_Rewind() override; 131 bool v_Rewind() override;
132 uint8_t* v_GetNextLine() override; 132 uint8_t* v_GetNextLine() override;
133 uint32_t GetSrcOffset() override { return m_SrcOffset; } 133 uint32_t GetSrcOffset() override { return m_SrcOffset; }
134 134
135 protected: 135 protected:
136 FX_BOOL CheckDestSize(); 136 bool CheckDestSize();
137 void GetNextOperator(); 137 void GetNextOperator();
138 void UpdateOperator(uint8_t used_bytes); 138 void UpdateOperator(uint8_t used_bytes);
139 139
140 uint8_t* m_pScanline; 140 uint8_t* m_pScanline;
141 const uint8_t* m_pSrcBuf; 141 const uint8_t* m_pSrcBuf;
142 uint32_t m_SrcSize; 142 uint32_t m_SrcSize;
143 uint32_t m_dwLineBytes; 143 uint32_t m_dwLineBytes;
144 uint32_t m_SrcOffset; 144 uint32_t m_SrcOffset;
145 FX_BOOL m_bEOD; 145 bool m_bEOD;
146 uint8_t m_Operator; 146 uint8_t m_Operator;
147 }; 147 };
148 CCodec_RLScanlineDecoder::CCodec_RLScanlineDecoder() 148 CCodec_RLScanlineDecoder::CCodec_RLScanlineDecoder()
149 : m_pScanline(nullptr), 149 : m_pScanline(nullptr),
150 m_pSrcBuf(nullptr), 150 m_pSrcBuf(nullptr),
151 m_SrcSize(0), 151 m_SrcSize(0),
152 m_dwLineBytes(0), 152 m_dwLineBytes(0),
153 m_SrcOffset(0), 153 m_SrcOffset(0),
154 m_bEOD(FALSE), 154 m_bEOD(false),
155 m_Operator(0) {} 155 m_Operator(0) {}
156 CCodec_RLScanlineDecoder::~CCodec_RLScanlineDecoder() { 156 CCodec_RLScanlineDecoder::~CCodec_RLScanlineDecoder() {
157 FX_Free(m_pScanline); 157 FX_Free(m_pScanline);
158 } 158 }
159 FX_BOOL CCodec_RLScanlineDecoder::CheckDestSize() { 159 bool CCodec_RLScanlineDecoder::CheckDestSize() {
160 uint32_t i = 0; 160 uint32_t i = 0;
161 uint32_t old_size = 0; 161 uint32_t old_size = 0;
162 uint32_t dest_size = 0; 162 uint32_t dest_size = 0;
163 while (i < m_SrcSize) { 163 while (i < m_SrcSize) {
164 if (m_pSrcBuf[i] < 128) { 164 if (m_pSrcBuf[i] < 128) {
165 old_size = dest_size; 165 old_size = dest_size;
166 dest_size += m_pSrcBuf[i] + 1; 166 dest_size += m_pSrcBuf[i] + 1;
167 if (dest_size < old_size) { 167 if (dest_size < old_size) {
168 return FALSE; 168 return false;
169 } 169 }
170 i += m_pSrcBuf[i] + 2; 170 i += m_pSrcBuf[i] + 2;
171 } else if (m_pSrcBuf[i] > 128) { 171 } else if (m_pSrcBuf[i] > 128) {
172 old_size = dest_size; 172 old_size = dest_size;
173 dest_size += 257 - m_pSrcBuf[i]; 173 dest_size += 257 - m_pSrcBuf[i];
174 if (dest_size < old_size) { 174 if (dest_size < old_size) {
175 return FALSE; 175 return false;
176 } 176 }
177 i += 2; 177 i += 2;
178 } else { 178 } else {
179 break; 179 break;
180 } 180 }
181 } 181 }
182 if (((uint32_t)m_OrigWidth * m_nComps * m_bpc * m_OrigHeight + 7) / 8 > 182 if (((uint32_t)m_OrigWidth * m_nComps * m_bpc * m_OrigHeight + 7) / 8 >
183 dest_size) { 183 dest_size) {
184 return FALSE; 184 return false;
185 } 185 }
186 return TRUE; 186 return true;
187 } 187 }
188 FX_BOOL CCodec_RLScanlineDecoder::Create(const uint8_t* src_buf, 188 bool CCodec_RLScanlineDecoder::Create(const uint8_t* src_buf,
189 uint32_t src_size, 189 uint32_t src_size,
190 int width, 190 int width,
191 int height, 191 int height,
192 int nComps, 192 int nComps,
193 int bpc) { 193 int bpc) {
194 m_pSrcBuf = src_buf; 194 m_pSrcBuf = src_buf;
195 m_SrcSize = src_size; 195 m_SrcSize = src_size;
196 m_OutputWidth = m_OrigWidth = width; 196 m_OutputWidth = m_OrigWidth = width;
197 m_OutputHeight = m_OrigHeight = height; 197 m_OutputHeight = m_OrigHeight = height;
198 m_nComps = nComps; 198 m_nComps = nComps;
199 m_bpc = bpc; 199 m_bpc = bpc;
200 // Aligning the pitch to 4 bytes requires an integer overflow check. 200 // Aligning the pitch to 4 bytes requires an integer overflow check.
201 FX_SAFE_UINT32 pitch = width; 201 FX_SAFE_UINT32 pitch = width;
202 pitch *= nComps; 202 pitch *= nComps;
203 pitch *= bpc; 203 pitch *= bpc;
204 pitch += 31; 204 pitch += 31;
205 pitch /= 32; 205 pitch /= 32;
206 pitch *= 4; 206 pitch *= 4;
207 if (!pitch.IsValid()) { 207 if (!pitch.IsValid()) {
208 return FALSE; 208 return false;
209 } 209 }
210 m_Pitch = pitch.ValueOrDie(); 210 m_Pitch = pitch.ValueOrDie();
211 // Overflow should already have been checked before this is called. 211 // Overflow should already have been checked before this is called.
212 m_dwLineBytes = (static_cast<uint32_t>(width) * nComps * bpc + 7) / 8; 212 m_dwLineBytes = (static_cast<uint32_t>(width) * nComps * bpc + 7) / 8;
213 m_pScanline = FX_Alloc(uint8_t, m_Pitch); 213 m_pScanline = FX_Alloc(uint8_t, m_Pitch);
214 return CheckDestSize(); 214 return CheckDestSize();
215 } 215 }
216 FX_BOOL CCodec_RLScanlineDecoder::v_Rewind() { 216 bool CCodec_RLScanlineDecoder::v_Rewind() {
217 FXSYS_memset(m_pScanline, 0, m_Pitch); 217 FXSYS_memset(m_pScanline, 0, m_Pitch);
218 m_SrcOffset = 0; 218 m_SrcOffset = 0;
219 m_bEOD = FALSE; 219 m_bEOD = false;
220 m_Operator = 0; 220 m_Operator = 0;
221 return TRUE; 221 return true;
222 } 222 }
223 uint8_t* CCodec_RLScanlineDecoder::v_GetNextLine() { 223 uint8_t* CCodec_RLScanlineDecoder::v_GetNextLine() {
224 if (m_SrcOffset == 0) { 224 if (m_SrcOffset == 0) {
225 GetNextOperator(); 225 GetNextOperator();
226 } else { 226 } else {
227 if (m_bEOD) { 227 if (m_bEOD) {
228 return nullptr; 228 return nullptr;
229 } 229 }
230 } 230 }
231 FXSYS_memset(m_pScanline, 0, m_Pitch); 231 FXSYS_memset(m_pScanline, 0, m_Pitch);
232 uint32_t col_pos = 0; 232 uint32_t col_pos = 0;
233 FX_BOOL eol = FALSE; 233 bool eol = false;
234 while (m_SrcOffset < m_SrcSize && !eol) { 234 while (m_SrcOffset < m_SrcSize && !eol) {
235 if (m_Operator < 128) { 235 if (m_Operator < 128) {
236 uint32_t copy_len = m_Operator + 1; 236 uint32_t copy_len = m_Operator + 1;
237 if (col_pos + copy_len >= m_dwLineBytes) { 237 if (col_pos + copy_len >= m_dwLineBytes) {
238 copy_len = m_dwLineBytes - col_pos; 238 copy_len = m_dwLineBytes - col_pos;
239 eol = TRUE; 239 eol = true;
240 } 240 }
241 if (copy_len >= m_SrcSize - m_SrcOffset) { 241 if (copy_len >= m_SrcSize - m_SrcOffset) {
242 copy_len = m_SrcSize - m_SrcOffset; 242 copy_len = m_SrcSize - m_SrcOffset;
243 m_bEOD = TRUE; 243 m_bEOD = true;
244 } 244 }
245 FXSYS_memcpy(m_pScanline + col_pos, m_pSrcBuf + m_SrcOffset, copy_len); 245 FXSYS_memcpy(m_pScanline + col_pos, m_pSrcBuf + m_SrcOffset, copy_len);
246 col_pos += copy_len; 246 col_pos += copy_len;
247 UpdateOperator((uint8_t)copy_len); 247 UpdateOperator((uint8_t)copy_len);
248 } else if (m_Operator > 128) { 248 } else if (m_Operator > 128) {
249 int fill = 0; 249 int fill = 0;
250 if (m_SrcOffset - 1 < m_SrcSize - 1) { 250 if (m_SrcOffset - 1 < m_SrcSize - 1) {
251 fill = m_pSrcBuf[m_SrcOffset]; 251 fill = m_pSrcBuf[m_SrcOffset];
252 } 252 }
253 uint32_t duplicate_len = 257 - m_Operator; 253 uint32_t duplicate_len = 257 - m_Operator;
254 if (col_pos + duplicate_len >= m_dwLineBytes) { 254 if (col_pos + duplicate_len >= m_dwLineBytes) {
255 duplicate_len = m_dwLineBytes - col_pos; 255 duplicate_len = m_dwLineBytes - col_pos;
256 eol = TRUE; 256 eol = true;
257 } 257 }
258 FXSYS_memset(m_pScanline + col_pos, fill, duplicate_len); 258 FXSYS_memset(m_pScanline + col_pos, fill, duplicate_len);
259 col_pos += duplicate_len; 259 col_pos += duplicate_len;
260 UpdateOperator((uint8_t)duplicate_len); 260 UpdateOperator((uint8_t)duplicate_len);
261 } else { 261 } else {
262 m_bEOD = TRUE; 262 m_bEOD = true;
263 break; 263 break;
264 } 264 }
265 } 265 }
266 return m_pScanline; 266 return m_pScanline;
267 } 267 }
268 void CCodec_RLScanlineDecoder::GetNextOperator() { 268 void CCodec_RLScanlineDecoder::GetNextOperator() {
269 if (m_SrcOffset >= m_SrcSize) { 269 if (m_SrcOffset >= m_SrcSize) {
270 m_Operator = 128; 270 m_Operator = 128;
271 return; 271 return;
272 } 272 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 int bpc) { 311 int bpc) {
312 std::unique_ptr<CCodec_RLScanlineDecoder> pRLScanlineDecoder( 312 std::unique_ptr<CCodec_RLScanlineDecoder> pRLScanlineDecoder(
313 new CCodec_RLScanlineDecoder); 313 new CCodec_RLScanlineDecoder);
314 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, 314 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps,
315 bpc)) { 315 bpc)) {
316 return nullptr; 316 return nullptr;
317 } 317 }
318 318
319 return pRLScanlineDecoder.release(); 319 return pRLScanlineDecoder.release();
320 } 320 }
OLDNEW
« no previous file with comments | « core/fxcodec/codec/ccodec_scanlinedecoder.h ('k') | core/fxcodec/codec/fx_codec_bmp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698