Simplify XFA_DrawImage() and related code
- Remove default arguments, since all callers pass in those parameters.
- Remove a bitmap nullptr check, since all callers do the same check
already.
- Combine ProgressiveDecoder::GetNumComponents() and GetBPC(), since
XFA_DrawImage() is the only caller and it wants the combined
bits-per-pixel value.
- Pass in the bpp value into XFA_GetDIBFormat() and also simplify that.
Change-Id: If7e744ddc4a5bd8769a841931b07596c95ca51e6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/112030
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcodec/progressive_decoder.h b/core/fxcodec/progressive_decoder.h
index 6325c88..1d9e9e8 100644
--- a/core/fxcodec/progressive_decoder.h
+++ b/core/fxcodec/progressive_decoder.h
@@ -79,8 +79,7 @@
FXCODEC_IMAGE_TYPE GetType() const { return m_imageType; }
int32_t GetWidth() const { return m_SrcWidth; }
int32_t GetHeight() const { return m_SrcHeight; }
- int32_t GetNumComponents() const { return m_SrcComponents; }
- int32_t GetBPC() const { return m_SrcBPC; }
+ int32_t GetBitsPerPixel() const { return m_SrcComponents * m_SrcBPC; }
void SetClipBox(FX_RECT* clip);
std::pair<FXCODEC_STATUS, size_t> GetFrames();
diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp
index 93bfb74..74b1cb2 100644
--- a/xfa/fxfa/cxfa_ffwidget.cpp
+++ b/xfa/fxfa/cxfa_ffwidget.cpp
@@ -37,10 +37,7 @@
namespace {
-FXDIB_Format XFA_GetDIBFormat(FXCODEC_IMAGE_TYPE type,
- int32_t iComponents,
- int32_t iBitsPerComponent) {
- FXDIB_Format dibFormat = FXDIB_Format::kArgb;
+FXDIB_Format XFA_GetDIBFormat(FXCODEC_IMAGE_TYPE type, int32_t bpp) {
switch (type) {
case FXCODEC_IMAGE_JPG:
#ifdef PDF_ENABLE_XFA_BMP
@@ -49,20 +46,13 @@
#ifdef PDF_ENABLE_XFA_TIFF
case FXCODEC_IMAGE_TIFF:
#endif // PDF_ENABLE_XFA_TIFF
- {
- dibFormat = FXDIB_Format::kRgb32;
- int32_t bpp = iComponents * iBitsPerComponent;
- if (bpp <= 24) {
- dibFormat = FXDIB_Format::kRgb;
- }
- } break;
+ return bpp <= 24 ? FXDIB_Format::kRgb : FXDIB_Format::kRgb32;
#ifdef PDF_ENABLE_XFA_PNG
case FXCODEC_IMAGE_PNG:
#endif // PDF_ENABLE_XFA_PNG
default:
- break;
+ return FXDIB_Format::kArgb;
}
- return dibFormat;
}
} // namespace
@@ -78,8 +68,10 @@
if (rtImage.IsEmpty())
return;
- if (!pDIBitmap || pDIBitmap->GetBuffer().empty())
+ CHECK(pDIBitmap);
+ if (pDIBitmap->GetBuffer().empty()) {
return;
+ }
CFX_RectF rtFit(rtImage.TopLeft(),
XFA_UnitPx2Pt(pDIBitmap->GetWidth(), dpi.width),
@@ -176,12 +168,14 @@
}
type = pProgressiveDecoder->GetType();
- int32_t iComponents = pProgressiveDecoder->GetNumComponents();
- int32_t iBpc = pProgressiveDecoder->GetBPC();
- FXDIB_Format dibFormat = XFA_GetDIBFormat(type, iComponents, iBpc);
+ FXDIB_Format format =
+ XFA_GetDIBFormat(type, pProgressiveDecoder->GetBitsPerPixel());
RetainPtr<CFX_DIBitmap> pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- pBitmap->Create(pProgressiveDecoder->GetWidth(),
- pProgressiveDecoder->GetHeight(), dibFormat);
+ if (!pBitmap->Create(pProgressiveDecoder->GetWidth(),
+ pProgressiveDecoder->GetHeight(), format)) {
+ return nullptr;
+ }
+
pBitmap->Clear(0xffffffff);
size_t nFrames;
diff --git a/xfa/fxfa/cxfa_ffwidget.h b/xfa/fxfa/cxfa_ffwidget.h
index e11bca7..e9afcab 100644
--- a/xfa/fxfa/cxfa_ffwidget.h
+++ b/xfa/fxfa/cxfa_ffwidget.h
@@ -51,8 +51,8 @@
RetainPtr<CFX_DIBitmap> pDIBitmap,
XFA_AttributeValue iAspect,
const CFX_Size& dpi,
- XFA_AttributeValue iHorzAlign = XFA_AttributeValue::Left,
- XFA_AttributeValue iVertAlign = XFA_AttributeValue::Top);
+ XFA_AttributeValue iHorzAlign,
+ XFA_AttributeValue iVertAlign);
RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer(
RetainPtr<IFX_SeekableReadStream> pImageFileRead,