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