| Index: src/core/SkColorTable.cpp
|
| diff --git a/src/core/SkColorTable.cpp b/src/core/SkColorTable.cpp
|
| index cb9f00cd0edb2ed40c20e975bca7da90bbe527ac..84469c2b06fdc0944f579b60395e80b250d95876 100644
|
| --- a/src/core/SkColorTable.cpp
|
| +++ b/src/core/SkColorTable.cpp
|
| @@ -16,19 +16,12 @@
|
| void SkColorTable::init(const SkPMColor colors[], int count) {
|
| SkASSERT((unsigned)count <= 256);
|
|
|
| - f16BitCache = NULL;
|
| fCount = count;
|
| fColors = reinterpret_cast<SkPMColor*>(sk_malloc_throw(count * sizeof(SkPMColor)));
|
|
|
| memcpy(fColors, colors, count * sizeof(SkPMColor));
|
| }
|
|
|
| -// As copy constructor is hidden in the class hierarchy, we need to call
|
| -// default constructor explicitly to suppress a compiler warning.
|
| -SkColorTable::SkColorTable(const SkColorTable& src) : INHERITED() {
|
| - this->init(src.fColors, src.fCount);
|
| -}
|
| -
|
| SkColorTable::SkColorTable(const SkPMColor colors[], int count) {
|
| SkASSERT(0 == count || colors);
|
| if (count < 0) {
|
| @@ -41,30 +34,34 @@ SkColorTable::SkColorTable(const SkPMColor colors[], int count) {
|
|
|
| SkColorTable::~SkColorTable() {
|
| sk_free(fColors);
|
| - sk_free(f16BitCache);
|
| + // f16BitCache frees itself
|
| }
|
|
|
| #include "SkColorPriv.h"
|
|
|
| -static inline void build_16bitcache(uint16_t dst[], const SkPMColor src[],
|
| - int count) {
|
| - while (--count >= 0) {
|
| - *dst++ = SkPixel32ToPixel16_ToU16(*src++);
|
| +namespace {
|
| +struct Build16BitCache {
|
| + const SkPMColor* fColors;
|
| + int fCount;
|
| +
|
| + uint16_t* operator()() const {
|
| + uint16_t* cache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t));
|
| + for (int i = 0; i < fCount; i++) {
|
| + cache[i] = SkPixel32ToPixel16_ToU16(fColors[i]);
|
| + }
|
| + return cache;
|
| }
|
| -}
|
| +};
|
| +}//namespace
|
|
|
| -const uint16_t* SkColorTable::read16BitCache() {
|
| - if (NULL == f16BitCache) {
|
| - f16BitCache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t));
|
| - build_16bitcache(f16BitCache, fColors, fCount);
|
| - }
|
| - return f16BitCache;
|
| +const uint16_t* SkColorTable::read16BitCache() const {
|
| + const Build16BitCache create = { fColors, fCount };
|
| + return f16BitCache.get(create);
|
| }
|
|
|
| ///////////////////////////////////////////////////////////////////////////////
|
|
|
| SkColorTable::SkColorTable(SkReadBuffer& buffer) {
|
| - f16BitCache = NULL;
|
| if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) {
|
| /*fAlphaType = */buffer.readUInt();
|
| }
|
|
|