Add CFX_GifContext::GetPaletteExp() helper.
Consolidate repeated code into a helper method.
Change-Id: Id4e916aadde8cbd26dbe5dbb457bef6596469c05
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/72333
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
diff --git a/core/fxcodec/gif/cfx_gifcontext.cpp b/core/fxcodec/gif/cfx_gifcontext.cpp
index bbeb8e1..0003b55 100644
--- a/core/fxcodec/gif/cfx_gifcontext.cpp
+++ b/core/fxcodec/gif/cfx_gifcontext.cpp
@@ -235,9 +235,7 @@
if (!lzw_decompressor_.get()) {
lzw_decompressor_ = CFX_LZWDecompressor::Create(
- !gif_image->local_palettes.empty() ? gif_image->local_palette_exp
- : global_palette_exp_,
- gif_image->code_exp);
+ GetPaletteExp(gif_image), gif_image->code_exp);
}
SaveDecodingStatus(GIF_D_STATUS_IMG_DATA);
img_row_offset_ += img_row_avail_size_;
@@ -275,11 +273,8 @@
}
if (!lzw_decompressor_.get()) {
- lzw_decompressor_ =
- CFX_LZWDecompressor::Create(!gif_image->local_palettes.empty()
- ? gif_image->local_palette_exp
- : global_palette_exp_,
- gif_image->code_exp);
+ lzw_decompressor_ = CFX_LZWDecompressor::Create(
+ GetPaletteExp(gif_image), gif_image->code_exp);
}
SaveDecodingStatus(GIF_D_STATUS_IMG_DATA);
img_row_offset_ += img_row_avail_size_;
@@ -513,10 +508,9 @@
// Need to test that the color that is going to be transparent is actually
// in the palette being used.
if (graphic_control_extension_->trans_index >=
- 2 << (gif_image->local_palettes.empty()
- ? global_palette_exp_
- : gif_image->local_palette_exp))
+ (2 << GetPaletteExp(gif_image.get()))) {
return CFX_GifDecodeStatus::Error;
+ }
}
gif_image->image_GCE = std::move(graphic_control_extension_);
graphic_control_extension_ = nullptr;
@@ -548,4 +542,9 @@
return true;
}
+uint8_t CFX_GifContext::GetPaletteExp(CFX_GifImage* gif_image) const {
+ return !gif_image->local_palettes.empty() ? gif_image->local_palette_exp
+ : global_palette_exp_;
+}
+
} // namespace fxcodec
diff --git a/core/fxcodec/gif/cfx_gifcontext.h b/core/fxcodec/gif/cfx_gifcontext.h
index 7533d7b..4d1f0e4 100644
--- a/core/fxcodec/gif/cfx_gifcontext.h
+++ b/core/fxcodec/gif/cfx_gifcontext.h
@@ -74,6 +74,7 @@
CFX_GifDecodeStatus DecodeImageInfo();
void DecodingFailureAtTailCleanup(CFX_GifImage* gif_image);
bool ScanForTerminalMarker();
+ uint8_t GetPaletteExp(CFX_GifImage* gif_image) const;
};
} // namespace fxcodec