1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "core/fpdfapi/render/cpdf_renderoptions.h"
8
CPDF_RenderOptions()9 CPDF_RenderOptions::CPDF_RenderOptions()
10 : m_ColorMode(RENDER_COLOR_NORMAL),
11 m_Flags(RENDER_CLEARTYPE),
12 m_Interpolation(0),
13 m_AddFlags(0),
14 m_dwLimitCacheSize(1024 * 1024 * 100),
15 m_HalftoneLimit(-1),
16 m_bDrawAnnots(false) {}
17
CPDF_RenderOptions(const CPDF_RenderOptions & rhs)18 CPDF_RenderOptions::CPDF_RenderOptions(const CPDF_RenderOptions& rhs)
19 : m_ColorMode(rhs.m_ColorMode),
20 m_BackColor(rhs.m_BackColor),
21 m_ForeColor(rhs.m_ForeColor),
22 m_Flags(rhs.m_Flags),
23 m_Interpolation(rhs.m_Interpolation),
24 m_AddFlags(rhs.m_AddFlags),
25 m_dwLimitCacheSize(rhs.m_dwLimitCacheSize),
26 m_HalftoneLimit(rhs.m_HalftoneLimit),
27 m_bDrawAnnots(rhs.m_bDrawAnnots),
28 m_pOCContext(rhs.m_pOCContext) {}
29
~CPDF_RenderOptions()30 CPDF_RenderOptions::~CPDF_RenderOptions() {}
31
TranslateColor(FX_ARGB argb) const32 FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const {
33 if (m_ColorMode == RENDER_COLOR_NORMAL)
34 return argb;
35
36 if (m_ColorMode == RENDER_COLOR_ALPHA)
37 return argb;
38
39 int a, r, g, b;
40 ArgbDecode(argb, a, r, g, b);
41 int gray = FXRGB2GRAY(r, g, b);
42 if (m_ColorMode == RENDER_COLOR_TWOCOLOR) {
43 int color = (r - gray) * (r - gray) + (g - gray) * (g - gray) +
44 (b - gray) * (b - gray);
45 if (gray < 35 && color < 20)
46 return ArgbEncode(a, m_ForeColor);
47
48 if (gray > 221 && color < 20)
49 return ArgbEncode(a, m_BackColor);
50
51 return argb;
52 }
53 int fr = FXSYS_GetRValue(m_ForeColor);
54 int fg = FXSYS_GetGValue(m_ForeColor);
55 int fb = FXSYS_GetBValue(m_ForeColor);
56 int br = FXSYS_GetRValue(m_BackColor);
57 int bg = FXSYS_GetGValue(m_BackColor);
58 int bb = FXSYS_GetBValue(m_BackColor);
59 r = (br - fr) * gray / 255 + fr;
60 g = (bg - fg) * gray / 255 + fg;
61 b = (bb - fb) * gray / 255 + fb;
62 return ArgbEncode(a, r, g, b);
63 }
64