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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); | 310 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); |
311 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); | 311 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); |
312 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || m_Height > 0x01ff ff) { | 312 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || m_Height > 0x01ff ff) { |
313 return 0; | 313 return 0; |
314 } | 314 } |
315 m_GroupFamily = GroupFamily; | 315 m_GroupFamily = GroupFamily; |
316 m_bLoadMask = bLoadMask; | 316 m_bLoadMask = bLoadMask; |
317 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag eResources)) { | 317 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag eResources)) { |
318 return 0; | 318 return 0; |
319 } | 319 } |
320 | |
321 if (m_bpc == 0 || m_nComponents == 0) { | 320 if (m_bpc == 0 || m_nComponents == 0) { |
322 return 0; | 321 return 0; |
323 } | 322 } |
324 | |
325 FX_SAFE_DWORD src_pitch = m_bpc; | 323 FX_SAFE_DWORD src_pitch = m_bpc; |
326 src_pitch *= m_nComponents; | 324 src_pitch *= m_nComponents; |
327 src_pitch *= m_Width; | 325 src_pitch *= m_Width; |
328 src_pitch += 7; | 326 src_pitch += 7; |
329 src_pitch /= 8; | 327 src_pitch /= 8; |
330 src_pitch *= m_Height; | 328 src_pitch *= m_Height; |
331 if (!src_pitch.IsValid()) { | 329 if (!src_pitch.IsValid()) { |
332 return 0; | 330 return 0; |
333 } | 331 } |
334 | |
335 m_pStreamAcc = FX_NEW CPDF_StreamAcc; | 332 m_pStreamAcc = FX_NEW CPDF_StreamAcc; |
336 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); | 333 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); |
337 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { | 334 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { |
338 return 0; | 335 return 0; |
339 } | 336 } |
340 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | 337 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); |
341 if (!decoder.IsEmpty() && decoder == FX_BSTRC("CCITTFaxDecode")) { | |
342 m_bpc = 1; | |
343 } | |
344 int ret = CreateDecoder(); | 338 int ret = CreateDecoder(); |
345 if (ret != 1) { | 339 if (ret != 1) { |
346 if (!ret) { | 340 if (!ret) { |
347 return ret; | 341 return ret; |
348 } | 342 } |
349 if (!ContinueToLoadMask()) { | 343 if (!ContinueToLoadMask()) { |
350 return 0; | 344 return 0; |
351 } | 345 } |
352 if (m_bHasMask) { | 346 if (m_bHasMask) { |
353 StratLoadMask(); | 347 StratLoadMask(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 m_pColorSpace->EnableStdConversion(FALSE); | 437 m_pColorSpace->EnableStdConversion(FALSE); |
444 } | 438 } |
445 return ret1; | 439 return ret1; |
446 } else if (m_Status == 2) { | 440 } else if (m_Status == 2) { |
447 return ContinueLoadMaskDIB(pPause); | 441 return ContinueLoadMaskDIB(pPause); |
448 } | 442 } |
449 return 0; | 443 return 0; |
450 } | 444 } |
451 FX_BOOL CPDF_DIBSource::LoadColorInfo(CPDF_Dictionary* pFormResources, CPDF_Dict ionary* pPageResources) | 445 FX_BOOL CPDF_DIBSource::LoadColorInfo(CPDF_Dictionary* pFormResources, CPDF_Dict ionary* pPageResources) |
452 { | 446 { |
453 m_bpc_orig = m_pDict->GetInteger(FX_BSTRC("BitsPerComponent")); | |
454 ValidateBpc(); | |
455 if (m_pDict->GetInteger("ImageMask")) { | 447 if (m_pDict->GetInteger("ImageMask")) { |
456 m_bImageMask = TRUE; | 448 m_bImageMask = TRUE; |
457 } | 449 } |
458 if (m_bImageMask || !m_pDict->KeyExist(FX_BSTRC("ColorSpace"))) { | 450 if (m_bImageMask || !m_pDict->KeyExist(FX_BSTRC("ColorSpace"))) { |
459 if (!m_bImageMask) { | 451 if (!m_bImageMask) { |
460 CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); | 452 CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); |
461 if (pFilter) { | 453 if (pFilter) { |
462 CFX_ByteString filter; | 454 CFX_ByteString filter; |
463 if (pFilter->GetType() == PDFOBJ_NAME) { | 455 if (pFilter->GetType() == PDFOBJ_NAME) { |
464 filter = pFilter->GetString(); | 456 filter = pFilter->GetString(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 if (m_Family == PDFCS_ICCBASED && pCSObj->GetType() == PDFOBJ_NAME) { | 490 if (m_Family == PDFCS_ICCBASED && pCSObj->GetType() == PDFOBJ_NAME) { |
499 CFX_ByteString cs = pCSObj->GetString(); | 491 CFX_ByteString cs = pCSObj->GetString(); |
500 if (cs == FX_BSTRC("DeviceGray")) { | 492 if (cs == FX_BSTRC("DeviceGray")) { |
501 m_nComponents = 1; | 493 m_nComponents = 1; |
502 } else if (cs == FX_BSTRC("DeviceRGB")) { | 494 } else if (cs == FX_BSTRC("DeviceRGB")) { |
503 m_nComponents = 3; | 495 m_nComponents = 3; |
504 } else if (cs == FX_BSTRC("DeviceCMYK")) { | 496 } else if (cs == FX_BSTRC("DeviceCMYK")) { |
505 m_nComponents = 4; | 497 m_nComponents = 4; |
506 } | 498 } |
507 } | 499 } |
500 m_bpc_orig = m_pDict->GetInteger(FX_BSTRC("BitsPerComponent")); | |
Tom Sepez
2014/09/02 22:11:54
Maybe this assignment goes as the first line of Va
Bo Xu
2014/09/02 22:27:13
Done.
| |
501 ValidateDictParam(); | |
508 m_pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); | 502 m_pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); |
509 if (m_bpc == 0) { | 503 if (m_bpc == 0) { |
510 return TRUE; | 504 return TRUE; |
511 } | 505 } |
512 int max_data = (1 << m_bpc) - 1; | 506 int max_data = (1 << m_bpc) - 1; |
513 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); | 507 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); |
514 if (pDecode) { | 508 if (pDecode) { |
515 for (FX_DWORD i = 0; i < m_nComponents; i ++) { | 509 for (FX_DWORD i = 0; i < m_nComponents; i ++) { |
516 m_pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2); | 510 m_pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2); |
517 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1); | 511 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1); |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
908 } | 902 } |
909 m_pColorSpace->GetRGB(temp_buf, R, G, B); | 903 m_pColorSpace->GetRGB(temp_buf, R, G, B); |
910 FX_Free(temp_buf); | 904 FX_Free(temp_buf); |
911 } else { | 905 } else { |
912 m_pColorSpace->GetRGB(color_value, R, G, B); | 906 m_pColorSpace->GetRGB(color_value, R, G, B); |
913 } | 907 } |
914 SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255), FXSYS_round( G * 255), FXSYS_round(B * 255))); | 908 SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255), FXSYS_round( G * 255), FXSYS_round(B * 255))); |
915 } | 909 } |
916 } | 910 } |
917 } | 911 } |
918 void CPDF_DIBSource::ValidateBpc() | 912 void CPDF_DIBSource::ValidateDictParam() |
919 { | 913 { |
920 m_bpc = m_bpc_orig; | 914 m_bpc = m_bpc_orig; |
921 CPDF_Object * pFilter = m_pDict ? m_pDict->GetElementValue(FX_BSTRC("Fil ter")) : NULL; | 915 CPDF_Object * pFilter = m_pDict ? m_pDict->GetElementValue(FX_BSTRC("Fil ter")) : NULL; |
Tom Sepez
2014/09/02 22:11:54
nit: we de-ref'd m_pDict just before calling this
Bo Xu
2014/09/02 22:27:13
Now check m_pDict in CPDF_DIBSource::Load to make
| |
922 if (pFilter) { | 916 if (pFilter) { |
923 if (pFilter->GetType() == PDFOBJ_NAME) { | 917 if (pFilter->GetType() == PDFOBJ_NAME) { |
924 CFX_ByteString filter = pFilter->GetString(); | 918 CFX_ByteString filter = pFilter->GetString(); |
925 if (filter == FX_BSTRC("CCITTFaxDecode") || filter == FX_BSTRC("JBIG 2Decode")) { | 919 if (filter == FX_BSTRC("CCITTFaxDecode") || filter == FX_BSTRC("JBIG 2Decode")) { |
926 m_bpc = 1; | 920 m_bpc = 1; |
921 m_nComponents = 1; | |
927 } | 922 } |
928 if (filter == FX_BSTRC("RunLengthDecode") || filter == FX_BSTRC("DCT Decode")) { | 923 if (filter == FX_BSTRC("RunLengthDecode") || filter == FX_BSTRC("DCT Decode")) { |
929 m_bpc = 8; | 924 m_bpc = 8; |
930 } | 925 } |
931 } else if (pFilter->GetType() == PDFOBJ_ARRAY) { | 926 } else if (pFilter->GetType() == PDFOBJ_ARRAY) { |
932 CPDF_Array *pArray = (CPDF_Array *)pFilter; | 927 CPDF_Array *pArray = (CPDF_Array *)pFilter; |
933 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("CCITTFacD ecode") || | 928 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("CCITTFacD ecode") || |
934 pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("JBIG2 Decode")) { | 929 pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("JBIG2 Decode")) { |
935 m_bpc = 1; | 930 m_bpc = 1; |
931 m_nComponents = 1; | |
936 } | 932 } |
937 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("RunLength Decode") || | 933 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("RunLength Decode") || |
938 pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("DCTDe code")) { | 934 pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("DCTDe code")) { |
939 m_bpc = 8; | 935 m_bpc = 8; |
940 } | 936 } |
941 } | 937 } |
942 } | 938 } |
943 if (m_bpc != 1 && m_bpc != 2 && m_bpc != 4 && m_bpc != 8 && m_bpc != 16) { | 939 if (m_bpc != 1 && m_bpc != 2 && m_bpc != 4 && m_bpc != 8 && m_bpc != 16) { |
944 m_bpc = 0; | 940 m_bpc = 0; |
945 } | 941 } |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1552 if (!m_bCached) { | 1548 if (!m_bCached) { |
1553 if (m_pBitmap) { | 1549 if (m_pBitmap) { |
1554 delete m_pBitmap; | 1550 delete m_pBitmap; |
1555 m_pBitmap = NULL; | 1551 m_pBitmap = NULL; |
1556 } | 1552 } |
1557 if (m_pMask) { | 1553 if (m_pMask) { |
1558 delete m_pMask; | 1554 delete m_pMask; |
1559 } | 1555 } |
1560 } | 1556 } |
1561 } | 1557 } |
OLD | NEW |