fix copyTo to only copy the minimum pixels per row, and to lock the src before
trying to access its colorTable. Update unittest for copyTo. Add sample for
using a mask to clip a layer.
git-svn-id: http://skia.googlecode.com/svn/trunk@168 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp
index f904859..95b49ce 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -1,5 +1,6 @@
#include "Test.h"
#include "SkBitmap.h"
+#include "SkRect.h"
static const char* boolStr(bool value) {
return value ? "true" : "false";
@@ -82,6 +83,30 @@
REPORTER_ASSERT(reporter, !memcmp(srcP, dstP,
src.getSize()));
}
+ // test extractSubset
+ {
+ SkBitmap subset;
+ SkIRect r;
+ r.set(1, 1, 2, 2);
+ if (src.extractSubset(&subset, r)) {
+ REPORTER_ASSERT(reporter, subset.width() == 1);
+ REPORTER_ASSERT(reporter, subset.height() == 1);
+
+ SkBitmap copy;
+ REPORTER_ASSERT(reporter,
+ subset.copyTo(©, subset.config()));
+ REPORTER_ASSERT(reporter, copy.width() == 1);
+ REPORTER_ASSERT(reporter, copy.height() == 1);
+ REPORTER_ASSERT(reporter, copy.rowBytes() <= 4);
+
+ SkAutoLockPixels alp0(subset);
+ SkAutoLockPixels alp1(copy);
+ // they should both have, or both not-have, a colortable
+ bool hasCT = subset.getColorTable() != NULL;
+ REPORTER_ASSERT(reporter,
+ (copy.getColorTable() != NULL) == hasCT);
+ }
+ }
} else {
// dst should be unchanged from its initial state
REPORTER_ASSERT(reporter, dst.config() == SkBitmap::kNo_Config);