Add ProgressiveDecoder::GetBitmapFormat()
In production code, instead of making the caller calculate the format,
move that code into ProgressiveDecoder. Then ProgressiveDecoder can stop
exposing 2 getters that are only used to support the format calculation.
Change-Id: I0514c160d94006e6d3374b8c42c16e71de488df7
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/122772
Reviewed-by: Tom Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcodec/progressive_decoder.cpp b/core/fxcodec/progressive_decoder.cpp
index e243f10..c0db252 100644
--- a/core/fxcodec/progressive_decoder.cpp
+++ b/core/fxcodec/progressive_decoder.cpp
@@ -1244,6 +1244,27 @@
ResampleScanline(pDeviceBitmap, src_line, m_DecodeBuf, src_format);
}
+FXDIB_Format ProgressiveDecoder::GetBitmapFormat() const {
+ switch (m_imageType) {
+ case FXCODEC_IMAGE_JPG:
+#ifdef PDF_ENABLE_XFA_BMP
+ case FXCODEC_IMAGE_BMP:
+#endif // PDF_ENABLE_XFA_BMP
+#ifdef PDF_ENABLE_XFA_TIFF
+ case FXCODEC_IMAGE_TIFF:
+#endif // PDF_ENABLE_XFA_TIFF
+ return GetBitsPerPixel() <= 24 ? FXDIB_Format::kRgb
+ : FXDIB_Format::kRgb32;
+#ifdef PDF_ENABLE_XFA_PNG
+ case FXCODEC_IMAGE_PNG:
+#endif // PDF_ENABLE_XFA_PNG
+ default:
+ // TODO(crbug.com/355630556): Consider adding support for
+ // `FXDIB_Format::kArgbPremul`
+ return FXDIB_Format::kArgb;
+ }
+}
+
std::pair<FXCODEC_STATUS, size_t> ProgressiveDecoder::GetFrames() {
if (!(m_status == FXCODEC_STATUS::kFrameReady ||
m_status == FXCODEC_STATUS::kFrameToBeContinued)) {
diff --git a/core/fxcodec/progressive_decoder.h b/core/fxcodec/progressive_decoder.h
index 367f4e8..2de8c96 100644
--- a/core/fxcodec/progressive_decoder.h
+++ b/core/fxcodec/progressive_decoder.h
@@ -74,10 +74,10 @@
CFX_DIBAttribute* pAttribute,
bool bSkipImageTypeCheck);
- FXCODEC_IMAGE_TYPE GetType() const { return m_imageType; }
int32_t GetWidth() const { return m_SrcWidth; }
int32_t GetHeight() const { return m_SrcHeight; }
- int32_t GetBitsPerPixel() const { return m_SrcComponents * m_SrcBPC; }
+
+ FXDIB_Format GetBitmapFormat() const;
std::pair<FXCODEC_STATUS, size_t> GetFrames();
FXCODEC_STATUS StartDecode(RetainPtr<CFX_DIBitmap> bitmap);
@@ -158,6 +158,8 @@
FXCODEC_STATUS JpegStartDecode();
FXCODEC_STATUS JpegContinueDecode();
+ int32_t GetBitsPerPixel() const { return m_SrcComponents * m_SrcBPC; }
+
bool DetectImageType(FXCODEC_IMAGE_TYPE imageType,
CFX_DIBAttribute* pAttribute);
bool ReadMoreData(ProgressiveDecoderIface* pModule,
diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp
index ae5dd5c..73ebbe4 100644
--- a/xfa/fxfa/cxfa_ffwidget.cpp
+++ b/xfa/fxfa/cxfa_ffwidget.cpp
@@ -35,30 +35,6 @@
#include "xfa/fxfa/parser/cxfa_margin.h"
#include "xfa/fxfa/parser/cxfa_node.h"
-namespace {
-
-FXDIB_Format XFA_GetDIBFormat(FXCODEC_IMAGE_TYPE type, int32_t bpp) {
- switch (type) {
- case FXCODEC_IMAGE_JPG:
-#ifdef PDF_ENABLE_XFA_BMP
- case FXCODEC_IMAGE_BMP:
-#endif // PDF_ENABLE_XFA_BMP
-#ifdef PDF_ENABLE_XFA_TIFF
- case FXCODEC_IMAGE_TIFF:
-#endif // PDF_ENABLE_XFA_TIFF
- return bpp <= 24 ? FXDIB_Format::kRgb : FXDIB_Format::kRgb32;
-#ifdef PDF_ENABLE_XFA_PNG
- case FXCODEC_IMAGE_PNG:
-#endif // PDF_ENABLE_XFA_PNG
- default:
- // TODO(crbug.com/355630556): Consider adding support for
- // `FXDIB_Format::kArgbPremul`
- return FXDIB_Format::kArgb;
- }
-}
-
-} // namespace
-
void XFA_DrawImage(CFGAS_GEGraphics* pGS,
const CFX_RectF& rtImage,
const CFX_Matrix& matrix,
@@ -171,12 +147,10 @@
return nullptr;
}
- type = pProgressiveDecoder->GetType();
- FXDIB_Format format =
- XFA_GetDIBFormat(type, pProgressiveDecoder->GetBitsPerPixel());
RetainPtr<CFX_DIBitmap> pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pBitmap->Create(pProgressiveDecoder->GetWidth(),
- pProgressiveDecoder->GetHeight(), format)) {
+ pProgressiveDecoder->GetHeight(),
+ pProgressiveDecoder->GetBitmapFormat())) {
return nullptr;
}