diff options
author | Lei Zhang <thestig@chromium.org> | 2015-10-01 14:08:32 -0700 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-10-01 14:08:32 -0700 |
commit | e95f39f10400746f0dc49c8afe3b3f21cdbbf381 (patch) | |
tree | f40e88e0427b53f36d1e8f0dff339de45f650fb4 /core/src/fxcodec/codec/fx_codec_jpx_opj.cpp | |
parent | 61d25619b1e7647b10689352039966a1394feae6 (diff) | |
download | pdfium-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/fxcodec/codec/fx_codec_jpx_opj.cpp')
-rw-r--r-- | core/src/fxcodec/codec/fx_codec_jpx_opj.cpp | 80 |
1 files changed, 35 insertions, 45 deletions
diff --git a/core/src/fxcodec/codec/fx_codec_jpx_opj.cpp b/core/src/fxcodec/codec/fx_codec_jpx_opj.cpp index b7e032e614..fdffcb66de 100644 --- a/core/src/fxcodec/codec/fx_codec_jpx_opj.cpp +++ b/core/src/fxcodec/codec/fx_codec_jpx_opj.cpp @@ -6,6 +6,7 @@ #include <algorithm> #include <limits> +#include <vector> #include "../../../../third_party/lcms2-2.6/include/lcms2.h" #include "../../../../third_party/libopenjpeg20/openjpeg.h" @@ -617,9 +618,9 @@ class CJPX_Decoder { ~CJPX_Decoder(); FX_BOOL Init(const unsigned char* src_data, int src_size); void GetInfo(FX_DWORD* width, FX_DWORD* height, FX_DWORD* components); - FX_BOOL Decode(uint8_t* dest_buf, - int pitch, - uint8_t* offsets); + bool Decode(uint8_t* dest_buf, + int pitch, + const std::vector<uint8_t>& offsets); private: const uint8_t* m_SrcData; @@ -738,45 +739,39 @@ void CJPX_Decoder::GetInfo(FX_DWORD* width, *components = (FX_DWORD)image->numcomps; } -FX_BOOL CJPX_Decoder::Decode(uint8_t* dest_buf, - int pitch, - uint8_t* offsets) { - int i, wid, hei, row, col, channel, src; - uint8_t* pChannel; - uint8_t* pScanline; - uint8_t* pPixel; +bool CJPX_Decoder::Decode(uint8_t* dest_buf, + int pitch, + const std::vector<uint8_t>& offsets) { + if (image->comps[0].w != image->x1 || image->comps[0].h != image->y1) + return false; + + if (pitch<(int)(image->comps[0].w * 8 * image->numcomps + 31)>> 5 << 2) + return false; - if (image->comps[0].w != image->x1 || image->comps[0].h != image->y1) { - return FALSE; - } - if (pitch<(int)(image->comps[0].w * 8 * image->numcomps + 31)>> 5 << 2) { - return FALSE; - } FXSYS_memset(dest_buf, 0xff, image->y1 * pitch); - uint8_t** channel_bufs = FX_Alloc(uint8_t*, image->numcomps); - FX_BOOL result = FALSE; - int* adjust_comps = FX_Alloc(int, image->numcomps); - for (i = 0; i < (int)image->numcomps; i++) { + std::vector<uint8_t*> channel_bufs(image->numcomps); + std::vector<int> adjust_comps(image->numcomps); + for (uint32_t i = 0; i < image->numcomps; i++) { channel_bufs[i] = dest_buf + offsets[i]; adjust_comps[i] = image->comps[i].prec - 8; if (i > 0) { if (image->comps[i].dx != image->comps[i - 1].dx || image->comps[i].dy != image->comps[i - 1].dy || image->comps[i].prec != image->comps[i - 1].prec) { - goto done; + return false; } } } - wid = image->comps[0].w; - hei = image->comps[0].h; - for (channel = 0; channel < (int)image->numcomps; channel++) { - pChannel = channel_bufs[channel]; + int width = image->comps[0].w; + int height = image->comps[0].h; + for (uint32_t channel = 0; channel < image->numcomps; ++channel) { + uint8_t* pChannel = channel_bufs[channel]; if (adjust_comps[channel] < 0) { - for (row = 0; row < hei; row++) { - pScanline = pChannel + row * pitch; - for (col = 0; col < wid; col++) { - pPixel = pScanline + col * image->numcomps; - src = image->comps[channel].data[row * wid + col]; + for (int row = 0; row < height; ++row) { + uint8_t* pScanline = pChannel + row * pitch; + for (int col = 0; col < width; ++col) { + uint8_t* pPixel = pScanline + col * image->numcomps; + int src = image->comps[channel].data[row * width + col]; src += image->comps[channel].sgnd ? 1 << (image->comps[channel].prec - 1) : 0; @@ -788,14 +783,14 @@ FX_BOOL CJPX_Decoder::Decode(uint8_t* dest_buf, } } } else { - for (row = 0; row < hei; row++) { - pScanline = pChannel + row * pitch; - for (col = 0; col < wid; col++) { - pPixel = pScanline + col * image->numcomps; + for (int row = 0; row < height; ++row) { + uint8_t* pScanline = pChannel + row * pitch; + for (int col = 0; col < width; ++col) { + uint8_t* pPixel = pScanline + col * image->numcomps; if (!image->comps[channel].data) { continue; } - src = image->comps[channel].data[row * wid + col]; + int src = image->comps[channel].data[row * width + col]; src += image->comps[channel].sgnd ? 1 << (image->comps[channel].prec - 1) : 0; @@ -815,12 +810,7 @@ FX_BOOL CJPX_Decoder::Decode(uint8_t* dest_buf, } } } - result = TRUE; - -done: - FX_Free(channel_bufs); - FX_Free(adjust_comps); - return result; + return true; } CCodec_JpxModule::CCodec_JpxModule() {} @@ -841,10 +831,10 @@ void CCodec_JpxModule::GetImageInfo(CJPX_Decoder* pDecoder, pDecoder->GetInfo(width, height, components); } -FX_BOOL CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, - uint8_t* dest_data, - int pitch, - uint8_t* offsets) { +bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, + uint8_t* dest_data, + int pitch, + const std::vector<uint8_t>& offsets) { return pDecoder->Decode(dest_data, pitch, offsets); } |