summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-01 13:49:28 -0700
committerLei Zhang <thestig@chromium.org>2015-10-01 13:49:28 -0700
commit022da0014faa103901ec107ed6a33e5ab00c7931 (patch)
tree3f117f805fbff77cd11cf4bde5aafca3e22eeee9 /core/src/fpdfapi
parentce37d7347f1ab4c9fc1f48a137628da641bb4f14 (diff)
downloadpdfium-022da0014faa103901ec107ed6a33e5ab00c7931.tar.xz
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. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1361053002 .
Diffstat (limited to 'core/src/fpdfapi')
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp6
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp31
2 files changed, 14 insertions, 23 deletions
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index c9bcff6db6..ace7bf925b 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -247,10 +247,10 @@ FX_DWORD _DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder,
dest_buf = FX_Alloc2D(uint8_t, pitch, height);
dest_size = pitch * height; // Safe since checked alloc returned.
for (int row = 0; row < height; row++) {
- uint8_t* pLine = pDecoder->GetScanline(row);
- if (pLine == NULL) {
+ const uint8_t* pLine = pDecoder->GetScanline(row);
+ if (!pLine)
break;
- }
+
FXSYS_memcpy(dest_buf + row * pitch, pLine, pitch);
}
FX_DWORD srcoff = pDecoder->GetSrcOffset();
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;
}