summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--fpdfsdk/fpdfformfill.cpp8
-rw-r--r--fpdfsdk/fpdfview.cpp7
-rw-r--r--fpdfsdk/fxedit/fxet_edit.cpp4
7 files changed, 27 insertions, 59 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,
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index f2ae621098..24cd64efa1 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -126,11 +126,9 @@ void FFLCommon(FPDF_FORMHANDLE hHandle,
options.m_Flags &= ~RENDER_CLEARTYPE;
// Grayscale output
- if (flags & FPDF_GRAYSCALE) {
- options.m_ColorMode = RENDER_COLOR_GRAY;
- options.m_ForeColor = 0;
- options.m_BackColor = 0xffffff;
- }
+ if (flags & FPDF_GRAYSCALE)
+ options.m_ColorMode = CPDF_RenderOptions::kGray;
+
options.m_bDrawAnnots = flags & FPDF_ANNOT;
#ifdef PDF_ENABLE_XFA
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 48322a74dc..905d3683a0 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -101,11 +101,8 @@ void RenderPageImpl(CPDF_PageRenderContext* pContext,
#endif // PDF_ENABLE_XFA
// Grayscale output
- if (flags & FPDF_GRAYSCALE) {
- pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
- pContext->m_pOptions->m_ForeColor = 0;
- pContext->m_pOptions->m_BackColor = 0xffffff;
- }
+ if (flags & FPDF_GRAYSCALE)
+ pContext->m_pOptions->m_ColorMode = CPDF_RenderOptions::kGray;
const CPDF_OCContext::UsageType usage =
(flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View;
diff --git a/fpdfsdk/fxedit/fxet_edit.cpp b/fpdfsdk/fxedit/fxet_edit.cpp
index 82f82477d8..cf382f8426 100644
--- a/fpdfsdk/fxedit/fxet_edit.cpp
+++ b/fpdfsdk/fxedit/fxet_edit.cpp
@@ -76,14 +76,14 @@ void DrawTextString(CFX_RenderDevice* pDevice,
CPDF_RenderOptions ro;
ro.m_Flags = RENDER_CLEARTYPE;
- ro.m_ColorMode = RENDER_COLOR_NORMAL;
+ ro.m_ColorMode = CPDF_RenderOptions::kNormal;
CPDF_TextRenderer::DrawTextString(pDevice, pos.x, pos.y, pFont, fFontSize,
&mt, str, crTextFill, nullptr, &ro);
} else {
CPDF_RenderOptions ro;
ro.m_Flags = RENDER_CLEARTYPE;
- ro.m_ColorMode = RENDER_COLOR_NORMAL;
+ ro.m_ColorMode = CPDF_RenderOptions::kNormal;
CPDF_TextRenderer::DrawTextString(pDevice, pos.x, pos.y, pFont, fFontSize,
pUser2Device, str, crTextFill, nullptr,