summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_render
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-01 14:08:32 -0700
committerLei Zhang <thestig@chromium.org>2015-10-01 14:08:32 -0700
commite95f39f10400746f0dc49c8afe3b3f21cdbbf381 (patch)
treef40e88e0427b53f36d1e8f0dff339de45f650fb4 /core/src/fpdfapi/fpdf_render
parent61d25619b1e7647b10689352039966a1394feae6 (diff)
downloadpdfium-e95f39f10400746f0dc49c8afe3b3f21cdbbf381.tar.xz
Merge to XFA: Clean up some image decoder classes:
- Use std::vector<uint8_t> instead of raw uint8_t* - Make ICodec_ScanlineDecoder::GetScanline() return const uint8_t* - Add FxFreeDeleter, use it in CCodec_ImageDataCache. - Make CCodec_ImageDataCache encapsulate its data members. TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1361053002 . (cherry picked from commit 022da0014faa103901ec107ed6a33e5ab00c7931) Review URL: https://codereview.chromium.org/1372993003 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_render')
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp31
1 files changed, 11 insertions, 20 deletions
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
index 9497943fbd..f1fbf41d6d 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
@@ -4,6 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <vector>
+
#include "../../../../third_party/base/nonstd_unique_ptr.h"
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fpdfapi/fpdf_pageobj.h"
@@ -57,15 +59,13 @@ FX_SAFE_DWORD CalculatePitch32(int bpp, int width) {
return pitch;
}
-// Wrapper class to hold objects allocated in CPDF_DIBSource::LoadJpxBitmap(),
-// because nonstd::unique_ptr does not support custom deleters yet.
+// Wrapper class to use with nonstd::unique_ptr for CJPX_Decoder.
class JpxBitMapContext {
public:
explicit JpxBitMapContext(ICodec_JpxModule* jpx_module)
- : jpx_module_(jpx_module), decoder_(nullptr), output_offsets_(nullptr) {}
+ : jpx_module_(jpx_module), decoder_(nullptr) {}
~JpxBitMapContext() {
- FX_Free(output_offsets_);
jpx_module_->DestroyDecoder(decoder_);
}
@@ -74,17 +74,9 @@ class JpxBitMapContext {
CJPX_Decoder* decoder() { return decoder_; }
- // Takes ownership of |output_offsets|.
- void set_output_offsets(unsigned char* output_offsets) {
- output_offsets_ = output_offsets;
- }
-
- unsigned char* output_offsets() { return output_offsets_; }
-
private:
- ICodec_JpxModule* jpx_module_; // Weak pointer.
- CJPX_Decoder* decoder_; // Decoder, owned.
- unsigned char* output_offsets_; // Output offsets for decoding, owned.
+ ICodec_JpxModule* const jpx_module_; // Weak pointer.
+ CJPX_Decoder* decoder_; // Decoder, owned.
// Disallow evil constructors
JpxBitMapContext(const JpxBitMapContext&);
@@ -747,16 +739,15 @@ void CPDF_DIBSource::LoadJpxBitmap() {
return;
}
m_pCachedBitmap->Clear(0xFFFFFFFF);
- context->set_output_offsets(FX_Alloc(uint8_t, components));
+ std::vector<uint8_t> output_offsets(components);
for (int i = 0; i < components; ++i)
- context->output_offsets()[i] = i;
+ output_offsets[i] = i;
if (bSwapRGB) {
- context->output_offsets()[0] = 2;
- context->output_offsets()[2] = 0;
+ output_offsets[0] = 2;
+ output_offsets[2] = 0;
}
if (!pJpxModule->Decode(context->decoder(), m_pCachedBitmap->GetBuffer(),
- m_pCachedBitmap->GetPitch(),
- context->output_offsets())) {
+ m_pCachedBitmap->GetPitch(), output_offsets)) {
m_pCachedBitmap.reset();
return;
}