Chromium Code Reviews| Index: xfa/fxgraphics/cfx_shading.cpp |
| diff --git a/xfa/fxgraphics/cfx_shading.cpp b/xfa/fxgraphics/cfx_shading.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e322cf1694e607a01fc4e02425f61e1a82b262f2 |
| --- /dev/null |
| +++ b/xfa/fxgraphics/cfx_shading.cpp |
| @@ -0,0 +1,77 @@ |
| +// Copyright 2016 PDFium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| + |
| +#include "xfa/fxgraphics/cfx_shading.h" |
| + |
| +CFX_Shading::CFX_Shading(const CFX_PointF& beginPoint, |
| + const CFX_PointF& endPoint, |
| + FX_BOOL isExtendedBegin, |
| + FX_BOOL isExtendedEnd, |
| + const FX_ARGB beginArgb, |
| + const FX_ARGB endArgb) |
| + : m_type(FX_SHADING_Axial), |
| + m_beginPoint(beginPoint), |
| + m_endPoint(endPoint), |
| + m_isExtendedBegin(isExtendedBegin), |
| + m_beginArgb(beginArgb), |
| + m_endArgb(endArgb) { |
| + InitArgbArray(); |
| +} |
| + |
| +CFX_Shading::CFX_Shading(const CFX_PointF& beginPoint, |
| + const CFX_PointF& endPoint, |
| + const FX_FLOAT beginRadius, |
| + const FX_FLOAT endRadius, |
| + FX_BOOL isExtendedBegin, |
| + FX_BOOL isExtendedEnd, |
| + const FX_ARGB beginArgb, |
| + const FX_ARGB endArgb) |
| + : m_type(FX_SHADING_Radial), |
| + m_beginPoint(beginPoint), |
| + m_endPoint(endPoint), |
| + m_beginRadius(beginRadius), |
| + m_endRadius(endRadius), |
| + m_isExtendedBegin(isExtendedBegin), |
| + m_isExtendedEnd(isExtendedEnd), |
| + m_beginArgb(beginArgb), |
| + m_endArgb(endArgb) { |
| + InitArgbArray(); |
| +} |
| + |
| +CFX_Shading::~CFX_Shading() {} |
| + |
| +void CFX_Shading::InitArgbArray() { |
| + int32_t a1; |
| + int32_t r1; |
| + int32_t g1; |
| + int32_t b1; |
| + ArgbDecode(m_beginArgb, a1, r1, g1, b1); |
| + |
| + int32_t a2; |
| + int32_t r2; |
| + int32_t g2; |
| + int32_t b2; |
| + ArgbDecode(m_endArgb, a2, r2, g2, b2); |
| + |
| + FX_FLOAT f = (FX_FLOAT)(FX_SHADING_Steps - 1); |
| + FX_FLOAT aScale = (FX_FLOAT)(1.0 * (a2 - a1) / f); |
|
Tom Sepez
2016/03/16 20:53:18
These casts are pointless as we assume an int's ra
dsinclair
2016/03/16 21:13:39
Done.
|
| + FX_FLOAT rScale = (FX_FLOAT)(1.0 * (r2 - r1) / f); |
| + FX_FLOAT gScale = (FX_FLOAT)(1.0 * (g2 - g1) / f); |
| + FX_FLOAT bScale = (FX_FLOAT)(1.0 * (b2 - b1) / f); |
| + |
| + int32_t a3; |
|
Tom Sepez
2016/03/16 20:53:18
nit: move these inside loop. They needn't persist
dsinclair
2016/03/16 21:13:39
Done.
|
| + int32_t r3; |
| + int32_t g3; |
| + int32_t b3; |
| + for (int32_t i = 0; i < FX_SHADING_Steps; i++) { |
| + a3 = (int32_t)(i * aScale); |
|
Tom Sepez
2016/03/16 20:53:17
nit: static_cast<>, just to emphasize that we thin
dsinclair
2016/03/16 21:13:39
Done.
|
| + r3 = (int32_t)(i * rScale); |
| + g3 = (int32_t)(i * gScale); |
| + b3 = (int32_t)(i * bScale); |
|
Tom Sepez
2016/03/16 20:53:18
Pity we dont define addition multiplicaton subtrac
dsinclair
2016/03/16 21:13:39
Done.
|
| + m_argbArray[i] = |
| + FXARGB_TODIB(FXARGB_MAKE((a1 + a3), (r1 + r3), (g1 + g3), (b1 + b3))); |
|
Tom Sepez
2016/03/16 20:53:18
nit: overparenthesized, unless FXARGB_MAKE is not
dsinclair
2016/03/16 21:13:39
Done.
|
| + } |
| +} |