summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJun Fang <jun_fang@foxitsoftware.com>2015-12-24 18:13:36 +0800
committerJun Fang <jun_fang@foxitsoftware.com>2015-12-24 18:13:36 +0800
commitf308885d1880bc0d9a6798512ef7c740550d08e9 (patch)
treedcc105fe0785b8be699d0452708f700ccbeca99e
parentf1d406f30ccdc5fe705faa590fbac0a8306b161c (diff)
downloadpdfium-f308885d1880bc0d9a6798512ef7c740550d08e9.tar.xz
Fix failed JPX image rendering
BUG=pdfium:338 R=thestig@chromium.org Review URL: https://codereview.chromium.org/1549043003 .
-rw-r--r--core/include/fxcodec/fx_codec.h3
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp5
-rw-r--r--core/src/fxcodec/codec/codec_int.h3
-rw-r--r--core/src/fxcodec/codec/fx_codec_jpx_opj.cpp21
4 files changed, 16 insertions, 16 deletions
diff --git a/core/include/fxcodec/fx_codec.h b/core/include/fxcodec/fx_codec.h
index c068a08025..1d4d333b33 100644
--- a/core/include/fxcodec/fx_codec.h
+++ b/core/include/fxcodec/fx_codec.h
@@ -15,6 +15,7 @@
class CFX_DIBSource;
class CJPX_Decoder;
+class CPDF_ColorSpace;
class CPDF_PrivateData;
class CPDF_StreamAcc;
class ICodec_ScanlineDecoder;
@@ -207,7 +208,7 @@ class ICodec_JpxModule {
virtual CJPX_Decoder* CreateDecoder(const uint8_t* src_buf,
FX_DWORD src_size,
- bool use_colorspace) = 0;
+ CPDF_ColorSpace* cs) = 0;
virtual void GetImageInfo(CJPX_Decoder* pDecoder,
FX_DWORD* width,
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
index 0306ff0227..6bb8033686 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
@@ -684,9 +684,8 @@ void CPDF_DIBSource::LoadJpxBitmap() {
nonstd::unique_ptr<JpxBitMapContext> context(
new JpxBitMapContext(pJpxModule));
- context->set_decoder(pJpxModule->CreateDecoder(m_pStreamAcc->GetData(),
- m_pStreamAcc->GetSize(),
- m_pColorSpace == nullptr));
+ context->set_decoder(pJpxModule->CreateDecoder(
+ m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), m_pColorSpace));
if (!context->decoder())
return;
diff --git a/core/src/fxcodec/codec/codec_int.h b/core/src/fxcodec/codec/codec_int.h
index 1495f9e680..0f2d565046 100644
--- a/core/src/fxcodec/codec/codec_int.h
+++ b/core/src/fxcodec/codec/codec_int.h
@@ -18,6 +18,7 @@
class CFX_IccProfileCache;
class CFX_IccTransformCache;
+class CPDF_ColorSpace;
class CCodec_BasicModule : public ICodec_BasicModule {
public:
@@ -258,7 +259,7 @@ class CCodec_JpxModule : public ICodec_JpxModule {
// ICodec_JpxModule:
CJPX_Decoder* CreateDecoder(const uint8_t* src_buf,
FX_DWORD src_size,
- bool use_colorspace) override;
+ CPDF_ColorSpace* cs) override;
void GetImageInfo(CJPX_Decoder* pDecoder,
FX_DWORD* width,
FX_DWORD* height,
diff --git a/core/src/fxcodec/codec/fx_codec_jpx_opj.cpp b/core/src/fxcodec/codec/fx_codec_jpx_opj.cpp
index 21c1e441f0..d3276450c9 100644
--- a/core/src/fxcodec/codec/fx_codec_jpx_opj.cpp
+++ b/core/src/fxcodec/codec/fx_codec_jpx_opj.cpp
@@ -9,6 +9,7 @@
#include <vector>
#include "codec_int.h"
+#include "core/include/fpdfapi/fpdf_resource.h"
#include "core/include/fxcodec/fx_codec.h"
#include "core/include/fxcrt/fx_safe_types.h"
#include "third_party/lcms2-2.6/include/lcms2.h"
@@ -660,7 +661,7 @@ void color_apply_conversion(opj_image_t* image) {
}
class CJPX_Decoder {
public:
- explicit CJPX_Decoder(bool use_colorspace);
+ explicit CJPX_Decoder(CPDF_ColorSpace* cs);
~CJPX_Decoder();
FX_BOOL Init(const unsigned char* src_data, FX_DWORD src_size);
void GetInfo(FX_DWORD* width, FX_DWORD* height, FX_DWORD* components);
@@ -674,15 +675,11 @@ class CJPX_Decoder {
opj_image_t* image;
opj_codec_t* l_codec;
opj_stream_t* l_stream;
- const bool m_UseColorSpace;
+ const CPDF_ColorSpace* const m_ColorSpace;
};
-CJPX_Decoder::CJPX_Decoder(bool use_colorspace)
- : image(nullptr),
- l_codec(nullptr),
- l_stream(nullptr),
- m_UseColorSpace(use_colorspace) {
-}
+CJPX_Decoder::CJPX_Decoder(CPDF_ColorSpace* cs)
+ : image(nullptr), l_codec(nullptr), l_stream(nullptr), m_ColorSpace(cs) {}
CJPX_Decoder::~CJPX_Decoder() {
if (l_codec) {
@@ -724,6 +721,8 @@ FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, FX_DWORD src_size) {
if (!l_codec) {
return FALSE;
}
+ if (m_ColorSpace && m_ColorSpace->GetFamily() == PDFCS_INDEXED)
+ parameters.flags |= OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
opj_set_info_handler(l_codec, fx_info_callback, 00);
opj_set_warning_handler(l_codec, fx_warning_callback, 00);
opj_set_error_handler(l_codec, fx_error_callback, 00);
@@ -734,7 +733,7 @@ FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, FX_DWORD src_size) {
image = NULL;
return FALSE;
}
- image->pdfium_use_colorspace = m_UseColorSpace;
+ image->pdfium_use_colorspace = !!m_ColorSpace;
if (!parameters.nb_tile_to_decode) {
if (!opj_set_decode_area(l_codec, image, parameters.DA_x0, parameters.DA_y0,
@@ -865,8 +864,8 @@ CCodec_JpxModule::~CCodec_JpxModule() {
CJPX_Decoder* CCodec_JpxModule::CreateDecoder(const uint8_t* src_buf,
FX_DWORD src_size,
- bool use_colorspace) {
- nonstd::unique_ptr<CJPX_Decoder> decoder(new CJPX_Decoder(use_colorspace));
+ CPDF_ColorSpace* cs) {
+ nonstd::unique_ptr<CJPX_Decoder> decoder(new CJPX_Decoder(cs));
return decoder->Init(src_buf, src_size) ? decoder.release() : nullptr;
}