OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 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 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 const size_t ramRB = info.minRowBytes(); | 1231 const size_t ramRB = info.minRowBytes(); |
1232 const int height = SkMax32(info.height(), 0); | 1232 const int height = SkMax32(info.height(), 0); |
1233 const uint64_t snugSize = sk_64_mul(snugRB, height); | 1233 const uint64_t snugSize = sk_64_mul(snugRB, height); |
1234 const uint64_t ramSize = sk_64_mul(ramRB, height); | 1234 const uint64_t ramSize = sk_64_mul(ramRB, height); |
1235 static const uint64_t max_size_t = (size_t)(-1); | 1235 static const uint64_t max_size_t = (size_t)(-1); |
1236 if (!buffer->validate((snugSize <= ramSize) && (ramSize <= max_size_t))) { | 1236 if (!buffer->validate((snugSize <= ramSize) && (ramSize <= max_size_t))) { |
1237 return false; | 1237 return false; |
1238 } | 1238 } |
1239 | 1239 |
1240 SkAutoDataUnref data(SkData::NewUninitialized(SkToSizeT(ramSize))); | 1240 SkAutoDataUnref data(SkData::NewUninitialized(SkToSizeT(ramSize))); |
1241 char* dst = (char*)data->writable_data(); | 1241 unsigned char* dst = (unsigned char*)data->writable_data(); |
1242 buffer->readByteArray(dst, SkToSizeT(snugSize)); | 1242 buffer->readByteArray(dst, SkToSizeT(snugSize)); |
1243 | 1243 |
1244 if (snugSize != ramSize) { | 1244 if (snugSize != ramSize) { |
1245 const char* srcRow = dst + snugRB * (height - 1); | 1245 const unsigned char* srcRow = dst + snugRB * (height - 1); |
1246 char* dstRow = dst + ramRB * (height - 1); | 1246 unsigned char* dstRow = dst + ramRB * (height - 1); |
1247 for (int y = height - 1; y >= 1; --y) { | 1247 for (int y = height - 1; y >= 1; --y) { |
1248 memmove(dstRow, srcRow, snugRB); | 1248 memmove(dstRow, srcRow, snugRB); |
1249 srcRow -= snugRB; | 1249 srcRow -= snugRB; |
1250 dstRow -= ramRB; | 1250 dstRow -= ramRB; |
1251 } | 1251 } |
1252 SkASSERT(srcRow == dstRow); // first row does not need to be moved | 1252 SkASSERT(srcRow == dstRow); // first row does not need to be moved |
1253 } | 1253 } |
1254 | 1254 |
1255 SkAutoTUnref<SkColorTable> ctable; | 1255 SkAutoTUnref<SkColorTable> ctable; |
1256 if (buffer->readBool()) { | 1256 if (buffer->readBool()) { |
1257 ctable.reset(SkNEW_ARGS(SkColorTable, (*buffer))); | 1257 ctable.reset(SkNEW_ARGS(SkColorTable, (*buffer))); |
| 1258 |
| 1259 unsigned char maxIndex = ctable->count() ? ctable->count()-1 : 0; |
| 1260 for (uint64_t i = 0; i < ramSize; ++i) { |
| 1261 dst[i] = SkTMin(dst[i], maxIndex); |
| 1262 } |
1258 } | 1263 } |
1259 | 1264 |
1260 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewWithData(info, info.minRowB
ytes(), | 1265 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewWithData(info, info.minRowB
ytes(), |
1261 ctable.get(), data
.get())); | 1266 ctable.get(), data
.get())); |
1262 if (!pr.get()) { | 1267 if (!pr.get()) { |
1263 return false; | 1268 return false; |
1264 } | 1269 } |
1265 bitmap->setInfo(pr->info()); | 1270 bitmap->setInfo(pr->info()); |
1266 bitmap->setPixelRef(pr, 0, 0); | 1271 bitmap->setPixelRef(pr, 0, 0); |
1267 return true; | 1272 return true; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 /////////////////////////////////////////////////////////////////////////////// | 1396 /////////////////////////////////////////////////////////////////////////////// |
1392 | 1397 |
1393 #ifdef SK_DEBUG | 1398 #ifdef SK_DEBUG |
1394 void SkImageInfo::validate() const { | 1399 void SkImageInfo::validate() const { |
1395 SkASSERT(fWidth >= 0); | 1400 SkASSERT(fWidth >= 0); |
1396 SkASSERT(fHeight >= 0); | 1401 SkASSERT(fHeight >= 0); |
1397 SkASSERT(SkColorTypeIsValid(fColorType)); | 1402 SkASSERT(SkColorTypeIsValid(fColorType)); |
1398 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1403 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1399 } | 1404 } |
1400 #endif | 1405 #endif |
OLD | NEW |