OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
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 | 8 |
9 | 9 |
10 #ifndef SkMath_DEFINED | 10 #ifndef SkMath_DEFINED |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 132 } |
133 #else | 133 #else |
134 #define SkMulS16(x, y) ((x) * (y)) | 134 #define SkMulS16(x, y) ((x) * (y)) |
135 #endif | 135 #endif |
136 #endif | 136 #endif |
137 | 137 |
138 /** | 138 /** |
139 * Return a*b/((1 << shift) - 1), rounding any fractional bits. | 139 * Return a*b/((1 << shift) - 1), rounding any fractional bits. |
140 * Only valid if a and b are unsigned and <= 32767 and shift is > 0 and <= 8 | 140 * Only valid if a and b are unsigned and <= 32767 and shift is > 0 and <= 8 |
141 */ | 141 */ |
142 static inline unsigned SkMul16ShiftRound(unsigned a, unsigned b, int shift) { | 142 static inline unsigned SkMul16ShiftRound(U16CPU a, U16CPU b, int shift) { |
143 SkASSERT(a <= 32767); | 143 SkASSERT(a <= 32767); |
144 SkASSERT(b <= 32767); | 144 SkASSERT(b <= 32767); |
145 SkASSERT(shift > 0 && shift <= 8); | 145 SkASSERT(shift > 0 && shift <= 8); |
146 unsigned prod = SkMulS16(a, b) + (1 << (shift - 1)); | 146 unsigned prod = SkMulS16(a, b) + (1 << (shift - 1)); |
147 return (prod + (prod >> shift)) >> shift; | 147 return (prod + (prod >> shift)) >> shift; |
148 } | 148 } |
149 | 149 |
150 /** | 150 /** |
151 * Return a*b/255, rounding any fractional bits. Only valid if both | 151 * Return a*b/255, rounding any fractional bits. |
152 * a and b are 0..255 | 152 * Only valid if a and b are unsigned and <= 32767. |
153 */ | 153 */ |
154 static inline U8CPU SkMulDiv255Round(U8CPU a, U8CPU b) { | 154 static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { |
155 SkASSERT((uint8_t)a == a); | 155 SkASSERT(a <= 32767); |
156 SkASSERT((uint8_t)b == b); | 156 SkASSERT(b <= 32767); |
157 unsigned prod = SkMulS16(a, b) + 128; | 157 unsigned prod = SkMulS16(a, b) + 128; |
158 return (prod + (prod >> 8)) >> 8; | 158 return (prod + (prod >> 8)) >> 8; |
159 } | 159 } |
160 | 160 |
161 #endif | 161 #endif |
OLD | NEW |