diff options
author | Cary Clark <caryclark@skia.org> | 2018-03-19 15:36:44 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-19 21:28:46 +0000 |
commit | 3b68882918e30e87a46b833ed5e6d8b231f638e0 (patch) | |
tree | b56fc6df8c62409cc0d69f65d0c305d736d39715 | |
parent | 19eaf2dbe785a06b76f11c2066c302f0aa89d5d2 (diff) |
remove imageinfo flatten altogether
If SkImageInfo flatten and unflatten aren't referenced outside
of one test, perhaps they can be removed altogether.
R=reed@google.com
Bug: skia:6898
Change-Id: Ia6f82b66d4496a628ad95c386d1865793f3e31a9
Reviewed-on: https://skia-review.googlesource.com/115074
Commit-Queue: Cary Clark <caryclark@skia.org>
Reviewed-by: Mike Reed <reed@google.com>
-rw-r--r-- | include/core/SkImageInfo.h | 3 | ||||
-rw-r--r-- | src/core/SkImageInfo.cpp | 81 | ||||
-rw-r--r-- | tests/ImageIsOpaqueTest.cpp | 52 |
3 files changed, 0 insertions, 136 deletions
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index ece47f5c41..1efb332750 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h @@ -260,9 +260,6 @@ public: return !(*this == other); } - void unflatten(SkReadBuffer& buffer); - void flatten(SkWriteBuffer& buffer) const; - /** * Returns the size (in bytes) of the image buffer that this info needs, given the specified * rowBytes. The rowBytes must be >= this->minRowBytes(). diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp index 0b06334484..f9933736e3 100644 --- a/src/core/SkImageInfo.cpp +++ b/src/core/SkImageInfo.cpp @@ -44,41 +44,6 @@ enum Stored_SkColorType { kRGB_101010x_Stored_SkColorType = 11, }; -static uint8_t live_to_stored(unsigned ct) { - switch (ct) { - case kUnknown_SkColorType: return kUnknown_Stored_SkColorType; - case kAlpha_8_SkColorType: return kAlpha_8_Stored_SkColorType; - case kRGB_565_SkColorType: return kRGB_565_Stored_SkColorType; - case kARGB_4444_SkColorType: return kARGB_4444_Stored_SkColorType; - case kRGBA_8888_SkColorType: return kRGBA_8888_Stored_SkColorType; - case kRGB_888x_SkColorType: return kRGB_888x_Stored_SkColorType; - case kBGRA_8888_SkColorType: return kBGRA_8888_Stored_SkColorType; - case kRGBA_1010102_SkColorType: return kRGBA_1010102_Stored_SkColorType; - case kRGB_101010x_SkColorType: return kRGB_101010x_Stored_SkColorType; - case kGray_8_SkColorType: return kGray_8_Stored_SkColorType; - case kRGBA_F16_SkColorType: return kRGBA_F16_Stored_SkColorType; - } - return kUnknown_Stored_SkColorType; -} - -static SkColorType stored_to_live(unsigned stored) { - switch (stored) { - case kUnknown_Stored_SkColorType: return kUnknown_SkColorType; - case kAlpha_8_Stored_SkColorType: return kAlpha_8_SkColorType; - case kRGB_565_Stored_SkColorType: return kRGB_565_SkColorType; - case kARGB_4444_Stored_SkColorType: return kARGB_4444_SkColorType; - case kRGBA_8888_Stored_SkColorType: return kRGBA_8888_SkColorType; - case kRGB_888x_Stored_SkColorType: return kRGB_888x_SkColorType; - case kBGRA_8888_Stored_SkColorType: return kBGRA_8888_SkColorType; - case kRGBA_1010102_Stored_SkColorType: return kRGBA_1010102_SkColorType; - case kRGB_101010x_Stored_SkColorType: return kRGB_101010x_SkColorType; - case kIndex_8_Stored_SkColorType_DEPRECATED: return kUnknown_SkColorType; - case kGray_8_Stored_SkColorType: return kGray_8_SkColorType; - case kRGBA_F16_Stored_SkColorType: return kRGBA_F16_SkColorType; - } - return kUnknown_SkColorType; -} - bool SkColorTypeIsAlwaysOpaque(SkColorType ct) { switch (ct) { case kRGB_565_SkColorType: @@ -114,57 +79,11 @@ size_t SkImageInfo::computeByteSize(size_t rowBytes) const { return safe ? bytes : SK_MaxSizeT; } -static bool alpha_type_is_valid(SkAlphaType alphaType) { - return (alphaType >= kUnknown_SkAlphaType) && (alphaType <= kLastEnum_SkAlphaType); -} - -static bool color_type_is_valid(SkColorType colorType) { - return (colorType >= kUnknown_SkColorType) && (colorType <= kLastEnum_SkColorType); -} - SkImageInfo SkImageInfo::MakeS32(int width, int height, SkAlphaType at) { return SkImageInfo(width, height, kN32_SkColorType, at, SkColorSpace::MakeSRGB()); } -static const int kColorTypeMask = 0x0F; -static const int kAlphaTypeMask = 0x03; - -void SkImageInfo::unflatten(SkReadBuffer& buffer) { - fWidth = buffer.read32(); - fHeight = buffer.read32(); - - uint32_t packed = buffer.read32(); - fColorType = stored_to_live((packed >> 0) & kColorTypeMask); - fAlphaType = (SkAlphaType)((packed >> 8) & kAlphaTypeMask); - buffer.validate(alpha_type_is_valid(fAlphaType) && color_type_is_valid(fColorType)); - - sk_sp<SkData> data = buffer.readByteArrayAsData(); - fColorSpace = SkColorSpace::Deserialize(data->data(), data->size()); -} - -void SkImageInfo::flatten(SkWriteBuffer& buffer) const { - buffer.write32(fWidth); - buffer.write32(fHeight); - - SkASSERT(0 == (fAlphaType & ~kAlphaTypeMask)); - SkASSERT(0 == (fColorType & ~kColorTypeMask)); - uint32_t packed = (fAlphaType << 8) | live_to_stored(fColorType); - buffer.write32(packed); - - if (fColorSpace) { - sk_sp<SkData> data = fColorSpace->serialize(); - if (data) { - buffer.writeDataAsByteArray(data.get()); - } else { - buffer.writeByteArray(nullptr, 0); - } - } else { - sk_sp<SkData> data = SkData::MakeEmpty(); - buffer.writeDataAsByteArray(data.get()); - } -} - bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, SkAlphaType* canonical) { switch (colorType) { diff --git a/tests/ImageIsOpaqueTest.cpp b/tests/ImageIsOpaqueTest.cpp index 607353c8da..5bec2b0590 100644 --- a/tests/ImageIsOpaqueTest.cpp +++ b/tests/ImageIsOpaqueTest.cpp @@ -18,58 +18,6 @@ #include "SkReadBuffer.h" #include "SkWriteBuffer.h" -static void test_flatten(skiatest::Reporter* reporter, const SkImageInfo& info) { - // Need a safe amount of 4-byte aligned storage. Note that one of the test ICC profiles - // is ~7500 bytes. - const size_t storageBytes = 8000; - SkAutoTMalloc<uint32_t> storage(storageBytes / sizeof(uint32_t)); - SkBinaryWriteBuffer wb(storage.get(), storageBytes); - info.flatten(wb); - SkASSERT(wb.bytesWritten() < storageBytes); - - SkReadBuffer rb(storage.get(), wb.bytesWritten()); - - // pick a noisy byte pattern, so we ensure that unflatten sets all of our fields - SkImageInfo info2 = SkImageInfo::Make(0xB8, 0xB8, (SkColorType) 0xB8, (SkAlphaType) 0xB8); - - info2.unflatten(rb); - REPORTER_ASSERT(reporter, rb.offset() == wb.bytesWritten()); - - REPORTER_ASSERT(reporter, info == info2); -} - -DEF_TEST(ImageInfo_flattening, reporter) { - sk_sp<SkData> data = GetResourceAsData("icc_profiles/HP_ZR30w.icc"); - sk_sp<SkColorSpace> space0 = SkColorSpace::MakeICC(data->data(), data->size()); - data = GetResourceAsData("icc_profiles/HP_Z32x.icc"); - sk_sp<SkColorSpace> space1 = SkColorSpace::MakeICC(data->data(), data->size()); - data = GetResourceAsData("icc_profiles/upperLeft.icc"); - sk_sp<SkColorSpace> space2 = SkColorSpace::MakeICC(data->data(), data->size()); - data = GetResourceAsData("icc_profiles/upperRight.icc"); - sk_sp<SkColorSpace> space3 = SkColorSpace::MakeICC(data->data(), data->size()); - - sk_sp<SkColorSpace> spaces[] = { - nullptr, - SkColorSpace::MakeSRGB(), - space0, - space1, - space2, - space3, - }; - - for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) { - for (int at = 0; at <= kLastEnum_SkAlphaType; ++at) { - for (auto& cs : spaces) { - SkImageInfo info = SkImageInfo::Make(100, 200, - static_cast<SkColorType>(ct), - static_cast<SkAlphaType>(at), - cs); - test_flatten(reporter, info); - } - } - } -} - static void check_isopaque(skiatest::Reporter* reporter, const sk_sp<SkSurface>& surface, bool expectedOpaque) { sk_sp<SkImage> image(surface->makeImageSnapshot()); |