Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Unified Diff: tests/SurfaceTest.cpp

Issue 793723002: add readPixels to SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use better name on test Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkSurface.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/SurfaceTest.cpp
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index c77c25186c32453fd712139fa214f3235fb87b9f..a25018f4cdfed1ac75c500669835d8caf43775b7 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -118,6 +118,63 @@ static SkImage* createImage(ImageType imageType, GrContext* context, SkColor col
return NULL;
}
+static void set_pixels(SkPMColor pixels[], int count, SkPMColor color) {
+ sk_memset32(pixels, color, count);
+}
+static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected) {
+ for (int i = 0; i < count; ++i) {
+ if (pixels[i] != expected) {
+ return false;
+ }
+ }
+ return true;
+}
+
+static void test_image_readpixels(skiatest::Reporter* reporter, SkImage* image,
+ SkPMColor expected) {
+ const SkPMColor notExpected = ~expected;
+
+ const int w = 2, h = 2;
+ const size_t rowBytes = w * sizeof(SkPMColor);
+ SkPMColor pixels[w*h];
+
+ SkImageInfo info;
+
+ info = SkImageInfo::MakeUnknown(w, h);
+ REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, 0, 0));
+
+ // out-of-bounds should fail
+ info = SkImageInfo::MakeN32Premul(w, h);
+ REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, -w, 0));
+ REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, 0, -h));
+ REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, image->width(), 0));
+ REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, 0, image->height()));
+
+ // top-left should succeed
+ set_pixels(pixels, w*h, notExpected);
+ REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, 0, 0));
+ REPORTER_ASSERT(reporter, has_pixels(pixels, w*h, expected));
+
+ // bottom-right should succeed
+ set_pixels(pixels, w*h, notExpected);
+ REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes,
+ image->width() - w, image->height() - h));
+ REPORTER_ASSERT(reporter, has_pixels(pixels, w*h, expected));
+
+ // partial top-left should succeed
+ set_pixels(pixels, w*h, notExpected);
+ REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, -1, -1));
+ REPORTER_ASSERT(reporter, pixels[3] == expected);
+ REPORTER_ASSERT(reporter, has_pixels(pixels, w*h - 1, notExpected));
+
+ // partial bottom-right should succeed
+ set_pixels(pixels, w*h, notExpected);
+ REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes,
+ image->width() - 1, image->height() - 1));
+ REPORTER_ASSERT(reporter, pixels[0] == expected);
+ REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected));
+}
+
static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* factory) {
static const struct {
ImageType fType;
@@ -159,6 +216,8 @@ static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto
REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes);
REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
}
+
+ test_image_readpixels(reporter, image, pmcolor);
}
}
« no previous file with comments | « src/image/SkSurface.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698