Mike Reed | fa78ece | 2017-07-25 17:11:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gm.h" |
| 9 | |
| 10 | #include "SkPM4fPriv.h" |
| 11 | #include "SkToSRGBColorFilter.h" |
| 12 | |
Mike Klein | c47f223 | 2017-07-25 13:48:51 -0400 | [diff] [blame] | 13 | DEF_SIMPLE_GM_BG(tosrgb_colorfilter, canvas, 130, 130, SK_ColorBLACK) { |
Mike Reed | fa78ece | 2017-07-25 17:11:10 +0000 | [diff] [blame] | 14 | // Src bitmap with some colors that we're going to interpret as being in a few different spaces |
| 15 | SkBitmap bmp; |
| 16 | bmp.allocN32Pixels(3, 2); |
| 17 | SkPMColor* pixels = reinterpret_cast<SkPMColor*>(bmp.getPixels()); |
| 18 | pixels[0] = SkPackARGB32(0xFF, 0xA0, 0x00, 0x00); |
| 19 | pixels[1] = SkPackARGB32(0xFF, 0x00, 0xA0, 0x00); |
| 20 | pixels[2] = SkPackARGB32(0xFF, 0x00, 0x00, 0xA0); |
| 21 | pixels[3] = SkPackARGB32(0xFF, 0x00, 0xA0, 0xA0); |
| 22 | pixels[4] = SkPackARGB32(0xFF, 0xA0, 0x00, 0xA0); |
| 23 | pixels[5] = SkPackARGB32(0xFF, 0xA0, 0xA0, 0x00); |
| 24 | |
| 25 | // Reference image |
| 26 | canvas->drawBitmapRect(bmp, SkRect::MakeXYWH(10, 10, 50, 50), nullptr); |
| 27 | |
| 28 | auto srgb = SkColorSpace::MakeSRGB(); |
| 29 | auto rec2020 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, |
| 30 | SkColorSpace::kRec2020_Gamut); |
| 31 | |
| 32 | // NarrowGamut RGB (an artifically smaller than sRGB gamut) |
| 33 | SkColorSpacePrimaries narrowPrimaries = { |
| 34 | 0.54f, 0.33f, // Rx, Ry |
| 35 | 0.33f, 0.50f, // Gx, Gy |
| 36 | 0.25f, 0.20f, // Bx, By |
| 37 | 0.3127f, 0.3290f, // Wx, Wy |
| 38 | }; |
| 39 | SkMatrix44 narrowGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor); |
| 40 | narrowPrimaries.toXYZD50(&narrowGamutRGBMatrix); |
| 41 | auto narrow = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, |
| 42 | narrowGamutRGBMatrix); |
| 43 | |
| 44 | SkPaint paint; |
| 45 | |
| 46 | // Transforming sRGB -> sRGB should do nothing. Top two squares should look identical. |
| 47 | paint.setColorFilter(SkToSRGBColorFilter::Make(srgb)); |
| 48 | canvas->drawBitmapRect(bmp, SkRect::MakeXYWH(70, 10, 50, 50), &paint); |
| 49 | |
| 50 | // Rec2020 -> sRGB should produce more vivid colors. |
| 51 | paint.setColorFilter(SkToSRGBColorFilter::Make(rec2020)); |
| 52 | canvas->drawBitmapRect(bmp, SkRect::MakeXYWH(10, 70, 50, 50), &paint); |
| 53 | |
| 54 | // Narrow -> sRGB should produce more muted colors. |
| 55 | paint.setColorFilter(SkToSRGBColorFilter::Make(narrow)); |
| 56 | canvas->drawBitmapRect(bmp, SkRect::MakeXYWH(70, 70, 50, 50), &paint); |
| 57 | } |