OLD | NEW |
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 102 } |
103 c += expand4444(*p); | 103 c += expand4444(*p); |
104 if (x < src.width() - 1) { | 104 if (x < src.width() - 1) { |
105 p += 1; | 105 p += 1; |
106 } | 106 } |
107 c += expand4444(*p); | 107 c += expand4444(*p); |
108 | 108 |
109 *dst->getAddr16(x >> 1, y >> 1) = (uint16_t)collaps4444(c >> 2); | 109 *dst->getAddr16(x >> 1, y >> 1) = (uint16_t)collaps4444(c >> 2); |
110 } | 110 } |
111 | 111 |
| 112 static bool isPos32Bits(const Sk64& value) { |
| 113 return !value.isNeg() && value.is32(); |
| 114 } |
| 115 |
112 SkMipMap::Level* SkMipMap::AllocLevels(int levelCount, size_t pixelSize) { | 116 SkMipMap::Level* SkMipMap::AllocLevels(int levelCount, size_t pixelSize) { |
113 if (levelCount < 0) { | 117 if (levelCount < 0) { |
114 return NULL; | 118 return NULL; |
115 } | 119 } |
116 int64_t size = sk_64_mul(levelCount + 1, sizeof(Level)) + pixelSize; | 120 Sk64 size; |
117 if (!sk_64_isS32(size)) { | 121 size.setMul(levelCount + 1, sizeof(Level)); |
| 122 size.add(SkToS32(pixelSize)); |
| 123 if (!isPos32Bits(size)) { |
118 return NULL; | 124 return NULL; |
119 } | 125 } |
120 return (Level*)sk_malloc_throw(sk_64_asS32(size)); | 126 return (Level*)sk_malloc_throw(size.get32()); |
121 } | 127 } |
122 | 128 |
123 SkMipMap* SkMipMap::Build(const SkBitmap& src) { | 129 SkMipMap* SkMipMap::Build(const SkBitmap& src) { |
124 void (*proc)(SkBitmap* dst, int x, int y, const SkBitmap& src); | 130 void (*proc)(SkBitmap* dst, int x, int y, const SkBitmap& src); |
125 | 131 |
126 const SkBitmap::Config config = src.config(); | 132 const SkBitmap::Config config = src.config(); |
127 switch (config) { | 133 switch (config) { |
128 case SkBitmap::kARGB_8888_Config: | 134 case SkBitmap::kARGB_8888_Config: |
129 proc = downsampleby2_proc32; | 135 proc = downsampleby2_proc32; |
130 break; | 136 break; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 253 } |
248 | 254 |
249 if (level > fCount) { | 255 if (level > fCount) { |
250 level = fCount; | 256 level = fCount; |
251 } | 257 } |
252 if (levelPtr) { | 258 if (levelPtr) { |
253 *levelPtr = fLevels[level - 1]; | 259 *levelPtr = fLevels[level - 1]; |
254 } | 260 } |
255 return true; | 261 return true; |
256 } | 262 } |
OLD | NEW |