Mike Reed | bdf6c62 | 2017-07-05 22:40:23 -0400 | [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 | #include "sk_tool_utils.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkImage.h" |
| 12 | #include "Resources.h" |
| 13 | #include "SkColorFilter.h" |
| 14 | |
| 15 | DEF_SIMPLE_GM(srgb_colorfilter, canvas, 512, 256*3) { |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 16 | auto img = GetResourceAsImage("images/mandrill_256.png"); |
Mike Reed | bdf6c62 | 2017-07-05 22:40:23 -0400 | [diff] [blame] | 17 | |
| 18 | const float array[] = { |
| 19 | 1, 0, 0, 0, 0, |
| 20 | 0, 1, 0, 0, 0, |
| 21 | 0, 0, 1, 0, 0, |
| 22 | -1, 0, 0, 1, 0, |
| 23 | }; |
| 24 | auto cf0 = SkColorFilter::MakeMatrixFilterRowMajor255(array); |
| 25 | auto cf1 = SkColorFilter::MakeLinearToSRGBGamma(); |
| 26 | auto cf2 = SkColorFilter::MakeSRGBToLinearGamma(); |
| 27 | |
| 28 | SkPaint p; |
| 29 | p.setColorFilter(cf0); |
| 30 | canvas->drawImage(img, 0, 0, nullptr); |
| 31 | canvas->drawImage(img, 256, 0, &p); |
| 32 | |
| 33 | p.setColorFilter(cf1); |
| 34 | canvas->drawImage(img, 0, 256, &p); |
Mike Reed | 19d7bd6 | 2018-02-19 14:10:57 -0500 | [diff] [blame] | 35 | p.setColorFilter(cf1->makeComposed(cf0)); |
Mike Reed | bdf6c62 | 2017-07-05 22:40:23 -0400 | [diff] [blame] | 36 | canvas->drawImage(img, 256, 256, &p); |
| 37 | |
| 38 | p.setColorFilter(cf2); |
| 39 | canvas->drawImage(img, 0, 512, &p); |
Mike Reed | 19d7bd6 | 2018-02-19 14:10:57 -0500 | [diff] [blame] | 40 | p.setColorFilter(cf2->makeComposed(cf0)); |
Mike Reed | bdf6c62 | 2017-07-05 22:40:23 -0400 | [diff] [blame] | 41 | canvas->drawImage(img, 256, 512, &p); |
| 42 | } |