Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Unified Diff: src/utils/SkUnitMappers.cpp

Issue 287063009: Revert of remove unused (by clients) SkUnitMapper (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/gradients/SkGradientShaderPriv.h ('k') | tests/DeferredCanvasTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkUnitMappers.cpp
diff --git a/src/utils/SkUnitMappers.cpp b/src/utils/SkUnitMappers.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..336a26e1643f52ae9d9947d8587cbc18fd6bbaf0
--- /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) {}
« no previous file with comments | « src/effects/gradients/SkGradientShaderPriv.h ('k') | tests/DeferredCanvasTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698