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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 128 } |
129 c += expand4444(*p); | 129 c += expand4444(*p); |
130 if (x < srcBM.width() - 1) { | 130 if (x < srcBM.width() - 1) { |
131 p += 1; | 131 p += 1; |
132 } | 132 } |
133 c += expand4444(*p); | 133 c += expand4444(*p); |
134 | 134 |
135 *((uint16_t*)dst) = (uint16_t)collaps4444(c >> 2); | 135 *((uint16_t*)dst) = (uint16_t)collaps4444(c >> 2); |
136 } | 136 } |
137 | 137 |
| 138 static void downsample8_nocheck(void* dst, int, int, const void* srcPtr, const S
kBitmap& srcBM) { |
| 139 const size_t rb = srcBM.rowBytes(); |
| 140 const uint8_t* p = static_cast<const uint8_t*>(srcPtr); |
| 141 *(uint8_t*)dst = (p[0] + p[1] + p[rb] + p[rb + 1]) >> 2; |
| 142 } |
| 143 |
| 144 static void downsample8_check(void* dst, int x, int y, const void* srcPtr, const
SkBitmap& srcBM) { |
| 145 const uint8_t* p = static_cast<const uint8_t*>(srcPtr); |
| 146 const uint8_t* baseP = p; |
| 147 |
| 148 x <<= 1; |
| 149 y <<= 1; |
| 150 SkASSERT(srcBM.getAddr8(x, y) == p); |
| 151 |
| 152 unsigned c = *p; |
| 153 if (x < srcBM.width() - 1) { |
| 154 p += 1; |
| 155 } |
| 156 c += *p; |
| 157 |
| 158 p = baseP; |
| 159 if (y < srcBM.height() - 1) { |
| 160 p += srcBM.rowBytes(); |
| 161 } |
| 162 c += *p; |
| 163 if (x < srcBM.width() - 1) { |
| 164 p += 1; |
| 165 } |
| 166 c += *p; |
| 167 |
| 168 *(uint8_t*)dst = c >> 2; |
| 169 } |
| 170 |
138 size_t SkMipMap::AllocLevelsSize(int levelCount, size_t pixelSize) { | 171 size_t SkMipMap::AllocLevelsSize(int levelCount, size_t pixelSize) { |
139 if (levelCount < 0) { | 172 if (levelCount < 0) { |
140 return 0; | 173 return 0; |
141 } | 174 } |
142 int64_t size = sk_64_mul(levelCount + 1, sizeof(Level)) + pixelSize; | 175 int64_t size = sk_64_mul(levelCount + 1, sizeof(Level)) + pixelSize; |
143 if (!sk_64_isS32(size)) { | 176 if (!sk_64_isS32(size)) { |
144 return 0; | 177 return 0; |
145 } | 178 } |
146 return sk_64_asS32(size); | 179 return sk_64_asS32(size); |
147 } | 180 } |
(...skipping 12 matching lines...) Expand all Loading... |
160 proc_nocheck = downsample32_nocheck; | 193 proc_nocheck = downsample32_nocheck; |
161 break; | 194 break; |
162 case kRGB_565_SkColorType: | 195 case kRGB_565_SkColorType: |
163 proc_check = downsample16; | 196 proc_check = downsample16; |
164 proc_nocheck = proc_check; | 197 proc_nocheck = proc_check; |
165 break; | 198 break; |
166 case kARGB_4444_SkColorType: | 199 case kARGB_4444_SkColorType: |
167 proc_check = downsample4444; | 200 proc_check = downsample4444; |
168 proc_nocheck = proc_check; | 201 proc_nocheck = proc_check; |
169 break; | 202 break; |
| 203 case kAlpha_8_SkColorType: |
| 204 case kGray_8_SkColorType: |
| 205 proc_check = downsample8_check; |
| 206 proc_nocheck = downsample8_nocheck; |
| 207 break; |
170 default: | 208 default: |
171 return NULL; // don't build mipmaps for any other colortypes (yet) | 209 return NULL; // don't build mipmaps for any other colortypes (yet) |
172 } | 210 } |
173 | 211 |
174 SkAutoLockPixels alp(src); | 212 SkAutoLockPixels alp(src); |
175 if (!src.readyToDraw()) { | 213 if (!src.readyToDraw()) { |
176 return NULL; | 214 return NULL; |
177 } | 215 } |
178 | 216 |
179 // whip through our loop to compute the exact size needed | 217 // whip through our loop to compute the exact size needed |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 } | 343 } |
306 | 344 |
307 if (level > fCount) { | 345 if (level > fCount) { |
308 level = fCount; | 346 level = fCount; |
309 } | 347 } |
310 if (levelPtr) { | 348 if (levelPtr) { |
311 *levelPtr = fLevels[level - 1]; | 349 *levelPtr = fLevels[level - 1]; |
312 } | 350 } |
313 return true; | 351 return true; |
314 } | 352 } |
OLD | NEW |