Modify SkBitmap::extractSubset() to respect opaqueness
authorskyostil@google.com <skyostil@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 13 Jan 2012 14:56:51 +0000 (14:56 +0000)
committerskyostil@google.com <skyostil@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 13 Jan 2012 14:56:51 +0000 (14:56 +0000)
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

src/core/SkBitmap.cpp
tests/BitmapCopyTest.cpp

index 2b3e7c4..fe32845 100644 (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
index b8d16bf..c3c6f12 100644 (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