xref: /aosp_15_r20/external/skia/gm/srgb.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColorFilter.h"
11 #include "include/core/SkPaint.h"
12 #include "include/core/SkRefCnt.h"
13 #include "tools/DecodeUtils.h"
14 #include "tools/Resources.h"
15 
16 DEF_SIMPLE_GM(srgb_colorfilter, canvas, 512, 256*3) {
17     auto img = ToolUtils::GetResourceAsImage("images/mandrill_256.png");
18 
19     const float array[] = {
20         1, 0, 0, 0, 0,
21         0, 1, 0, 0, 0,
22         0, 0, 1, 0, 0,
23         -1, 0, 0, 1, 0,
24     };
25     auto cf0 = SkColorFilters::Matrix(array);
26     auto cf1 = SkColorFilters::LinearToSRGBGamma();
27     auto cf2 = SkColorFilters::SRGBToLinearGamma();
28 
29     SkSamplingOptions sampling;
30     SkPaint p;
31     p.setColorFilter(cf0);
32     canvas->drawImage(img, 0, 0);
33     canvas->drawImage(img, 256, 0, sampling, &p);
34 
35     p.setColorFilter(cf1);
36     canvas->drawImage(img, 0, 256, sampling, &p);
37     p.setColorFilter(cf1->makeComposed(cf0));
38     canvas->drawImage(img, 256, 256, sampling, &p);
39 
40     p.setColorFilter(cf2);
41     canvas->drawImage(img, 0, 512, sampling, &p);
42     p.setColorFilter(cf2->makeComposed(cf0));
43     canvas->drawImage(img, 256, 512, sampling, &p);
44 }
45