| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkUnitMappers.h" | 8 #include "SkUnitMappers.h" |
| 9 #include "SkFlattenableBuffers.h" | 9 #include "SkFlattenableBuffers.h" |
| 10 | 10 |
| 11 |
| 11 SkDiscreteMapper::SkDiscreteMapper(int segments) { | 12 SkDiscreteMapper::SkDiscreteMapper(int segments) { |
| 12 if (segments < 2) { | 13 if (segments < 2) { |
| 13 fSegments = 0; | 14 fSegments = 0; |
| 14 fScale = 0; | 15 fScale = 0; |
| 15 } else { | 16 } else { |
| 16 if (segments > 0xFFFF) { | 17 if (segments > 0xFFFF) { |
| 17 segments = 0xFFFF; | 18 segments = 0xFFFF; |
| 18 } | 19 } |
| 19 fSegments = segments; | 20 fSegments = segments; |
| 20 fScale = SK_Fract1 / (segments - 1); | 21 fScale = (1 << 30) / (segments - 1); |
| 21 } | 22 } |
| 22 } | 23 } |
| 23 | 24 |
| 24 uint16_t SkDiscreteMapper::mapUnit16(uint16_t input) { | 25 uint16_t SkDiscreteMapper::mapUnit16(uint16_t input) { |
| 25 SkFixed x = input * fSegments >> 16; | 26 SkFixed x = input * fSegments >> 16; |
| 26 x = x * fScale >> 14; | 27 x = x * fScale >> 14; |
| 27 x += x << 15 >> 31; // map 0x10000 to 0xFFFF | 28 x += x << 15 >> 31; // map 0x10000 to 0xFFFF |
| 28 return SkToU16(x); | 29 return SkToU16(x); |
| 29 } | 30 } |
| 30 | 31 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 16bits and pi/2 is 17bits, so we shift down our pi const before we mul | 51 16bits and pi/2 is 17bits, so we shift down our pi const before we mul |
| 51 */ | 52 */ |
| 52 SkFixed rads = (unsigned)(input * (SK_FixedPI >> 2)) >> 15; | 53 SkFixed rads = (unsigned)(input * (SK_FixedPI >> 2)) >> 15; |
| 53 SkFixed x = SkFixedCos(rads); | 54 SkFixed x = SkFixedCos(rads); |
| 54 x += x << 15 >> 31; // map 0x10000 to 0xFFFF | 55 x += x << 15 >> 31; // map 0x10000 to 0xFFFF |
| 55 return SkToU16(x); | 56 return SkToU16(x); |
| 56 } | 57 } |
| 57 | 58 |
| 58 SkCosineMapper::SkCosineMapper(SkFlattenableReadBuffer& rb) | 59 SkCosineMapper::SkCosineMapper(SkFlattenableReadBuffer& rb) |
| 59 : SkUnitMapper(rb) {} | 60 : SkUnitMapper(rb) {} |
| OLD | NEW |