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

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: Move AllocCompData into LoadColorInfo 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 AllocCompData();
500 return TRUE;
501 }
502 void CPDF_DIBSource::AllocCompData()
Tom Sepez 2014/09/03 16:59:11 maybe this is a bool so we can return FALSE if the
Tom Sepez 2014/09/03 16:59:11 nit: maybe AllocCompDataAndDecode().
Bo Xu 2014/09/03 18:10:15 I changed the function prototype to return m_pComp
Bo Xu 2014/09/03 18:10:15 Checked PDF reference, this struct contains decode
503 {
499 m_pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); 504 m_pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents);
Tom Sepez 2014/09/03 16:59:11 check return value for NULL?
Bo Xu 2014/09/03 18:10:16 Done.
500 if (m_bpc == 0) {
501 return TRUE;
502 }
503 int max_data = (1 << m_bpc) - 1; 505 int max_data = (1 << m_bpc) - 1;
504 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); 506 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode"));
505 if (pDecode) { 507 if (pDecode) {
506 for (FX_DWORD i = 0; i < m_nComponents; i ++) { 508 for (FX_DWORD i = 0; i < m_nComponents; i ++) {
507 m_pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2); 509 m_pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2);
508 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1); 510 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1);
509 m_pCompData[i].m_DecodeStep = (max - m_pCompData[i].m_DecodeMin) / m ax_data; 511 m_pCompData[i].m_DecodeStep = (max - m_pCompData[i].m_DecodeMin) / m ax_data;
510 FX_FLOAT def_value, def_min, def_max; 512 FX_FLOAT def_value, def_min, def_max;
511 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max); 513 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max);
512 if (m_Family == PDFCS_INDEXED) { 514 if (m_Family == PDFCS_INDEXED) {
513 def_max = (FX_FLOAT)max_data; 515 def_max = (FX_FLOAT)max_data;
514 } 516 }
515 if (def_min != m_pCompData[i].m_DecodeMin || def_max != max) { 517 if (def_min != m_pCompData[i].m_DecodeMin || def_max != max) {
516 m_bDefaultDecode = FALSE; 518 m_bDefaultDecode = FALSE;
517 } 519 }
518 } 520 }
519 } else { 521 } else {
520 for (FX_DWORD i = 0; i < m_nComponents; i ++) { 522 for (FX_DWORD i = 0; i < m_nComponents; i ++) {
521 FX_FLOAT def_value; 523 FX_FLOAT def_value;
522 m_pColorSpace->GetDefaultValue(i, def_value, m_pCompData[i].m_Decode Min, m_pCompData[i].m_DecodeStep); 524 m_pColorSpace->GetDefaultValue(i, def_value, m_pCompData[i].m_Decode Min, m_pCompData[i].m_DecodeStep);
523 if (m_Family == PDFCS_INDEXED) { 525 if (m_Family == PDFCS_INDEXED) {
524 m_pCompData[i].m_DecodeStep = (FX_FLOAT)max_data; 526 m_pCompData[i].m_DecodeStep = (FX_FLOAT)max_data;
525 } 527 }
526 m_pCompData[i].m_DecodeStep = (m_pCompData[i].m_DecodeStep - m_pComp Data[i].m_DecodeMin) / max_data; 528 m_pCompData[i].m_DecodeStep = (m_pCompData[i].m_DecodeStep - m_pComp Data[i].m_DecodeMin) / max_data;
527 } 529 }
528 } 530 }
529 if (!m_pDict->KeyExist(FX_BSTRC("SMask"))) { 531 if (!m_pDict->KeyExist(FX_BSTRC("SMask"))) {
530 CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask")); 532 CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask"));
531 if (pMask == NULL) { 533 if (pMask == NULL) {
532 return TRUE; 534 return;
533 } 535 }
534 if (pMask->GetType() == PDFOBJ_ARRAY) { 536 if (pMask->GetType() == PDFOBJ_ARRAY) {
535 CPDF_Array* pArray = (CPDF_Array*)pMask; 537 CPDF_Array* pArray = (CPDF_Array*)pMask;
536 if (pArray->GetCount() >= m_nComponents * 2) 538 if (pArray->GetCount() >= m_nComponents * 2) {
537 for (FX_DWORD i = 0; i < m_nComponents * 2; i ++) { 539 int min_num, max_num;
Tom Sepez 2014/09/03 16:59:11 nit: these declarations can go inside the next lo
Bo Xu 2014/09/03 18:10:15 Done.
538 if (i % 2) { 540 for (FX_DWORD i = 0; i < m_nComponents; i++) {
539 m_pCompData[i / 2].m_ColorKeyMax = pArray->GetInteger(i) ; 541 min_num = pArray->GetInteger(i * 2);
540 } else { 542 max_num = pArray->GetInteger(i * 2 + 1);
541 m_pCompData[i / 2].m_ColorKeyMin = pArray->GetInteger(i) ; 543 m_pCompData[i].m_ColorKeyMin = FX_MAX(0, min_num);
542 } 544 m_pCompData[i].m_ColorKeyMax = FX_MIN((1 << m_bpc) - 1, max_ num);
Tom Sepez 2014/09/03 16:59:11 I'd expect MIN to take two arguments?
Bo Xu 2014/09/03 18:10:15 I cleaned this a little bit.
543 } 545 }
546 }
544 m_bColorKey = TRUE; 547 m_bColorKey = TRUE;
545 } 548 }
546 } 549 }
547 return TRUE;
548 } 550 }
549 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr c_size, int width, int height, 551 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr c_size, int width, int height,
550 const CPDF_Dictionary* pParams); 552 const CPDF_Dictionary* pParams);
551 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height, 553 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); 554 int nComps, int bpc, const CPDF_Dictionary* pParams);
553 int CPDF_DIBSource::CreateDecoder() 555 int CPDF_DIBSource::CreateDecoder()
554 { 556 {
555 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); 557 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder();
556 if (decoder.IsEmpty()) { 558 if (decoder.IsEmpty()) {
557 return 1; 559 return 1;
558 } 560 }
559 if (m_bpc == 0) { 561 if (m_bpc == 0) {
560 return 0; 562 return 0;
561 } 563 }
562 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); 564 FX_LPCBYTE src_data = m_pStreamAcc->GetData();
563 FX_DWORD src_size = m_pStreamAcc->GetSize(); 565 FX_DWORD src_size = m_pStreamAcc->GetSize();
564 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); 566 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam();
565 if (decoder == FX_BSTRC("CCITTFaxDecode")) { 567 if (decoder == FX_BSTRC("CCITTFaxDecode")) {
566 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei ght, pParams); 568 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei ght, pParams);
567 } else if (decoder == FX_BSTRC("DCTDecode")) { 569 } else if (decoder == FX_BSTRC("DCTDecode")) {
568 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d ata, src_size, m_Width, m_Height, 570 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); 571 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color Transform"), 1) : 1);
570 if (NULL == m_pDecoder) { 572 if (NULL == m_pDecoder) {
571 FX_BOOL bTransform = FALSE; 573 FX_BOOL bTransform = FALSE;
572 int comps, bpc; 574 int comps, bpc;
573 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e(); 575 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e();
574 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, bpc, bTransform)) { 576 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, bpc, bTransform)) {
575 m_nComponents = comps; 577 if (m_nComponents != comps) {
578 m_nComponents = comps;
579 FX_Free(m_pCompData);
580 AllocCompData();
581 }
576 m_bpc = bpc; 582 m_bpc = bpc;
577 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height, 583 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height,
578 m_nComponents, bTransform); 584 m_nComponents, bTransform);
579 } 585 }
580 } 586 }
581 } else if (decoder == FX_BSTRC("FlateDecode")) { 587 } 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); 588 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")) { 589 } else if (decoder == FX_BSTRC("JPXDecode")) {
584 LoadJpxBitmap(); 590 LoadJpxBitmap();
585 return m_pCachedBitmap != NULL ? 1 : 0; 591 return m_pCachedBitmap != NULL ? 1 : 0;
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 } 1158 }
1153 return m_pMaskedLine; 1159 return m_pMaskedLine;
1154 } 1160 }
1155 return m_pLineBuf; 1161 return m_pLineBuf;
1156 } 1162 }
1157 if (m_bColorKey) { 1163 if (m_bColorKey) {
1158 if (m_nComponents == 3 && m_bpc == 8) { 1164 if (m_nComponents == 3 && m_bpc == 8) {
1159 FX_LPBYTE alpha_channel = m_pMaskedLine + 3; 1165 FX_LPBYTE alpha_channel = m_pMaskedLine + 3;
1160 for (int col = 0; col < m_Width; col ++) { 1166 for (int col = 0; col < m_Width; col ++) {
1161 FX_LPCBYTE pPixel = pSrcLine + col * 3; 1167 FX_LPCBYTE pPixel = pSrcLine + col * 3;
1162 alpha_channel[col * 4] = (pPixel[0] < m_pCompData[0].m_ColorKeyM in || 1168 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 || 1169 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; 1170 pPixel[2] < m_pCompData[2].m_ColorKeyM in || pPixel[2] > m_pCompData[2].m_ColorKeyMax) ? 0xff : 0;
1166 } 1171 }
1167 } else { 1172 } else {
1168 FXSYS_memset8(m_pMaskedLine, 0xff, m_Pitch); 1173 FXSYS_memset8(m_pMaskedLine, 0xff, m_Pitch);
1169 } 1174 }
1170 } 1175 }
1171 if (m_pColorSpace) { 1176 if (m_pColorSpace) {
1172 TranslateScanline24bpp(m_pLineBuf, pSrcLine); 1177 TranslateScanline24bpp(m_pLineBuf, pSrcLine);
1173 pSrcLine = m_pLineBuf; 1178 pSrcLine = m_pLineBuf;
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 if (!m_bCached) { 1550 if (!m_bCached) {
1546 if (m_pBitmap) { 1551 if (m_pBitmap) {
1547 delete m_pBitmap; 1552 delete m_pBitmap;
1548 m_pBitmap = NULL; 1553 m_pBitmap = NULL;
1549 } 1554 }
1550 if (m_pMask) { 1555 if (m_pMask) {
1551 delete m_pMask; 1556 delete m_pMask;
1552 } 1557 }
1553 } 1558 }
1554 } 1559 }
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