From 22f348281a202f79989447cfde45a3834649e89f Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Mon, 28 Nov 2016 17:17:38 -0500 Subject: [PATCH] don't support converting from alpha to non-alpha BUG=skia: Change-Id: Ia06bef6c0bfc03b5ca9f569c07e993da0bbd67c3 Reviewed-on: https://skia-review.googlesource.com/5288 Reviewed-by: Matt Sarett Commit-Queue: Mike Reed --- src/core/SkBitmap.cpp | 9 ++++++--- src/core/SkConfig8888.cpp | 6 ++++++ tests/BitmapCopyTest.cpp | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 7ea49a8..e4097b4 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -707,15 +707,18 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const { /////////////////////////////////////////////////////////////////////////////// -bool SkBitmap::canCopyTo(SkColorType dstColorType) const { +bool SkBitmap::canCopyTo(SkColorType dstCT) const { const SkColorType srcCT = this->colorType(); if (srcCT == kUnknown_SkColorType) { return false; } + if (srcCT == kAlpha_8_SkColorType && dstCT != kAlpha_8_SkColorType) { + return false; // can't convert from alpha to non-alpha + } - bool sameConfigs = (srcCT == dstColorType); - switch (dstColorType) { + bool sameConfigs = (srcCT == dstCT); + switch (dstCT) { case kAlpha_8_SkColorType: case kRGB_565_SkColorType: case kRGBA_8888_SkColorType: diff --git a/src/core/SkConfig8888.cpp b/src/core/SkConfig8888.cpp index 9af3621..3906a9a 100644 --- a/src/core/SkConfig8888.cpp +++ b/src/core/SkConfig8888.cpp @@ -324,6 +324,12 @@ bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t return false; } + if (srcInfo.colorType() == kAlpha_8_SkColorType && + dstInfo.colorType() != kAlpha_8_SkColorType) + { + return false; // can't convert from alpha to non-alpha + } + const int width = srcInfo.width(); const int height = srcInfo.height(); diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp index 639c51a..ab0ec30 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -183,7 +183,7 @@ static void writeCoordPixels(SkBitmap& bm, const Coordinates& coords) { static const Pair gPairs[] = { { kUnknown_SkColorType, "000000" }, - { kAlpha_8_SkColorType, "010101" }, + { kAlpha_8_SkColorType, "010000" }, { kIndex_8_SkColorType, "011111" }, { kRGB_565_SkColorType, "010101" }, { kARGB_4444_SkColorType, "010111" }, -- 2.7.4