Chromium Code Reviews| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 return FALSE; | 175 return FALSE; |
| 176 } | 176 } |
| 177 m_GroupFamily = GroupFamily; | 177 m_GroupFamily = GroupFamily; |
| 178 m_bLoadMask = bLoadMask; | 178 m_bLoadMask = bLoadMask; |
| 179 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag eResources)) { | 179 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag eResources)) { |
| 180 return FALSE; | 180 return FALSE; |
| 181 } | 181 } |
| 182 if (m_bpc == 0 || m_nComponents == 0) { | 182 if (m_bpc == 0 || m_nComponents == 0) { |
| 183 return FALSE; | 183 return FALSE; |
| 184 } | 184 } |
| 185 AllocCompData(); | |
|
jun_fang
2014/09/03 04:17:08
m_pCompData = GetCompData();
if (!m_pCompData) {
| |
| 185 FX_SAFE_DWORD src_pitch = m_bpc; | 186 FX_SAFE_DWORD src_pitch = m_bpc; |
| 186 src_pitch *= m_nComponents; | 187 src_pitch *= m_nComponents; |
| 187 src_pitch *= m_Width; | 188 src_pitch *= m_Width; |
| 188 src_pitch += 7; | 189 src_pitch += 7; |
| 189 src_pitch /= 8; | 190 src_pitch /= 8; |
| 190 src_pitch *= m_Height; | 191 src_pitch *= m_Height; |
| 191 if (!src_pitch.IsValid()) { | 192 if (!src_pitch.IsValid()) { |
| 192 return FALSE; | 193 return FALSE; |
| 193 } | 194 } |
| 194 m_pStreamAcc = FX_NEW CPDF_StreamAcc; | 195 m_pStreamAcc = FX_NEW CPDF_StreamAcc; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 return 0; | 311 return 0; |
| 311 } | 312 } |
| 312 m_GroupFamily = GroupFamily; | 313 m_GroupFamily = GroupFamily; |
| 313 m_bLoadMask = bLoadMask; | 314 m_bLoadMask = bLoadMask; |
| 314 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag eResources)) { | 315 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag eResources)) { |
| 315 return 0; | 316 return 0; |
| 316 } | 317 } |
| 317 if (m_bpc == 0 || m_nComponents == 0) { | 318 if (m_bpc == 0 || m_nComponents == 0) { |
| 318 return 0; | 319 return 0; |
| 319 } | 320 } |
| 321 AllocCompData(); | |
| 320 FX_SAFE_DWORD src_pitch = m_bpc; | 322 FX_SAFE_DWORD src_pitch = m_bpc; |
| 321 src_pitch *= m_nComponents; | 323 src_pitch *= m_nComponents; |
| 322 src_pitch *= m_Width; | 324 src_pitch *= m_Width; |
| 323 src_pitch += 7; | 325 src_pitch += 7; |
| 324 src_pitch /= 8; | 326 src_pitch /= 8; |
| 325 src_pitch *= m_Height; | 327 src_pitch *= m_Height; |
| 326 if (!src_pitch.IsValid()) { | 328 if (!src_pitch.IsValid()) { |
| 327 return 0; | 329 return 0; |
| 328 } | 330 } |
| 329 m_pStreamAcc = FX_NEW CPDF_StreamAcc; | 331 m_pStreamAcc = FX_NEW CPDF_StreamAcc; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 CFX_ByteString cs = pCSObj->GetString(); | 491 CFX_ByteString cs = pCSObj->GetString(); |
| 490 if (cs == FX_BSTRC("DeviceGray")) { | 492 if (cs == FX_BSTRC("DeviceGray")) { |
| 491 m_nComponents = 1; | 493 m_nComponents = 1; |
| 492 } else if (cs == FX_BSTRC("DeviceRGB")) { | 494 } else if (cs == FX_BSTRC("DeviceRGB")) { |
| 493 m_nComponents = 3; | 495 m_nComponents = 3; |
| 494 } else if (cs == FX_BSTRC("DeviceCMYK")) { | 496 } else if (cs == FX_BSTRC("DeviceCMYK")) { |
| 495 m_nComponents = 4; | 497 m_nComponents = 4; |
| 496 } | 498 } |
| 497 } | 499 } |
| 498 ValidateDictParam(); | 500 ValidateDictParam(); |
| 501 return TRUE; | |
| 502 } | |
| 503 void CPDF_DIBSource::AllocCompData() | |
| 504 { | |
| 499 m_pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); | 505 m_pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); |
| 500 if (m_bpc == 0) { | |
| 501 return TRUE; | |
| 502 } | |
| 503 int max_data = (1 << m_bpc) - 1; | 506 int max_data = (1 << m_bpc) - 1; |
| 504 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); | 507 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); |
| 505 if (pDecode) { | 508 if (pDecode) { |
| 506 for (FX_DWORD i = 0; i < m_nComponents; i ++) { | 509 for (FX_DWORD i = 0; i < m_nComponents; i ++) { |
| 507 m_pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2); | 510 m_pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2); |
| 508 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1); | 511 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1); |
| 509 m_pCompData[i].m_DecodeStep = (max - m_pCompData[i].m_DecodeMin) / m ax_data; | 512 m_pCompData[i].m_DecodeStep = (max - m_pCompData[i].m_DecodeMin) / m ax_data; |
| 510 FX_FLOAT def_value, def_min, def_max; | 513 FX_FLOAT def_value, def_min, def_max; |
| 511 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max); | 514 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max); |
| 512 if (m_Family == PDFCS_INDEXED) { | 515 if (m_Family == PDFCS_INDEXED) { |
| 513 def_max = (FX_FLOAT)max_data; | 516 def_max = (FX_FLOAT)max_data; |
| 514 } | 517 } |
| 515 if (def_min != m_pCompData[i].m_DecodeMin || def_max != max) { | 518 if (def_min != m_pCompData[i].m_DecodeMin || def_max != max) { |
| 516 m_bDefaultDecode = FALSE; | 519 m_bDefaultDecode = FALSE; |
| 517 } | 520 } |
| 518 } | 521 } |
| 519 } else { | 522 } else { |
| 520 for (FX_DWORD i = 0; i < m_nComponents; i ++) { | 523 for (FX_DWORD i = 0; i < m_nComponents; i ++) { |
| 521 FX_FLOAT def_value; | 524 FX_FLOAT def_value; |
| 522 m_pColorSpace->GetDefaultValue(i, def_value, m_pCompData[i].m_Decode Min, m_pCompData[i].m_DecodeStep); | 525 m_pColorSpace->GetDefaultValue(i, def_value, m_pCompData[i].m_Decode Min, m_pCompData[i].m_DecodeStep); |
| 523 if (m_Family == PDFCS_INDEXED) { | 526 if (m_Family == PDFCS_INDEXED) { |
| 524 m_pCompData[i].m_DecodeStep = (FX_FLOAT)max_data; | 527 m_pCompData[i].m_DecodeStep = (FX_FLOAT)max_data; |
| 525 } | 528 } |
| 526 m_pCompData[i].m_DecodeStep = (m_pCompData[i].m_DecodeStep - m_pComp Data[i].m_DecodeMin) / max_data; | 529 m_pCompData[i].m_DecodeStep = (m_pCompData[i].m_DecodeStep - m_pComp Data[i].m_DecodeMin) / max_data; |
| 527 } | 530 } |
| 528 } | 531 } |
| 529 if (!m_pDict->KeyExist(FX_BSTRC("SMask"))) { | 532 if (!m_pDict->KeyExist(FX_BSTRC("SMask"))) { |
| 530 CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask")); | 533 CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask")); |
| 531 if (pMask == NULL) { | 534 if (pMask == NULL) { |
| 532 return TRUE; | 535 return; |
| 533 } | 536 } |
| 534 if (pMask->GetType() == PDFOBJ_ARRAY) { | 537 if (pMask->GetType() == PDFOBJ_ARRAY) { |
| 535 CPDF_Array* pArray = (CPDF_Array*)pMask; | 538 CPDF_Array* pArray = (CPDF_Array*)pMask; |
| 536 if (pArray->GetCount() >= m_nComponents * 2) | 539 if (pArray->GetCount() >= m_nComponents * 2) { |
| 537 for (FX_DWORD i = 0; i < m_nComponents * 2; i ++) { | 540 int min_num, max_num; |
| 538 if (i % 2) { | 541 for (FX_DWORD i = 0; i < m_nComponents; i++) { |
| 539 m_pCompData[i / 2].m_ColorKeyMax = pArray->GetInteger(i) ; | 542 min_num = pArray->GetInteger(i * 2); |
| 540 } else { | 543 max_num = pArray->GetInteger(i * 2 + 1); |
| 541 m_pCompData[i / 2].m_ColorKeyMin = pArray->GetInteger(i) ; | 544 m_pCompData[i].m_ColorKeyMin = FX_MAX(0, min_num); |
| 542 } | 545 m_pCompData[i].m_ColorKeyMax = FX_MIN((1 << m_bpc) - 1, max_ num); |
| 543 } | 546 } |
| 547 } | |
| 544 m_bColorKey = TRUE; | 548 m_bColorKey = TRUE; |
| 545 } | 549 } |
| 546 } | 550 } |
| 547 return TRUE; | |
| 548 } | 551 } |
| 549 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, |
| 550 const CPDF_Dictionary* pParams); | 553 const CPDF_Dictionary* pParams); |
| 551 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, |
| 552 int nComps, int bpc, const CPDF_Dictionary* pParams); | 555 int nComps, int bpc, const CPDF_Dictionary* pParams); |
| 553 int CPDF_DIBSource::CreateDecoder() | 556 int CPDF_DIBSource::CreateDecoder() |
| 554 { | 557 { |
| 555 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | 558 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); |
| 556 if (decoder.IsEmpty()) { | 559 if (decoder.IsEmpty()) { |
| 557 return 1; | 560 return 1; |
| 558 } | 561 } |
| 559 if (m_bpc == 0) { | 562 if (m_bpc == 0) { |
| 560 return 0; | 563 return 0; |
| 561 } | 564 } |
| 562 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); | 565 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); |
| 563 FX_DWORD src_size = m_pStreamAcc->GetSize(); | 566 FX_DWORD src_size = m_pStreamAcc->GetSize(); |
| 564 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); | 567 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); |
| 565 if (decoder == FX_BSTRC("CCITTFaxDecode")) { | 568 if (decoder == FX_BSTRC("CCITTFaxDecode")) { |
| 566 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); |
| 567 } else if (decoder == FX_BSTRC("DCTDecode")) { | 570 } else if (decoder == FX_BSTRC("DCTDecode")) { |
| 568 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, |
| 569 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color Transform"), 1) : 1); | 572 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color Transform"), 1) : 1); |
| 570 if (NULL == m_pDecoder) { | 573 if (NULL == m_pDecoder) { |
| 571 FX_BOOL bTransform = FALSE; | 574 FX_BOOL bTransform = FALSE; |
| 572 int comps, bpc; | 575 int comps, bpc; |
| 573 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e(); | 576 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e(); |
| 574 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, bpc, bTransform)) { | 577 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, bpc, bTransform)) { |
| 575 m_nComponents = comps; | 578 if (m_nComponents != comps) { |
| 579 m_nComponents = comps; | |
| 580 FX_Free(m_pCompData); | |
| 581 AllocCompData(); | |
| 582 } | |
| 576 m_bpc = bpc; | 583 m_bpc = bpc; |
| 577 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height, | 584 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height, |
| 578 m_nComponents, bTransform); | 585 m_nComponents, bTransform); |
| 579 } | 586 } |
| 580 } | 587 } |
| 581 } else if (decoder == FX_BSTRC("FlateDecode")) { | 588 } 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); | 589 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")) { | 590 } else if (decoder == FX_BSTRC("JPXDecode")) { |
| 584 LoadJpxBitmap(); | 591 LoadJpxBitmap(); |
| 585 return m_pCachedBitmap != NULL ? 1 : 0; | 592 return m_pCachedBitmap != NULL ? 1 : 0; |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1152 } | 1159 } |
| 1153 return m_pMaskedLine; | 1160 return m_pMaskedLine; |
| 1154 } | 1161 } |
| 1155 return m_pLineBuf; | 1162 return m_pLineBuf; |
| 1156 } | 1163 } |
| 1157 if (m_bColorKey) { | 1164 if (m_bColorKey) { |
| 1158 if (m_nComponents == 3 && m_bpc == 8) { | 1165 if (m_nComponents == 3 && m_bpc == 8) { |
| 1159 FX_LPBYTE alpha_channel = m_pMaskedLine + 3; | 1166 FX_LPBYTE alpha_channel = m_pMaskedLine + 3; |
| 1160 for (int col = 0; col < m_Width; col ++) { | 1167 for (int col = 0; col < m_Width; col ++) { |
| 1161 FX_LPCBYTE pPixel = pSrcLine + col * 3; | 1168 FX_LPCBYTE pPixel = pSrcLine + col * 3; |
| 1162 alpha_channel[col * 4] = (pPixel[0] < m_pCompData[0].m_ColorKeyM in || | 1169 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 || | 1170 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; | 1171 pPixel[2] < m_pCompData[2].m_ColorKeyM in || pPixel[2] > m_pCompData[2].m_ColorKeyMax) ? 0xff : 0; |
| 1166 } | 1172 } |
| 1167 } else { | 1173 } else { |
| 1168 FXSYS_memset8(m_pMaskedLine, 0xff, m_Pitch); | 1174 FXSYS_memset8(m_pMaskedLine, 0xff, m_Pitch); |
| 1169 } | 1175 } |
| 1170 } | 1176 } |
| 1171 if (m_pColorSpace) { | 1177 if (m_pColorSpace) { |
| 1172 TranslateScanline24bpp(m_pLineBuf, pSrcLine); | 1178 TranslateScanline24bpp(m_pLineBuf, pSrcLine); |
| 1173 pSrcLine = m_pLineBuf; | 1179 pSrcLine = m_pLineBuf; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1545 if (!m_bCached) { | 1551 if (!m_bCached) { |
| 1546 if (m_pBitmap) { | 1552 if (m_pBitmap) { |
| 1547 delete m_pBitmap; | 1553 delete m_pBitmap; |
| 1548 m_pBitmap = NULL; | 1554 m_pBitmap = NULL; |
| 1549 } | 1555 } |
| 1550 if (m_pMask) { | 1556 if (m_pMask) { |
| 1551 delete m_pMask; | 1557 delete m_pMask; |
| 1552 } | 1558 } |
| 1553 } | 1559 } |
| 1554 } | 1560 } |
| OLD | NEW |