From 6644d9353f3f0c09914385fd762e073f98d54205 Mon Sep 17 00:00:00 2001 From: reed Date: Fri, 10 Jun 2016 11:41:47 -0700 Subject: 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 --- gm/mipmap.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'gm/mipmap.cpp') 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 make(sk_sp 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 limg = make(nullptr); + sk_sp 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()); +} + -- cgit v1.2.3