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

Side by Side Diff: include/core/SkMath.h

Issue 13934010: fix asserts in SkMulDiv255Round, and add test (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | « no previous file | tests/MathTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | tests/MathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698