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

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: Revert bad m_pColorSpace logic 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 pitch += 31; 55 pitch += 31;
56 pitch /= 8; 56 pitch /= 8;
57 return pitch; 57 return pitch;
58 } 58 }
59 59
60 // Wrapper class to hold objects allocated in CPDF_DIBSource::LoadJpxBitmap(), 60 // Wrapper class to hold objects allocated in CPDF_DIBSource::LoadJpxBitmap(),
61 // because nonstd::unique_ptr does not support custom deleters yet. 61 // because nonstd::unique_ptr does not support custom deleters yet.
62 class JpxBitMapContext { 62 class JpxBitMapContext {
63 public: 63 public:
64 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module) 64 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module)
65 : jpx_module_(jpx_module), ctx_(nullptr), output_offsets_(nullptr) {} 65 : jpx_module_(jpx_module), decoder_(nullptr), output_offsets_(nullptr) {}
66 66
67 ~JpxBitMapContext() { 67 ~JpxBitMapContext() {
68 FX_Free(output_offsets_); 68 FX_Free(output_offsets_);
69 jpx_module_->DestroyDecoder(ctx_); 69 jpx_module_->DestroyDecoder(decoder_);
70 } 70 }
71 71
72 // Takes ownership of |ctx|. 72 // Takes ownership of |decoder|.
73 void set_context(void* ctx) { ctx_ = ctx; } 73 void set_decoder(CJPX_Decoder* decoder) { decoder_ = decoder; }
74 74
75 void* context() { return ctx_; } 75 CJPX_Decoder* decoder() { return decoder_; }
76 76
77 // Takes ownership of |output_offsets|. 77 // Takes ownership of |output_offsets|.
78 void set_output_offsets(unsigned char* output_offsets) { 78 void set_output_offsets(unsigned char* output_offsets) {
79 output_offsets_ = output_offsets; 79 output_offsets_ = output_offsets;
80 } 80 }
81 81
82 unsigned char* output_offsets() { return output_offsets_; } 82 unsigned char* output_offsets() { return output_offsets_; }
83 83
84 private: 84 private:
85 ICodec_JpxModule* jpx_module_; // Weak pointer. 85 ICodec_JpxModule* jpx_module_; // Weak pointer.
86 void* ctx_; // Decoder context, owned. 86 CJPX_Decoder* decoder_; // Decoder, owned.
87 unsigned char* output_offsets_; // Output offsets for decoding, owned. 87 unsigned char* output_offsets_; // Output offsets for decoding, owned.
88 88
89 // Disallow evil constructors 89 // Disallow evil constructors
90 JpxBitMapContext(const JpxBitMapContext&); 90 JpxBitMapContext(const JpxBitMapContext&);
91 void operator=(const JpxBitMapContext&); 91 void operator=(const JpxBitMapContext&);
92 }; 92 };
93 93
94 const int kMaxImageDimension = 0x01FFFF; 94 const int kMaxImageDimension = 0x01FFFF;
95 95
96 } // namespace 96 } // namespace
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 } 691 }
692 return 1; 692 return 1;
693 } 693 }
694 void CPDF_DIBSource::LoadJpxBitmap() { 694 void CPDF_DIBSource::LoadJpxBitmap() {
695 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); 695 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule();
696 if (!pJpxModule) 696 if (!pJpxModule)
697 return; 697 return;
698 698
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_decoder(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->decoder())
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->decoder(), &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; 718
723 bTranslateColor = FALSE;
724 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) { 719 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) {
725 bSwapRGB = TRUE; 720 bSwapRGB = TRUE;
726 m_pColorSpace = nullptr; 721 m_pColorSpace = nullptr;
727 } 722 }
728 } else { 723 } else {
729 bTranslateColor = TRUE; 724 if (components == 3) {
730 if (image_nComps) { 725 bSwapRGB = TRUE;
731 output_nComps = image_nComps; 726 } else if (components == 4) {
732 } else { 727 m_pColorSpace = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
733 output_nComps = codestream_nComps;
734 } 728 }
735 if (output_nComps == 3) { 729 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 } 730 }
731
743 FXDIB_Format format; 732 FXDIB_Format format;
744 if (output_nComps == 1) { 733 if (components == 1) {
745 format = FXDIB_8bppRgb; 734 format = FXDIB_8bppRgb;
746 } else if (output_nComps <= 3) { 735 } else if (components <= 3) {
747 format = FXDIB_Rgb; 736 format = FXDIB_Rgb;
748 } else if (output_nComps == 4) { 737 } else if (components == 4) {
749 format = FXDIB_Rgb32; 738 format = FXDIB_Rgb32;
750 } else { 739 } else {
751 width = (width * output_nComps + 2) / 3; 740 width = (width * components + 2) / 3;
752 format = FXDIB_Rgb; 741 format = FXDIB_Rgb;
753 } 742 }
743
754 m_pCachedBitmap.reset(new CFX_DIBitmap); 744 m_pCachedBitmap.reset(new CFX_DIBitmap);
755 if (!m_pCachedBitmap->Create(width, height, format)) { 745 if (!m_pCachedBitmap->Create(width, height, format)) {
756 m_pCachedBitmap.reset(); 746 m_pCachedBitmap.reset();
757 return; 747 return;
758 } 748 }
759 m_pCachedBitmap->Clear(0xFFFFFFFF); 749 m_pCachedBitmap->Clear(0xFFFFFFFF);
760 context->set_output_offsets(FX_Alloc(uint8_t, output_nComps)); 750 context->set_output_offsets(FX_Alloc(uint8_t, components));
761 for (int i = 0; i < output_nComps; ++i) 751 for (int i = 0; i < components; ++i)
762 context->output_offsets()[i] = i; 752 context->output_offsets()[i] = i;
763 if (bSwapRGB) { 753 if (bSwapRGB) {
764 context->output_offsets()[0] = 2; 754 context->output_offsets()[0] = 2;
765 context->output_offsets()[2] = 0; 755 context->output_offsets()[2] = 0;
766 } 756 }
767 if (!pJpxModule->Decode(context->context(), m_pCachedBitmap->GetBuffer(), 757 if (!pJpxModule->Decode(context->decoder(), m_pCachedBitmap->GetBuffer(),
768 m_pCachedBitmap->GetPitch(), bTranslateColor, 758 m_pCachedBitmap->GetPitch(),
769 context->output_offsets())) { 759 context->output_offsets())) {
770 m_pCachedBitmap.reset(); 760 m_pCachedBitmap.reset();
771 return; 761 return;
772 } 762 }
773 if (m_pColorSpace && m_pColorSpace->GetFamily() == PDFCS_INDEXED && 763 if (m_pColorSpace && m_pColorSpace->GetFamily() == PDFCS_INDEXED &&
774 m_bpc < 8) { 764 m_bpc < 8) {
775 int scale = 8 - m_bpc; 765 int scale = 8 - m_bpc;
776 for (FX_DWORD row = 0; row < height; ++row) { 766 for (FX_DWORD row = 0; row < height; ++row) {
777 uint8_t* scanline = (uint8_t*)m_pCachedBitmap->GetScanline(row); 767 uint8_t* scanline = (uint8_t*)m_pCachedBitmap->GetScanline(row);
778 for (FX_DWORD col = 0; col < width; ++col) { 768 for (FX_DWORD col = 0; col < width; ++col) {
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 } 1663 }
1674 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) { 1664 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) {
1675 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); 1665 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause);
1676 } 1666 }
1677 CPDF_ImageLoader::~CPDF_ImageLoader() { 1667 CPDF_ImageLoader::~CPDF_ImageLoader() {
1678 if (!m_bCached) { 1668 if (!m_bCached) {
1679 delete m_pBitmap; 1669 delete m_pBitmap;
1680 delete m_pMask; 1670 delete m_pMask;
1681 } 1671 }
1682 } 1672 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698