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

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

Issue 1310603006: Cleanup dead code in CPDF_DIBSource::LoadJpxBitmap() and friends. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: remove redundent components params / variables Created 5 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
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 "../../../../third_party/base/nonstd_unique_ptr.h" 7 #include "../../../../third_party/base/nonstd_unique_ptr.h"
8 #include "../../../include/fpdfapi/fpdf_module.h" 8 #include "../../../include/fpdfapi/fpdf_module.h"
9 #include "../../../include/fpdfapi/fpdf_pageobj.h" 9 #include "../../../include/fpdfapi/fpdf_pageobj.h"
10 #include "../../../include/fpdfapi/fpdf_render.h" 10 #include "../../../include/fpdfapi/fpdf_render.h"
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 nonstd::unique_ptr<JpxBitMapContext> context( 699 nonstd::unique_ptr<JpxBitMapContext> context(
700 new JpxBitMapContext(pJpxModule)); 700 new JpxBitMapContext(pJpxModule));
701 context->set_context(pJpxModule->CreateDecoder(m_pStreamAcc->GetData(), 701 context->set_context(pJpxModule->CreateDecoder(m_pStreamAcc->GetData(),
702 m_pStreamAcc->GetSize(), 702 m_pStreamAcc->GetSize(),
703 m_pColorSpace != nullptr)); 703 m_pColorSpace != nullptr));
704 if (!context->context()) 704 if (!context->context())
705 return; 705 return;
706 706
707 FX_DWORD width = 0; 707 FX_DWORD width = 0;
708 FX_DWORD height = 0; 708 FX_DWORD height = 0;
709 FX_DWORD codestream_nComps = 0; 709 FX_DWORD components = 0;
710 FX_DWORD image_nComps = 0; 710 pJpxModule->GetImageInfo(context->context(), &width, &height, &components);
711 pJpxModule->GetImageInfo(context->context(), width, height, codestream_nComps,
712 image_nComps);
713 if ((int)width < m_Width || (int)height < m_Height) 711 if ((int)width < m_Width || (int)height < m_Height)
714 return; 712 return;
715 713
716 int output_nComps;
717 FX_BOOL bTranslateColor;
718 FX_BOOL bSwapRGB = FALSE; 714 FX_BOOL bSwapRGB = FALSE;
719 if (m_pColorSpace) { 715 if (m_pColorSpace) {
720 if (codestream_nComps != (FX_DWORD)m_pColorSpace->CountComponents()) 716 if (components != (FX_DWORD)m_pColorSpace->CountComponents())
721 return; 717 return;
722 output_nComps = codestream_nComps;
723 bTranslateColor = FALSE;
724 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) { 718 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) {
725 bSwapRGB = TRUE; 719 bSwapRGB = TRUE;
726 m_pColorSpace = nullptr; 720 m_pColorSpace = nullptr;
727 } 721 }
728 } else { 722 } else {
729 bTranslateColor = TRUE; 723 if (components == 3) {
730 if (image_nComps) { 724 bSwapRGB = TRUE;
731 output_nComps = image_nComps; 725 } else if (components == 4) {
732 } else { 726 m_pColorSpace = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
733 output_nComps = codestream_nComps;
734 } 727 }
735 if (output_nComps == 3) { 728 m_nComponents = components;
736 bSwapRGB = TRUE;
737 } else if (output_nComps == 4) {
738 m_pColorSpace = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
739 bTranslateColor = FALSE;
740 }
741 m_nComponents = output_nComps;
742 } 729 }
743 FXDIB_Format format; 730 FXDIB_Format format;
744 if (output_nComps == 1) { 731 if (components == 1) {
745 format = FXDIB_8bppRgb; 732 format = FXDIB_8bppRgb;
746 } else if (output_nComps <= 3) { 733 } else if (components <= 3) {
747 format = FXDIB_Rgb; 734 format = FXDIB_Rgb;
748 } else if (output_nComps == 4) { 735 } else if (components == 4) {
749 format = FXDIB_Rgb32; 736 format = FXDIB_Rgb32;
750 } else { 737 } else {
751 width = (width * output_nComps + 2) / 3; 738 width = (width * components + 2) / 3;
752 format = FXDIB_Rgb; 739 format = FXDIB_Rgb;
753 } 740 }
754 m_pCachedBitmap.reset(new CFX_DIBitmap); 741 m_pCachedBitmap.reset(new CFX_DIBitmap);
755 if (!m_pCachedBitmap->Create(width, height, format)) { 742 if (!m_pCachedBitmap->Create(width, height, format)) {
756 m_pCachedBitmap.reset(); 743 m_pCachedBitmap.reset();
757 return; 744 return;
758 } 745 }
759 m_pCachedBitmap->Clear(0xFFFFFFFF); 746 m_pCachedBitmap->Clear(0xFFFFFFFF);
760 context->set_output_offsets(FX_Alloc(uint8_t, output_nComps)); 747 context->set_output_offsets(FX_Alloc(uint8_t, components));
761 for (int i = 0; i < output_nComps; ++i) 748 for (int i = 0; i < components; ++i)
762 context->output_offsets()[i] = i; 749 context->output_offsets()[i] = i;
763 if (bSwapRGB) { 750 if (bSwapRGB) {
764 context->output_offsets()[0] = 2; 751 context->output_offsets()[0] = 2;
765 context->output_offsets()[2] = 0; 752 context->output_offsets()[2] = 0;
766 } 753 }
767 if (!pJpxModule->Decode(context->context(), m_pCachedBitmap->GetBuffer(), 754 if (!pJpxModule->Decode(context->context(), m_pCachedBitmap->GetBuffer(),
768 m_pCachedBitmap->GetPitch(), bTranslateColor, 755 m_pCachedBitmap->GetPitch(),
769 context->output_offsets())) { 756 context->output_offsets())) {
770 m_pCachedBitmap.reset(); 757 m_pCachedBitmap.reset();
771 return; 758 return;
772 } 759 }
773 if (m_pColorSpace && m_pColorSpace->GetFamily() == PDFCS_INDEXED && 760 if (m_pColorSpace && m_pColorSpace->GetFamily() == PDFCS_INDEXED &&
774 m_bpc < 8) { 761 m_bpc < 8) {
775 int scale = 8 - m_bpc; 762 int scale = 8 - m_bpc;
776 for (FX_DWORD row = 0; row < height; ++row) { 763 for (FX_DWORD row = 0; row < height; ++row) {
777 uint8_t* scanline = (uint8_t*)m_pCachedBitmap->GetScanline(row); 764 uint8_t* scanline = (uint8_t*)m_pCachedBitmap->GetScanline(row);
778 for (FX_DWORD col = 0; col < width; ++col) { 765 for (FX_DWORD col = 0; col < width; ++col) {
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 } 1660 }
1674 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) { 1661 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) {
1675 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); 1662 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause);
1676 } 1663 }
1677 CPDF_ImageLoader::~CPDF_ImageLoader() { 1664 CPDF_ImageLoader::~CPDF_ImageLoader() {
1678 if (!m_bCached) { 1665 if (!m_bCached) {
1679 delete m_pBitmap; 1666 delete m_pBitmap;
1680 delete m_pMask; 1667 delete m_pMask;
1681 } 1668 }
1682 } 1669 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698