aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2020-01-29 21:57:15 +0000
committerChromium commit bot <commit-bot@chromium.org>2020-01-29 21:57:15 +0000
commitde679a2f8c60608509e9c7e01503fad3df2be9b6 (patch)
treed15eeffe4a7e2e55327cbcc9a8886105ea228e6c /core
parentb1fbfbfd529b65068da88766ff24cbf2b64445a2 (diff)
downloadpdfium-de679a2f8c60608509e9c7e01503fad3df2be9b6.tar.gz
Change CJPX_Decoder::GetInfo() to return a struct.
Return the image info in a struct, instead of 3 separate out parameters. Change-Id: I5e1d86820a5aa6a53e0b1c6eec0415e6bb472689 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/65750 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/page/cpdf_dib.cpp29
-rw-r--r--core/fxcodec/jpx/cjpx_decoder.cpp8
-rw-r--r--core/fxcodec/jpx/cjpx_decoder.h8
3 files changed, 23 insertions, 22 deletions
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index 87845b703..cbad6b530 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -627,16 +627,15 @@ RetainPtr<CFX_DIBitmap> CPDF_DIB::LoadJpxBitmap() {
if (!decoder->StartDecode())
return nullptr;
- uint32_t width = 0;
- uint32_t height = 0;
- uint32_t components = 0;
- decoder->GetInfo(&width, &height, &components);
- if (static_cast<int>(width) < m_Width || static_cast<int>(height) < m_Height)
+ CJPX_Decoder::JpxImageInfo image_info = decoder->GetInfo();
+ if (static_cast<int>(image_info.width) < m_Width ||
+ static_cast<int>(image_info.height) < m_Height) {
return nullptr;
+ }
RetainPtr<CPDF_ColorSpace> original_colorspace = m_pColorSpace;
bool swap_rgb = false;
- switch (GetJpxDecodeAction(components, m_pColorSpace.Get())) {
+ switch (GetJpxDecodeAction(image_info.components, m_pColorSpace.Get())) {
case JpxDecodeAction::kFail:
return nullptr;
@@ -659,28 +658,28 @@ RetainPtr<CFX_DIBitmap> CPDF_DIB::LoadJpxBitmap() {
DCHECK_NE(0, m_nComponents);
} else {
DCHECK_EQ(0, m_nComponents);
- m_nComponents = components;
+ m_nComponents = image_info.components;
}
FXDIB_Format format;
- if (components == 1) {
+ if (image_info.components == 1) {
format = FXDIB_8bppRgb;
- } else if (components <= 3) {
+ } else if (image_info.components <= 3) {
format = FXDIB_Rgb;
- } else if (components == 4) {
+ } else if (image_info.components == 4) {
format = FXDIB_Rgb32;
} else {
- width = (width * components + 2) / 3;
+ image_info.width = (image_info.width * image_info.components + 2) / 3;
format = FXDIB_Rgb;
}
auto pCachedBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pCachedBitmap->Create(width, height, format))
+ if (!pCachedBitmap->Create(image_info.width, image_info.height, format))
return nullptr;
pCachedBitmap->Clear(0xFFFFFFFF);
// Fill |output_offsets| with 0, 1, ... N.
- std::vector<uint8_t> output_offsets(components);
+ std::vector<uint8_t> output_offsets(image_info.components);
std::iota(output_offsets.begin(), output_offsets.end(), 0);
if (swap_rgb)
std::swap(output_offsets[0], output_offsets[2]);
@@ -692,9 +691,9 @@ RetainPtr<CFX_DIBitmap> CPDF_DIB::LoadJpxBitmap() {
if (m_pColorSpace && m_pColorSpace->GetFamily() == PDFCS_INDEXED &&
m_bpc < 8) {
int scale = 8 - m_bpc;
- for (uint32_t row = 0; row < height; ++row) {
+ for (uint32_t row = 0; row < image_info.height; ++row) {
uint8_t* scanline = pCachedBitmap->GetWritableScanline(row);
- for (uint32_t col = 0; col < width; ++col) {
+ for (uint32_t col = 0; col < image_info.width; ++col) {
*scanline = (*scanline) >> scale;
++scanline;
}
diff --git a/core/fxcodec/jpx/cjpx_decoder.cpp b/core/fxcodec/jpx/cjpx_decoder.cpp
index 4653b5e96..986d2f15f 100644
--- a/core/fxcodec/jpx/cjpx_decoder.cpp
+++ b/core/fxcodec/jpx/cjpx_decoder.cpp
@@ -489,12 +489,8 @@ bool CJPX_Decoder::StartDecode() {
return true;
}
-void CJPX_Decoder::GetInfo(uint32_t* width,
- uint32_t* height,
- uint32_t* components) {
- *width = m_Image->x1;
- *height = m_Image->y1;
- *components = m_Image->numcomps;
+CJPX_Decoder::JpxImageInfo CJPX_Decoder::GetInfo() const {
+ return {m_Image->x1, m_Image->y1, m_Image->numcomps};
}
bool CJPX_Decoder::Decode(uint8_t* dest_buf,
diff --git a/core/fxcodec/jpx/cjpx_decoder.h b/core/fxcodec/jpx/cjpx_decoder.h
index 1fe50437d..0fdccb9e6 100644
--- a/core/fxcodec/jpx/cjpx_decoder.h
+++ b/core/fxcodec/jpx/cjpx_decoder.h
@@ -30,13 +30,19 @@ class CJPX_Decoder {
kIndexedColorSpace
};
+ struct JpxImageInfo {
+ uint32_t width;
+ uint32_t height;
+ uint32_t components;
+ };
+
static void Sycc420ToRgbForTesting(opj_image_t* img);
explicit CJPX_Decoder(ColorSpaceOption option);
~CJPX_Decoder();
bool Init(pdfium::span<const uint8_t> src_data);
- void GetInfo(uint32_t* width, uint32_t* height, uint32_t* components);
+ JpxImageInfo GetInfo() const;
bool StartDecode();
bool Decode(uint8_t* dest_buf,
uint32_t pitch,