Modify SkBitmap::extractSubset() to respect opaqueness

The resulting subset bitmap will always have the same opaqueness flag as the
source bitmap.

BUG=439
Review URL: http://codereview.appspot.com/5534051

git-svn-id: http://skia.googlecode.com/svn/trunk@3036 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
skyostil@google.com 2012-01-13 14:56:51 +00:00
parent 9f169a4b01
commit ce7adb580e
2 changed files with 11 additions and 1 deletions

View File

@ -821,6 +821,7 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const {
SkBitmap dst;
dst.setConfig(this->config(), r.width(), r.height(), this->rowBytes());
dst.setIsOpaque(this->isOpaque());
if (fPixelRef) {
// share the pixelref with a custom offset

View File

@ -308,12 +308,16 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) {
}
// test extractSubset
{
SkBitmap bitmap(src);
SkBitmap subset;
SkIRect r;
r.set(1, 1, 2, 2);
if (src.extractSubset(&subset, r)) {
bitmap.setIsOpaque(true);
if (bitmap.extractSubset(&subset, r)) {
REPORTER_ASSERT(reporter, subset.width() == 1);
REPORTER_ASSERT(reporter, subset.height() == 1);
REPORTER_ASSERT(reporter,
subset.isOpaque() == bitmap.isOpaque());
SkBitmap copy;
REPORTER_ASSERT(reporter,
@ -329,6 +333,11 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter,
(copy.getColorTable() != NULL) == hasCT);
}
bitmap.setIsOpaque(false);
if (bitmap.extractSubset(&subset, r)) {
REPORTER_ASSERT(reporter,
subset.isOpaque() == bitmap.isOpaque());
}
}
} else {
// dst should be unchanged from its initial state