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

Unified Diff: src/core/SkBitmap.cpp

Issue 1165493003: Cap color index values (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmap.cpp
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index cb4f1c6057b230229bddbd202dac2f48b18acaf2..6200a6d6ba4749e0e4b9abb432acc9e78fa740ea 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -1238,12 +1238,12 @@ bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) {
}
SkAutoDataUnref data(SkData::NewUninitialized(SkToSizeT(ramSize)));
- char* dst = (char*)data->writable_data();
+ unsigned char* dst = (unsigned char*)data->writable_data();
buffer->readByteArray(dst, SkToSizeT(snugSize));
if (snugSize != ramSize) {
- const char* srcRow = dst + snugRB * (height - 1);
- char* dstRow = dst + ramRB * (height - 1);
+ const unsigned char* srcRow = dst + snugRB * (height - 1);
+ unsigned char* dstRow = dst + ramRB * (height - 1);
for (int y = height - 1; y >= 1; --y) {
memmove(dstRow, srcRow, snugRB);
srcRow -= snugRB;
@@ -1255,6 +1255,11 @@ bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) {
SkAutoTUnref<SkColorTable> ctable;
if (buffer->readBool()) {
ctable.reset(SkNEW_ARGS(SkColorTable, (*buffer)));
+
+ unsigned char maxIndex = ctable->count() ? ctable->count()-1 : 0;
+ for (uint64_t i = 0; i < ramSize; ++i) {
+ dst[i] = SkTMin(dst[i], maxIndex);
+ }
}
SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewWithData(info, info.minRowBytes(),
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698