summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-07-13 14:53:28 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-13 19:34:45 +0000
commitf55e72e0476e5f5699b887099f213982e207afd0 (patch)
tree5108b56962094fb7588f4f860fc3bb9c9f00e3c3 /core/fpdfapi
parent7f55a5410f665cfdbb5796d6d9a5387a5f6fa2eb (diff)
downloadpdfium-f55e72e0476e5f5699b887099f213982e207afd0.tar.xz
Cleanup CPDF_RenderOptions colour members.
This CL removes the fore/back colours in favour of just using the colours inline and converts the m_ColorMode to an enum. Change-Id: I1796e200d5c470680126af8625d45fc3062a1042 Reviewed-on: https://pdfium-review.googlesource.com/7751 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/render/cpdf_imagerenderer.cpp8
-rw-r--r--core/fpdfapi/render/cpdf_renderoptions.cpp31
-rw-r--r--core/fpdfapi/render/cpdf_renderoptions.h10
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp18
4 files changed, 20 insertions, 47 deletions
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index 6fcf89c83a..e6280772c8 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -76,7 +76,7 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() {
CPDF_GeneralState& state = m_pImageObject->m_GeneralState;
m_BitmapAlpha = FXSYS_round(255 * state.GetFillAlpha());
m_pDIBSource = m_Loader.m_pBitmap;
- if (m_pRenderStatus->m_Options.m_ColorMode == RENDER_COLOR_ALPHA &&
+ if (m_pRenderStatus->m_Options.m_ColorMode == CPDF_RenderOptions::kAlpha &&
!m_Loader.m_pMask) {
return StartBitmapAlpha();
}
@@ -103,10 +103,10 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() {
m_bPatternColor = true;
}
m_FillArgb = m_pRenderStatus->GetFillArgb(m_pImageObject.Get());
- } else if (m_pRenderStatus->m_Options.m_ColorMode == RENDER_COLOR_GRAY) {
+ } else if (m_pRenderStatus->m_Options.m_ColorMode ==
+ CPDF_RenderOptions::kGray) {
m_pClone = m_pDIBSource->Clone(nullptr);
- m_pClone->ConvertColorScale(m_pRenderStatus->m_Options.m_BackColor,
- m_pRenderStatus->m_Options.m_ForeColor);
+ m_pClone->ConvertColorScale(0xffffff, 0);
m_pDIBSource = m_pClone;
}
m_Flags = 0;
diff --git a/core/fpdfapi/render/cpdf_renderoptions.cpp b/core/fpdfapi/render/cpdf_renderoptions.cpp
index b452405c3d..7916243cba 100644
--- a/core/fpdfapi/render/cpdf_renderoptions.cpp
+++ b/core/fpdfapi/render/cpdf_renderoptions.cpp
@@ -7,15 +7,13 @@
#include "core/fpdfapi/render/cpdf_renderoptions.h"
CPDF_RenderOptions::CPDF_RenderOptions()
- : m_ColorMode(RENDER_COLOR_NORMAL),
+ : m_ColorMode(kNormal),
m_Flags(RENDER_CLEARTYPE),
m_dwLimitCacheSize(1024 * 1024 * 100),
m_bDrawAnnots(false) {}
CPDF_RenderOptions::CPDF_RenderOptions(const CPDF_RenderOptions& rhs)
: m_ColorMode(rhs.m_ColorMode),
- m_BackColor(rhs.m_BackColor),
- m_ForeColor(rhs.m_ForeColor),
m_Flags(rhs.m_Flags),
m_dwLimitCacheSize(rhs.m_dwLimitCacheSize),
m_bDrawAnnots(rhs.m_bDrawAnnots),
@@ -24,10 +22,9 @@ CPDF_RenderOptions::CPDF_RenderOptions(const CPDF_RenderOptions& rhs)
CPDF_RenderOptions::~CPDF_RenderOptions() {}
FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const {
- if (m_ColorMode == RENDER_COLOR_NORMAL)
+ if (m_ColorMode == kNormal)
return argb;
-
- if (m_ColorMode == RENDER_COLOR_ALPHA)
+ if (m_ColorMode == kAlpha)
return argb;
int a;
@@ -36,25 +33,5 @@ FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const {
int b;
std::tie(a, r, g, b) = ArgbDecode(argb);
int gray = FXRGB2GRAY(r, g, b);
- if (m_ColorMode == RENDER_COLOR_TWOCOLOR) {
- int color = (r - gray) * (r - gray) + (g - gray) * (g - gray) +
- (b - gray) * (b - gray);
- if (gray < 35 && color < 20)
- return ArgbEncode(a, m_ForeColor);
-
- if (gray > 221 && color < 20)
- return ArgbEncode(a, m_BackColor);
-
- return argb;
- }
- int fr = FXSYS_GetRValue(m_ForeColor);
- int fg = FXSYS_GetGValue(m_ForeColor);
- int fb = FXSYS_GetBValue(m_ForeColor);
- int br = FXSYS_GetRValue(m_BackColor);
- int bg = FXSYS_GetGValue(m_BackColor);
- int bb = FXSYS_GetBValue(m_BackColor);
- r = (br - fr) * gray / 255 + fr;
- g = (bg - fg) * gray / 255 + fg;
- b = (bb - fb) * gray / 255 + fb;
- return ArgbEncode(a, r, g, b);
+ return ArgbEncode(a, gray, gray, gray);
}
diff --git a/core/fpdfapi/render/cpdf_renderoptions.h b/core/fpdfapi/render/cpdf_renderoptions.h
index bdcae55ad3..aa48b4e5dc 100644
--- a/core/fpdfapi/render/cpdf_renderoptions.h
+++ b/core/fpdfapi/render/cpdf_renderoptions.h
@@ -12,10 +12,6 @@
#include "core/fxcrt/fx_system.h"
#include "core/fxge/fx_dib.h"
-#define RENDER_COLOR_NORMAL 0
-#define RENDER_COLOR_GRAY 1
-#define RENDER_COLOR_TWOCOLOR 2
-#define RENDER_COLOR_ALPHA 3
#define RENDER_CLEARTYPE 0x00000001
#define RENDER_PRINTGRAPHICTEXT 0x00000002
#define RENDER_FORCE_DOWNSAMPLE 0x00000004
@@ -36,15 +32,15 @@
class CPDF_RenderOptions {
public:
+ enum Type { kNormal = 0, kGray, kAlpha };
+
CPDF_RenderOptions();
CPDF_RenderOptions(const CPDF_RenderOptions& rhs);
~CPDF_RenderOptions();
FX_ARGB TranslateColor(FX_ARGB argb) const;
- int m_ColorMode;
- FX_COLORREF m_BackColor;
- FX_COLORREF m_ForeColor;
+ Type m_ColorMode;
uint32_t m_Flags;
uint32_t m_dwLimitCacheSize;
bool m_bDrawAnnots;
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index a3b1bb8567..ccbe39ea07 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -937,7 +937,7 @@ CFX_RetainPtr<CFX_DIBitmap> DrawPatternBitmap(CPDF_Document* pDoc,
mtPattern2Bitmap.Concat(mtAdjust);
CPDF_RenderOptions options;
if (!pPattern->colored())
- options.m_ColorMode = RENDER_COLOR_ALPHA;
+ options.m_ColorMode = CPDF_RenderOptions::kAlpha;
flags |= RENDER_FORCE_HALFTONE;
options.m_Flags = flags;
@@ -2138,8 +2138,8 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern,
if (bAlphaMode)
pBitmap->LoadChannel(FXDIB_Red, pBitmap, FXDIB_Alpha);
- if (m_Options.m_ColorMode == RENDER_COLOR_GRAY)
- pBitmap->ConvertColorScale(m_Options.m_ForeColor, m_Options.m_BackColor);
+ if (m_Options.m_ColorMode == CPDF_RenderOptions::kGray)
+ pBitmap->ConvertColorScale(0, 0xffffff);
buffer.OutputToDevice();
}
@@ -2170,7 +2170,7 @@ void CPDF_RenderStatus::DrawShadingPattern(CPDF_ShadingPattern* pattern,
FXSYS_round(255 * (bStroke ? pPageObj->m_GeneralState.GetStrokeAlpha()
: pPageObj->m_GeneralState.GetFillAlpha()));
DrawShading(pattern, &matrix, rect, alpha,
- m_Options.m_ColorMode == RENDER_COLOR_ALPHA);
+ m_Options.m_ColorMode == CPDF_RenderOptions::kAlpha);
}
void CPDF_RenderStatus::ProcessShading(const CPDF_ShadingObject* pShadingObj,
@@ -2185,7 +2185,7 @@ void CPDF_RenderStatus::ProcessShading(const CPDF_ShadingObject* pShadingObj,
matrix.Concat(*pObj2Device);
DrawShading(pShadingObj->m_pShading.Get(), &matrix, rect,
FXSYS_round(255 * pShadingObj->m_GeneralState.GetFillAlpha()),
- m_Options.m_ColorMode == RENDER_COLOR_ALPHA);
+ m_Options.m_ColorMode == CPDF_RenderOptions::kAlpha);
}
void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
@@ -2310,9 +2310,8 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
if (!pPatternBitmap)
return;
- if (m_Options.m_ColorMode == RENDER_COLOR_GRAY) {
- pPatternBitmap->ConvertColorScale(m_Options.m_ForeColor,
- m_Options.m_BackColor);
+ if (m_Options.m_ColorMode == CPDF_RenderOptions::kGray) {
+ pPatternBitmap->ConvertColorScale(0, 0xffffff);
}
FX_ARGB fill_argb = GetFillArgb(pPageObj);
int clip_width = clip_box.right - clip_box.left;
@@ -2616,7 +2615,8 @@ CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
pFormResource = form.m_pFormDict->GetDictFor("Resources");
}
CPDF_RenderOptions options;
- options.m_ColorMode = bLuminosity ? RENDER_COLOR_NORMAL : RENDER_COLOR_ALPHA;
+ options.m_ColorMode =
+ bLuminosity ? CPDF_RenderOptions::kNormal : CPDF_RenderOptions::kAlpha;
CPDF_RenderStatus status;
status.Initialize(m_pContext.Get(), &bitmap_device, nullptr, nullptr, nullptr,
nullptr, &options, 0, m_bDropObjects, pFormResource, true,