summaryrefslogtreecommitdiff
path: root/core/fpdfapi/render/cpdf_renderstatus.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-09 19:20:43 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-09 19:20:43 +0000
commit56b272e9cb6c680c1fcda2984c23c47b6cc4b421 (patch)
tree6d24ffca02572afdda79edfdf1ea18f21308f556 /core/fpdfapi/render/cpdf_renderstatus.cpp
parent575ceba24463a2211e8669f8d919d3c91385d72b (diff)
downloadpdfium-56b272e9cb6c680c1fcda2984c23c47b6cc4b421.tar.xz
Break backcolor code out of CPDF_RenderStatus::LoadSMask().
Fix some nits in the code in the process. Change-Id: I660b3bf547823a11bc291ed2dd1ec19a76b24b5b Reviewed-on: https://pdfium-review.googlesource.com/32178 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/render/cpdf_renderstatus.cpp')
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp71
1 files changed, 42 insertions, 29 deletions
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 708d7076c1..3672729f2e 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -2561,35 +2561,10 @@ RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
return nullptr;
CFX_DIBitmap& bitmap = *bitmap_device.GetBitmap();
- int color_space_family = 0;
+ int nCSFamily = 0;
if (bLuminosity) {
- CPDF_Array* pBC = pSMaskDict->GetArrayFor("BC");
- FX_ARGB back_color = 0xff000000;
- if (pBC) {
- CPDF_Object* pCSObj = nullptr;
- CPDF_Dictionary* pDict = pGroup->GetDict();
- if (pDict && pDict->GetDictFor("Group")) {
- pCSObj = pDict->GetDictFor("Group")->GetDirectObjectFor("CS");
- }
- const CPDF_ColorSpace* pCS =
- m_pContext->GetDocument()->LoadColorSpace(pCSObj);
- if (pCS) {
- // Store Color Space Family to use in CPDF_RenderStatus::Initialize.
- color_space_family = pCS->GetFamily();
-
- float R, G, B;
- uint32_t comps = std::max(8u, pCS->CountComponents());
- std::vector<float> floats(comps);
- size_t count = std::min<size_t>(8, pBC->GetCount());
- for (size_t i = 0; i < count; i++) {
- floats[i] = pBC->GetNumberAt(i);
- }
- pCS->GetRGB(floats.data(), &R, &G, &B);
- back_color = 0xff000000 | ((int32_t)(R * 255) << 16) |
- ((int32_t)(G * 255) << 8) | (int32_t)(B * 255);
- m_pContext->GetDocument()->GetPageData()->ReleaseColorSpace(pCSObj);
- }
- }
+ FX_ARGB back_color =
+ GetBackColor(pSMaskDict, pGroup->GetDict(), &nCSFamily);
bitmap.Clear(back_color);
} else {
bitmap.Clear(0);
@@ -2604,7 +2579,7 @@ RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
CPDF_RenderStatus status;
status.Initialize(m_pContext.Get(), &bitmap_device, nullptr, nullptr, nullptr,
nullptr, &options, 0, m_bDropObjects, pFormResource, true,
- nullptr, 0, color_space_family, bLuminosity);
+ nullptr, 0, nCSFamily, bLuminosity);
status.RenderObjectList(&form, &matrix);
auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
@@ -2649,3 +2624,41 @@ RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
}
return pMask;
}
+
+FX_ARGB CPDF_RenderStatus::GetBackColor(const CPDF_Dictionary* pSMaskDict,
+ const CPDF_Dictionary* pGroupDict,
+ int* pCSFamily) {
+ static constexpr FX_ARGB kDefaultColor = ArgbEncode(255, 0, 0, 0);
+ CPDF_Array* pBC = pSMaskDict->GetArrayFor("BC");
+ if (!pBC)
+ return kDefaultColor;
+
+ CPDF_Object* pCSObj = nullptr;
+ const CPDF_Dictionary* pGroup =
+ pGroupDict ? pGroupDict->GetDictFor("Group") : nullptr;
+ if (pGroup) {
+ // TODO(thestig): Check if "CS" is from PDF spec 1.7, table 13.
+ pCSObj = pGroup->GetDirectObjectFor("CS");
+ }
+ const CPDF_ColorSpace* pCS =
+ m_pContext->GetDocument()->LoadColorSpace(pCSObj);
+ if (!pCS)
+ return kDefaultColor;
+
+ // Store Color Space Family to use in CPDF_RenderStatus::Initialize().
+ *pCSFamily = pCS->GetFamily();
+
+ uint32_t comps = std::max(8u, pCS->CountComponents());
+ std::vector<float> floats(comps);
+ size_t count = std::min<size_t>(8, pBC->GetCount());
+ for (size_t i = 0; i < count; i++)
+ floats[i] = pBC->GetNumberAt(i);
+
+ float R;
+ float G;
+ float B;
+ pCS->GetRGB(floats.data(), &R, &G, &B);
+ m_pContext->GetDocument()->GetPageData()->ReleaseColorSpace(pCSObj);
+ return ArgbEncode(255, static_cast<int>(R * 255), static_cast<int>(G * 255),
+ static_cast<int>(B * 255));
+}