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

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

Issue 1153633009: Fix potentially massive memory leak in CPDF_DIBSource::LoadJpxBitmap(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address comments Created 5 years, 6 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 "../../../../third_party/base/nonstd_unique_ptr.h"
7 #include "../../../include/fpdfapi/fpdf_module.h" 8 #include "../../../include/fpdfapi/fpdf_module.h"
8 #include "../../../include/fpdfapi/fpdf_pageobj.h" 9 #include "../../../include/fpdfapi/fpdf_pageobj.h"
9 #include "../../../include/fpdfapi/fpdf_render.h" 10 #include "../../../include/fpdfapi/fpdf_render.h"
10 #include "../../../include/fxcodec/fx_codec.h" 11 #include "../../../include/fxcodec/fx_codec.h"
11 #include "../../../include/fxcrt/fx_safe_types.h" 12 #include "../../../include/fxcrt/fx_safe_types.h"
12 #include "../../../include/fxge/fx_ge.h" 13 #include "../../../include/fxge/fx_ge.h"
13 #include "../fpdf_page/pageint.h" 14 #include "../fpdf_page/pageint.h"
14 #include "render_int.h" 15 #include "render_int.h"
15 16
16 namespace { 17 namespace {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 49
49 FX_SAFE_DWORD CalculatePitch32(int bpp, int width) 50 FX_SAFE_DWORD CalculatePitch32(int bpp, int width)
50 { 51 {
51 FX_SAFE_DWORD pitch = bpp; 52 FX_SAFE_DWORD pitch = bpp;
52 pitch *= width; 53 pitch *= width;
53 pitch += 31; 54 pitch += 31;
54 pitch /= 8; 55 pitch /= 8;
55 return pitch; 56 return pitch;
56 } 57 }
57 58
59 // Wrapper class to hold objects allocated in CPDF_DIBSource::LoadJpxBitmap(),
60 // because nonstd::unique_ptr does not support custom deleters yet.
61 class JpxBitMapContext
62 {
63 public:
64 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module)
65 : jpx_module_(jpx_module),
66 ctx_(nullptr),
67 output_offsets_(nullptr) {}
68
69 ~JpxBitMapContext() {
70 FX_Free(output_offsets_);
71 jpx_module_->DestroyDecoder(ctx_);
72 }
73
74 // Takes ownership of |ctx|.
75 void set_context(void* ctx) {
76 ctx_ = ctx;
77 }
78
79 void* context() {
80 return ctx_;
81 }
82
83 // Takes ownership of |output_offsets|.
84 void set_output_offsets(unsigned char* output_offsets) {
85 output_offsets_ = output_offsets;
86 }
87
88 unsigned char* output_offsets() {
89 return output_offsets_;
90 }
91
92 private:
93 ICodec_JpxModule* jpx_module_; // Weak pointer.
94 void* ctx_; // Decoder context, owned.
95 unsigned char* output_offsets_; // Output offsets for decoding, owned.
96
97 // Disallow evil constructors
98 JpxBitMapContext(const JpxBitMapContext&);
99 void operator=(const JpxBitMapContext&);
100 };
101
58 } // namespace 102 } // namespace
59 103
60 CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask, FX_DWORD* pMatt eColor, FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask) const 104 CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask, FX_DWORD* pMatt eColor, FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask) const
61 { 105 {
62 CPDF_DIBSource* pSource = new CPDF_DIBSource; 106 CPDF_DIBSource* pSource = new CPDF_DIBSource;
63 if (pSource->Load(m_pDocument, m_pStream, (CPDF_DIBSource**)ppMask, pMatteCo lor, NULL, NULL, bStdCS, GroupFamily, bLoadMask)) { 107 if (pSource->Load(m_pDocument, m_pStream, (CPDF_DIBSource**)ppMask, pMatteCo lor, NULL, NULL, bStdCS, GroupFamily, bLoadMask)) {
64 return pSource; 108 return pSource;
65 } 109 }
66 delete pSource; 110 delete pSource;
67 return NULL; 111 return NULL;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 m_bpp = 0; 161 m_bpp = 0;
118 m_Width = m_Height = 0; 162 m_Width = m_Height = 0;
119 m_pColorSpace = NULL; 163 m_pColorSpace = NULL;
120 m_bDefaultDecode = TRUE; 164 m_bDefaultDecode = TRUE;
121 m_bImageMask = FALSE; 165 m_bImageMask = FALSE;
122 m_bDoBpcCheck = TRUE; 166 m_bDoBpcCheck = TRUE;
123 m_pPalette = NULL; 167 m_pPalette = NULL;
124 m_pCompData = NULL; 168 m_pCompData = NULL;
125 m_bColorKey = FALSE; 169 m_bColorKey = FALSE;
126 m_pMaskedLine = m_pLineBuf = NULL; 170 m_pMaskedLine = m_pLineBuf = NULL;
127 m_pCachedBitmap = NULL;
128 m_pDecoder = NULL; 171 m_pDecoder = NULL;
129 m_nComponents = 0; 172 m_nComponents = 0;
130 m_bpc = 0; 173 m_bpc = 0;
131 m_bLoadMask = FALSE; 174 m_bLoadMask = FALSE;
132 m_Family = 0; 175 m_Family = 0;
133 m_pMask = NULL; 176 m_pMask = NULL;
134 m_MatteColor = 0; 177 m_MatteColor = 0;
135 m_pJbig2Context = NULL; 178 m_pJbig2Context = NULL;
136 m_pGlobalStream = NULL; 179 m_pGlobalStream = NULL;
137 m_bStdCS = FALSE; 180 m_bStdCS = FALSE;
138 m_pMaskStream = NULL; 181 m_pMaskStream = NULL;
139 m_Status = 0; 182 m_Status = 0;
140 m_bHasMask = FALSE; 183 m_bHasMask = FALSE;
141 } 184 }
142 CPDF_DIBSource::~CPDF_DIBSource() 185 CPDF_DIBSource::~CPDF_DIBSource()
143 { 186 {
144 delete m_pStreamAcc; 187 delete m_pStreamAcc;
145 if (m_pMaskedLine) { 188 if (m_pMaskedLine) {
146 FX_Free(m_pMaskedLine); 189 FX_Free(m_pMaskedLine);
147 } 190 }
148 if (m_pLineBuf) { 191 if (m_pLineBuf) {
149 FX_Free(m_pLineBuf); 192 FX_Free(m_pLineBuf);
150 } 193 }
151 delete m_pCachedBitmap; 194 m_pCachedBitmap.reset();
152 delete m_pDecoder; 195 delete m_pDecoder;
153 if (m_pCompData) { 196 if (m_pCompData) {
154 FX_Free(m_pCompData); 197 FX_Free(m_pCompData);
155 } 198 }
156 CPDF_ColorSpace* pCS = m_pColorSpace; 199 CPDF_ColorSpace* pCS = m_pColorSpace;
157 if (pCS && m_pDocument) { 200 if (pCS && m_pDocument) {
158 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); 201 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
159 } 202 }
160 if (m_pJbig2Context) { 203 if (m_pJbig2Context) {
161 ICodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module (); 204 ICodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module ();
162 pJbig2Module->DestroyJbig2Context(m_pJbig2Context); 205 pJbig2Module->DestroyJbig2Context(m_pJbig2Context);
163 } 206 }
164 delete m_pGlobalStream; 207 delete m_pGlobalStream;
165 } 208 }
166 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const 209 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const
167 { 210 {
168 if (m_pCachedBitmap) { 211 return m_pCachedBitmap ? m_pCachedBitmap.get() : Clone();
169 return m_pCachedBitmap;
170 }
171 return Clone();
172 } 212 }
173 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const 213 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const
174 { 214 {
175 if (pBitmap && pBitmap != m_pCachedBitmap) { 215 if (pBitmap && pBitmap != m_pCachedBitmap) {
176 delete pBitmap; 216 delete pBitmap;
177 } 217 }
178 } 218 }
179 FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, const CPDF_Stream* pStream, CP DF_DIBSource** ppMask, 219 FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, const CPDF_Stream* pStream, CP DF_DIBSource** ppMask,
180 FX_DWORD* pMatteColor, CPDF_Dictionary* pFormResour ces, CPDF_Dictionary* pPageResources, FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_B OOL bLoadMask) 220 FX_DWORD* pMatteColor, CPDF_Dictionary* pFormResour ces, CPDF_Dictionary* pPageResources, FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_B OOL bLoadMask)
181 { 221 {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 CPDF_Stream* pGlobals = m_pStreamAcc->GetImageParam()->GetStream (FX_BSTRC("JBIG2Globals")); 408 CPDF_Stream* pGlobals = m_pStreamAcc->GetImageParam()->GetStream (FX_BSTRC("JBIG2Globals"));
369 if (pGlobals) { 409 if (pGlobals) {
370 m_pGlobalStream = new CPDF_StreamAcc; 410 m_pGlobalStream = new CPDF_StreamAcc;
371 m_pGlobalStream->LoadAllData(pGlobals, FALSE); 411 m_pGlobalStream->LoadAllData(pGlobals, FALSE);
372 } 412 }
373 } 413 }
374 ret = pJbig2Module->StartDecode(m_pJbig2Context, m_Width, m_Height, m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), 414 ret = pJbig2Module->StartDecode(m_pJbig2Context, m_Width, m_Height, m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(),
375 m_pGlobalStream ? m_pGlobalStream->G etData() : NULL, m_pGlobalStream ? m_pGlobalStream->GetSize() : 0, m_pCachedBitm ap->GetBuffer(), 415 m_pGlobalStream ? m_pGlobalStream->G etData() : NULL, m_pGlobalStream ? m_pGlobalStream->GetSize() : 0, m_pCachedBitm ap->GetBuffer(),
376 m_pCachedBitmap->GetPitch(), pPause) ; 416 m_pCachedBitmap->GetPitch(), pPause) ;
377 if (ret < 0) { 417 if (ret < 0) {
378 delete m_pCachedBitmap; 418 m_pCachedBitmap.reset();
379 m_pCachedBitmap = NULL;
380 delete m_pGlobalStream; 419 delete m_pGlobalStream;
381 m_pGlobalStream = NULL; 420 m_pGlobalStream = NULL;
382 pJbig2Module->DestroyJbig2Context(m_pJbig2Context); 421 pJbig2Module->DestroyJbig2Context(m_pJbig2Context);
383 m_pJbig2Context = NULL; 422 m_pJbig2Context = NULL;
384 return 0; 423 return 0;
385 } 424 }
386 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 425 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
387 return 2; 426 return 2;
388 } 427 }
389 int ret1 = 1; 428 int ret1 = 1;
390 if (m_bHasMask) { 429 if (m_bHasMask) {
391 ret1 = ContinueLoadMaskDIB(pPause); 430 ret1 = ContinueLoadMaskDIB(pPause);
392 m_Status = 2; 431 m_Status = 2;
393 } 432 }
394 if (ret1 == 2) { 433 if (ret1 == 2) {
395 return ret1; 434 return ret1;
396 } 435 }
397 if (m_pColorSpace && m_bStdCS) { 436 if (m_pColorSpace && m_bStdCS) {
398 m_pColorSpace->EnableStdConversion(FALSE); 437 m_pColorSpace->EnableStdConversion(FALSE);
399 } 438 }
400 return ret1; 439 return ret1;
401 } 440 }
402 FXCODEC_STATUS ret = pJbig2Module->ContinueDecode(m_pJbig2Context, pPaus e); 441 FXCODEC_STATUS ret = pJbig2Module->ContinueDecode(m_pJbig2Context, pPaus e);
403 if (ret < 0) { 442 if (ret < 0) {
404 delete m_pCachedBitmap; 443 m_pCachedBitmap.reset();
405 m_pCachedBitmap = NULL;
406 delete m_pGlobalStream; 444 delete m_pGlobalStream;
407 m_pGlobalStream = NULL; 445 m_pGlobalStream = NULL;
408 pJbig2Module->DestroyJbig2Context(m_pJbig2Context); 446 pJbig2Module->DestroyJbig2Context(m_pJbig2Context);
409 m_pJbig2Context = NULL; 447 m_pJbig2Context = NULL;
410 return 0; 448 return 0;
411 } 449 }
412 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 450 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
413 return 2; 451 return 2;
414 } 452 }
415 int ret1 = 1; 453 int ret1 = 1;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 624 }
587 m_bpc = bpc; 625 m_bpc = bpc;
588 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height, 626 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height,
589 m_nComponents, bTransform); 627 m_nComponents, bTransform);
590 } 628 }
591 } 629 }
592 } else if (decoder == FX_BSTRC("FlateDecode")) { 630 } else if (decoder == FX_BSTRC("FlateDecode")) {
593 m_pDecoder = FPDFAPI_CreateFlateDecoder(src_data, src_size, m_Width, m_H eight, m_nComponents, m_bpc, pParams); 631 m_pDecoder = FPDFAPI_CreateFlateDecoder(src_data, src_size, m_Width, m_H eight, m_nComponents, m_bpc, pParams);
594 } else if (decoder == FX_BSTRC("JPXDecode")) { 632 } else if (decoder == FX_BSTRC("JPXDecode")) {
595 LoadJpxBitmap(); 633 LoadJpxBitmap();
596 return m_pCachedBitmap != NULL ? 1 : 0; 634 return m_pCachedBitmap ? 1 : 0;
597 } else if (decoder == FX_BSTRC("JBIG2Decode")) { 635 } else if (decoder == FX_BSTRC("JBIG2Decode")) {
598 m_pCachedBitmap = new CFX_DIBitmap; 636 m_pCachedBitmap.reset(new CFX_DIBitmap);
599 if (!m_pCachedBitmap->Create(m_Width, m_Height, m_bImageMask ? FXDIB_1bp pMask : FXDIB_1bppRgb)) { 637 if (!m_pCachedBitmap->Create(m_Width, m_Height, m_bImageMask ? FXDIB_1bp pMask : FXDIB_1bppRgb)) {
600 delete m_pCachedBitmap; 638 m_pCachedBitmap.reset();
601 m_pCachedBitmap = NULL;
602 return 0; 639 return 0;
603 } 640 }
604 m_Status = 1; 641 m_Status = 1;
605 return 2; 642 return 2;
606 } else if (decoder == FX_BSTRC("RunLengthDecode")) { 643 } else if (decoder == FX_BSTRC("RunLengthDecode")) {
607 m_pDecoder = CPDF_ModuleMgr::Get()->GetCodecModule()->GetBasicModule()-> CreateRunLengthDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, m_b pc); 644 m_pDecoder = CPDF_ModuleMgr::Get()->GetCodecModule()->GetBasicModule()-> CreateRunLengthDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, m_b pc);
608 } 645 }
609 if (!m_pDecoder) 646 if (!m_pDecoder)
610 return 0; 647 return 0;
611 648
(...skipping 10 matching lines...) Expand all
622 return 0; 659 return 0;
623 } 660 }
624 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) { 661 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) {
625 return 0; 662 return 0;
626 } 663 }
627 return 1; 664 return 1;
628 } 665 }
629 void CPDF_DIBSource::LoadJpxBitmap() 666 void CPDF_DIBSource::LoadJpxBitmap()
630 { 667 {
631 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); 668 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule();
632 if (pJpxModule == NULL) { 669 if (!pJpxModule)
633 return; 670 return;
634 } 671
635 FX_LPVOID ctx = pJpxModule->CreateDecoder(m_pStreamAcc->GetData(), m_pStream Acc->GetSize(), m_pColorSpace != NULL); 672 nonstd::unique_ptr<JpxBitMapContext> context(
636 if (ctx == NULL) { 673 new JpxBitMapContext(pJpxModule));
674 context->set_context(pJpxModule->CreateDecoder(m_pStreamAcc->GetData(),
675 m_pStreamAcc->GetSize(),
676 m_pColorSpace != nullptr));
677 if (!context->context())
637 return; 678 return;
638 } 679
639 FX_DWORD width = 0, height = 0, codestream_nComps = 0, image_nComps = 0; 680 FX_DWORD width = 0;
640 pJpxModule->GetImageInfo(ctx, width, height, codestream_nComps, image_nComps ); 681 FX_DWORD height = 0;
641 if ((int)width < m_Width || (int)height < m_Height) { 682 FX_DWORD codestream_nComps = 0;
642 pJpxModule->DestroyDecoder(ctx); 683 FX_DWORD image_nComps = 0;
684 pJpxModule->GetImageInfo(context->context(), width, height,
685 codestream_nComps, image_nComps);
686 if ((int)width < m_Width || (int)height < m_Height)
643 return; 687 return;
644 } 688
645 int output_nComps; 689 int output_nComps;
646 FX_BOOL bTranslateColor, bSwapRGB = FALSE; 690 FX_BOOL bTranslateColor;
691 FX_BOOL bSwapRGB = FALSE;
647 if (m_pColorSpace) { 692 if (m_pColorSpace) {
648 if (codestream_nComps != (FX_DWORD)m_pColorSpace->CountComponents()) { 693 if (codestream_nComps != (FX_DWORD)m_pColorSpace->CountComponents())
649 return; 694 return;
650 }
651 output_nComps = codestream_nComps; 695 output_nComps = codestream_nComps;
652 bTranslateColor = FALSE; 696 bTranslateColor = FALSE;
653 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) { 697 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) {
654 bSwapRGB = TRUE; 698 bSwapRGB = TRUE;
655 m_pColorSpace = NULL; 699 m_pColorSpace = nullptr;
656 } 700 }
657 } else { 701 } else {
658 bTranslateColor = TRUE; 702 bTranslateColor = TRUE;
659 if (image_nComps) { 703 if (image_nComps) {
660 output_nComps = image_nComps; 704 output_nComps = image_nComps;
661 } else { 705 } else {
662 output_nComps = codestream_nComps; 706 output_nComps = codestream_nComps;
663 } 707 }
664 if (output_nComps == 3) { 708 if (output_nComps == 3) {
665 bSwapRGB = TRUE; 709 bSwapRGB = TRUE;
666 } else if (output_nComps == 4) { 710 } else if (output_nComps == 4) {
667 m_pColorSpace = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK); 711 m_pColorSpace = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
668 bTranslateColor = FALSE; 712 bTranslateColor = FALSE;
669 } 713 }
670 m_nComponents = output_nComps; 714 m_nComponents = output_nComps;
671 } 715 }
672 FXDIB_Format format; 716 FXDIB_Format format;
673 if (output_nComps == 1) { 717 if (output_nComps == 1) {
674 format = FXDIB_8bppRgb; 718 format = FXDIB_8bppRgb;
675 } else if (output_nComps <= 3) { 719 } else if (output_nComps <= 3) {
676 format = FXDIB_Rgb; 720 format = FXDIB_Rgb;
677 } else if (output_nComps == 4) { 721 } else if (output_nComps == 4) {
678 format = FXDIB_Rgb32; 722 format = FXDIB_Rgb32;
679 } else { 723 } else {
680 width = (width * output_nComps + 2) / 3; 724 width = (width * output_nComps + 2) / 3;
681 format = FXDIB_Rgb; 725 format = FXDIB_Rgb;
682 } 726 }
683 m_pCachedBitmap = new CFX_DIBitmap; 727 m_pCachedBitmap.reset(new CFX_DIBitmap);
684 if (!m_pCachedBitmap->Create(width, height, format)) { 728 if (!m_pCachedBitmap->Create(width, height, format)) {
685 delete m_pCachedBitmap; 729 m_pCachedBitmap.reset();
686 m_pCachedBitmap = NULL;
687 return; 730 return;
688 } 731 }
689 m_pCachedBitmap->Clear(0xFFFFFFFF); 732 m_pCachedBitmap->Clear(0xFFFFFFFF);
690 FX_LPBYTE output_offsets = FX_Alloc(FX_BYTE, output_nComps); 733 context->set_output_offsets(FX_Alloc(unsigned char, output_nComps));
691 for (int i = 0; i < output_nComps; i ++) { 734 for (int i = 0; i < output_nComps; ++i)
692 output_offsets[i] = i; 735 context->output_offsets()[i] = i;
736 if (bSwapRGB) {
737 context->output_offsets()[0] = 2;
738 context->output_offsets()[2] = 0;
693 } 739 }
694 if (bSwapRGB) { 740 if (!pJpxModule->Decode(context->context(),
695 output_offsets[0] = 2; 741 m_pCachedBitmap->GetBuffer(),
696 output_offsets[2] = 0; 742 m_pCachedBitmap->GetPitch(),
697 } 743 bTranslateColor,
698 if (!pJpxModule->Decode(ctx, m_pCachedBitmap->GetBuffer(), m_pCachedBitmap-> GetPitch(), bTranslateColor, output_offsets)) { 744 context->output_offsets())) {
699 delete m_pCachedBitmap; 745 m_pCachedBitmap.reset();
700 m_pCachedBitmap = NULL;
701 return; 746 return;
702 } 747 }
703 FX_Free(output_offsets); 748 if (m_pColorSpace &&
704 pJpxModule->DestroyDecoder(ctx); 749 m_pColorSpace->GetFamily() == PDFCS_INDEXED &&
705 if (m_pColorSpace && m_pColorSpace->GetFamily() == PDFCS_INDEXED && m_bpc < 8) { 750 m_bpc < 8) {
706 int scale = 8 - m_bpc; 751 int scale = 8 - m_bpc;
707 for (FX_DWORD row = 0; row < height; row ++) { 752 for (FX_DWORD row = 0; row < height; ++row) {
708 FX_LPBYTE scanline = (FX_LPBYTE)m_pCachedBitmap->GetScanline(row); 753 FX_LPBYTE scanline = (FX_LPBYTE)m_pCachedBitmap->GetScanline(row);
709 for (FX_DWORD col = 0; col < width; col ++) { 754 for (FX_DWORD col = 0; col < width; ++col) {
710 *scanline = (*scanline) >> scale; 755 *scanline = (*scanline) >> scale;
711 scanline++; 756 ++scanline;
712 } 757 }
713 } 758 }
714 } 759 }
715 m_bpc = 8; 760 m_bpc = 8;
716 } 761 }
717 CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) 762 CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor)
718 { 763 {
719 MatteColor = 0xffffffff; 764 MatteColor = 0xffffffff;
720 CPDF_Stream* pSoftMask = m_pDict->GetStream(FX_BSTRC("SMask")); 765 CPDF_Stream* pSoftMask = m_pDict->GetStream(FX_BSTRC("SMask"));
721 if (pSoftMask) { 766 if (pSoftMask) {
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 { 1549 {
1505 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); 1550 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause);
1506 } 1551 }
1507 CPDF_ImageLoader::~CPDF_ImageLoader() 1552 CPDF_ImageLoader::~CPDF_ImageLoader()
1508 { 1553 {
1509 if (!m_bCached) { 1554 if (!m_bCached) {
1510 delete m_pBitmap; 1555 delete m_pBitmap;
1511 delete m_pMask; 1556 delete m_pMask;
1512 } 1557 }
1513 } 1558 }
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