Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp

Issue 528163002: Allocate m_pCompData when |m_nComponents| is updated. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: check return value Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/src/fpdfapi/fpdf_render/render_int.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
500 if (m_bpc == 0) { 500 if (m_pCompData == NULL) {
501 return TRUE; 501 return FALSE;
502 }
503 return TRUE;
504 }
505 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode, FX _BOOL& bColorKey)
506 {
507 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents);
508 if (pCompData == NULL) {
509 return NULL;
502 } 510 }
503 int max_data = (1 << m_bpc) - 1; 511 int max_data = (1 << m_bpc) - 1;
504 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); 512 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode"));
505 if (pDecode) { 513 if (pDecode) {
506 for (FX_DWORD i = 0; i < m_nComponents; i ++) { 514 for (FX_DWORD i = 0; i < m_nComponents; i ++) {
507 m_pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2); 515 pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2);
508 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1); 516 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1);
509 m_pCompData[i].m_DecodeStep = (max - m_pCompData[i].m_DecodeMin) / m ax_data; 517 pCompData[i].m_DecodeStep = (max - pCompData[i].m_DecodeMin) / max_d ata;
510 FX_FLOAT def_value, def_min, def_max; 518 FX_FLOAT def_value, def_min, def_max;
511 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max); 519 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max);
512 if (m_Family == PDFCS_INDEXED) { 520 if (m_Family == PDFCS_INDEXED) {
513 def_max = (FX_FLOAT)max_data; 521 def_max = (FX_FLOAT)max_data;
514 } 522 }
515 if (def_min != m_pCompData[i].m_DecodeMin || def_max != max) { 523 if (def_min != pCompData[i].m_DecodeMin || def_max != max) {
516 m_bDefaultDecode = FALSE; 524 DefaultDecode = FALSE;
jun_fang 2014/09/03 19:42:17 bDefaultDecode?
Bo Xu 2014/09/03 20:12:23 Done.
517 } 525 }
518 } 526 }
519 } else { 527 } else {
520 for (FX_DWORD i = 0; i < m_nComponents; i ++) { 528 for (FX_DWORD i = 0; i < m_nComponents; i ++) {
521 FX_FLOAT def_value; 529 FX_FLOAT def_value;
522 m_pColorSpace->GetDefaultValue(i, def_value, m_pCompData[i].m_Decode Min, m_pCompData[i].m_DecodeStep); 530 m_pColorSpace->GetDefaultValue(i, def_value, pCompData[i].m_DecodeMi n, pCompData[i].m_DecodeStep);
523 if (m_Family == PDFCS_INDEXED) { 531 if (m_Family == PDFCS_INDEXED) {
524 m_pCompData[i].m_DecodeStep = (FX_FLOAT)max_data; 532 pCompData[i].m_DecodeStep = (FX_FLOAT)max_data;
525 } 533 }
526 m_pCompData[i].m_DecodeStep = (m_pCompData[i].m_DecodeStep - m_pComp Data[i].m_DecodeMin) / max_data; 534 pCompData[i].m_DecodeStep = (pCompData[i].m_DecodeStep - pCompData[i ].m_DecodeMin) / max_data;
527 } 535 }
528 } 536 }
529 if (!m_pDict->KeyExist(FX_BSTRC("SMask"))) { 537 if (!m_pDict->KeyExist(FX_BSTRC("SMask"))) {
530 CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask")); 538 CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask"));
531 if (pMask == NULL) { 539 if (pMask == NULL) {
532 return TRUE; 540 return pCompData;
533 } 541 }
534 if (pMask->GetType() == PDFOBJ_ARRAY) { 542 if (pMask->GetType() == PDFOBJ_ARRAY) {
535 CPDF_Array* pArray = (CPDF_Array*)pMask; 543 CPDF_Array* pArray = (CPDF_Array*)pMask;
536 if (pArray->GetCount() >= m_nComponents * 2) 544 if (pArray->GetCount() >= m_nComponents * 2) {
537 for (FX_DWORD i = 0; i < m_nComponents * 2; i ++) { 545 for (FX_DWORD i = 0; i < m_nComponents; i++) {
538 if (i % 2) { 546 int min_num = pArray->GetInteger(i * 2);
539 m_pCompData[i / 2].m_ColorKeyMax = pArray->GetInteger(i) ; 547 int max_num = pArray->GetInteger(i * 2 + 1);
540 } else { 548 pCompData[i].m_ColorKeyMin = FX_MAX(min_num, 0);
541 m_pCompData[i / 2].m_ColorKeyMin = pArray->GetInteger(i) ; 549 pCompData[i].m_ColorKeyMax = FX_MIN(max_num, max_data);
542 }
543 } 550 }
544 m_bColorKey = TRUE; 551 }
552 ColorKey = TRUE;
jun_fang 2014/09/03 19:42:17 bColorKey?
Bo Xu 2014/09/03 20:12:23 Done.
545 } 553 }
546 } 554 }
547 return TRUE; 555 return pCompData;
548 } 556 }
549 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr c_size, int width, int height, 557 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr c_size, int width, int height,
550 const CPDF_Dictionary* pParams); 558 const CPDF_Dictionary* pParams);
551 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height, 559 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); 560 int nComps, int bpc, const CPDF_Dictionary* pParams);
553 int CPDF_DIBSource::CreateDecoder() 561 int CPDF_DIBSource::CreateDecoder()
554 { 562 {
555 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); 563 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder();
556 if (decoder.IsEmpty()) { 564 if (decoder.IsEmpty()) {
557 return 1; 565 return 1;
558 } 566 }
559 if (m_bpc == 0) { 567 if (m_bpc == 0) {
560 return 0; 568 return 0;
561 } 569 }
562 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); 570 FX_LPCBYTE src_data = m_pStreamAcc->GetData();
563 FX_DWORD src_size = m_pStreamAcc->GetSize(); 571 FX_DWORD src_size = m_pStreamAcc->GetSize();
564 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); 572 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam();
565 if (decoder == FX_BSTRC("CCITTFaxDecode")) { 573 if (decoder == FX_BSTRC("CCITTFaxDecode")) {
566 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei ght, pParams); 574 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei ght, pParams);
567 } else if (decoder == FX_BSTRC("DCTDecode")) { 575 } else if (decoder == FX_BSTRC("DCTDecode")) {
568 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d ata, src_size, m_Width, m_Height, 576 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); 577 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color Transform"), 1) : 1);
570 if (NULL == m_pDecoder) { 578 if (NULL == m_pDecoder) {
571 FX_BOOL bTransform = FALSE; 579 FX_BOOL bTransform = FALSE;
572 int comps, bpc; 580 int comps, bpc;
573 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e(); 581 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e();
574 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, bpc, bTransform)) { 582 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, bpc, bTransform)) {
575 m_nComponents = comps; 583 if (m_nComponents != comps) {
584 FX_Free(m_pCompData);
585 m_nComponents = comps;
586 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bCol orKey);
587 if (m_pCompData == NULL) {
588 return 0;
589 }
590 }
576 m_bpc = bpc; 591 m_bpc = bpc;
577 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height, 592 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height,
578 m_nComponents, bTransform); 593 m_nComponents, bTransform);
579 } 594 }
580 } 595 }
581 } else if (decoder == FX_BSTRC("FlateDecode")) { 596 } 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); 597 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")) { 598 } else if (decoder == FX_BSTRC("JPXDecode")) {
584 LoadJpxBitmap(); 599 LoadJpxBitmap();
585 return m_pCachedBitmap != NULL ? 1 : 0; 600 return m_pCachedBitmap != NULL ? 1 : 0;
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 } 1167 }
1153 return m_pMaskedLine; 1168 return m_pMaskedLine;
1154 } 1169 }
1155 return m_pLineBuf; 1170 return m_pLineBuf;
1156 } 1171 }
1157 if (m_bColorKey) { 1172 if (m_bColorKey) {
1158 if (m_nComponents == 3 && m_bpc == 8) { 1173 if (m_nComponents == 3 && m_bpc == 8) {
1159 FX_LPBYTE alpha_channel = m_pMaskedLine + 3; 1174 FX_LPBYTE alpha_channel = m_pMaskedLine + 3;
1160 for (int col = 0; col < m_Width; col ++) { 1175 for (int col = 0; col < m_Width; col ++) {
1161 FX_LPCBYTE pPixel = pSrcLine + col * 3; 1176 FX_LPCBYTE pPixel = pSrcLine + col * 3;
1162 alpha_channel[col * 4] = (pPixel[0] < m_pCompData[0].m_ColorKeyM in || 1177 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 || 1178 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; 1179 pPixel[2] < m_pCompData[2].m_ColorKeyM in || pPixel[2] > m_pCompData[2].m_ColorKeyMax) ? 0xff : 0;
1166 } 1180 }
1167 } else { 1181 } else {
1168 FXSYS_memset8(m_pMaskedLine, 0xff, m_Pitch); 1182 FXSYS_memset8(m_pMaskedLine, 0xff, m_Pitch);
1169 } 1183 }
1170 } 1184 }
1171 if (m_pColorSpace) { 1185 if (m_pColorSpace) {
1172 TranslateScanline24bpp(m_pLineBuf, pSrcLine); 1186 TranslateScanline24bpp(m_pLineBuf, pSrcLine);
1173 pSrcLine = m_pLineBuf; 1187 pSrcLine = m_pLineBuf;
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 if (!m_bCached) { 1559 if (!m_bCached) {
1546 if (m_pBitmap) { 1560 if (m_pBitmap) {
1547 delete m_pBitmap; 1561 delete m_pBitmap;
1548 m_pBitmap = NULL; 1562 m_pBitmap = NULL;
1549 } 1563 }
1550 if (m_pMask) { 1564 if (m_pMask) {
1551 delete m_pMask; 1565 delete m_pMask;
1552 } 1566 }
1553 } 1567 }
1554 } 1568 }
OLDNEW
« no previous file with comments | « no previous file | core/src/fpdfapi/fpdf_render/render_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698