OLD | NEW |
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/fpdfapi/render/render_int.h" | 7 #include "core/fpdfapi/render/render_int.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 : m_pDocument(nullptr), | 95 : m_pDocument(nullptr), |
96 m_pStream(nullptr), | 96 m_pStream(nullptr), |
97 m_pDict(nullptr), | 97 m_pDict(nullptr), |
98 m_pColorSpace(nullptr), | 98 m_pColorSpace(nullptr), |
99 m_Family(0), | 99 m_Family(0), |
100 m_bpc(0), | 100 m_bpc(0), |
101 m_bpc_orig(0), | 101 m_bpc_orig(0), |
102 m_nComponents(0), | 102 m_nComponents(0), |
103 m_GroupFamily(0), | 103 m_GroupFamily(0), |
104 m_MatteColor(0), | 104 m_MatteColor(0), |
105 m_bLoadMask(FALSE), | 105 m_bLoadMask(false), |
106 m_bDefaultDecode(TRUE), | 106 m_bDefaultDecode(true), |
107 m_bImageMask(FALSE), | 107 m_bImageMask(false), |
108 m_bDoBpcCheck(TRUE), | 108 m_bDoBpcCheck(true), |
109 m_bColorKey(FALSE), | 109 m_bColorKey(false), |
110 m_bHasMask(FALSE), | 110 m_bHasMask(false), |
111 m_bStdCS(FALSE), | 111 m_bStdCS(false), |
112 m_pCompData(nullptr), | 112 m_pCompData(nullptr), |
113 m_pLineBuf(nullptr), | 113 m_pLineBuf(nullptr), |
114 m_pMaskedLine(nullptr), | 114 m_pMaskedLine(nullptr), |
115 m_pMask(nullptr), | 115 m_pMask(nullptr), |
116 m_pMaskStream(nullptr), | 116 m_pMaskStream(nullptr), |
117 m_Status(0) {} | 117 m_Status(0) {} |
118 | 118 |
119 CPDF_DIBSource::~CPDF_DIBSource() { | 119 CPDF_DIBSource::~CPDF_DIBSource() { |
120 FX_Free(m_pMaskedLine); | 120 FX_Free(m_pMaskedLine); |
121 FX_Free(m_pLineBuf); | 121 FX_Free(m_pLineBuf); |
122 m_pCachedBitmap.reset(); | 122 m_pCachedBitmap.reset(); |
123 FX_Free(m_pCompData); | 123 FX_Free(m_pCompData); |
124 CPDF_ColorSpace* pCS = m_pColorSpace; | 124 CPDF_ColorSpace* pCS = m_pColorSpace; |
125 if (pCS && m_pDocument) { | 125 if (pCS && m_pDocument) { |
126 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); | 126 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const { | 130 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const { |
131 return m_pCachedBitmap ? m_pCachedBitmap.get() : Clone(); | 131 return m_pCachedBitmap ? m_pCachedBitmap.get() : Clone(); |
132 } | 132 } |
133 | 133 |
134 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const { | 134 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const { |
135 if (pBitmap && pBitmap != m_pCachedBitmap.get()) { | 135 if (pBitmap && pBitmap != m_pCachedBitmap.get()) { |
136 delete pBitmap; | 136 delete pBitmap; |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, | 140 bool CPDF_DIBSource::Load(CPDF_Document* pDoc, |
141 const CPDF_Stream* pStream, | 141 const CPDF_Stream* pStream, |
142 CPDF_DIBSource** ppMask, | 142 CPDF_DIBSource** ppMask, |
143 uint32_t* pMatteColor, | 143 uint32_t* pMatteColor, |
144 CPDF_Dictionary* pFormResources, | 144 CPDF_Dictionary* pFormResources, |
145 CPDF_Dictionary* pPageResources, | 145 CPDF_Dictionary* pPageResources, |
146 FX_BOOL bStdCS, | 146 bool bStdCS, |
147 uint32_t GroupFamily, | 147 uint32_t GroupFamily, |
148 FX_BOOL bLoadMask) { | 148 bool bLoadMask) { |
149 if (!pStream) { | 149 if (!pStream) { |
150 return FALSE; | 150 return false; |
151 } | 151 } |
152 m_pDocument = pDoc; | 152 m_pDocument = pDoc; |
153 m_pDict = pStream->GetDict(); | 153 m_pDict = pStream->GetDict(); |
154 if (!m_pDict) { | 154 if (!m_pDict) { |
155 return FALSE; | 155 return false; |
156 } | 156 } |
157 m_pStream = pStream; | 157 m_pStream = pStream; |
158 m_Width = m_pDict->GetIntegerFor("Width"); | 158 m_Width = m_pDict->GetIntegerFor("Width"); |
159 m_Height = m_pDict->GetIntegerFor("Height"); | 159 m_Height = m_pDict->GetIntegerFor("Height"); |
160 if (m_Width <= 0 || m_Height <= 0 || m_Width > kMaxImageDimension || | 160 if (m_Width <= 0 || m_Height <= 0 || m_Width > kMaxImageDimension || |
161 m_Height > kMaxImageDimension) { | 161 m_Height > kMaxImageDimension) { |
162 return FALSE; | 162 return false; |
163 } | 163 } |
164 m_GroupFamily = GroupFamily; | 164 m_GroupFamily = GroupFamily; |
165 m_bLoadMask = bLoadMask; | 165 m_bLoadMask = bLoadMask; |
166 if (!LoadColorInfo(m_pStream->IsInline() ? pFormResources : nullptr, | 166 if (!LoadColorInfo(m_pStream->IsInline() ? pFormResources : nullptr, |
167 pPageResources)) { | 167 pPageResources)) { |
168 return FALSE; | 168 return false; |
169 } | 169 } |
170 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { | 170 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { |
171 return FALSE; | 171 return false; |
172 } | 172 } |
173 FX_SAFE_UINT32 src_size = | 173 FX_SAFE_UINT32 src_size = |
174 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; | 174 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; |
175 if (!src_size.IsValid()) { | 175 if (!src_size.IsValid()) { |
176 return FALSE; | 176 return false; |
177 } | 177 } |
178 m_pStreamAcc.reset(new CPDF_StreamAcc); | 178 m_pStreamAcc.reset(new CPDF_StreamAcc); |
179 m_pStreamAcc->LoadAllData(pStream, FALSE, src_size.ValueOrDie(), TRUE); | 179 m_pStreamAcc->LoadAllData(pStream, false, src_size.ValueOrDie(), true); |
180 if (m_pStreamAcc->GetSize() == 0 || !m_pStreamAcc->GetData()) { | 180 if (m_pStreamAcc->GetSize() == 0 || !m_pStreamAcc->GetData()) { |
181 return FALSE; | 181 return false; |
182 } | 182 } |
183 if (!CreateDecoder()) { | 183 if (!CreateDecoder()) { |
184 return FALSE; | 184 return false; |
185 } | 185 } |
186 if (m_bImageMask) { | 186 if (m_bImageMask) { |
187 m_bpp = 1; | 187 m_bpp = 1; |
188 m_bpc = 1; | 188 m_bpc = 1; |
189 m_nComponents = 1; | 189 m_nComponents = 1; |
190 m_AlphaFlag = 1; | 190 m_AlphaFlag = 1; |
191 } else if (m_bpc * m_nComponents == 1) { | 191 } else if (m_bpc * m_nComponents == 1) { |
192 m_bpp = 1; | 192 m_bpp = 1; |
193 } else if (m_bpc * m_nComponents <= 8) { | 193 } else if (m_bpc * m_nComponents <= 8) { |
194 m_bpp = 8; | 194 m_bpp = 8; |
195 } else { | 195 } else { |
196 m_bpp = 24; | 196 m_bpp = 24; |
197 } | 197 } |
198 FX_SAFE_UINT32 pitch = CalculatePitch32(m_bpp, m_Width); | 198 FX_SAFE_UINT32 pitch = CalculatePitch32(m_bpp, m_Width); |
199 if (!pitch.IsValid()) { | 199 if (!pitch.IsValid()) { |
200 return FALSE; | 200 return false; |
201 } | 201 } |
202 m_pLineBuf = FX_Alloc(uint8_t, pitch.ValueOrDie()); | 202 m_pLineBuf = FX_Alloc(uint8_t, pitch.ValueOrDie()); |
203 if (m_pColorSpace && bStdCS) { | 203 if (m_pColorSpace && bStdCS) { |
204 m_pColorSpace->EnableStdConversion(TRUE); | 204 m_pColorSpace->EnableStdConversion(true); |
205 } | 205 } |
206 LoadPalette(); | 206 LoadPalette(); |
207 if (m_bColorKey) { | 207 if (m_bColorKey) { |
208 m_bpp = 32; | 208 m_bpp = 32; |
209 m_AlphaFlag = 2; | 209 m_AlphaFlag = 2; |
210 pitch = CalculatePitch32(m_bpp, m_Width); | 210 pitch = CalculatePitch32(m_bpp, m_Width); |
211 if (!pitch.IsValid()) { | 211 if (!pitch.IsValid()) { |
212 return FALSE; | 212 return false; |
213 } | 213 } |
214 m_pMaskedLine = FX_Alloc(uint8_t, pitch.ValueOrDie()); | 214 m_pMaskedLine = FX_Alloc(uint8_t, pitch.ValueOrDie()); |
215 } | 215 } |
216 m_Pitch = pitch.ValueOrDie(); | 216 m_Pitch = pitch.ValueOrDie(); |
217 if (ppMask) { | 217 if (ppMask) { |
218 *ppMask = LoadMask(*pMatteColor); | 218 *ppMask = LoadMask(*pMatteColor); |
219 } | 219 } |
220 if (m_pColorSpace && bStdCS) { | 220 if (m_pColorSpace && bStdCS) { |
221 m_pColorSpace->EnableStdConversion(FALSE); | 221 m_pColorSpace->EnableStdConversion(false); |
222 } | 222 } |
223 return TRUE; | 223 return true; |
224 } | 224 } |
225 | 225 |
226 int CPDF_DIBSource::ContinueToLoadMask() { | 226 int CPDF_DIBSource::ContinueToLoadMask() { |
227 if (m_bImageMask) { | 227 if (m_bImageMask) { |
228 m_bpp = 1; | 228 m_bpp = 1; |
229 m_bpc = 1; | 229 m_bpc = 1; |
230 m_nComponents = 1; | 230 m_nComponents = 1; |
231 m_AlphaFlag = 1; | 231 m_AlphaFlag = 1; |
232 } else if (m_bpc * m_nComponents == 1) { | 232 } else if (m_bpc * m_nComponents == 1) { |
233 m_bpp = 1; | 233 m_bpp = 1; |
234 } else if (m_bpc * m_nComponents <= 8) { | 234 } else if (m_bpc * m_nComponents <= 8) { |
235 m_bpp = 8; | 235 m_bpp = 8; |
236 } else { | 236 } else { |
237 m_bpp = 24; | 237 m_bpp = 24; |
238 } | 238 } |
239 if (!m_bpc || !m_nComponents) { | 239 if (!m_bpc || !m_nComponents) { |
240 return 0; | 240 return 0; |
241 } | 241 } |
242 FX_SAFE_UINT32 pitch = CalculatePitch32(m_bpp, m_Width); | 242 FX_SAFE_UINT32 pitch = CalculatePitch32(m_bpp, m_Width); |
243 if (!pitch.IsValid()) { | 243 if (!pitch.IsValid()) { |
244 return 0; | 244 return 0; |
245 } | 245 } |
246 m_pLineBuf = FX_Alloc(uint8_t, pitch.ValueOrDie()); | 246 m_pLineBuf = FX_Alloc(uint8_t, pitch.ValueOrDie()); |
247 if (m_pColorSpace && m_bStdCS) { | 247 if (m_pColorSpace && m_bStdCS) { |
248 m_pColorSpace->EnableStdConversion(TRUE); | 248 m_pColorSpace->EnableStdConversion(true); |
249 } | 249 } |
250 LoadPalette(); | 250 LoadPalette(); |
251 if (m_bColorKey) { | 251 if (m_bColorKey) { |
252 m_bpp = 32; | 252 m_bpp = 32; |
253 m_AlphaFlag = 2; | 253 m_AlphaFlag = 2; |
254 pitch = CalculatePitch32(m_bpp, m_Width); | 254 pitch = CalculatePitch32(m_bpp, m_Width); |
255 if (!pitch.IsValid()) { | 255 if (!pitch.IsValid()) { |
256 return 0; | 256 return 0; |
257 } | 257 } |
258 m_pMaskedLine = FX_Alloc(uint8_t, pitch.ValueOrDie()); | 258 m_pMaskedLine = FX_Alloc(uint8_t, pitch.ValueOrDie()); |
259 } | 259 } |
260 m_Pitch = pitch.ValueOrDie(); | 260 m_Pitch = pitch.ValueOrDie(); |
261 return 1; | 261 return 1; |
262 } | 262 } |
263 | 263 |
264 int CPDF_DIBSource::StartLoadDIBSource(CPDF_Document* pDoc, | 264 int CPDF_DIBSource::StartLoadDIBSource(CPDF_Document* pDoc, |
265 const CPDF_Stream* pStream, | 265 const CPDF_Stream* pStream, |
266 FX_BOOL bHasMask, | 266 bool bHasMask, |
267 CPDF_Dictionary* pFormResources, | 267 CPDF_Dictionary* pFormResources, |
268 CPDF_Dictionary* pPageResources, | 268 CPDF_Dictionary* pPageResources, |
269 FX_BOOL bStdCS, | 269 bool bStdCS, |
270 uint32_t GroupFamily, | 270 uint32_t GroupFamily, |
271 FX_BOOL bLoadMask) { | 271 bool bLoadMask) { |
272 if (!pStream) { | 272 if (!pStream) { |
273 return 0; | 273 return 0; |
274 } | 274 } |
275 m_pDocument = pDoc; | 275 m_pDocument = pDoc; |
276 m_pDict = pStream->GetDict(); | 276 m_pDict = pStream->GetDict(); |
277 m_pStream = pStream; | 277 m_pStream = pStream; |
278 m_bStdCS = bStdCS; | 278 m_bStdCS = bStdCS; |
279 m_bHasMask = bHasMask; | 279 m_bHasMask = bHasMask; |
280 m_Width = m_pDict->GetIntegerFor("Width"); | 280 m_Width = m_pDict->GetIntegerFor("Width"); |
281 m_Height = m_pDict->GetIntegerFor("Height"); | 281 m_Height = m_pDict->GetIntegerFor("Height"); |
282 if (m_Width <= 0 || m_Height <= 0 || m_Width > kMaxImageDimension || | 282 if (m_Width <= 0 || m_Height <= 0 || m_Width > kMaxImageDimension || |
283 m_Height > kMaxImageDimension) { | 283 m_Height > kMaxImageDimension) { |
284 return 0; | 284 return 0; |
285 } | 285 } |
286 m_GroupFamily = GroupFamily; | 286 m_GroupFamily = GroupFamily; |
287 m_bLoadMask = bLoadMask; | 287 m_bLoadMask = bLoadMask; |
288 if (!LoadColorInfo(m_pStream->IsInline() ? pFormResources : nullptr, | 288 if (!LoadColorInfo(m_pStream->IsInline() ? pFormResources : nullptr, |
289 pPageResources)) { | 289 pPageResources)) { |
290 return 0; | 290 return 0; |
291 } | 291 } |
292 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { | 292 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { |
293 return 0; | 293 return 0; |
294 } | 294 } |
295 FX_SAFE_UINT32 src_size = | 295 FX_SAFE_UINT32 src_size = |
296 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; | 296 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; |
297 if (!src_size.IsValid()) { | 297 if (!src_size.IsValid()) { |
298 return 0; | 298 return 0; |
299 } | 299 } |
300 m_pStreamAcc.reset(new CPDF_StreamAcc); | 300 m_pStreamAcc.reset(new CPDF_StreamAcc); |
301 m_pStreamAcc->LoadAllData(pStream, FALSE, src_size.ValueOrDie(), TRUE); | 301 m_pStreamAcc->LoadAllData(pStream, false, src_size.ValueOrDie(), true); |
302 if (m_pStreamAcc->GetSize() == 0 || !m_pStreamAcc->GetData()) { | 302 if (m_pStreamAcc->GetSize() == 0 || !m_pStreamAcc->GetData()) { |
303 return 0; | 303 return 0; |
304 } | 304 } |
305 int ret = CreateDecoder(); | 305 int ret = CreateDecoder(); |
306 if (!ret) | 306 if (!ret) |
307 return ret; | 307 return ret; |
308 | 308 |
309 if (ret != 1) { | 309 if (ret != 1) { |
310 if (!ContinueToLoadMask()) { | 310 if (!ContinueToLoadMask()) { |
311 return 0; | 311 return 0; |
312 } | 312 } |
313 if (m_bHasMask) { | 313 if (m_bHasMask) { |
314 StratLoadMask(); | 314 StratLoadMask(); |
315 } | 315 } |
316 return ret; | 316 return ret; |
317 } | 317 } |
318 if (!ContinueToLoadMask()) { | 318 if (!ContinueToLoadMask()) { |
319 return 0; | 319 return 0; |
320 } | 320 } |
321 if (m_bHasMask) { | 321 if (m_bHasMask) { |
322 ret = StratLoadMask(); | 322 ret = StratLoadMask(); |
323 } | 323 } |
324 if (ret == 2) { | 324 if (ret == 2) { |
325 return ret; | 325 return ret; |
326 } | 326 } |
327 if (m_pColorSpace && m_bStdCS) { | 327 if (m_pColorSpace && m_bStdCS) { |
328 m_pColorSpace->EnableStdConversion(FALSE); | 328 m_pColorSpace->EnableStdConversion(false); |
329 } | 329 } |
330 return ret; | 330 return ret; |
331 } | 331 } |
332 | 332 |
333 int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) { | 333 int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) { |
334 FXCODEC_STATUS ret; | 334 FXCODEC_STATUS ret; |
335 if (m_Status == 1) { | 335 if (m_Status == 1) { |
336 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | 336 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); |
337 if (decoder == "JPXDecode") { | 337 if (decoder == "JPXDecode") { |
338 return 0; | 338 return 0; |
339 } | 339 } |
340 CCodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module(); | 340 CCodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module(); |
341 if (!m_pJbig2Context) { | 341 if (!m_pJbig2Context) { |
342 m_pJbig2Context.reset(new CCodec_Jbig2Context()); | 342 m_pJbig2Context.reset(new CCodec_Jbig2Context()); |
343 if (m_pStreamAcc->GetImageParam()) { | 343 if (m_pStreamAcc->GetImageParam()) { |
344 CPDF_Stream* pGlobals = | 344 CPDF_Stream* pGlobals = |
345 m_pStreamAcc->GetImageParam()->GetStreamFor("JBIG2Globals"); | 345 m_pStreamAcc->GetImageParam()->GetStreamFor("JBIG2Globals"); |
346 if (pGlobals) { | 346 if (pGlobals) { |
347 m_pGlobalStream.reset(new CPDF_StreamAcc); | 347 m_pGlobalStream.reset(new CPDF_StreamAcc); |
348 m_pGlobalStream->LoadAllData(pGlobals, FALSE); | 348 m_pGlobalStream->LoadAllData(pGlobals, false); |
349 } | 349 } |
350 } | 350 } |
351 ret = pJbig2Module->StartDecode( | 351 ret = pJbig2Module->StartDecode( |
352 m_pJbig2Context.get(), m_pDocument->CodecContext(), m_Width, m_Height, | 352 m_pJbig2Context.get(), m_pDocument->CodecContext(), m_Width, m_Height, |
353 m_pStreamAcc.get(), m_pGlobalStream.get(), | 353 m_pStreamAcc.get(), m_pGlobalStream.get(), |
354 m_pCachedBitmap->GetBuffer(), m_pCachedBitmap->GetPitch(), pPause); | 354 m_pCachedBitmap->GetBuffer(), m_pCachedBitmap->GetPitch(), pPause); |
355 if (ret < 0) { | 355 if (ret < 0) { |
356 m_pCachedBitmap.reset(); | 356 m_pCachedBitmap.reset(); |
357 m_pGlobalStream.reset(); | 357 m_pGlobalStream.reset(); |
358 m_pJbig2Context.reset(); | 358 m_pJbig2Context.reset(); |
359 return 0; | 359 return 0; |
360 } | 360 } |
361 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 361 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
362 return 2; | 362 return 2; |
363 } | 363 } |
364 int ret1 = 1; | 364 int ret1 = 1; |
365 if (m_bHasMask) { | 365 if (m_bHasMask) { |
366 ret1 = ContinueLoadMaskDIB(pPause); | 366 ret1 = ContinueLoadMaskDIB(pPause); |
367 m_Status = 2; | 367 m_Status = 2; |
368 } | 368 } |
369 if (ret1 == 2) { | 369 if (ret1 == 2) { |
370 return ret1; | 370 return ret1; |
371 } | 371 } |
372 if (m_pColorSpace && m_bStdCS) { | 372 if (m_pColorSpace && m_bStdCS) { |
373 m_pColorSpace->EnableStdConversion(FALSE); | 373 m_pColorSpace->EnableStdConversion(false); |
374 } | 374 } |
375 return ret1; | 375 return ret1; |
376 } | 376 } |
377 ret = pJbig2Module->ContinueDecode(m_pJbig2Context.get(), pPause); | 377 ret = pJbig2Module->ContinueDecode(m_pJbig2Context.get(), pPause); |
378 if (ret < 0) { | 378 if (ret < 0) { |
379 m_pCachedBitmap.reset(); | 379 m_pCachedBitmap.reset(); |
380 m_pGlobalStream.reset(); | 380 m_pGlobalStream.reset(); |
381 m_pJbig2Context.reset(); | 381 m_pJbig2Context.reset(); |
382 return 0; | 382 return 0; |
383 } | 383 } |
384 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 384 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
385 return 2; | 385 return 2; |
386 } | 386 } |
387 int ret1 = 1; | 387 int ret1 = 1; |
388 if (m_bHasMask) { | 388 if (m_bHasMask) { |
389 ret1 = ContinueLoadMaskDIB(pPause); | 389 ret1 = ContinueLoadMaskDIB(pPause); |
390 m_Status = 2; | 390 m_Status = 2; |
391 } | 391 } |
392 if (ret1 == 2) { | 392 if (ret1 == 2) { |
393 return ret1; | 393 return ret1; |
394 } | 394 } |
395 if (m_pColorSpace && m_bStdCS) { | 395 if (m_pColorSpace && m_bStdCS) { |
396 m_pColorSpace->EnableStdConversion(FALSE); | 396 m_pColorSpace->EnableStdConversion(false); |
397 } | 397 } |
398 return ret1; | 398 return ret1; |
399 } | 399 } |
400 if (m_Status == 2) { | 400 if (m_Status == 2) { |
401 return ContinueLoadMaskDIB(pPause); | 401 return ContinueLoadMaskDIB(pPause); |
402 } | 402 } |
403 return 0; | 403 return 0; |
404 } | 404 } |
405 | 405 |
406 bool CPDF_DIBSource::LoadColorInfo(const CPDF_Dictionary* pFormResources, | 406 bool CPDF_DIBSource::LoadColorInfo(const CPDF_Dictionary* pFormResources, |
407 const CPDF_Dictionary* pPageResources) { | 407 const CPDF_Dictionary* pPageResources) { |
408 m_bpc_orig = m_pDict->GetIntegerFor("BitsPerComponent"); | 408 m_bpc_orig = m_pDict->GetIntegerFor("BitsPerComponent"); |
409 if (m_pDict->GetIntegerFor("ImageMask")) | 409 if (m_pDict->GetIntegerFor("ImageMask")) |
410 m_bImageMask = TRUE; | 410 m_bImageMask = true; |
411 | 411 |
412 if (m_bImageMask || !m_pDict->KeyExist("ColorSpace")) { | 412 if (m_bImageMask || !m_pDict->KeyExist("ColorSpace")) { |
413 if (!m_bImageMask) { | 413 if (!m_bImageMask) { |
414 CPDF_Object* pFilter = m_pDict->GetDirectObjectFor("Filter"); | 414 CPDF_Object* pFilter = m_pDict->GetDirectObjectFor("Filter"); |
415 if (pFilter) { | 415 if (pFilter) { |
416 CFX_ByteString filter; | 416 CFX_ByteString filter; |
417 if (pFilter->IsName()) { | 417 if (pFilter->IsName()) { |
418 filter = pFilter->GetString(); | 418 filter = pFilter->GetString(); |
419 } else if (CPDF_Array* pArray = pFilter->AsArray()) { | 419 } else if (CPDF_Array* pArray = pFilter->AsArray()) { |
420 filter = pArray->GetStringAt(pArray->GetCount() - 1); | 420 filter = pArray->GetStringAt(pArray->GetCount() - 1); |
421 } | 421 } |
422 | 422 |
423 if (filter == "JPXDecode") { | 423 if (filter == "JPXDecode") { |
424 m_bDoBpcCheck = FALSE; | 424 m_bDoBpcCheck = false; |
425 return true; | 425 return true; |
426 } | 426 } |
427 } | 427 } |
428 } | 428 } |
429 m_bImageMask = TRUE; | 429 m_bImageMask = true; |
430 m_bpc = m_nComponents = 1; | 430 m_bpc = m_nComponents = 1; |
431 CPDF_Array* pDecode = m_pDict->GetArrayFor("Decode"); | 431 CPDF_Array* pDecode = m_pDict->GetArrayFor("Decode"); |
432 m_bDefaultDecode = !pDecode || !pDecode->GetIntegerAt(0); | 432 m_bDefaultDecode = !pDecode || !pDecode->GetIntegerAt(0); |
433 return true; | 433 return true; |
434 } | 434 } |
435 | 435 |
436 CPDF_Object* pCSObj = m_pDict->GetDirectObjectFor("ColorSpace"); | 436 CPDF_Object* pCSObj = m_pDict->GetDirectObjectFor("ColorSpace"); |
437 if (!pCSObj) | 437 if (!pCSObj) |
438 return false; | 438 return false; |
439 | 439 |
(...skipping 15 matching lines...) Expand all Loading... |
455 m_nComponents = 3; | 455 m_nComponents = 3; |
456 } else if (cs == "DeviceCMYK") { | 456 } else if (cs == "DeviceCMYK") { |
457 m_nComponents = 4; | 457 m_nComponents = 4; |
458 } | 458 } |
459 } | 459 } |
460 ValidateDictParam(); | 460 ValidateDictParam(); |
461 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); | 461 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); |
462 return !!m_pCompData; | 462 return !!m_pCompData; |
463 } | 463 } |
464 | 464 |
465 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode, | 465 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(bool& bDefaultDecode, |
466 FX_BOOL& bColorKey) { | 466 bool& bColorKey) { |
467 if (!m_pColorSpace) { | 467 if (!m_pColorSpace) { |
468 return nullptr; | 468 return nullptr; |
469 } | 469 } |
470 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); | 470 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); |
471 int max_data = (1 << m_bpc) - 1; | 471 int max_data = (1 << m_bpc) - 1; |
472 CPDF_Array* pDecode = m_pDict->GetArrayFor("Decode"); | 472 CPDF_Array* pDecode = m_pDict->GetArrayFor("Decode"); |
473 if (pDecode) { | 473 if (pDecode) { |
474 for (uint32_t i = 0; i < m_nComponents; i++) { | 474 for (uint32_t i = 0; i < m_nComponents; i++) { |
475 pCompData[i].m_DecodeMin = pDecode->GetNumberAt(i * 2); | 475 pCompData[i].m_DecodeMin = pDecode->GetNumberAt(i * 2); |
476 FX_FLOAT max = pDecode->GetNumberAt(i * 2 + 1); | 476 FX_FLOAT max = pDecode->GetNumberAt(i * 2 + 1); |
477 pCompData[i].m_DecodeStep = (max - pCompData[i].m_DecodeMin) / max_data; | 477 pCompData[i].m_DecodeStep = (max - pCompData[i].m_DecodeMin) / max_data; |
478 FX_FLOAT def_value; | 478 FX_FLOAT def_value; |
479 FX_FLOAT def_min; | 479 FX_FLOAT def_min; |
480 FX_FLOAT def_max; | 480 FX_FLOAT def_max; |
481 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max); | 481 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max); |
482 if (m_Family == PDFCS_INDEXED) { | 482 if (m_Family == PDFCS_INDEXED) { |
483 def_max = max_data; | 483 def_max = max_data; |
484 } | 484 } |
485 if (def_min != pCompData[i].m_DecodeMin || def_max != max) { | 485 if (def_min != pCompData[i].m_DecodeMin || def_max != max) { |
486 bDefaultDecode = FALSE; | 486 bDefaultDecode = false; |
487 } | 487 } |
488 } | 488 } |
489 } else { | 489 } else { |
490 for (uint32_t i = 0; i < m_nComponents; i++) { | 490 for (uint32_t i = 0; i < m_nComponents; i++) { |
491 FX_FLOAT def_value; | 491 FX_FLOAT def_value; |
492 m_pColorSpace->GetDefaultValue(i, def_value, pCompData[i].m_DecodeMin, | 492 m_pColorSpace->GetDefaultValue(i, def_value, pCompData[i].m_DecodeMin, |
493 pCompData[i].m_DecodeStep); | 493 pCompData[i].m_DecodeStep); |
494 if (m_Family == PDFCS_INDEXED) { | 494 if (m_Family == PDFCS_INDEXED) { |
495 pCompData[i].m_DecodeStep = max_data; | 495 pCompData[i].m_DecodeStep = max_data; |
496 } | 496 } |
497 pCompData[i].m_DecodeStep = | 497 pCompData[i].m_DecodeStep = |
498 (pCompData[i].m_DecodeStep - pCompData[i].m_DecodeMin) / max_data; | 498 (pCompData[i].m_DecodeStep - pCompData[i].m_DecodeMin) / max_data; |
499 } | 499 } |
500 } | 500 } |
501 if (!m_pDict->KeyExist("SMask")) { | 501 if (!m_pDict->KeyExist("SMask")) { |
502 CPDF_Object* pMask = m_pDict->GetDirectObjectFor("Mask"); | 502 CPDF_Object* pMask = m_pDict->GetDirectObjectFor("Mask"); |
503 if (!pMask) { | 503 if (!pMask) { |
504 return pCompData; | 504 return pCompData; |
505 } | 505 } |
506 if (CPDF_Array* pArray = pMask->AsArray()) { | 506 if (CPDF_Array* pArray = pMask->AsArray()) { |
507 if (pArray->GetCount() >= m_nComponents * 2) { | 507 if (pArray->GetCount() >= m_nComponents * 2) { |
508 for (uint32_t i = 0; i < m_nComponents; i++) { | 508 for (uint32_t i = 0; i < m_nComponents; i++) { |
509 int min_num = pArray->GetIntegerAt(i * 2); | 509 int min_num = pArray->GetIntegerAt(i * 2); |
510 int max_num = pArray->GetIntegerAt(i * 2 + 1); | 510 int max_num = pArray->GetIntegerAt(i * 2 + 1); |
511 pCompData[i].m_ColorKeyMin = std::max(min_num, 0); | 511 pCompData[i].m_ColorKeyMin = std::max(min_num, 0); |
512 pCompData[i].m_ColorKeyMax = std::min(max_num, max_data); | 512 pCompData[i].m_ColorKeyMax = std::min(max_num, max_data); |
513 } | 513 } |
514 } | 514 } |
515 bColorKey = TRUE; | 515 bColorKey = true; |
516 } | 516 } |
517 } | 517 } |
518 return pCompData; | 518 return pCompData; |
519 } | 519 } |
520 | 520 |
521 CCodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( | 521 CCodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( |
522 const uint8_t* src_buf, | 522 const uint8_t* src_buf, |
523 uint32_t src_size, | 523 uint32_t src_size, |
524 int width, | 524 int width, |
525 int height, | 525 int height, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 if (!context->decoder()) | 628 if (!context->decoder()) |
629 return; | 629 return; |
630 | 630 |
631 uint32_t width = 0; | 631 uint32_t width = 0; |
632 uint32_t height = 0; | 632 uint32_t height = 0; |
633 uint32_t components = 0; | 633 uint32_t components = 0; |
634 pJpxModule->GetImageInfo(context->decoder(), &width, &height, &components); | 634 pJpxModule->GetImageInfo(context->decoder(), &width, &height, &components); |
635 if (static_cast<int>(width) < m_Width || static_cast<int>(height) < m_Height) | 635 if (static_cast<int>(width) < m_Width || static_cast<int>(height) < m_Height) |
636 return; | 636 return; |
637 | 637 |
638 FX_BOOL bSwapRGB = FALSE; | 638 bool bSwapRGB = false; |
639 if (m_pColorSpace) { | 639 if (m_pColorSpace) { |
640 if (components != m_pColorSpace->CountComponents()) | 640 if (components != m_pColorSpace->CountComponents()) |
641 return; | 641 return; |
642 | 642 |
643 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) { | 643 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) { |
644 bSwapRGB = TRUE; | 644 bSwapRGB = true; |
645 m_pColorSpace = nullptr; | 645 m_pColorSpace = nullptr; |
646 } | 646 } |
647 } else { | 647 } else { |
648 if (components == 3) { | 648 if (components == 3) { |
649 bSwapRGB = TRUE; | 649 bSwapRGB = true; |
650 } else if (components == 4) { | 650 } else if (components == 4) { |
651 m_pColorSpace = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK); | 651 m_pColorSpace = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK); |
652 } | 652 } |
653 m_nComponents = components; | 653 m_nComponents = components; |
654 } | 654 } |
655 | 655 |
656 FXDIB_Format format; | 656 FXDIB_Format format; |
657 if (components == 1) { | 657 if (components == 1) { |
658 format = FXDIB_8bppRgb; | 658 format = FXDIB_8bppRgb; |
659 } else if (components <= 3) { | 659 } else if (components <= 3) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 748 |
749 int CPDF_DIBSource::ContinueLoadMaskDIB(IFX_Pause* pPause) { | 749 int CPDF_DIBSource::ContinueLoadMaskDIB(IFX_Pause* pPause) { |
750 if (!m_pMask) { | 750 if (!m_pMask) { |
751 return 1; | 751 return 1; |
752 } | 752 } |
753 int ret = m_pMask->ContinueLoadDIBSource(pPause); | 753 int ret = m_pMask->ContinueLoadDIBSource(pPause); |
754 if (ret == 2) { | 754 if (ret == 2) { |
755 return ret; | 755 return ret; |
756 } | 756 } |
757 if (m_pColorSpace && m_bStdCS) { | 757 if (m_pColorSpace && m_bStdCS) { |
758 m_pColorSpace->EnableStdConversion(FALSE); | 758 m_pColorSpace->EnableStdConversion(false); |
759 } | 759 } |
760 if (!ret) { | 760 if (!ret) { |
761 delete m_pMask; | 761 delete m_pMask; |
762 m_pMask = nullptr; | 762 m_pMask = nullptr; |
763 return ret; | 763 return ret; |
764 } | 764 } |
765 return 1; | 765 return 1; |
766 } | 766 } |
767 | 767 |
768 CPDF_DIBSource* CPDF_DIBSource::DetachMask() { | 768 CPDF_DIBSource* CPDF_DIBSource::DetachMask() { |
769 CPDF_DIBSource* pDIBSource = m_pMask; | 769 CPDF_DIBSource* pDIBSource = m_pMask; |
770 m_pMask = nullptr; | 770 m_pMask = nullptr; |
771 return pDIBSource; | 771 return pDIBSource; |
772 } | 772 } |
773 | 773 |
774 CPDF_DIBSource* CPDF_DIBSource::LoadMaskDIB(CPDF_Stream* pMask) { | 774 CPDF_DIBSource* CPDF_DIBSource::LoadMaskDIB(CPDF_Stream* pMask) { |
775 CPDF_DIBSource* pMaskSource = new CPDF_DIBSource; | 775 CPDF_DIBSource* pMaskSource = new CPDF_DIBSource; |
776 if (!pMaskSource->Load(m_pDocument, pMask, nullptr, nullptr, nullptr, nullptr, | 776 if (!pMaskSource->Load(m_pDocument, pMask, nullptr, nullptr, nullptr, nullptr, |
777 TRUE)) { | 777 true)) { |
778 delete pMaskSource; | 778 delete pMaskSource; |
779 return nullptr; | 779 return nullptr; |
780 } | 780 } |
781 return pMaskSource; | 781 return pMaskSource; |
782 } | 782 } |
783 | 783 |
784 int CPDF_DIBSource::StartLoadMaskDIB() { | 784 int CPDF_DIBSource::StartLoadMaskDIB() { |
785 m_pMask = new CPDF_DIBSource; | 785 m_pMask = new CPDF_DIBSource; |
786 int ret = m_pMask->StartLoadDIBSource(m_pDocument, m_pMaskStream, FALSE, | 786 int ret = m_pMask->StartLoadDIBSource(m_pDocument, m_pMaskStream, false, |
787 nullptr, nullptr, TRUE); | 787 nullptr, nullptr, true); |
788 if (ret == 2) { | 788 if (ret == 2) { |
789 if (m_Status == 0) | 789 if (m_Status == 0) |
790 m_Status = 2; | 790 m_Status = 2; |
791 return 2; | 791 return 2; |
792 } | 792 } |
793 if (!ret) { | 793 if (!ret) { |
794 delete m_pMask; | 794 delete m_pMask; |
795 m_pMask = nullptr; | 795 m_pMask = nullptr; |
796 return 1; | 796 return 1; |
797 } | 797 } |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 *pDestPixel++ = *pSrcPixel++; | 1145 *pDestPixel++ = *pSrcPixel++; |
1146 *pDestPixel++ = *pSrcPixel++; | 1146 *pDestPixel++ = *pSrcPixel++; |
1147 *pDestPixel++ = *pSrcPixel++; | 1147 *pDestPixel++ = *pSrcPixel++; |
1148 pDestPixel++; | 1148 pDestPixel++; |
1149 } | 1149 } |
1150 return m_pMaskedLine; | 1150 return m_pMaskedLine; |
1151 } | 1151 } |
1152 return pSrcLine; | 1152 return pSrcLine; |
1153 } | 1153 } |
1154 | 1154 |
1155 FX_BOOL CPDF_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const { | 1155 bool CPDF_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const { |
1156 return m_pDecoder && m_pDecoder->SkipToScanline(line, pPause); | 1156 return m_pDecoder && m_pDecoder->SkipToScanline(line, pPause); |
1157 } | 1157 } |
1158 | 1158 |
1159 void CPDF_DIBSource::DownSampleScanline(int line, | 1159 void CPDF_DIBSource::DownSampleScanline(int line, |
1160 uint8_t* dest_scan, | 1160 uint8_t* dest_scan, |
1161 int dest_bpp, | 1161 int dest_bpp, |
1162 int dest_width, | 1162 int dest_width, |
1163 FX_BOOL bFlipX, | 1163 bool bFlipX, |
1164 int clip_left, | 1164 int clip_left, |
1165 int clip_width) const { | 1165 int clip_width) const { |
1166 if (line < 0 || !dest_scan || dest_bpp <= 0 || dest_width <= 0 || | 1166 if (line < 0 || !dest_scan || dest_bpp <= 0 || dest_width <= 0 || |
1167 clip_left < 0 || clip_width <= 0) { | 1167 clip_left < 0 || clip_width <= 0) { |
1168 return; | 1168 return; |
1169 } | 1169 } |
1170 | 1170 |
1171 uint32_t src_width = m_Width; | 1171 uint32_t src_width = m_Width; |
1172 FX_SAFE_UINT32 pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width); | 1172 FX_SAFE_UINT32 pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width); |
1173 if (!pitch.IsValid()) | 1173 if (!pitch.IsValid()) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 dest_width, bFlipX, clip_left, clip_width); | 1214 dest_width, bFlipX, clip_left, clip_width); |
1215 } | 1215 } |
1216 } | 1216 } |
1217 | 1217 |
1218 void CPDF_DIBSource::DownSampleScanline1Bit(int orig_Bpp, | 1218 void CPDF_DIBSource::DownSampleScanline1Bit(int orig_Bpp, |
1219 int dest_Bpp, | 1219 int dest_Bpp, |
1220 uint32_t src_width, | 1220 uint32_t src_width, |
1221 const uint8_t* pSrcLine, | 1221 const uint8_t* pSrcLine, |
1222 uint8_t* dest_scan, | 1222 uint8_t* dest_scan, |
1223 int dest_width, | 1223 int dest_width, |
1224 FX_BOOL bFlipX, | 1224 bool bFlipX, |
1225 int clip_left, | 1225 int clip_left, |
1226 int clip_width) const { | 1226 int clip_width) const { |
1227 uint32_t set_argb = (uint32_t)-1; | 1227 uint32_t set_argb = (uint32_t)-1; |
1228 uint32_t reset_argb = 0; | 1228 uint32_t reset_argb = 0; |
1229 if (m_bImageMask) { | 1229 if (m_bImageMask) { |
1230 if (m_bDefaultDecode) { | 1230 if (m_bDefaultDecode) { |
1231 set_argb = 0; | 1231 set_argb = 0; |
1232 reset_argb = (uint32_t)-1; | 1232 reset_argb = (uint32_t)-1; |
1233 } | 1233 } |
1234 } else if (m_bColorKey) { | 1234 } else if (m_bColorKey) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 } | 1293 } |
1294 } | 1294 } |
1295 } | 1295 } |
1296 | 1296 |
1297 void CPDF_DIBSource::DownSampleScanline8Bit(int orig_Bpp, | 1297 void CPDF_DIBSource::DownSampleScanline8Bit(int orig_Bpp, |
1298 int dest_Bpp, | 1298 int dest_Bpp, |
1299 uint32_t src_width, | 1299 uint32_t src_width, |
1300 const uint8_t* pSrcLine, | 1300 const uint8_t* pSrcLine, |
1301 uint8_t* dest_scan, | 1301 uint8_t* dest_scan, |
1302 int dest_width, | 1302 int dest_width, |
1303 FX_BOOL bFlipX, | 1303 bool bFlipX, |
1304 int clip_left, | 1304 int clip_left, |
1305 int clip_width) const { | 1305 int clip_width) const { |
1306 if (m_bpc < 8) { | 1306 if (m_bpc < 8) { |
1307 uint64_t src_bit_pos = 0; | 1307 uint64_t src_bit_pos = 0; |
1308 for (uint32_t col = 0; col < src_width; col++) { | 1308 for (uint32_t col = 0; col < src_width; col++) { |
1309 unsigned int color_index = 0; | 1309 unsigned int color_index = 0; |
1310 for (uint32_t color = 0; color < m_nComponents; color++) { | 1310 for (uint32_t color = 0; color < m_nComponents; color++) { |
1311 unsigned int data = GetBits8(pSrcLine, src_bit_pos, m_bpc); | 1311 unsigned int data = GetBits8(pSrcLine, src_bit_pos, m_bpc); |
1312 color_index |= data << (color * m_bpc); | 1312 color_index |= data << (color * m_bpc); |
1313 src_bit_pos += m_bpc; | 1313 src_bit_pos += m_bpc; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1359 } | 1359 } |
1360 } | 1360 } |
1361 } | 1361 } |
1362 | 1362 |
1363 void CPDF_DIBSource::DownSampleScanline32Bit(int orig_Bpp, | 1363 void CPDF_DIBSource::DownSampleScanline32Bit(int orig_Bpp, |
1364 int dest_Bpp, | 1364 int dest_Bpp, |
1365 uint32_t src_width, | 1365 uint32_t src_width, |
1366 const uint8_t* pSrcLine, | 1366 const uint8_t* pSrcLine, |
1367 uint8_t* dest_scan, | 1367 uint8_t* dest_scan, |
1368 int dest_width, | 1368 int dest_width, |
1369 FX_BOOL bFlipX, | 1369 bool bFlipX, |
1370 int clip_left, | 1370 int clip_left, |
1371 int clip_width) const { | 1371 int clip_width) const { |
1372 // last_src_x used to store the last seen src_x position which should be | 1372 // last_src_x used to store the last seen src_x position which should be |
1373 // in [0, src_width). Set the initial value to be an invalid src_x value. | 1373 // in [0, src_width). Set the initial value to be an invalid src_x value. |
1374 uint32_t last_src_x = src_width; | 1374 uint32_t last_src_x = src_width; |
1375 FX_ARGB last_argb = FXARGB_MAKE(0xFF, 0xFF, 0xFF, 0xFF); | 1375 FX_ARGB last_argb = FXARGB_MAKE(0xFF, 0xFF, 0xFF, 0xFF); |
1376 FX_FLOAT unit_To8Bpc = 255.0f / ((1 << m_bpc) - 1); | 1376 FX_FLOAT unit_To8Bpc = 255.0f / ((1 << m_bpc) - 1); |
1377 for (int i = 0; i < clip_width; i++) { | 1377 for (int i = 0; i < clip_width; i++) { |
1378 int dest_x = clip_left + i; | 1378 int dest_x = clip_left + i; |
1379 uint32_t src_x = (bFlipX ? (dest_width - dest_x - 1) : dest_x) * | 1379 uint32_t src_x = (bFlipX ? (dest_width - dest_x - 1) : dest_x) * |
(...skipping 24 matching lines...) Expand all Loading... |
1404 pSrcPixel = pSrcLine + src_x * orig_Bpp; | 1404 pSrcPixel = pSrcLine + src_x * orig_Bpp; |
1405 if (m_bpc == 16) { | 1405 if (m_bpc == 16) { |
1406 for (uint32_t j = 0; j < m_nComponents; ++j) | 1406 for (uint32_t j = 0; j < m_nComponents; ++j) |
1407 extracted_components[j] = pSrcPixel[j * 2]; | 1407 extracted_components[j] = pSrcPixel[j * 2]; |
1408 pSrcPixel = extracted_components; | 1408 pSrcPixel = extracted_components; |
1409 } | 1409 } |
1410 } | 1410 } |
1411 | 1411 |
1412 if (m_pColorSpace) { | 1412 if (m_pColorSpace) { |
1413 uint8_t color[4]; | 1413 uint8_t color[4]; |
1414 const FX_BOOL bTransMask = TransMask(); | 1414 const bool bTransMask = TransMask(); |
1415 if (m_bDefaultDecode) { | 1415 if (m_bDefaultDecode) { |
1416 m_pColorSpace->TranslateImageLine(color, pSrcPixel, 1, 0, 0, | 1416 m_pColorSpace->TranslateImageLine(color, pSrcPixel, 1, 0, 0, |
1417 bTransMask); | 1417 bTransMask); |
1418 } else { | 1418 } else { |
1419 for (uint32_t j = 0; j < m_nComponents; ++j) { | 1419 for (uint32_t j = 0; j < m_nComponents; ++j) { |
1420 FX_FLOAT component_value = | 1420 FX_FLOAT component_value = |
1421 static_cast<FX_FLOAT>(extracted_components[j]); | 1421 static_cast<FX_FLOAT>(extracted_components[j]); |
1422 int color_value = static_cast<int>( | 1422 int color_value = static_cast<int>( |
1423 (m_pCompData[j].m_DecodeMin + | 1423 (m_pCompData[j].m_DecodeMin + |
1424 m_pCompData[j].m_DecodeStep * component_value) * | 1424 m_pCompData[j].m_DecodeStep * component_value) * |
(...skipping 30 matching lines...) Expand all Loading... |
1455 if (dest_Bpp == 4) { | 1455 if (dest_Bpp == 4) { |
1456 *reinterpret_cast<uint32_t*>(pDestPixel) = FXARGB_TODIB(argb); | 1456 *reinterpret_cast<uint32_t*>(pDestPixel) = FXARGB_TODIB(argb); |
1457 } else { | 1457 } else { |
1458 *pDestPixel++ = FXARGB_B(argb); | 1458 *pDestPixel++ = FXARGB_B(argb); |
1459 *pDestPixel++ = FXARGB_G(argb); | 1459 *pDestPixel++ = FXARGB_G(argb); |
1460 *pDestPixel = FXARGB_R(argb); | 1460 *pDestPixel = FXARGB_R(argb); |
1461 } | 1461 } |
1462 } | 1462 } |
1463 } | 1463 } |
1464 | 1464 |
1465 FX_BOOL CPDF_DIBSource::TransMask() const { | 1465 bool CPDF_DIBSource::TransMask() const { |
1466 return m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK && | 1466 return m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK && |
1467 m_Family == PDFCS_DEVICECMYK; | 1467 m_Family == PDFCS_DEVICECMYK; |
1468 } | 1468 } |
1469 | 1469 |
1470 CPDF_ImageLoaderHandle::CPDF_ImageLoaderHandle() { | 1470 CPDF_ImageLoaderHandle::CPDF_ImageLoaderHandle() { |
1471 m_pImageLoader = nullptr; | 1471 m_pImageLoader = nullptr; |
1472 m_pCache = nullptr; | 1472 m_pCache = nullptr; |
1473 m_pImage = nullptr; | 1473 m_pImage = nullptr; |
1474 } | 1474 } |
1475 | 1475 |
1476 CPDF_ImageLoaderHandle::~CPDF_ImageLoaderHandle() {} | 1476 CPDF_ImageLoaderHandle::~CPDF_ImageLoaderHandle() {} |
1477 | 1477 |
1478 FX_BOOL CPDF_ImageLoaderHandle::Start(CPDF_ImageLoader* pImageLoader, | 1478 bool CPDF_ImageLoaderHandle::Start(CPDF_ImageLoader* pImageLoader, |
1479 const CPDF_ImageObject* pImage, | 1479 const CPDF_ImageObject* pImage, |
1480 CPDF_PageRenderCache* pCache, | 1480 CPDF_PageRenderCache* pCache, |
1481 FX_BOOL bStdCS, | 1481 bool bStdCS, |
1482 uint32_t GroupFamily, | 1482 uint32_t GroupFamily, |
1483 FX_BOOL bLoadMask, | 1483 bool bLoadMask, |
1484 CPDF_RenderStatus* pRenderStatus, | 1484 CPDF_RenderStatus* pRenderStatus, |
1485 int32_t nDownsampleWidth, | 1485 int32_t nDownsampleWidth, |
1486 int32_t nDownsampleHeight) { | 1486 int32_t nDownsampleHeight) { |
1487 m_pImageLoader = pImageLoader; | 1487 m_pImageLoader = pImageLoader; |
1488 m_pCache = pCache; | 1488 m_pCache = pCache; |
1489 m_pImage = const_cast<CPDF_ImageObject*>(pImage); | 1489 m_pImage = const_cast<CPDF_ImageObject*>(pImage); |
1490 m_nDownsampleWidth = nDownsampleWidth; | 1490 m_nDownsampleWidth = nDownsampleWidth; |
1491 m_nDownsampleHeight = nDownsampleHeight; | 1491 m_nDownsampleHeight = nDownsampleHeight; |
1492 FX_BOOL ret; | 1492 bool ret; |
1493 if (pCache) { | 1493 if (pCache) { |
1494 ret = pCache->StartGetCachedBitmap( | 1494 ret = pCache->StartGetCachedBitmap( |
1495 m_pImage->GetImage()->GetStream(), bStdCS, GroupFamily, bLoadMask, | 1495 m_pImage->GetImage()->GetStream(), bStdCS, GroupFamily, bLoadMask, |
1496 pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight); | 1496 pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight); |
1497 } else { | 1497 } else { |
1498 ret = m_pImage->GetImage()->StartLoadDIBSource( | 1498 ret = m_pImage->GetImage()->StartLoadDIBSource( |
1499 pRenderStatus->m_pFormResource, pRenderStatus->m_pPageResource, bStdCS, | 1499 pRenderStatus->m_pFormResource, pRenderStatus->m_pPageResource, bStdCS, |
1500 GroupFamily, bLoadMask); | 1500 GroupFamily, bLoadMask); |
1501 } | 1501 } |
1502 if (!ret) | 1502 if (!ret) |
1503 HandleFailure(); | 1503 HandleFailure(); |
1504 return ret; | 1504 return ret; |
1505 } | 1505 } |
1506 | 1506 |
1507 FX_BOOL CPDF_ImageLoaderHandle::Continue(IFX_Pause* pPause) { | 1507 bool CPDF_ImageLoaderHandle::Continue(IFX_Pause* pPause) { |
1508 FX_BOOL ret = m_pCache ? m_pCache->Continue(pPause) | 1508 bool ret = m_pCache ? m_pCache->Continue(pPause) |
1509 : m_pImage->GetImage()->Continue(pPause); | 1509 : m_pImage->GetImage()->Continue(pPause); |
1510 if (!ret) | 1510 if (!ret) |
1511 HandleFailure(); | 1511 HandleFailure(); |
1512 return ret; | 1512 return ret; |
1513 } | 1513 } |
1514 | 1514 |
1515 void CPDF_ImageLoaderHandle::HandleFailure() { | 1515 void CPDF_ImageLoaderHandle::HandleFailure() { |
1516 if (m_pCache) { | 1516 if (m_pCache) { |
1517 CPDF_ImageCacheEntry* entry = m_pCache->GetCurImageCacheEntry(); | 1517 CPDF_ImageCacheEntry* entry = m_pCache->GetCurImageCacheEntry(); |
1518 m_pImageLoader->m_bCached = TRUE; | 1518 m_pImageLoader->m_bCached = true; |
1519 m_pImageLoader->m_pBitmap = entry->DetachBitmap(); | 1519 m_pImageLoader->m_pBitmap = entry->DetachBitmap(); |
1520 m_pImageLoader->m_pMask = entry->DetachMask(); | 1520 m_pImageLoader->m_pMask = entry->DetachMask(); |
1521 m_pImageLoader->m_MatteColor = entry->m_MatteColor; | 1521 m_pImageLoader->m_MatteColor = entry->m_MatteColor; |
1522 } else { | 1522 } else { |
1523 CPDF_Image* pImage = m_pImage->GetImage(); | 1523 CPDF_Image* pImage = m_pImage->GetImage(); |
1524 m_pImageLoader->m_bCached = FALSE; | 1524 m_pImageLoader->m_bCached = false; |
1525 m_pImageLoader->m_pBitmap = pImage->DetachBitmap(); | 1525 m_pImageLoader->m_pBitmap = pImage->DetachBitmap(); |
1526 m_pImageLoader->m_pMask = pImage->DetachMask(); | 1526 m_pImageLoader->m_pMask = pImage->DetachMask(); |
1527 m_pImageLoader->m_MatteColor = pImage->m_MatteColor; | 1527 m_pImageLoader->m_MatteColor = pImage->m_MatteColor; |
1528 } | 1528 } |
1529 } | 1529 } |
1530 | 1530 |
1531 FX_BOOL CPDF_ImageLoader::Start( | 1531 bool CPDF_ImageLoader::Start( |
1532 const CPDF_ImageObject* pImage, | 1532 const CPDF_ImageObject* pImage, |
1533 CPDF_PageRenderCache* pCache, | 1533 CPDF_PageRenderCache* pCache, |
1534 std::unique_ptr<CPDF_ImageLoaderHandle>* pLoadHandle, | 1534 std::unique_ptr<CPDF_ImageLoaderHandle>* pLoadHandle, |
1535 FX_BOOL bStdCS, | 1535 bool bStdCS, |
1536 uint32_t GroupFamily, | 1536 uint32_t GroupFamily, |
1537 FX_BOOL bLoadMask, | 1537 bool bLoadMask, |
1538 CPDF_RenderStatus* pRenderStatus, | 1538 CPDF_RenderStatus* pRenderStatus, |
1539 int32_t nDownsampleWidth, | 1539 int32_t nDownsampleWidth, |
1540 int32_t nDownsampleHeight) { | 1540 int32_t nDownsampleHeight) { |
1541 m_nDownsampleWidth = nDownsampleWidth; | 1541 m_nDownsampleWidth = nDownsampleWidth; |
1542 m_nDownsampleHeight = nDownsampleHeight; | 1542 m_nDownsampleHeight = nDownsampleHeight; |
1543 pLoadHandle->reset(new CPDF_ImageLoaderHandle); | 1543 pLoadHandle->reset(new CPDF_ImageLoaderHandle); |
1544 return (*pLoadHandle) | 1544 return (*pLoadHandle) |
1545 ->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask, | 1545 ->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask, |
1546 pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight); | 1546 pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight); |
1547 } | 1547 } |
1548 | 1548 |
1549 FX_BOOL CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle, | 1549 bool CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle, |
1550 IFX_Pause* pPause) { | 1550 IFX_Pause* pPause) { |
1551 return LoadHandle->Continue(pPause); | 1551 return LoadHandle->Continue(pPause); |
1552 } | 1552 } |
1553 | 1553 |
1554 CPDF_ImageLoader::~CPDF_ImageLoader() { | 1554 CPDF_ImageLoader::~CPDF_ImageLoader() { |
1555 if (!m_bCached) { | 1555 if (!m_bCached) { |
1556 delete m_pBitmap; | 1556 delete m_pBitmap; |
1557 delete m_pMask; | 1557 delete m_pMask; |
1558 } | 1558 } |
1559 } | 1559 } |
OLD | NEW |