diff options
-rw-r--r-- | bench/BitmapBench.cpp | 2 | ||||
-rw-r--r-- | bench/RepeatTileBench.cpp | 2 | ||||
-rw-r--r-- | include/core/SkColorTable.h | 16 | ||||
-rw-r--r-- | include/core/SkPicture.h | 3 | ||||
-rw-r--r-- | samplecode/SampleDitherBitmap.cpp | 5 | ||||
-rw-r--r-- | src/core/SkColorTable.cpp | 51 | ||||
-rw-r--r-- | src/core/SkReadBuffer.h | 1 | ||||
-rw-r--r-- | src/images/SkImageDecoder_libgif.cpp | 6 | ||||
-rw-r--r-- | src/images/SkImageDecoder_libpng.cpp | 12 | ||||
-rw-r--r-- | src/images/SkImageDecoder_wbmp.cpp | 2 | ||||
-rw-r--r-- | tests/BitmapCopyTest.cpp | 19 |
11 files changed, 44 insertions, 75 deletions
diff --git a/bench/BitmapBench.cpp b/bench/BitmapBench.cpp index e9ba1dcb91..efd6d96684 100644 --- a/bench/BitmapBench.cpp +++ b/bench/BitmapBench.cpp @@ -44,7 +44,7 @@ static void convertToIndex666(const SkBitmap& src, SkBitmap* dst, SkAlphaType aT } } } - SkColorTable* ctable = new SkColorTable(storage, 216, aType); + SkColorTable* ctable = new SkColorTable(storage, 216); dst->allocPixels(SkImageInfo::Make(src.width(), src.height(), kIndex_8_SkColorType, aType), NULL, ctable); ctable->unref(); diff --git a/bench/RepeatTileBench.cpp b/bench/RepeatTileBench.cpp index cf29b6a460..cf147d8c21 100644 --- a/bench/RepeatTileBench.cpp +++ b/bench/RepeatTileBench.cpp @@ -63,7 +63,7 @@ static void convert_to_index666(const SkBitmap& src, SkBitmap* dst) { } } } - SkColorTable* ctable = new SkColorTable(storage, 216, kOpaque_SkAlphaType); + SkColorTable* ctable = new SkColorTable(storage, 216); dst->allocPixels(SkImageInfo::Make(src.width(), src.height(), kIndex_8_SkColorType, kOpaque_SkAlphaType), NULL, ctable); diff --git a/include/core/SkColorTable.h b/include/core/SkColorTable.h index c73b431921..00ef8548f6 100644 --- a/include/core/SkColorTable.h +++ b/include/core/SkColorTable.h @@ -26,16 +26,9 @@ public: /** Makes a deep copy of colors. */ SkColorTable(const SkColorTable& src); - SkColorTable(const SkPMColor colors[], int count, - SkAlphaType alphaType = kPremul_SkAlphaType); + SkColorTable(const SkPMColor colors[], int count); virtual ~SkColorTable(); - SkAlphaType alphaType() const { return (SkAlphaType)fAlphaType; } - - bool isOpaque() const { - return SkAlphaTypeIsOpaque(this->alphaType()); - } - /** Returns the number of colors in the table. */ int count() const { return fCount; } @@ -44,7 +37,7 @@ public: the index is in range (0 <= index < count). */ SkPMColor operator[](int index) const { - SkASSERT(fColors != NULL && (unsigned)index < fCount); + SkASSERT(fColors != NULL && (unsigned)index < (unsigned)fCount); return fColors[index]; } @@ -81,11 +74,12 @@ public: private: SkPMColor* fColors; uint16_t* f16BitCache; - uint16_t fCount; - uint8_t fAlphaType; + int fCount; SkDEBUGCODE(int fColorLockCount;) SkDEBUGCODE(int f16BitCacheLockCount;) + void init(const SkPMColor* colors, int count); + void inval16BitCache(); typedef SkRefCnt INHERITED; diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index af4f1237d2..9da8de9383 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -249,13 +249,14 @@ private: // V33: Serialize only public API of effects. // V34: Add SkTextBlob serialization. // V35: Store SkRect (rather then width & height) in header + // V36: Remove (obsolete) alphatype from SkColorTable // Note: If the picture version needs to be increased then please follow the // steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw // Only SKPs within the min/current picture version range (inclusive) can be read. static const uint32_t MIN_PICTURE_VERSION = 19; - static const uint32_t CURRENT_PICTURE_VERSION = 35; + static const uint32_t CURRENT_PICTURE_VERSION = 36; mutable uint32_t fUniqueID; diff --git a/samplecode/SampleDitherBitmap.cpp b/samplecode/SampleDitherBitmap.cpp index e05d074f3b..d825c71a50 100644 --- a/samplecode/SampleDitherBitmap.cpp +++ b/samplecode/SampleDitherBitmap.cpp @@ -57,11 +57,10 @@ static SkBitmap make_bitmap() { for (int i = 0; i < 256; i++) { c[i] = SkPackARGB32(0xFF, i, 0, 0); } - SkColorTable* ctable = new SkColorTable(c, 256, kOpaque_SkAlphaType); + SkColorTable* ctable = new SkColorTable(c, 256); SkBitmap bm; - bm.allocPixels(SkImageInfo::Make(256, 32, kIndex_8_SkColorType, - kPremul_SkAlphaType), + bm.allocPixels(SkImageInfo::Make(256, 32, kIndex_8_SkColorType, kPremul_SkAlphaType), NULL, ctable); ctable->unref(); diff --git a/src/core/SkColorTable.cpp b/src/core/SkColorTable.cpp index 2607f9ae0f..f2eab61483 100644 --- a/src/core/SkColorTable.cpp +++ b/src/core/SkColorTable.cpp @@ -13,44 +13,36 @@ #include "SkStream.h" #include "SkTemplates.h" -// 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() { - f16BitCache = NULL; - fAlphaType = src.fAlphaType; - int count = src.count(); - fCount = SkToU16(count); - fColors = reinterpret_cast<SkPMColor*>( - sk_malloc_throw(count * sizeof(SkPMColor))); - memcpy(fColors, src.fColors, count * sizeof(SkPMColor)); +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)); + SkDEBUGCODE(fColorLockCount = 0;) SkDEBUGCODE(f16BitCacheLockCount = 0;) } -SkColorTable::SkColorTable(const SkPMColor colors[], int count, SkAlphaType at) - : f16BitCache(NULL), fAlphaType(SkToU8(at)) -{ - SkASSERT(0 == count || colors); +// 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) { count = 0; } else if (count > 256) { count = 256; } - - fCount = SkToU16(count); - fColors = reinterpret_cast<SkPMColor*>( - sk_malloc_throw(count * sizeof(SkPMColor))); - - memcpy(fColors, colors, count * sizeof(SkPMColor)); - - SkDEBUGCODE(fColorLockCount = 0;) - SkDEBUGCODE(f16BitCacheLockCount = 0;) + this->init(colors, count); } -SkColorTable::~SkColorTable() -{ +SkColorTable::~SkColorTable() { SkASSERT(fColorLockCount == 0); SkASSERT(f16BitCacheLockCount == 0); @@ -73,9 +65,6 @@ static inline void build_16bitcache(uint16_t dst[], const SkPMColor src[], } const uint16_t* SkColorTable::lock16BitCache() { - // Assert that we're opaque, since our 16-bit cache will be sort of useless - // if there is alpha (which we're throwing away) - SkASSERT(this->isOpaque()); if (NULL == f16BitCache) { f16BitCache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t)); build_16bitcache(f16BitCache, fColors, fCount); @@ -92,7 +81,10 @@ SkColorTable::SkColorTable(SkReadBuffer& buffer) { SkDEBUGCODE(fColorLockCount = 0;) SkDEBUGCODE(f16BitCacheLockCount = 0;) - fAlphaType = SkToU8(buffer.readUInt()); + if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { + /*fAlphaType = */buffer.readUInt(); + } + fCount = buffer.getArrayCount(); size_t allocSize = fCount * sizeof(SkPMColor); SkDEBUGCODE(bool success = false;) @@ -110,6 +102,5 @@ SkColorTable::SkColorTable(SkReadBuffer& buffer) { } void SkColorTable::writeToBuffer(SkWriteBuffer& buffer) const { - buffer.writeUInt(fAlphaType); buffer.writeColorArray(fColors, fCount); } diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h index a5b983095b..b073847528 100644 --- a/src/core/SkReadBuffer.h +++ b/src/core/SkReadBuffer.h @@ -49,6 +49,7 @@ public: kImageFilterUniqueID_Version = 31, kRemoveAndroidPaintOpts_Version = 32, kFlattenCreateProc_Version = 33, + kRemoveColorTableAlpha_Version = 36, }; /** diff --git a/src/images/SkImageDecoder_libgif.cpp b/src/images/SkImageDecoder_libgif.cpp index 745f4e11f1..81071c9515 100644 --- a/src/images/SkImageDecoder_libgif.cpp +++ b/src/images/SkImageDecoder_libgif.cpp @@ -332,7 +332,6 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, Mode mode) { // Declare colorPtr here for scope. SkPMColor colorPtr[256]; // storage for worst-case const ColorMapObject* cmap = find_colormap(gif); - SkAlphaType alphaType = kOpaque_SkAlphaType; if (cmap != NULL) { SkASSERT(cmap->ColorCount == (1 << (cmap->BitsPerPixel))); colorCount = cmap->ColorCount; @@ -355,16 +354,13 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, Mode mode) { transpIndex = find_transpIndex(temp_save, colorCount); if (transpIndex >= 0) { colorPtr[transpIndex] = SK_ColorTRANSPARENT; // ram in a transparent SkPMColor - alphaType = kPremul_SkAlphaType; fillIndex = transpIndex; } else if (fillIndex >= colorCount) { // gif->SBackGroundColor should be less than colorCount. fillIndex = 0; // If not, fix it. } - SkAutoTUnref<SkColorTable> ctable(SkNEW_ARGS(SkColorTable, - (colorPtr, colorCount, - alphaType))); + SkAutoTUnref<SkColorTable> ctable(SkNEW_ARGS(SkColorTable, (colorPtr, colorCount))); if (!this->allocPixelRef(bm, ctable)) { return error_return(*bm, "allocPixelRef"); } diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp index dd1d1c8a98..7911a293f6 100644 --- a/src/images/SkImageDecoder_libpng.cpp +++ b/src/images/SkImageDecoder_libpng.cpp @@ -709,17 +709,7 @@ bool SkPNGImageDecoder::decodePalette(png_structp png_ptr, png_infop info_ptr, *colorPtr = colorPtr[-1]; } - SkAlphaType alphaType = kOpaque_SkAlphaType; - if (reallyHasAlpha) { - if (this->getRequireUnpremultipliedColors()) { - alphaType = kUnpremul_SkAlphaType; - } else { - alphaType = kPremul_SkAlphaType; - } - } - - *colorTablep = SkNEW_ARGS(SkColorTable, - (colorStorage, colorCount, alphaType)); + *colorTablep = SkNEW_ARGS(SkColorTable, (colorStorage, colorCount)); *reallyHasAlphap = reallyHasAlpha; return true; } diff --git a/src/images/SkImageDecoder_wbmp.cpp b/src/images/SkImageDecoder_wbmp.cpp index ddb7c3df02..0bf138940d 100644 --- a/src/images/SkImageDecoder_wbmp.cpp +++ b/src/images/SkImageDecoder_wbmp.cpp @@ -119,7 +119,7 @@ bool SkWBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap, } const SkPMColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; - SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2, kOpaque_SkAlphaType)); + SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2)); SkAutoUnref aur(ct); if (!this->allocPixelRef(decodedBitmap, ct)) { diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp index 3923846226..eb7c663254 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -61,11 +61,11 @@ static void init_src(const SkBitmap& bitmap) { } } -static SkColorTable* init_ctable(SkAlphaType alphaType) { +static SkColorTable* init_ctable() { static const SkColor colors[] = { SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE }; - return new SkColorTable(colors, SK_ARRAY_COUNT(colors), alphaType); + return new SkColorTable(colors, SK_ARRAY_COUNT(colors)); } struct Pair { @@ -196,19 +196,16 @@ static const int H = 33; static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul, SkColorType ct) { - SkColorTable* ctOpaque = NULL; - SkColorTable* ctPremul = NULL; + SkColorTable* ctable = NULL; if (kIndex_8_SkColorType == ct) { - ctOpaque = init_ctable(kOpaque_SkAlphaType); - ctPremul = init_ctable(kPremul_SkAlphaType); + ctable = init_ctable(); } srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType), - NULL, ctOpaque); + NULL, ctable); srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType), - NULL, ctPremul); - SkSafeUnref(ctOpaque); - SkSafeUnref(ctPremul); + NULL, ctable); + SkSafeUnref(ctable); init_src(*srcOpaque); init_src(*srcPremul); } @@ -384,7 +381,7 @@ DEF_TEST(BitmapCopy, reporter) { SkBitmap src, subset; SkColorTable* ct = NULL; if (kIndex_8_SkColorType == src.colorType()) { - ct = init_ctable(kPremul_SkAlphaType); + ct = init_ctable(); } int localSubW; |