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

Side by Side Diff: skia/effects/SkUnitMappers.cpp

Issue 113827: Remove the remainder of the skia source code from the Chromium repo.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « skia/effects/SkTransparentShader.cpp ('k') | skia/gl/SkGL.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "SkUnitMappers.h"
2
3 SkDiscreteMapper::SkDiscreteMapper(int segments)
4 {
5 if (segments < 2)
6 {
7 fSegments = 0;
8 fScale = 0;
9 }
10 else
11 {
12 if (segments > 0xFFFF)
13 segments = 0xFFFF;
14 fSegments = segments;
15 fScale = SK_Fract1 / (segments - 1);
16 }
17 }
18
19 uint16_t SkDiscreteMapper::mapUnit16(uint16_t input)
20 {
21 SkFixed x = input * fSegments >> 16;
22 x = x * fScale >> 14;
23 x += x << 15 >> 31; // map 0x10000 to 0xFFFF
24 return SkToU16(x);
25 }
26
27 SkDiscreteMapper::SkDiscreteMapper(SkFlattenableReadBuffer& rb)
28 : SkUnitMapper(rb)
29 {
30 fSegments = rb.readU32();
31 fScale = rb.readU32();
32 }
33
34 SkFlattenable::Factory SkDiscreteMapper::getFactory()
35 {
36 return Create;
37 }
38
39 SkFlattenable* SkDiscreteMapper::Create(SkFlattenableReadBuffer& rb)
40 {
41 return SkNEW_ARGS(SkDiscreteMapper, (rb));
42 }
43
44 void SkDiscreteMapper::flatten(SkFlattenableWriteBuffer& wb)
45 {
46 this->INHERITED::flatten(wb);
47
48 wb.write32(fSegments);
49 wb.write32(fScale);
50 }
51
52 ///////////////////////////////////////////////////////////////////////////////
53
54 uint16_t SkCosineMapper::mapUnit16(uint16_t input)
55 {
56 /* we want to call cosine(input * pi/2) treating input as [0...1)
57 however, the straight multitply would overflow 32bits since input is
58 16bits and pi/2 is 17bits, so we shift down our pi const before we mul
59 */
60 SkFixed rads = (unsigned)(input * (SK_FixedPI >> 2)) >> 15;
61 SkFixed x = SkFixedCos(rads);
62 x += x << 15 >> 31; // map 0x10000 to 0xFFFF
63 return SkToU16(x);
64 }
65
66 SkCosineMapper::SkCosineMapper(SkFlattenableReadBuffer& rb)
67 : SkUnitMapper(rb)
68 {
69 }
70
71 SkFlattenable::Factory SkCosineMapper::getFactory()
72 {
73 return Create;
74 }
75
76 SkFlattenable* SkCosineMapper::Create(SkFlattenableReadBuffer& rb)
77 {
78 return SkNEW_ARGS(SkCosineMapper, (rb));
79 }
80
OLDNEW
« no previous file with comments | « skia/effects/SkTransparentShader.cpp ('k') | skia/gl/SkGL.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698