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