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

Side by Side Diff: src/core/SkMipMap.cpp

Issue 729373004: Watch out for SkFixed overflow in SkMipMap.cpp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nan Created 6 years 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
« no previous file with comments | « include/core/SkTypes.h ('k') | no next file » | 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 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkMipMap.h" 8 #include "SkMipMap.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 SkASSERT(addr == baseAddr + size); 221 SkASSERT(addr == baseAddr + size);
222 222
223 return mipmap; 223 return mipmap;
224 } 224 }
225 225
226 /////////////////////////////////////////////////////////////////////////////// 226 ///////////////////////////////////////////////////////////////////////////////
227 227
228 //static int gCounter; 228 //static int gCounter;
229 229
230 static SkFixed compute_level(SkScalar scale) { 230 static SkFixed compute_level(SkScalar scale) {
231 SkFixed s = SkAbs32(SkScalarToFixed(SkScalarInvert(scale))); 231 SkScalar inv = SkScalarAbs(SkScalarInvert(scale));
232 if (inv > 32767) { // Watch out for SkFixed overflow.
233 inv = 32767;
234 }
235 SkFixed s = SkScalarToFixed(inv);
232 236
233 if (s < SK_Fixed1) { 237 if (s < SK_Fixed1) {
234 return 0; 238 return 0;
235 } 239 }
236 int clz = SkCLZ(s); 240 int clz = SkCLZ(s);
237 SkASSERT(clz >= 1 && clz <= 15); 241 SkASSERT(clz >= 1 && clz <= 15);
238 return SkIntToFixed(15 - clz) + ((unsigned)(s << (clz + 1)) >> 16); 242 return SkIntToFixed(15 - clz) + ((unsigned)(s << (clz + 1)) >> 16);
239 } 243 }
240 244
241 bool SkMipMap::extractLevel(SkScalar scale, Level* levelPtr) const { 245 bool SkMipMap::extractLevel(SkScalar scale, Level* levelPtr) const {
(...skipping 12 matching lines...) Expand all
254 } 258 }
255 259
256 if (level > fCount) { 260 if (level > fCount) {
257 level = fCount; 261 level = fCount;
258 } 262 }
259 if (levelPtr) { 263 if (levelPtr) {
260 *levelPtr = fLevels[level - 1]; 264 *levelPtr = fLevels[level - 1];
261 } 265 }
262 return true; 266 return true;
263 } 267 }
OLDNEW
« no previous file with comments | « include/core/SkTypes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698