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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 CFX_ByteString cs = pCSObj->GetString(); | 489 CFX_ByteString cs = pCSObj->GetString(); |
490 if (cs == FX_BSTRC("DeviceGray")) { | 490 if (cs == FX_BSTRC("DeviceGray")) { |
491 m_nComponents = 1; | 491 m_nComponents = 1; |
492 } else if (cs == FX_BSTRC("DeviceRGB")) { | 492 } else if (cs == FX_BSTRC("DeviceRGB")) { |
493 m_nComponents = 3; | 493 m_nComponents = 3; |
494 } else if (cs == FX_BSTRC("DeviceCMYK")) { | 494 } else if (cs == FX_BSTRC("DeviceCMYK")) { |
495 m_nComponents = 4; | 495 m_nComponents = 4; |
496 } | 496 } |
497 } | 497 } |
498 ValidateDictParam(); | 498 ValidateDictParam(); |
499 m_pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); | 499 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); |
jun_fang
2014/09/03 19:12:02
check |m_pCompData == NULL|?
Bo Xu
2014/09/03 19:36:59
Done.
| |
500 if (m_bpc == 0) { | 500 return TRUE; |
501 return TRUE; | 501 } |
502 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& DefaultDecode, FX_ BOOL& ColorKey) | |
jun_fang
2014/09/03 19:12:02
rename DefaultDecode to bDefaultDecode and ColorKe
Bo Xu
2014/09/03 19:36:59
Done.
| |
503 { | |
504 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); | |
505 if (pCompData == NULL) { | |
506 return NULL; | |
502 } | 507 } |
503 int max_data = (1 << m_bpc) - 1; | 508 int max_data = (1 << m_bpc) - 1; |
504 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); | 509 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); |
505 if (pDecode) { | 510 if (pDecode) { |
506 for (FX_DWORD i = 0; i < m_nComponents; i ++) { | 511 for (FX_DWORD i = 0; i < m_nComponents; i ++) { |
507 m_pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2); | 512 pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2); |
508 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1); | 513 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1); |
509 m_pCompData[i].m_DecodeStep = (max - m_pCompData[i].m_DecodeMin) / m ax_data; | 514 pCompData[i].m_DecodeStep = (max - pCompData[i].m_DecodeMin) / max_d ata; |
510 FX_FLOAT def_value, def_min, def_max; | 515 FX_FLOAT def_value, def_min, def_max; |
511 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max); | 516 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max); |
512 if (m_Family == PDFCS_INDEXED) { | 517 if (m_Family == PDFCS_INDEXED) { |
513 def_max = (FX_FLOAT)max_data; | 518 def_max = (FX_FLOAT)max_data; |
514 } | 519 } |
515 if (def_min != m_pCompData[i].m_DecodeMin || def_max != max) { | 520 if (def_min != pCompData[i].m_DecodeMin || def_max != max) { |
516 m_bDefaultDecode = FALSE; | 521 DefaultDecode = FALSE; |
517 } | 522 } |
518 } | 523 } |
519 } else { | 524 } else { |
520 for (FX_DWORD i = 0; i < m_nComponents; i ++) { | 525 for (FX_DWORD i = 0; i < m_nComponents; i ++) { |
521 FX_FLOAT def_value; | 526 FX_FLOAT def_value; |
522 m_pColorSpace->GetDefaultValue(i, def_value, m_pCompData[i].m_Decode Min, m_pCompData[i].m_DecodeStep); | 527 m_pColorSpace->GetDefaultValue(i, def_value, pCompData[i].m_DecodeMi n, pCompData[i].m_DecodeStep); |
523 if (m_Family == PDFCS_INDEXED) { | 528 if (m_Family == PDFCS_INDEXED) { |
524 m_pCompData[i].m_DecodeStep = (FX_FLOAT)max_data; | 529 pCompData[i].m_DecodeStep = (FX_FLOAT)max_data; |
525 } | 530 } |
526 m_pCompData[i].m_DecodeStep = (m_pCompData[i].m_DecodeStep - m_pComp Data[i].m_DecodeMin) / max_data; | 531 pCompData[i].m_DecodeStep = (pCompData[i].m_DecodeStep - pCompData[i ].m_DecodeMin) / max_data; |
527 } | 532 } |
528 } | 533 } |
529 if (!m_pDict->KeyExist(FX_BSTRC("SMask"))) { | 534 if (!m_pDict->KeyExist(FX_BSTRC("SMask"))) { |
530 CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask")); | 535 CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask")); |
531 if (pMask == NULL) { | 536 if (pMask == NULL) { |
532 return TRUE; | 537 return pCompData; |
533 } | 538 } |
534 if (pMask->GetType() == PDFOBJ_ARRAY) { | 539 if (pMask->GetType() == PDFOBJ_ARRAY) { |
535 CPDF_Array* pArray = (CPDF_Array*)pMask; | 540 CPDF_Array* pArray = (CPDF_Array*)pMask; |
536 if (pArray->GetCount() >= m_nComponents * 2) | 541 if (pArray->GetCount() >= m_nComponents * 2) { |
537 for (FX_DWORD i = 0; i < m_nComponents * 2; i ++) { | 542 for (FX_DWORD i = 0; i < m_nComponents; i++) { |
538 if (i % 2) { | 543 int min_num = pArray->GetInteger(i * 2); |
539 m_pCompData[i / 2].m_ColorKeyMax = pArray->GetInteger(i) ; | 544 int max_num = pArray->GetInteger(i * 2 + 1); |
540 } else { | 545 pCompData[i].m_ColorKeyMin = FX_MAX(min_num, 0); |
541 m_pCompData[i / 2].m_ColorKeyMin = pArray->GetInteger(i) ; | 546 pCompData[i].m_ColorKeyMax = FX_MIN(max_num, max_data); |
542 } | |
543 } | 547 } |
544 m_bColorKey = TRUE; | 548 } |
549 ColorKey = TRUE; | |
545 } | 550 } |
546 } | 551 } |
547 return TRUE; | 552 return pCompData; |
548 } | 553 } |
549 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr c_size, int width, int height, | 554 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr c_size, int width, int height, |
550 const CPDF_Dictionary* pParams); | 555 const CPDF_Dictionary* pParams); |
551 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height, | 556 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height, |
552 int nComps, int bpc, const CPDF_Dictionary* pParams); | 557 int nComps, int bpc, const CPDF_Dictionary* pParams); |
553 int CPDF_DIBSource::CreateDecoder() | 558 int CPDF_DIBSource::CreateDecoder() |
554 { | 559 { |
555 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | 560 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); |
556 if (decoder.IsEmpty()) { | 561 if (decoder.IsEmpty()) { |
557 return 1; | 562 return 1; |
558 } | 563 } |
559 if (m_bpc == 0) { | 564 if (m_bpc == 0) { |
560 return 0; | 565 return 0; |
561 } | 566 } |
562 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); | 567 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); |
563 FX_DWORD src_size = m_pStreamAcc->GetSize(); | 568 FX_DWORD src_size = m_pStreamAcc->GetSize(); |
564 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); | 569 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); |
565 if (decoder == FX_BSTRC("CCITTFaxDecode")) { | 570 if (decoder == FX_BSTRC("CCITTFaxDecode")) { |
566 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei ght, pParams); | 571 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei ght, pParams); |
567 } else if (decoder == FX_BSTRC("DCTDecode")) { | 572 } else if (decoder == FX_BSTRC("DCTDecode")) { |
568 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d ata, src_size, m_Width, m_Height, | 573 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d ata, src_size, m_Width, m_Height, |
569 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color Transform"), 1) : 1); | 574 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color Transform"), 1) : 1); |
570 if (NULL == m_pDecoder) { | 575 if (NULL == m_pDecoder) { |
571 FX_BOOL bTransform = FALSE; | 576 FX_BOOL bTransform = FALSE; |
572 int comps, bpc; | 577 int comps, bpc; |
573 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e(); | 578 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e(); |
574 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, bpc, bTransform)) { | 579 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, bpc, bTransform)) { |
575 m_nComponents = comps; | 580 if (m_nComponents != comps) { |
581 m_nComponents = comps; | |
582 FX_Free(m_pCompData); | |
Tom Sepez
2014/09/03 19:22:51
nit: I'd do the free before the assign to m_nComp
Bo Xu
2014/09/03 19:36:59
Done.
| |
583 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bCol orKey); | |
jun_fang
2014/09/03 19:12:02
Check |m_pCompData == NULL|?
Bo Xu
2014/09/03 19:36:59
Done.
| |
584 } | |
576 m_bpc = bpc; | 585 m_bpc = bpc; |
577 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height, | 586 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height, |
578 m_nComponents, bTransform); | 587 m_nComponents, bTransform); |
579 } | 588 } |
580 } | 589 } |
581 } else if (decoder == FX_BSTRC("FlateDecode")) { | 590 } else if (decoder == FX_BSTRC("FlateDecode")) { |
582 m_pDecoder = FPDFAPI_CreateFlateDecoder(src_data, src_size, m_Width, m_H eight, m_nComponents, m_bpc, pParams); | 591 m_pDecoder = FPDFAPI_CreateFlateDecoder(src_data, src_size, m_Width, m_H eight, m_nComponents, m_bpc, pParams); |
583 } else if (decoder == FX_BSTRC("JPXDecode")) { | 592 } else if (decoder == FX_BSTRC("JPXDecode")) { |
584 LoadJpxBitmap(); | 593 LoadJpxBitmap(); |
585 return m_pCachedBitmap != NULL ? 1 : 0; | 594 return m_pCachedBitmap != NULL ? 1 : 0; |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1152 } | 1161 } |
1153 return m_pMaskedLine; | 1162 return m_pMaskedLine; |
1154 } | 1163 } |
1155 return m_pLineBuf; | 1164 return m_pLineBuf; |
1156 } | 1165 } |
1157 if (m_bColorKey) { | 1166 if (m_bColorKey) { |
1158 if (m_nComponents == 3 && m_bpc == 8) { | 1167 if (m_nComponents == 3 && m_bpc == 8) { |
1159 FX_LPBYTE alpha_channel = m_pMaskedLine + 3; | 1168 FX_LPBYTE alpha_channel = m_pMaskedLine + 3; |
1160 for (int col = 0; col < m_Width; col ++) { | 1169 for (int col = 0; col < m_Width; col ++) { |
1161 FX_LPCBYTE pPixel = pSrcLine + col * 3; | 1170 FX_LPCBYTE pPixel = pSrcLine + col * 3; |
1162 alpha_channel[col * 4] = (pPixel[0] < m_pCompData[0].m_ColorKeyM in || | 1171 alpha_channel[col * 4] = (pPixel[0] < m_pCompData[0].m_ColorKeyM in || pPixel[0] > m_pCompData[0].m_ColorKeyMax || |
1163 pPixel[0] > m_pCompData[0].m_ColorKeyM ax || | |
1164 pPixel[1] < m_pCompData[1].m_ColorKeyM in || pPixel[1] > m_pCompData[1].m_ColorKeyMax || | 1172 pPixel[1] < m_pCompData[1].m_ColorKeyM in || pPixel[1] > m_pCompData[1].m_ColorKeyMax || |
1165 pPixel[2] < m_pCompData[2].m_ColorKeyM in || pPixel[2] > m_pCompData[2].m_ColorKeyMax) ? 0xff : 0; | 1173 pPixel[2] < m_pCompData[2].m_ColorKeyM in || pPixel[2] > m_pCompData[2].m_ColorKeyMax) ? 0xff : 0; |
1166 } | 1174 } |
1167 } else { | 1175 } else { |
1168 FXSYS_memset8(m_pMaskedLine, 0xff, m_Pitch); | 1176 FXSYS_memset8(m_pMaskedLine, 0xff, m_Pitch); |
1169 } | 1177 } |
1170 } | 1178 } |
1171 if (m_pColorSpace) { | 1179 if (m_pColorSpace) { |
1172 TranslateScanline24bpp(m_pLineBuf, pSrcLine); | 1180 TranslateScanline24bpp(m_pLineBuf, pSrcLine); |
1173 pSrcLine = m_pLineBuf; | 1181 pSrcLine = m_pLineBuf; |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1545 if (!m_bCached) { | 1553 if (!m_bCached) { |
1546 if (m_pBitmap) { | 1554 if (m_pBitmap) { |
1547 delete m_pBitmap; | 1555 delete m_pBitmap; |
1548 m_pBitmap = NULL; | 1556 m_pBitmap = NULL; |
1549 } | 1557 } |
1550 if (m_pMask) { | 1558 if (m_pMask) { |
1551 delete m_pMask; | 1559 delete m_pMask; |
1552 } | 1560 } |
1553 } | 1561 } |
1554 } | 1562 } |
OLD | NEW |