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

Unified Diff: tests/SkImageTest.cpp

Issue 951483002: Make SkNewImageFromBitmap take pixel ref origin into account (Closed) Base URL: https://skia.googlesource.com/skia.git@skimage-filters-01-deferred-canvas-writepixels-skip
Patch Set: Created 5 years, 10 months 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/SkImage_Raster.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/SkImageTest.cpp
diff --git a/tests/SkImageTest.cpp b/tests/SkImageTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..80ba776af106ae85b827332b97f253f8195ce078
--- /dev/null
+++ b/tests/SkImageTest.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBitmapDevice.h"
+#include "SkImagePriv.h"
+#include "Test.h"
+
+static const int gWidth = 20;
+static const int gHeight = 20;
+
+// Tests that SkNewImageFromBitmap obeys pixelref origin.
+DEF_TEST(SkImageFromBitmap_extractSubset, reporter) {
+ SkAutoTUnref<SkImage> image;
+ {
+ SkBitmap srcBitmap;
+ srcBitmap.allocN32Pixels(gWidth, gHeight);
+ srcBitmap.eraseColor(SK_ColorRED);
+ SkBitmapDevice dev(srcBitmap);
+ SkCanvas canvas(&dev);
+ SkIRect r = SkIRect::MakeXYWH(5, 5, gWidth - 5, gWidth - 5);
+ SkPaint p;
+ p.setColor(SK_ColorGREEN);
+ canvas.drawIRect(r, p);
+ SkBitmap dstBitmap;
+ srcBitmap.extractSubset(&dstBitmap, r);
+ image.reset(SkNewImageFromBitmap(dstBitmap, true, NULL));
+ }
+
+ SkBitmap tgt;
+ tgt.allocN32Pixels(gWidth, gHeight);
+ SkBitmapDevice dev(tgt);
+ SkCanvas canvas(&dev);
+ canvas.clear(SK_ColorTRANSPARENT);
+ canvas.drawImage(image, 0, 0, NULL);
+
+ uint32_t pixel = 0;
+ SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
+ canvas.readPixels(info, &pixel, 4, 0, 0);
+ REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
+ canvas.readPixels(info, &pixel, 4, gWidth - 6, gWidth - 6);
+ REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
+
+ canvas.readPixels(info, &pixel, 4, gWidth - 5, gWidth - 5);
+ REPORTER_ASSERT(reporter, pixel == SK_ColorTRANSPARENT);
+}
« no previous file with comments | « src/image/SkImage_Raster.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698