| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkTableColorFilter.h" | 9 #include "SkTableColorFilter.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 1, 2, 2, 3, | 194 1, 2, 2, 3, |
| 195 1, 2, 2, 3, | 195 1, 2, 2, 3, |
| 196 2, 3, 3, 4 | 196 2, 3, 3, 4 |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 #include "SkPackBits.h" | 199 #include "SkPackBits.h" |
| 200 | 200 |
| 201 void SkTable_ColorFilter::flatten(SkWriteBuffer& buffer) const { | 201 void SkTable_ColorFilter::flatten(SkWriteBuffer& buffer) const { |
| 202 uint8_t storage[5*256]; | 202 uint8_t storage[5*256]; |
| 203 int count = gCountNibBits[fFlags & 0xF]; | 203 int count = gCountNibBits[fFlags & 0xF]; |
| 204 size_t size = SkPackBits::Pack8(fStorage, count * 256, storage); | 204 size_t size = SkPackBits::Pack8(fStorage, count * 256, storage, |
| 205 SkASSERT(size <= sizeof(storage)); | 205 sizeof(storage)); |
| 206 | 206 |
| 207 buffer.write32(fFlags); | 207 buffer.write32(fFlags); |
| 208 buffer.writeByteArray(storage, size); | 208 buffer.writeByteArray(storage, size); |
| 209 } | 209 } |
| 210 | 210 |
| 211 SkFlattenable* SkTable_ColorFilter::CreateProc(SkReadBuffer& buffer) { | 211 SkFlattenable* SkTable_ColorFilter::CreateProc(SkReadBuffer& buffer) { |
| 212 const int flags = buffer.read32(); | 212 const int flags = buffer.read32(); |
| 213 const size_t count = gCountNibBits[flags & 0xF]; | 213 const size_t count = gCountNibBits[flags & 0xF]; |
| 214 SkASSERT(count <= 4); | 214 SkASSERT(count <= 4); |
| 215 | 215 |
| 216 uint8_t packedStorage[5*256]; | 216 uint8_t packedStorage[5*256]; |
| 217 size_t packedSize = buffer.getArrayCount(); | 217 size_t packedSize = buffer.getArrayCount(); |
| 218 if (!buffer.validate(packedSize <= sizeof(packedStorage))) { | 218 if (!buffer.validate(packedSize <= sizeof(packedStorage))) { |
| 219 return NULL; | 219 return NULL; |
| 220 } | 220 } |
| 221 if (!buffer.readByteArray(packedStorage, packedSize)) { | 221 if (!buffer.readByteArray(packedStorage, packedSize)) { |
| 222 return NULL; | 222 return NULL; |
| 223 } | 223 } |
| 224 | 224 |
| 225 uint8_t unpackedStorage[4*256]; | 225 uint8_t unpackedStorage[4*256]; |
| 226 size_t unpackedSize = SkPackBits::Unpack8(packedStorage, packedSize, unpacke
dStorage); | 226 size_t unpackedSize = SkPackBits::Unpack8(packedStorage, packedSize, |
| 227 unpackedStorage, sizeof(unpackedStorage)); |
| 227 // now check that we got the size we expected | 228 // now check that we got the size we expected |
| 228 if (!buffer.validate(unpackedSize == count*256)) { | 229 if (!buffer.validate(unpackedSize == count*256)) { |
| 229 return NULL; | 230 return NULL; |
| 230 } | 231 } |
| 231 | 232 |
| 232 const uint8_t* a = NULL; | 233 const uint8_t* a = NULL; |
| 233 const uint8_t* r = NULL; | 234 const uint8_t* r = NULL; |
| 234 const uint8_t* g = NULL; | 235 const uint8_t* g = NULL; |
| 235 const uint8_t* b = NULL; | 236 const uint8_t* b = NULL; |
| 236 const uint8_t* ptr = unpackedStorage; | 237 const uint8_t* ptr = unpackedStorage; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], | 619 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], |
| 619 const uint8_t tableR[256], | 620 const uint8_t tableR[256], |
| 620 const uint8_t tableG[256], | 621 const uint8_t tableG[256], |
| 621 const uint8_t tableB[256]) { | 622 const uint8_t tableB[256]) { |
| 622 return SkNEW_ARGS(SkTable_ColorFilter, (tableA, tableR, tableG, tableB)); | 623 return SkNEW_ARGS(SkTable_ColorFilter, (tableA, tableR, tableG, tableB)); |
| 623 } | 624 } |
| 624 | 625 |
| 625 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) | 626 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) |
| 626 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) | 627 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) |
| 627 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 628 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |