summaryrefslogtreecommitdiff
path: root/core/fxcodec/lgif/cgifcontext.cpp
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-09-26 15:39:10 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-26 19:58:33 +0000
commite2df5b7305df66efbd81232d911615af60624ae3 (patch)
tree5c5aff0ae260792790cfb1ed2f3f15863c0c0d63 /core/fxcodec/lgif/cgifcontext.cpp
parent7d04f1b0ab4848f1d10983b7a7b1444ac93dec70 (diff)
downloadpdfium-e2df5b7305df66efbd81232d911615af60624ae3.tar.xz
Move LZW decoder out of fx_gif
CGifLZWDecoder has been moved out into its own file, name changed to CFX_LZWDecoder, member variable names updated, creation pattern changed, and unit tests added. Wrt the creation pattern, there is no longer a constructor and 2 initialization methods that need to be called. Instead all of the initialization is done as part of the constructor. A wrapper has been added for generating a std::unique_ptr<CFX_LZWDecoder>, so that params can be validated. BUG=pdfium:900,pdfium:901,pdfium:903,pdfium:904 Change-Id: Idcbe773f7fb18b08e64d5a89bfd87d4801332c53 Reviewed-on: https://pdfium-review.googlesource.com/14814 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fxcodec/lgif/cgifcontext.cpp')
-rw-r--r--core/fxcodec/lgif/cgifcontext.cpp53
1 files changed, 34 insertions, 19 deletions
diff --git a/core/fxcodec/lgif/cgifcontext.cpp b/core/fxcodec/lgif/cgifcontext.cpp
index 1eb1b335aa..b1de89f2b6 100644
--- a/core/fxcodec/lgif/cgifcontext.cpp
+++ b/core/fxcodec/lgif/cgifcontext.cpp
@@ -267,19 +267,14 @@ GifDecodeStatus CGifContext::LoadFrame(int32_t frame_num) {
AddError("Error Invalid Code Size");
return GifDecodeStatus::Error;
}
- if (!m_ImgDecoder.get())
- m_ImgDecoder = pdfium::MakeUnique<CGifLZWDecoder>(m_szLastError);
- m_ImgDecoder->InitTable(!gif_image_ptr->m_LocalPalettes.empty()
- ? gif_image_ptr->local_pallette_exp
- : global_pal_exp,
- gif_image_ptr->image_code_exp);
+
img_row_offset = 0;
img_row_avail_size = 0;
img_pass_num = 0;
gif_image_ptr->image_row_num = 0;
SaveDecodingStatus(GIF_D_STATUS_IMG_DATA);
}
- CGifLZWDecoder* img_decoder_ptr = m_ImgDecoder.get();
+
if (decode_status == GIF_D_STATUS_IMG_DATA) {
if (!ReadData(&data_size_ptr, 1))
return GifDecodeStatus::Unfinished;
@@ -289,13 +284,22 @@ GifDecodeStatus CGifContext::LoadFrame(int32_t frame_num) {
skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
- img_decoder_ptr->Input(data_ptr, *data_size_ptr);
+ if (!m_ImgDecoder.get())
+ m_ImgDecoder =
+ CFX_LZWDecoder::Create(gif_image_ptr->m_LocalPalettes.empty()
+ ? gif_image_ptr->local_pallette_exp
+ : global_pal_exp,
+ gif_image_ptr->image_code_exp);
SaveDecodingStatus(GIF_D_STATUS_IMG_DATA);
img_row_offset += img_row_avail_size;
img_row_avail_size = gif_img_row_bytes - img_row_offset;
- GifDecodeStatus ret = img_decoder_ptr->Decode(
- gif_image_ptr->m_ImageRowBuf.data() + img_row_offset,
- &img_row_avail_size);
+ GifDecodeStatus ret =
+ m_ImgDecoder.get()
+ ? m_ImgDecoder->Decode(
+ data_ptr, *data_size_ptr,
+ gif_image_ptr->m_ImageRowBuf.data() + img_row_offset,
+ &img_row_avail_size)
+ : GifDecodeStatus::Error;
if (ret == GifDecodeStatus::Error) {
DecodingFailureAtTailCleanup(gif_image_ptr);
return GifDecodeStatus::Error;
@@ -309,7 +313,6 @@ GifDecodeStatus CGifContext::LoadFrame(int32_t frame_num) {
return GifDecodeStatus::Success;
}
if (ret == GifDecodeStatus::Unfinished) {
- ASSERT(img_decoder_ptr->GetAvailInput() == 0);
skip_size_org = skip_size;
if (!ReadData(&data_size_ptr, 1))
return GifDecodeStatus::Unfinished;
@@ -319,13 +322,22 @@ GifDecodeStatus CGifContext::LoadFrame(int32_t frame_num) {
skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
- img_decoder_ptr->Input(data_ptr, *data_size_ptr);
+ if (!m_ImgDecoder.get())
+ m_ImgDecoder =
+ CFX_LZWDecoder::Create(!gif_image_ptr->m_LocalPalettes.empty()
+ ? gif_image_ptr->local_pallette_exp
+ : global_pal_exp,
+ gif_image_ptr->image_code_exp);
SaveDecodingStatus(GIF_D_STATUS_IMG_DATA);
img_row_offset += img_row_avail_size;
img_row_avail_size = gif_img_row_bytes - img_row_offset;
- ret = img_decoder_ptr->Decode(
- gif_image_ptr->m_ImageRowBuf.data() + img_row_offset,
- &img_row_avail_size);
+ ret =
+ m_ImgDecoder.get()
+ ? m_ImgDecoder->Decode(
+ data_ptr, *data_size_ptr,
+ gif_image_ptr->m_ImageRowBuf.data() + img_row_offset,
+ &img_row_avail_size)
+ : GifDecodeStatus::Error;
}
}
if (ret == GifDecodeStatus::InsufficientDestSize) {
@@ -349,9 +361,12 @@ GifDecodeStatus CGifContext::LoadFrame(int32_t frame_num) {
}
img_row_offset = 0;
img_row_avail_size = gif_img_row_bytes;
- ret = img_decoder_ptr->Decode(
- gif_image_ptr->m_ImageRowBuf.data() + img_row_offset,
- &img_row_avail_size);
+ ret = m_ImgDecoder.get()
+ ? m_ImgDecoder->Decode(
+ data_ptr, *data_size_ptr,
+ gif_image_ptr->m_ImageRowBuf.data() + img_row_offset,
+ &img_row_avail_size)
+ : GifDecodeStatus::Error;
}
if (ret == GifDecodeStatus::Error) {
DecodingFailureAtTailCleanup(gif_image_ptr);