aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-22 02:55:59 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-22 02:55:59 +0000
commit3339ac54a5ed75f2872ab16e9052a8b9ff3564bf (patch)
tree42852098db6117ad0f15cf332bc2aacffa322e38 /src/utils
parent8991c67f0c1b9364bb12dfb0f32a53bd5a3357f3 (diff)
Reason for revert: required blink change failed to land Original issue's description: > Remove unused (by clients) SkUnitMapper (https://codereview.chromium.org/283273002/) > > This reverts commit dd50c83b5b34dab3a077741861b50ed1f2bc6b8f. > > BUG=skia: > > Committed: http://code.google.com/p/skia/source/detail?r=14830 R=scroggo@google.com, reed@google.com TBR=reed@google.com, scroggo@google.com NOTREECHECKS=true NOTRY=true BUG=skia: Author: reed@chromium.org Review URL: https://codereview.chromium.org/296823008 git-svn-id: http://skia.googlecode.com/svn/trunk@14838 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/SkUnitMappers.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/utils/SkUnitMappers.cpp b/src/utils/SkUnitMappers.cpp
new file mode 100644
index 0000000000..336a26e164
--- /dev/null
+++ b/src/utils/SkUnitMappers.cpp
@@ -0,0 +1,61 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkUnitMappers.h"
+#include "SkReadBuffer.h"
+#include "SkWriteBuffer.h"
+
+
+SkDiscreteMapper::SkDiscreteMapper(int segments) {
+ if (segments < 2) {
+ fSegments = 0;
+ fScale = 0;
+ } else {
+ if (segments > 0xFFFF) {
+ segments = 0xFFFF;
+ }
+ fSegments = segments;
+ fScale = (1 << 30) / (segments - 1);
+ }
+}
+
+uint16_t SkDiscreteMapper::mapUnit16(uint16_t input) {
+ SkFixed x = input * fSegments >> 16;
+ x = x * fScale >> 14;
+ x += x << 15 >> 31; // map 0x10000 to 0xFFFF
+ return SkToU16(x);
+}
+
+SkDiscreteMapper::SkDiscreteMapper(SkReadBuffer& rb)
+ : SkUnitMapper(rb) {
+ fSegments = rb.readInt();
+ fScale = rb.read32();
+}
+
+void SkDiscreteMapper::flatten(SkWriteBuffer& wb) const {
+ this->INHERITED::flatten(wb);
+
+ wb.writeInt(fSegments);
+ wb.write32(fScale);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+uint16_t SkCosineMapper::mapUnit16(uint16_t input)
+{
+ /* we want to call cosine(input * pi/2) treating input as [0...1)
+ however, the straight multitply would overflow 32bits since input is
+ 16bits and pi/2 is 17bits, so we shift down our pi const before we mul
+ */
+ SkFixed rads = (unsigned)(input * (SK_FixedPI >> 2)) >> 15;
+ SkFixed x = SkFixedCos(rads);
+ x += x << 15 >> 31; // map 0x10000 to 0xFFFF
+ return SkToU16(x);
+}
+
+SkCosineMapper::SkCosineMapper(SkReadBuffer& rb)
+ : SkUnitMapper(rb) {}