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 "xfa/fxgraphics/cxfa_geshading.h"
8
CXFA_GEShading(const CFX_PointF & beginPoint,const CFX_PointF & endPoint,bool isExtendedBegin,bool isExtendedEnd,const FX_ARGB beginArgb,const FX_ARGB endArgb)9 CXFA_GEShading::CXFA_GEShading(const CFX_PointF& beginPoint,
10 const CFX_PointF& endPoint,
11 bool isExtendedBegin,
12 bool isExtendedEnd,
13 const FX_ARGB beginArgb,
14 const FX_ARGB endArgb)
15 : m_type(FX_SHADING_Axial),
16 m_beginPoint(beginPoint),
17 m_endPoint(endPoint),
18 m_beginRadius(0),
19 m_endRadius(0),
20 m_isExtendedBegin(isExtendedBegin),
21 m_isExtendedEnd(isExtendedEnd),
22 m_beginArgb(beginArgb),
23 m_endArgb(endArgb) {
24 InitArgbArray();
25 }
26
CXFA_GEShading(const CFX_PointF & beginPoint,const CFX_PointF & endPoint,const float beginRadius,const float endRadius,bool isExtendedBegin,bool isExtendedEnd,const FX_ARGB beginArgb,const FX_ARGB endArgb)27 CXFA_GEShading::CXFA_GEShading(const CFX_PointF& beginPoint,
28 const CFX_PointF& endPoint,
29 const float beginRadius,
30 const float endRadius,
31 bool isExtendedBegin,
32 bool isExtendedEnd,
33 const FX_ARGB beginArgb,
34 const FX_ARGB endArgb)
35 : m_type(FX_SHADING_Radial),
36 m_beginPoint(beginPoint),
37 m_endPoint(endPoint),
38 m_beginRadius(beginRadius),
39 m_endRadius(endRadius),
40 m_isExtendedBegin(isExtendedBegin),
41 m_isExtendedEnd(isExtendedEnd),
42 m_beginArgb(beginArgb),
43 m_endArgb(endArgb) {
44 InitArgbArray();
45 }
46
~CXFA_GEShading()47 CXFA_GEShading::~CXFA_GEShading() {}
48
InitArgbArray()49 void CXFA_GEShading::InitArgbArray() {
50 int32_t a1;
51 int32_t r1;
52 int32_t g1;
53 int32_t b1;
54 std::tie(a1, r1, g1, b1) = ArgbDecode(m_beginArgb);
55
56 int32_t a2;
57 int32_t r2;
58 int32_t g2;
59 int32_t b2;
60 std::tie(a2, r2, g2, b2) = ArgbDecode(m_endArgb);
61
62 float f = static_cast<float>(FX_SHADING_Steps - 1);
63 float aScale = 1.0 * (a2 - a1) / f;
64 float rScale = 1.0 * (r2 - r1) / f;
65 float gScale = 1.0 * (g2 - g1) / f;
66 float bScale = 1.0 * (b2 - b1) / f;
67
68 for (int32_t i = 0; i < FX_SHADING_Steps; i++) {
69 int32_t a3 = static_cast<int32_t>(i * aScale);
70 int32_t r3 = static_cast<int32_t>(i * rScale);
71 int32_t g3 = static_cast<int32_t>(i * gScale);
72 int32_t b3 = static_cast<int32_t>(i * bScale);
73
74 // TODO(dsinclair): Add overloads for FX_ARGB. pdfium:437
75 m_argbArray[i] =
76 FXARGB_TODIB(ArgbEncode(a1 + a3, r1 + r3, g1 + g3, b1 + b3));
77 }
78 }
79