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 "../../../include/fxge/fx_ge.h" | 7 #include "../../../include/fxge/fx_ge.h" |
8 #include "../../../include/fxcodec/fx_codec.h" | 8 #include "../../../include/fxcodec/fx_codec.h" |
9 #include "../../../include/fpdfapi/fpdf_module.h" | 9 #include "../../../include/fpdfapi/fpdf_module.h" |
10 #include "../../../include/fpdfapi/fpdf_render.h" | 10 #include "../../../include/fpdfapi/fpdf_render.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 CPDF_DIBSource::CPDF_DIBSource() | 112 CPDF_DIBSource::CPDF_DIBSource() |
113 { | 113 { |
114 m_pDocument = NULL; | 114 m_pDocument = NULL; |
115 m_pStreamAcc = NULL; | 115 m_pStreamAcc = NULL; |
116 m_pDict = NULL; | 116 m_pDict = NULL; |
117 m_bpp = 0; | 117 m_bpp = 0; |
118 m_Width = m_Height = 0; | 118 m_Width = m_Height = 0; |
119 m_pColorSpace = NULL; | 119 m_pColorSpace = NULL; |
120 m_bDefaultDecode = TRUE; | 120 m_bDefaultDecode = TRUE; |
121 m_bImageMask = FALSE; | 121 m_bImageMask = FALSE; |
| 122 m_bDoBpcCheck = TRUE; |
122 m_pPalette = NULL; | 123 m_pPalette = NULL; |
123 m_pCompData = NULL; | 124 m_pCompData = NULL; |
124 m_bColorKey = FALSE; | 125 m_bColorKey = FALSE; |
125 m_pMaskedLine = m_pLineBuf = NULL; | 126 m_pMaskedLine = m_pLineBuf = NULL; |
126 m_pCachedBitmap = NULL; | 127 m_pCachedBitmap = NULL; |
127 m_pDecoder = NULL; | 128 m_pDecoder = NULL; |
128 m_nComponents = 0; | 129 m_nComponents = 0; |
129 m_bpc = 0; | 130 m_bpc = 0; |
130 m_bLoadMask = FALSE; | 131 m_bLoadMask = FALSE; |
131 m_Family = 0; | 132 m_Family = 0; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); | 191 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); |
191 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); | 192 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); |
192 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || m_Height > 0x01ff
ff) { | 193 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || m_Height > 0x01ff
ff) { |
193 return FALSE; | 194 return FALSE; |
194 } | 195 } |
195 m_GroupFamily = GroupFamily; | 196 m_GroupFamily = GroupFamily; |
196 m_bLoadMask = bLoadMask; | 197 m_bLoadMask = bLoadMask; |
197 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag
eResources)) { | 198 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag
eResources)) { |
198 return FALSE; | 199 return FALSE; |
199 } | 200 } |
200 if (m_bpc == 0 || m_nComponents == 0) { | 201 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { |
201 return FALSE; | 202 return FALSE; |
202 } | 203 } |
203 FX_SAFE_DWORD src_pitch = | 204 FX_SAFE_DWORD src_pitch = |
204 CalculatePitch8(m_bpc, m_nComponents, m_Width, m_Height); | 205 CalculatePitch8(m_bpc, m_nComponents, m_Width, m_Height); |
205 if (!src_pitch.IsValid()) { | 206 if (!src_pitch.IsValid()) { |
206 return FALSE; | 207 return FALSE; |
207 } | 208 } |
208 m_pStreamAcc = FX_NEW CPDF_StreamAcc; | 209 m_pStreamAcc = FX_NEW CPDF_StreamAcc; |
209 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); | 210 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); |
210 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { | 211 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { |
211 return FALSE; | 212 return FALSE; |
212 } | 213 } |
213 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | |
214 if (!decoder.IsEmpty() && decoder == FX_BSTRC("CCITTFaxDecode")) { | |
215 m_bpc = 1; | |
216 } | |
217 if (!CreateDecoder()) { | 214 if (!CreateDecoder()) { |
218 return FALSE; | 215 return FALSE; |
219 } | 216 } |
220 if (m_bImageMask) { | 217 if (m_bImageMask) { |
221 m_bpp = 1; | 218 m_bpp = 1; |
222 m_bpc = 1; | 219 m_bpc = 1; |
223 m_nComponents = 1; | 220 m_nComponents = 1; |
224 m_AlphaFlag = 1; | 221 m_AlphaFlag = 1; |
225 } else if (m_bpc * m_nComponents == 1) { | 222 } else if (m_bpc * m_nComponents == 1) { |
226 m_bpp = 1; | 223 m_bpp = 1; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); | 306 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); |
310 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); | 307 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); |
311 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || m_Height > 0x01ff
ff) { | 308 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || m_Height > 0x01ff
ff) { |
312 return 0; | 309 return 0; |
313 } | 310 } |
314 m_GroupFamily = GroupFamily; | 311 m_GroupFamily = GroupFamily; |
315 m_bLoadMask = bLoadMask; | 312 m_bLoadMask = bLoadMask; |
316 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag
eResources)) { | 313 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag
eResources)) { |
317 return 0; | 314 return 0; |
318 } | 315 } |
319 if (m_bpc == 0 || m_nComponents == 0) { | 316 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { |
320 return 0; | 317 return 0; |
321 } | 318 } |
322 FX_SAFE_DWORD src_pitch = | 319 FX_SAFE_DWORD src_pitch = |
323 CalculatePitch8(m_bpc, m_nComponents, m_Width, m_Height); | 320 CalculatePitch8(m_bpc, m_nComponents, m_Width, m_Height); |
324 if (!src_pitch.IsValid()) { | 321 if (!src_pitch.IsValid()) { |
325 return 0; | 322 return 0; |
326 } | 323 } |
327 m_pStreamAcc = FX_NEW CPDF_StreamAcc; | 324 m_pStreamAcc = FX_NEW CPDF_StreamAcc; |
328 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); | 325 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); |
329 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { | 326 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 m_bImageMask = TRUE; | 436 m_bImageMask = TRUE; |
440 } | 437 } |
441 if (m_bImageMask || !m_pDict->KeyExist(FX_BSTRC("ColorSpace"))) { | 438 if (m_bImageMask || !m_pDict->KeyExist(FX_BSTRC("ColorSpace"))) { |
442 if (!m_bImageMask) { | 439 if (!m_bImageMask) { |
443 CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); | 440 CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); |
444 if (pFilter) { | 441 if (pFilter) { |
445 CFX_ByteString filter; | 442 CFX_ByteString filter; |
446 if (pFilter->GetType() == PDFOBJ_NAME) { | 443 if (pFilter->GetType() == PDFOBJ_NAME) { |
447 filter = pFilter->GetString(); | 444 filter = pFilter->GetString(); |
448 if (filter == FX_BSTRC("JPXDecode")) { | 445 if (filter == FX_BSTRC("JPXDecode")) { |
| 446 m_bDoBpcCheck = FALSE; |
449 return TRUE; | 447 return TRUE; |
450 } | 448 } |
451 } else if (pFilter->GetType() == PDFOBJ_ARRAY) { | 449 } else if (pFilter->GetType() == PDFOBJ_ARRAY) { |
452 CPDF_Array* pArray = (CPDF_Array*)pFilter; | 450 CPDF_Array* pArray = (CPDF_Array*)pFilter; |
453 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("J
PXDecode")) { | 451 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("J
PXDecode")) { |
| 452 m_bDoBpcCheck = FALSE; |
454 return TRUE; | 453 return TRUE; |
455 } | 454 } |
456 } | 455 } |
457 } | 456 } |
458 } | 457 } |
459 m_bImageMask = TRUE; | 458 m_bImageMask = TRUE; |
460 m_bpc = m_nComponents = 1; | 459 m_bpc = m_nComponents = 1; |
461 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); | 460 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); |
462 m_bDefaultDecode = pDecode == NULL || pDecode->GetInteger(0) == 0; | 461 m_bDefaultDecode = pDecode == NULL || pDecode->GetInteger(0) == 0; |
463 return TRUE; | 462 return TRUE; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr
c_size, int width, int height, | 552 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr
c_size, int width, int height, |
554 const CPDF_Dictionary* pParams); | 553 const CPDF_Dictionary* pParams); |
555 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD
src_size, int width, int height, | 554 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD
src_size, int width, int height, |
556 int nComps, int bpc, const CPDF_Dictionary* pParams); | 555 int nComps, int bpc, const CPDF_Dictionary* pParams); |
557 int CPDF_DIBSource::CreateDecoder() | 556 int CPDF_DIBSource::CreateDecoder() |
558 { | 557 { |
559 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | 558 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); |
560 if (decoder.IsEmpty()) { | 559 if (decoder.IsEmpty()) { |
561 return 1; | 560 return 1; |
562 } | 561 } |
563 if (m_bpc == 0) { | 562 if (m_bDoBpcCheck && m_bpc == 0) { |
564 return 0; | 563 return 0; |
565 } | 564 } |
566 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); | 565 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); |
567 FX_DWORD src_size = m_pStreamAcc->GetSize(); | 566 FX_DWORD src_size = m_pStreamAcc->GetSize(); |
568 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); | 567 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); |
569 if (decoder == FX_BSTRC("CCITTFaxDecode")) { | 568 if (decoder == FX_BSTRC("CCITTFaxDecode")) { |
570 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei
ght, pParams); | 569 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei
ght, pParams); |
571 } else if (decoder == FX_BSTRC("DCTDecode")) { | 570 } else if (decoder == FX_BSTRC("DCTDecode")) { |
572 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d
ata, src_size, m_Width, m_Height, | 571 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d
ata, src_size, m_Width, m_Height, |
573 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color
Transform"), 1) : 1); | 572 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color
Transform"), 1) : 1); |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 { | 1508 { |
1510 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); | 1509 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); |
1511 } | 1510 } |
1512 CPDF_ImageLoader::~CPDF_ImageLoader() | 1511 CPDF_ImageLoader::~CPDF_ImageLoader() |
1513 { | 1512 { |
1514 if (!m_bCached) { | 1513 if (!m_bCached) { |
1515 delete m_pBitmap; | 1514 delete m_pBitmap; |
1516 delete m_pMask; | 1515 delete m_pMask; |
1517 } | 1516 } |
1518 } | 1517 } |
OLD | NEW |