diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 7a0130eb7a..10d1c251bd 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -121,7 +121,12 @@ public: /** Return true iff drawing this bitmap has no effect. */ bool drawsNothing() const { - return this->colorType() == kIndex_8_SkColorType || this->empty() || this->isNull(); +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE + if (this->colorType() == kIndex_8_SkColorType) { + return true; + } +#endif + return this->empty() || this->isNull(); } /** Return the number of bytes between subsequent rows of the bitmap. */ @@ -424,8 +429,12 @@ public: non-null colortable. Returns true if all of the above are met. */ bool readyToDraw() const { - return this->getPixels() != NULL && - (this->colorType() != kIndex_8_SkColorType || this->getColorTable()); +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE + if (this->colorType() == kIndex_8_SkColorType) { + return false; + } +#endif + return this->getPixels() != NULL; } /** Return the bitmap's colortable, if it uses one (i.e. colorType is @@ -725,6 +734,7 @@ inline uint8_t* SkBitmap::getAddr8(int x, int y) const { return (uint8_t*)fPixels + y * fRowBytes + x; } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { SkASSERT(fPixels); SkASSERT(kIndex_8_SkColorType == this->colorType()); @@ -732,5 +742,6 @@ inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { SkASSERT(this->getColorTable()); return (*this->getColorTable())[*((const uint8_t*)fPixels + y * fRowBytes + x)]; } +#endif #endif diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index 4a8c2860fc..551eb86988 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h @@ -72,7 +72,9 @@ enum SkColorType { kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE kIndex_8_SkColorType, +#endif kGray_8_SkColorType, kRGBA_F16_SkColorType, @@ -95,7 +97,9 @@ static int SkColorTypeBytesPerPixel(SkColorType ct) { 2, // ARGB_4444 4, // RGBA_8888 4, // BGRA_8888 +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE 1, // kIndex_8 +#endif 1, // kGray_8 8, // kRGBA_F16 }; @@ -114,7 +118,9 @@ static int SkColorTypeShiftPerPixel(SkColorType ct) { 1, // ARGB_4444 2, // RGBA_8888 2, // BGRA_8888 +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE 0, // kIndex_8 +#endif 0, // kGray_8 3, // kRGBA_F16 }; diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h index 1e79bba225..be821ec470 100644 --- a/include/core/SkPixmap.h +++ b/include/core/SkPixmap.h @@ -30,9 +30,12 @@ public: SkColorTable* ctable = NULL) : fPixels(addr), fCTable(ctable), fRowBytes(rowBytes), fInfo(info) { +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE if (kIndex_8_SkColorType == info.colorType()) { SkASSERT(ctable); - } else { + } else +#endif + { SkASSERT(NULL == ctable); } } diff --git a/src/android/SkBitmapRegionCodec.cpp b/src/android/SkBitmapRegionCodec.cpp index c4e1ea124c..52774bcfa0 100644 --- a/src/android/SkBitmapRegionCodec.cpp +++ b/src/android/SkBitmapRegionCodec.cpp @@ -57,7 +57,9 @@ bool SkBitmapRegionCodec::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocat SkImageInfo decodeInfo = SkImageInfo::Make(scaledSize.width(), scaledSize.height(), dstColorType, dstAlphaType, dstColorSpace); +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE SkASSERT(dstColorType != kIndex_8_SkColorType); +#endif // Initialize the destination bitmap int scaledOutX = 0; diff --git a/src/codec/SkAndroidCodec.cpp b/src/codec/SkAndroidCodec.cpp index 6c9152b08a..8f3146ed16 100644 --- a/src/codec/SkAndroidCodec.cpp +++ b/src/codec/SkAndroidCodec.cpp @@ -17,6 +17,7 @@ static bool is_valid_sample_size(int sampleSize) { return sampleSize > 0; } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE /** * Loads the gamut as a set of three points (triangle). */ @@ -59,6 +60,7 @@ static bool is_wide_gamut(const SkColorSpace* colorSpace) { return false; } +#endif SkAndroidCodec::SkAndroidCodec(SkCodec* codec) : fInfo(codec->getInfo()) @@ -110,7 +112,9 @@ SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorTyp case kARGB_4444_SkColorType: return kN32_SkColorType; case kN32_SkColorType: +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: +#endif break; case kAlpha_8_SkColorType: // Fall through to kGray_8. Before kGray_8_SkColorType existed, @@ -148,6 +152,7 @@ sk_sp SkAndroidCodec::computeOutputColorSpace(SkColorType outputCo switch (outputColorType) { case kRGBA_8888_SkColorType: case kBGRA_8888_SkColorType: +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: { // If |prefColorSpace| is supported, choose it. SkColorSpaceTransferFn fn; @@ -169,6 +174,7 @@ sk_sp SkAndroidCodec::computeOutputColorSpace(SkColorType outputCo return SkColorSpace::MakeSRGB(); } +#endif case kRGBA_F16_SkColorType: // Note that |prefColorSpace| is ignored, F16 is always linear sRGB. return SkColorSpace::MakeSRGBLinear(); diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp index 57f7fb865e..79cb253bfe 100644 --- a/src/codec/SkCodecImageGenerator.cpp +++ b/src/codec/SkCodecImageGenerator.cpp @@ -23,10 +23,11 @@ static SkImageInfo adjust_info(const SkImageInfo& info) { newInfo = newInfo.makeAlphaType(kPremul_SkAlphaType); } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE if (kIndex_8_SkColorType == info.colorType()) { newInfo = newInfo.makeColorType(kN32_SkColorType); } - +#endif return newInfo; } diff --git a/src/codec/SkSampler.cpp b/src/codec/SkSampler.cpp index 244aa3b873..0dbe320827 100644 --- a/src/codec/SkSampler.cpp +++ b/src/codec/SkSampler.cpp @@ -57,9 +57,11 @@ void SkSampler::Fill(const SkImageInfo& info, void* dst, size_t rowBytes, } break; } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: // On an index destination color type, always assume the input is an index. // Fall through +#endif case kGray_8_SkColorType: // If the destination is kGray, the caller passes in an 8-bit color. // We will not assert that the high bits of colorOrIndex must be zeroed. diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp index 31fc063aec..c19dd05b65 100644 --- a/src/codec/SkSwizzler.cpp +++ b/src/codec/SkSwizzler.cpp @@ -104,6 +104,7 @@ static void swizzle_bit_to_grayscale( #undef GRAYSCALE_BLACK #undef GRAYSCALE_WHITE +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE // same as swizzle_bit_to_grayscale and swizzle_bit_to_n32 except for value assigned to dst[x] static void swizzle_bit_to_index( void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, @@ -124,6 +125,7 @@ static void swizzle_bit_to_index( dst[x] = ((currByte >> (7-bitIndex)) & 1); } } +#endif // same as swizzle_bit_to_grayscale and swizzle_bit_to_index except for value assigned to dst[x] static void swizzle_bit_to_n32( @@ -203,6 +205,7 @@ static void swizzle_bit_to_f16( // kIndex1, kIndex2, kIndex4 +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE static void swizzle_small_index_to_index( void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { @@ -223,6 +226,7 @@ static void swizzle_small_index_to_index( dst[x] = index; } } +#endif static void swizzle_small_index_to_565( void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, @@ -887,9 +891,11 @@ SkSwizzler* SkSwizzler::CreateSwizzler(const SkEncodedInfo& encodedInfo, case kBGRA_8888_SkColorType: proc = &swizzle_bit_to_n32; break; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: proc = &swizzle_bit_to_index; break; +#endif case kRGB_565_SkColorType: proc = &swizzle_bit_to_565; break; @@ -970,9 +976,11 @@ SkSwizzler* SkSwizzler::CreateSwizzler(const SkEncodedInfo& encodedInfo, case kRGB_565_SkColorType: proc = &swizzle_small_index_to_565; break; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: proc = &swizzle_small_index_to_index; break; +#endif default: return nullptr; } @@ -990,10 +998,12 @@ SkSwizzler* SkSwizzler::CreateSwizzler(const SkEncodedInfo& encodedInfo, case kRGB_565_SkColorType: proc = &swizzle_index_to_565; break; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: proc = &sample1; fastProc = © break; +#endif default: return nullptr; } diff --git a/src/codec/SkWbmpCodec.cpp b/src/codec/SkWbmpCodec.cpp index fe9a29133e..aab0a41b14 100644 --- a/src/codec/SkWbmpCodec.cpp +++ b/src/codec/SkWbmpCodec.cpp @@ -25,7 +25,9 @@ static inline bool valid_color_type(const SkImageInfo& dstInfo) { switch (dstInfo.colorType()) { case kRGBA_8888_SkColorType: case kBGRA_8888_SkColorType: +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: +#endif case kGray_8_SkColorType: case kRGB_565_SkColorType: return true; diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp index e8e409a486..096d50529a 100644 --- a/src/codec/SkWebpCodec.cpp +++ b/src/codec/SkWebpCodec.cpp @@ -311,7 +311,9 @@ static void pick_memory_stages(SkColorType ct, SkRasterPipeline::StockStage* loa case kUnknown_SkColorType: case kAlpha_8_SkColorType: case kARGB_4444_SkColorType: +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: +#endif case kGray_8_SkColorType: SkASSERT(false); break; diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index e88fa5ec57..8f8d70f525 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -242,9 +242,11 @@ bool SkBitmap::tryAllocPixels(Allocator* allocator, SkColorTable* ctable) { /////////////////////////////////////////////////////////////////////////////// bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) { +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE if (kIndex_8_SkColorType == requestedInfo.colorType()) { return reset_return_false(this); } +#endif if (!this->setInfo(requestedInfo, rowBytes)) { return reset_return_false(this); } @@ -268,9 +270,11 @@ bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, sk_sp ctable, uint32_t allocFlags) { +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE if (kIndex_8_SkColorType == requestedInfo.colorType() && nullptr == ctable) { return reset_return_false(this); } +#endif if (!this->setInfo(requestedInfo)) { return reset_return_false(this); } @@ -428,7 +432,9 @@ void* SkBitmap::getAddr(int x, int y) const { base += x << 1; break; case kAlpha_8_SkColorType: +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: +#endif case kGray_8_SkColorType: base += x; break; @@ -449,7 +455,9 @@ void SkBitmap::erase(SkColor c, const SkIRect& area) const { switch (fInfo.colorType()) { case kUnknown_SkColorType: +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: +#endif // TODO: can we ASSERT that we never get here? return; // can't erase. Should we bzero so the memory is not uninitialized? default: @@ -651,11 +659,14 @@ static void write_raw_pixels(SkWriteBuffer* buffer, const SkPixmap& pmap) { } buffer->writeByteArray(storage.get(), size); +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE const SkColorTable* ct = pmap.ctable(); if (kIndex_8_SkColorType == info.colorType() && ct) { buffer->writeBool(true); ct->writeToBuffer(*buffer); - } else { + } else +#endif + { buffer->writeBool(false); } } diff --git a/src/core/SkBlitter_Sprite.cpp b/src/core/SkBlitter_Sprite.cpp index 99b185a1ad..ff7d466066 100644 --- a/src/core/SkBlitter_Sprite.cpp +++ b/src/core/SkBlitter_Sprite.cpp @@ -105,8 +105,12 @@ public: {} static bool Supports(const SkPixmap& src) { +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE // We'd need to add a load_i8 stage. return src.colorType() != kIndex_8_SkColorType; +#else + return true; +#endif } void setup(const SkPixmap& dst, int left, int top, const SkPaint& paint) override { diff --git a/src/core/SkConvertPixels.cpp b/src/core/SkConvertPixels.cpp index 7859972188..2f4c889d1b 100644 --- a/src/core/SkConvertPixels.cpp +++ b/src/core/SkConvertPixels.cpp @@ -243,6 +243,7 @@ static void convert_to_alpha8(uint8_t* dst, size_t dstRB, const SkImageInfo& src } break; } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: { SkASSERT(ctable); const uint32_t* table = ctable->readColors(); @@ -256,6 +257,7 @@ static void convert_to_alpha8(uint8_t* dst, size_t dstRB, const SkImageInfo& src } break; } +#endif case kRGBA_F16_SkColorType: { auto src64 = (const uint64_t*) src; for (int y = 0; y < srcInfo.height(); y++) { @@ -428,6 +430,7 @@ void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, return; } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE // Fast Path 4: Index 8 sources. if (kIndex_8_SkColorType == srcInfo.colorType()) { SkASSERT(ctable); @@ -435,6 +438,7 @@ void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, ctable, behavior); return; } +#endif // Fast Path 5: Alpha 8 dsts. if (kAlpha_8_SkColorType == dstInfo.colorType()) { diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp index ab7667426e..7ce944be58 100644 --- a/src/core/SkImageGenerator.cpp +++ b/src/core/SkImageGenerator.cpp @@ -16,9 +16,14 @@ SkImageGenerator::SkImageGenerator(const SkImageInfo& info, uint32_t uniqueID) bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options* opts) { - if (kUnknown_SkColorType == info.colorType() || kIndex_8_SkColorType == info.colorType()) { + if (kUnknown_SkColorType == info.colorType()) { return false; } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE + if (kIndex_8_SkColorType == info.colorType()) { + return false; + } +#endif if (nullptr == pixels) { return false; } diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp index 5d0710dc1f..667b2321a2 100644 --- a/src/core/SkImageInfo.cpp +++ b/src/core/SkImageInfo.cpp @@ -9,6 +9,66 @@ #include "SkReadBuffer.h" #include "SkWriteBuffer.h" +// These values must be constant over revisions, though they can be renamed to reflect if/when +// they are deprecated. +enum Stored_SkColorType { + kUnknown_Stored_SkColorType = 0, + kAlpha_8_Stored_SkColorType = 1, + kRGB_565_Stored_SkColorType = 2, + kARGB_4444_Stored_SkColorType = 3, + kRGBA_8888_Stored_SkColorType = 4, + kBGRA_8888_Stored_SkColorType = 5, + kIndex_8_Stored_SkColorType_DEPRECATED = 6, + kGray_8_Stored_SkColorType = 7, + kRGBA_F16_Stored_SkColorType = 8, + + kLast_Stored_SkColorType = kRGBA_F16_Stored_SkColorType, +}; + +// Index with Stored_SkColorType +const SkColorType gStoredToLive[] = { + kUnknown_SkColorType, + kAlpha_8_SkColorType, + kRGB_565_SkColorType, + kARGB_4444_SkColorType, + kRGBA_8888_SkColorType, + kBGRA_8888_SkColorType, + kUnknown_SkColorType, // was kIndex_8 + kGray_8_SkColorType, + kRGBA_F16_SkColorType, +}; + +// Index with SkColorType +const Stored_SkColorType gLiveToStored[] = { + kUnknown_Stored_SkColorType, + kAlpha_8_Stored_SkColorType, + kRGB_565_Stored_SkColorType, + kARGB_4444_Stored_SkColorType, + kRGBA_8888_Stored_SkColorType, + kBGRA_8888_Stored_SkColorType, +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE + kIndex_8_Stored_SkColorType_DEPRECATED, +#endif + kGray_8_Stored_SkColorType, + kRGBA_F16_Stored_SkColorType, +}; + +static uint8_t live_to_stored(unsigned ct) { + static_assert(SK_ARRAY_COUNT(gLiveToStored) == (kLastEnum_SkColorType + 1), ""); + SkASSERT(ct < SK_ARRAY_COUNT(gLiveToStored)); + + return gLiveToStored[ct]; +} + +static SkColorType stored_to_live(unsigned stored) { + static_assert(SK_ARRAY_COUNT(gStoredToLive) == (kLast_Stored_SkColorType + 1), ""); + SkASSERT(stored < SK_ARRAY_COUNT(gStoredToLive)); + + return gStoredToLive[stored]; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + static bool alpha_type_is_valid(SkAlphaType alphaType) { return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType); } @@ -30,7 +90,7 @@ void SkImageInfo::unflatten(SkReadBuffer& buffer) { fHeight = buffer.read32(); uint32_t packed = buffer.read32(); - fColorType = (SkColorType)((packed >> 0) & kColorTypeMask); + fColorType = stored_to_live((SkColorType)((packed >> 0) & kColorTypeMask)); fAlphaType = (SkAlphaType)((packed >> 8) & kAlphaTypeMask); buffer.validate(alpha_type_is_valid(fAlphaType) && color_type_is_valid(fColorType)); @@ -44,7 +104,7 @@ void SkImageInfo::flatten(SkWriteBuffer& buffer) const { SkASSERT(0 == (fAlphaType & ~kAlphaTypeMask)); SkASSERT(0 == (fColorType & ~kColorTypeMask)); - uint32_t packed = (fAlphaType << 8) | fColorType; + uint32_t packed = (fAlphaType << 8) | live_to_stored(fColorType); buffer.write32(packed); if (fColorSpace) { @@ -71,7 +131,9 @@ bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, alphaType = kPremul_SkAlphaType; } // fall-through +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: +#endif case kARGB_4444_SkColorType: case kRGBA_8888_SkColorType: case kBGRA_8888_SkColorType: diff --git a/src/core/SkImageInfoPriv.h b/src/core/SkImageInfoPriv.h index c9b4b6c3d9..43680ad605 100644 --- a/src/core/SkImageInfoPriv.h +++ b/src/core/SkImageInfoPriv.h @@ -111,6 +111,7 @@ static inline bool SkImageInfoValidConversion(const SkImageInfo& dst, const SkIm return false; } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE if (kIndex_8_SkColorType == dst.colorType()) { if (kIndex_8_SkColorType != src.colorType()) { return false; @@ -126,6 +127,7 @@ static inline bool SkImageInfoValidConversion(const SkImageInfo& dst, const SkIm return false; } } +#endif if (kGray_8_SkColorType == dst.colorType()) { if (kGray_8_SkColorType != src.colorType()) { diff --git a/src/core/SkLinearBitmapPipeline.cpp b/src/core/SkLinearBitmapPipeline.cpp index cf2dfdc09f..8c4d06281a 100644 --- a/src/core/SkLinearBitmapPipeline.cpp +++ b/src/core/SkLinearBitmapPipeline.cpp @@ -372,9 +372,11 @@ SkLinearBitmapPipeline::SkLinearBitmapPipeline( // If it is an index 8 color type, the sampler converts to unpremul for better fidelity. SkAlphaType alphaType = srcImageInfo.alphaType(); +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE if (srcPixmap.colorType() == kIndex_8_SkColorType) { alphaType = kUnpremul_SkAlphaType; } +#endif float postAlpha = SkColorGetA(paintColor) * (1.0f / 255.0f); // As the stages are built, the chooser function may skip a stage. For example, with the @@ -596,8 +598,10 @@ SkLinearBitmapPipeline::PixelAccessorInterface* SkLinearBitmapPipeline::choosePi return this->chooseSpecificAccessor(srcPixmap, allocator); case kBGRA_8888_SkColorType: return this->chooseSpecificAccessor(srcPixmap, allocator); +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: return this->chooseSpecificAccessor(srcPixmap, allocator); +#endif case kGray_8_SkColorType: return this->chooseSpecificAccessor(srcPixmap, allocator); case kRGBA_F16_SkColorType: { @@ -632,12 +636,14 @@ SkLinearBitmapPipeline::SampleProcessorInterface* SkLinearBitmapPipeline::choose PixelAccessor, Blender>; return allocator->make(next, srcPixmap); } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: { using Sampler = NearestNeighborSampler< PixelAccessor, Blender>; return allocator->make(next, srcPixmap); } +#endif default: break; } @@ -649,12 +655,14 @@ SkLinearBitmapPipeline::SampleProcessorInterface* SkLinearBitmapPipeline::choose PixelAccessor, Blender>; return allocator->make(next, dimensions, xTile, yTile, srcPixmap); } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: { using Sampler = BilerpSampler< PixelAccessor, Blender>; return allocator->make(next, dimensions, xTile, yTile, srcPixmap); } +#endif default: break; } diff --git a/src/core/SkLinearBitmapPipeline_sample.h b/src/core/SkLinearBitmapPipeline_sample.h index a7f5d7383e..74599786c8 100644 --- a/src/core/SkLinearBitmapPipeline_sample.h +++ b/src/core/SkLinearBitmapPipeline_sample.h @@ -133,6 +133,7 @@ public: } }; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE template class PixelConverter { public: @@ -166,7 +167,8 @@ private: SkAutoMalloc fColorTableStorage{kColorTableSize}; Sk4f* fColorTable; }; - +#endif + template class PixelConverter { public: diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp index cf4fac7929..ce1c6c1a03 100644 --- a/src/core/SkMallocPixelRef.cpp +++ b/src/core/SkMallocPixelRef.cpp @@ -144,9 +144,12 @@ sk_sp SkMallocPixelRef::MakeWithData(const SkImageInfo& info, /////////////////////////////////////////////////////////////////////////////// static sk_sp sanitize(const SkImageInfo& info, sk_sp ctable) { +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE if (kIndex_8_SkColorType == info.colorType()) { SkASSERT(ctable); - } else { + } else +#endif + { ctable.reset(nullptr); } return ctable; diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp index 9646d7c433..cbb40a8fdc 100644 --- a/src/core/SkPixmap.cpp +++ b/src/core/SkPixmap.cpp @@ -272,11 +272,13 @@ SkColor SkPixmap::getColor(int x, int y) const { case kAlpha_8_SkColorType: { return SkColorSetA(0, *this->addr8(x, y)); } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: { SkASSERT(this->ctable()); SkPMColor c = (*this->ctable())[*this->addr8(x, y)]; return toColor(c); } +#endif case kRGB_565_SkColorType: { return SkPixel16ToColor(*this->addr16(x, y)); } @@ -332,6 +334,7 @@ bool SkPixmap::computeIsOpaque() const { } return true; } break; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: { const SkColorTable* ctable = this->ctable(); if (nullptr == ctable) { @@ -344,6 +347,7 @@ bool SkPixmap::computeIsOpaque() const { } return 0xFF == SkGetPackedA32(c); } break; +#endif case kRGB_565_SkColorType: case kGray_8_SkColorType: return true; diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 35cd843d96..b9c63ac980 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -113,6 +113,7 @@ static const SkPixmap* compute_desc(const GrCaps& caps, const SkPixmap& pixmap, pmap = tmpPixmap; // must rebuild desc, since we've forced the info to be N32 *desc = GrImageInfoToSurfaceDesc(pmap->info(), caps); +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE } else if (kIndex_8_SkColorType == pixmap.colorType()) { SkImageInfo info = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap.height()); tmpBitmap->allocPixels(info); @@ -125,6 +126,7 @@ static const SkPixmap* compute_desc(const GrCaps& caps, const SkPixmap& pixmap, pmap = tmpPixmap; // must rebuild desc, since we've forced the info to be N32 *desc = GrImageInfoToSurfaceDesc(pmap->info(), caps); +#endif } return pmap; @@ -339,8 +341,10 @@ GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& c case kBGRA_8888_SkColorType: return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB()) ? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: return kSkia8888_GrPixelConfig; +#endif case kGray_8_SkColorType: return kGray_8_GrPixelConfig; case kRGBA_F16_SkColorType: diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp index 09130a6b76..809ada01f6 100644 --- a/src/image/SkImage_Lazy.cpp +++ b/src/image/SkImage_Lazy.cpp @@ -201,11 +201,13 @@ SkImage_Lazy::Validator::Validator(sk_sp gen, const SkIRect* su fUniqueID = SkNextID::ImageID(); } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE // colortables are poorly to not-at-all supported in our resourcecache, so we // bully them into N32 (the generator will perform the up-sample) if (fInfo.colorType() == kIndex_8_SkColorType) { fInfo = fInfo.makeColorType(kN32_SkColorType); } +#endif } /////////////////////////////////////////////////////////////////////////////// @@ -240,7 +242,9 @@ SkImage_Lazy::SkImage_Lazy(Validator* validator) , fInfo(validator->fInfo) , fOrigin(validator->fOrigin) { SkASSERT(fSharedGenerator); +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE SkASSERT(kIndex_8_SkColorType != fInfo.colorType()); +#endif // We explicit set the legacy format slot, but leave the others uninitialized (via SkOnce) // and only resolove them to IDs as needed (by calling getUniqueID()). fIDRecs[kLegacy_CachedFormat].fOnce([this, validator] { @@ -307,9 +311,11 @@ SkImageCacherator::CachedFormat SkImage_Lazy::chooseCacheFormat(SkColorSpace* ds // TODO: Ask the codec to decode these to something else (at least sRGB 8888)? return kLegacy_CachedFormat; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: SkDEBUGFAIL("Index_8 should have been remapped at construction time."); return kLegacy_CachedFormat; +#endif case kGray_8_SkColorType: // TODO: What do we do with grayscale sources that have strange color spaces attached? diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index c69e5ff7f9..eba6dc69e2 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -57,10 +57,11 @@ public: if (kUnknown_SkColorType == info.colorType()) { return false; } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE if (kIndex_8_SkColorType == info.colorType()) { return false; } - +#endif if (rowBytes < info.minRowBytes()) { return false; } diff --git a/src/images/SkJpegEncoder.cpp b/src/images/SkJpegEncoder.cpp index a0ee398615..ef78b214a3 100644 --- a/src/images/SkJpegEncoder.cpp +++ b/src/images/SkJpegEncoder.cpp @@ -113,6 +113,7 @@ bool SkJpegEncoderMgr::setParams(const SkImageInfo& srcInfo, const SkJpegEncoder jpegColorType = JCS_RGB; numComponents = 3; break; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: if (SkJpegEncoder::AlphaOption::kBlendOnBlack == options.fAlphaOption) { return false; @@ -122,6 +123,7 @@ bool SkJpegEncoderMgr::setParams(const SkImageInfo& srcInfo, const SkJpegEncoder jpegColorType = JCS_RGB; numComponents = 3; break; +#endif case kGray_8_SkColorType: SkASSERT(srcInfo.isOpaque()); jpegColorType = JCS_GRAYSCALE; diff --git a/src/images/SkPngEncoder.cpp b/src/images/SkPngEncoder.cpp index b0c2b23dfb..1e112690df 100644 --- a/src/images/SkPngEncoder.cpp +++ b/src/images/SkPngEncoder.cpp @@ -115,6 +115,7 @@ bool SkPngEncoderMgr::setHeader(const SkImageInfo& srcInfo, const SkPngEncoder:: pngColorType = srcInfo.isOpaque() ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGB_ALPHA; fPngBytesPerPixel = 8; break; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: sigBit.red = 8; sigBit.green = 8; @@ -123,6 +124,7 @@ bool SkPngEncoderMgr::setHeader(const SkImageInfo& srcInfo, const SkPngEncoder:: pngColorType = PNG_COLOR_TYPE_PALETTE; fPngBytesPerPixel = 1; break; +#endif case kGray_8_SkColorType: sigBit.gray = 8; pngColorType = PNG_COLOR_TYPE_GRAY; @@ -250,7 +252,9 @@ static transform_scanline_proc choose_proc(const SkImageInfo& info, SkASSERT(false); return nullptr; } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: +#endif case kGray_8_SkColorType: return transform_scanline_memcpy; case kRGBA_F16_SkColorType: @@ -270,6 +274,7 @@ static transform_scanline_proc choose_proc(const SkImageInfo& info, } } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE /* * Pack palette[] with the corresponding colors, and if the image has alpha, also * pack trans[] and return the number of alphas[] entries written. If the image is @@ -331,6 +336,7 @@ static inline int pack_palette(SkColorTable* ctable, png_color* SK_RESTRICT pale return numWithAlpha; } +#endif bool SkPngEncoderMgr::setPalette(const SkImageInfo& srcInfo, SkColorTable* colorTable, SkTransferFunctionBehavior unpremulBehavior) { @@ -338,6 +344,7 @@ bool SkPngEncoderMgr::setPalette(const SkImageInfo& srcInfo, SkColorTable* color return false; } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE png_color paletteColors[256]; png_byte trans[256]; if (kIndex_8_SkColorType == srcInfo.colorType()) { @@ -351,7 +358,7 @@ bool SkPngEncoderMgr::setPalette(const SkImageInfo& srcInfo, SkColorTable* color png_set_tRNS(fPngPtr, fInfoPtr, trans, numTrans, nullptr); } } - +#endif return true; } diff --git a/src/images/SkWebpEncoder.cpp b/src/images/SkWebpEncoder.cpp index 296d4f4cf0..a5d0ffa838 100644 --- a/src/images/SkWebpEncoder.cpp +++ b/src/images/SkWebpEncoder.cpp @@ -86,6 +86,7 @@ static transform_scanline_proc choose_proc(const SkImageInfo& info, default: return nullptr; } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: switch (info.alphaType()) { case kOpaque_SkAlphaType: @@ -98,6 +99,7 @@ static transform_scanline_proc choose_proc(const SkImageInfo& info, default: return nullptr; } +#endif case kGray_8_SkColorType: return transform_scanline_gray; case kRGBA_F16_SkColorType: @@ -147,6 +149,7 @@ bool SkWebpEncoder::Encode(SkWStream* stream, const SkPixmap& pixmap, const Opti } const SkPMColor* colors = nullptr; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE SkPMColor storage[256]; if (kIndex_8_SkColorType == pixmap.colorType()) { if (!pixmap.ctable()) { @@ -162,6 +165,7 @@ bool SkWebpEncoder::Encode(SkWStream* stream, const SkPixmap& pixmap, const Opti colors = storage; } } +#endif WebPConfig webp_config; if (!WebPConfigPreset(&webp_config, WEBP_PRESET_DEFAULT, opts.fQuality)) { diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp index 68d5272277..47facff8c3 100644 --- a/src/pdf/SkPDFBitmap.cpp +++ b/src/pdf/SkPDFBitmap.cpp @@ -20,13 +20,16 @@ void image_get_ro_pixels(const SkImage* image, SkBitmap* dst) { SkColorSpace* legacyColorSpace = nullptr; if(as_IB(image)->getROPixels(dst, legacyColorSpace) && dst->dimensions() == image->dimensions()) { +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE if (dst->colorType() != kIndex_8_SkColorType) { return; } if (!dst->getColorTable()) { // We can't use an indexed bitmap with no colortable. dst->reset(); - } else { + } else +#endif + { return; } } @@ -163,7 +166,9 @@ static size_t pdf_color_component_count(SkColorType ct) { case kBGRA_8888_SkColorType: return 3; case kAlpha_8_SkColorType: +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: +#endif case kGray_8_SkColorType: return 1; case kUnknown_SkColorType: @@ -234,7 +239,9 @@ static void bitmap_to_pdf_pixels(const SkBitmap& bitmap, SkWStream* out) { fill_stream(out, '\x00', pixel_count(bm)); return; case kGray_8_SkColorType: +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: +#endif SkASSERT(1 == pdf_color_component_count(colorType)); // these two formats need no transformation to serialize. for (int y = 0; y < bm.height(); ++y) { @@ -277,6 +284,7 @@ static void bitmap_alpha_to_a8(const SkBitmap& bitmap, SkWStream* out) { out->write(bm.getAddr8(0, y), bm.width()); } return; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: { SkColorTable* ct = bm.getColorTable(); SkASSERT(ct); @@ -291,6 +299,7 @@ static void bitmap_alpha_to_a8(const SkBitmap& bitmap, SkWStream* out) { } return; } +#endif case kRGB_565_SkColorType: case kGray_8_SkColorType: SkDEBUGFAIL("color type has no alpha"); @@ -304,6 +313,7 @@ static void bitmap_alpha_to_a8(const SkBitmap& bitmap, SkWStream* out) { } } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE static sk_sp make_indexed_color_space( const SkColorTable* table, SkAlphaType alphaType) { @@ -341,6 +351,7 @@ static sk_sp make_indexed_color_space( result->appendString(tableString); return result; } +#endif static void emit_image_xobject(SkWStream* stream, const SkImage* image, @@ -366,11 +377,13 @@ static void emit_image_xobject(SkWStream* stream, pdfDict.insertInt("Height", bitmap.height()); if (alpha) { pdfDict.insertName("ColorSpace", "DeviceGray"); +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE } else if (bitmap.colorType() == kIndex_8_SkColorType) { SkASSERT(1 == pdf_color_component_count(bitmap.colorType())); pdfDict.insertObject("ColorSpace", make_indexed_color_space(bitmap.getColorTable(), bitmap.alphaType())); +#endif } else if (1 == pdf_color_component_count(bitmap.colorType())) { pdfDict.insertName("ColorSpace", "DeviceGray"); } else { diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp index f8f0f88a21..1fc9145b6a 100644 --- a/src/shaders/SkImageShader.cpp +++ b/src/shaders/SkImageShader.cpp @@ -326,7 +326,9 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dstCS, SkA } switch (info.colorType()) { case kAlpha_8_SkColorType: p->append(SkRasterPipeline::gather_a8, gather); break; +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE case kIndex_8_SkColorType: p->append(SkRasterPipeline::gather_i8, gather); break; +#endif case kGray_8_SkColorType: p->append(SkRasterPipeline::gather_g8, gather); break; case kRGB_565_SkColorType: p->append(SkRasterPipeline::gather_565, gather); break; case kARGB_4444_SkColorType: p->append(SkRasterPipeline::gather_4444, gather); break; @@ -390,9 +392,11 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dstCS, SkA p->append(SkRasterPipeline::move_dst_src); } +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE if (info.colorType() == kIndex_8_SkColorType && kN32_SkColorType == kBGRA_8888_SkColorType) { p->append(SkRasterPipeline::swap_rb); } +#endif if (info.colorType() == kAlpha_8_SkColorType) { p->append(SkRasterPipeline::set_rgb, &misc->paint_color); } diff --git a/tools/debugger/SkObjectParser.cpp b/tools/debugger/SkObjectParser.cpp index 227532a6f4..57f7d91c45 100644 --- a/tools/debugger/SkObjectParser.cpp +++ b/tools/debugger/SkObjectParser.cpp @@ -28,7 +28,11 @@ SkString* SkObjectParser::BitmapToString(const SkBitmap& bitmap) { mBitmap->appendS32(bitmap.height()); const char* gColorTypeStrings[] = { - "None", "A8", "565", "4444", "RGBA", "BGRA", "Index8", "G8", "RGBAf16" + "None", "A8", "565", "4444", "RGBA", "BGRA", +#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE + "Index8", +#endif + "G8", "RGBAf16" }; static_assert(kLastEnum_SkColorType + 1 == SK_ARRAY_COUNT(gColorTypeStrings), "colortype names do not match colortype enum");