aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/mipmap.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-06-10 11:41:47 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-10 11:41:47 -0700
commit6644d9353f3f0c09914385fd762e073f98d54205 (patch)
tree617f3b1d2ca2b06cc34decfb44c4c975ba903ca5 /gm/mipmap.cpp
parent7049396b65660907af5292d899053280430d929a (diff)
respect srgb gamma when building mips
Proposed policy: - If the target is *legacy* (e.g. L32/PMColor) ignore gamma - If the target is S32/F16 respect gamma BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2029373004 Review-Url: https://codereview.chromium.org/2029373004
Diffstat (limited to 'gm/mipmap.cpp')
-rw-r--r--gm/mipmap.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/gm/mipmap.cpp b/gm/mipmap.cpp
index ae73a8de9d..45b4d15126 100644
--- a/gm/mipmap.cpp
+++ b/gm/mipmap.cpp
@@ -47,3 +47,52 @@ DEF_SIMPLE_GM(mipmap, canvas, 400, 200) {
}
canvas->drawImage(img.get(), 20, 20, nullptr);
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+// create a circle image computed raw, so we can wrap it as a linear or srgb image
+static sk_sp<SkImage> make(sk_sp<SkColorSpace> cs) {
+ const int N = 100;
+ SkImageInfo info = SkImageInfo::Make(N, N, kN32_SkColorType, kPremul_SkAlphaType, cs);
+ SkBitmap bm;
+ bm.allocPixels(info);
+
+ for (int y = 0; y < N; ++y) {
+ for (int x = 0; x < N; ++x) {
+ *bm.getAddr32(x, y) = (x ^ y) & 1 ? 0xFFFFFFFF : 0xFF000000;
+ }
+ }
+ bm.setImmutable();
+ return SkImage::MakeFromBitmap(bm);
+}
+
+static void show_mips(SkCanvas* canvas, SkImage* img) {
+ SkPaint paint;
+ paint.setFilterQuality(kMedium_SkFilterQuality);
+
+ SkRect dst = SkRect::MakeIWH(img->width(), img->height());
+ while (dst.width() > 5) {
+ canvas->drawImageRect(img, dst, &paint);
+ dst.offset(dst.width() + 10, 0);
+ dst.fRight = dst.fLeft + SkScalarHalf(dst.width());
+ dst.fBottom = dst.fTop + SkScalarHalf(dst.height());
+ }
+}
+
+/*
+ * Ensure that in L32 drawing mode, both images/mips look the same as each other, and
+ * their mips are darker than the original (since the mips should ignore the gamma in L32).
+ *
+ * Ensure that in S32 drawing mode, all images/mips look the same, and look correct (i.e.
+ * the mip levels match the original in brightness).
+ */
+DEF_SIMPLE_GM(mipmap_srgb, canvas, 260, 230) {
+ sk_sp<SkImage> limg = make(nullptr);
+ sk_sp<SkImage> simg = make(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named));
+
+ canvas->translate(10, 10);
+ show_mips(canvas, limg.get());
+ canvas->translate(0, limg->height() + 10.0f);
+ show_mips(canvas, simg.get());
+}
+