• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors
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/fgas/graphics/cfgas_geshading.h"
8 
CFGAS_GEShading(const CFX_PointF & beginPoint,const CFX_PointF & endPoint,bool isExtendedBegin,bool isExtendedEnd,FX_ARGB beginArgb,FX_ARGB endArgb)9 CFGAS_GEShading::CFGAS_GEShading(const CFX_PointF& beginPoint,
10                                  const CFX_PointF& endPoint,
11                                  bool isExtendedBegin,
12                                  bool isExtendedEnd,
13                                  FX_ARGB beginArgb,
14                                  FX_ARGB endArgb)
15     : m_type(Type::kAxial),
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   InitArgbArray(beginArgb, endArgb);
23 }
24 
CFGAS_GEShading(const CFX_PointF & beginPoint,const CFX_PointF & endPoint,float beginRadius,float endRadius,bool isExtendedBegin,bool isExtendedEnd,FX_ARGB beginArgb,FX_ARGB endArgb)25 CFGAS_GEShading::CFGAS_GEShading(const CFX_PointF& beginPoint,
26                                  const CFX_PointF& endPoint,
27                                  float beginRadius,
28                                  float endRadius,
29                                  bool isExtendedBegin,
30                                  bool isExtendedEnd,
31                                  FX_ARGB beginArgb,
32                                  FX_ARGB endArgb)
33     : m_type(Type::kRadial),
34       m_beginPoint(beginPoint),
35       m_endPoint(endPoint),
36       m_beginRadius(beginRadius),
37       m_endRadius(endRadius),
38       m_isExtendedBegin(isExtendedBegin),
39       m_isExtendedEnd(isExtendedEnd) {
40   InitArgbArray(beginArgb, endArgb);
41 }
42 
43 CFGAS_GEShading::~CFGAS_GEShading() = default;
44 
InitArgbArray(FX_ARGB begin_argb,FX_ARGB end_argb)45 void CFGAS_GEShading::InitArgbArray(FX_ARGB begin_argb, FX_ARGB end_argb) {
46   FX_BGRA_STRUCT<uint8_t> bgra0 = ArgbToBGRAStruct(begin_argb);
47   FX_BGRA_STRUCT<uint8_t> bgra1 = ArgbToBGRAStruct(end_argb);
48 
49   constexpr float f = static_cast<float>(kSteps - 1);
50   const float a_scale = 1.0 * (bgra1.alpha - bgra0.alpha) / f;
51   const float r_scale = 1.0 * (bgra1.red - bgra0.red) / f;
52   const float g_scale = 1.0 * (bgra1.green - bgra0.green) / f;
53   const float b_scale = 1.0 * (bgra1.blue - bgra0.blue) / f;
54 
55   for (size_t i = 0; i < kSteps; i++) {
56     m_argbArray[i] = ArgbEncode(static_cast<int32_t>(i * a_scale) + bgra0.alpha,
57                                 static_cast<int32_t>(i * r_scale) + bgra0.red,
58                                 static_cast<int32_t>(i * g_scale) + bgra0.green,
59                                 static_cast<int32_t>(i * b_scale) + bgra0.blue);
60   }
61 }
62