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

Unified Diff: tests/ImageTest.cpp

Issue 2179123005: add unittests for roundtripping premul (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use 0 != Created 4 years, 5 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageTest.cpp
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 34660d84de9497f1b8c13210a791334079242d5f..dd40f3608939c8d7b100908c2cd08e5d5742d433 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -938,3 +938,57 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredTextureImage, reporter, ctxInfo) {
}
}
#endif
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+static void make_all_premul(SkBitmap* bm) {
+ bm->allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType));
+ for (int a = 0; a < 256; ++a) {
+ for (int r = 0; r < 256; ++r) {
+ // make all valid premul combinations
+ int c = SkTMin(a, r);
+ *bm->getAddr32(a, r) = SkPackARGB32(a, c, c, c);
+ }
+ }
+}
+
+static bool equal(const SkBitmap& a, const SkBitmap& b) {
+ SkASSERT(a.width() == b.width());
+ SkASSERT(a.height() == b.height());
+ for (int y = 0; y < a.height(); ++y) {
+ if (0 != memcmp(a.getAddr32(0, y), b.getAddr32(0, y), a.width() * sizeof(SkPMColor))) {
+ return false;
+ }
+ }
+ return true;
+}
+
+DEF_TEST(image_roundtrip_encode, reporter) {
+ SkBitmap bm0;
+ make_all_premul(&bm0);
+
+ auto img0 = SkImage::MakeFromBitmap(bm0);
+ sk_sp<SkData> data(img0->encode(SkImageEncoder::kPNG_Type, 100));
+ auto img1 = SkImage::MakeFromEncoded(data);
+
+ SkBitmap bm1;
+ bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType));
+ img1->readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0);
+
+ REPORTER_ASSERT(reporter, equal(bm0, bm1));
+}
+
+DEF_TEST(image_roundtrip_premul, reporter) {
+ SkBitmap bm0;
+ make_all_premul(&bm0);
+
+ SkBitmap bm1;
+ bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType));
+ bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0);
+
+ SkBitmap bm2;
+ bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType));
+ bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0);
+
+ REPORTER_ASSERT(reporter, equal(bm0, bm2));
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698