From 0d63e4e4a8e3df7a9e0ae5d46967513201ef731d Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Thu, 13 Apr 2017 12:15:50 -0400 Subject: [PATCH] Use a simpler method for calculating atan Change-Id: I675851350c02c85f3f212c214766b3e8a6761dc9 Reviewed-on: https://skia-review.googlesource.com/13402 Reviewed-by: Florin Malita Commit-Queue: Herb Derby --- src/effects/gradients/SkSweepGradient.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp index 79013b3..06b9f21 100644 --- a/src/effects/gradients/SkSweepGradient.cpp +++ b/src/effects/gradients/SkSweepGradient.cpp @@ -7,6 +7,8 @@ #include "SkSweepGradient.h" +#include + static SkMatrix translate(SkScalar dx, SkScalar dy) { SkMatrix matrix; matrix.setTranslate(dx, dy); @@ -56,6 +58,7 @@ SkSweepGradient::SweepGradientContext::SweepGradientContext( : INHERITED(shader, rec) {} // returns angle in a circle [0..2PI) -> [0..255] +#ifdef SK_LEGACY_SWEEP_GRADIENT static unsigned SkATan2_255(float y, float x) { // static const float g255Over2PI = 255 / (2 * SK_ScalarPI); static const float g255Over2PI = 40.584510488433314f; @@ -74,6 +77,26 @@ static unsigned SkATan2_255(float y, float x) { SkASSERT(ir >= 0 && ir <= 255); return ir; } +#else +static unsigned SkATan2_255(float y, float x) { + if (y == 0 && x == 0) return 0; + float yabs = sk_float_abs(y), + xabs = sk_float_abs(x); + float little, big; + std::tie(little, big) = std::minmax(yabs, xabs); + float a = little/big; + float s = a * a; + float r = a*(40.57589784014689f + + s*(-13.222755844396332f + s*(6.314046289038564f - s*1.7989502668982151f))); + r = xabs < yabs ? 255/4.0f - r : r; + r = x < 0.0f ? 255/2.0f - r : r; + r = y < 0.0f ? 255 - r : r; + + int ir = (int)r; + SkASSERT(ir >= 0 && ir <= 255); + return ir; +} +#endif void SkSweepGradient::SweepGradientContext::shadeSpan(int x, int y, SkPMColor* SK_RESTRICT dstC, int count) { -- 2.7.4