blob: 4b704b7a29b20bd35c81b894d8d48f9cbf4a69f8 [file] [log] [blame]
Mike Reedbdf6c622017-07-05 22:40:23 -04001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
10#include "include/core/SkColorFilter.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040011#include "include/core/SkPaint.h"
12#include "include/core/SkRefCnt.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "tools/Resources.h"
Mike Reedbdf6c622017-07-05 22:40:23 -040014
15DEF_SIMPLE_GM(srgb_colorfilter, canvas, 512, 256*3) {
Hal Canaryc465d132017-12-08 10:21:31 -050016 auto img = GetResourceAsImage("images/mandrill_256.png");
Mike Reedbdf6c622017-07-05 22:40:23 -040017
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 };
Mike Reede869a1e2019-04-30 12:18:54 -040024 auto cf0 = SkColorFilters::Matrix(array);
Mike Reedb286bc22019-04-08 16:23:20 -040025 auto cf1 = SkColorFilters::LinearToSRGBGamma();
26 auto cf2 = SkColorFilters::SRGBToLinearGamma();
Mike Reedbdf6c622017-07-05 22:40:23 -040027
Mike Reed07c5f522021-01-23 12:23:23 -050028 SkSamplingOptions sampling;
Mike Reedbdf6c622017-07-05 22:40:23 -040029 SkPaint p;
30 p.setColorFilter(cf0);
Mike Reed07c5f522021-01-23 12:23:23 -050031 canvas->drawImage(img, 0, 0);
32 canvas->drawImage(img, 256, 0, sampling, &p);
Mike Reedbdf6c622017-07-05 22:40:23 -040033
34 p.setColorFilter(cf1);
Mike Reed07c5f522021-01-23 12:23:23 -050035 canvas->drawImage(img, 0, 256, sampling, &p);
Mike Reed19d7bd62018-02-19 14:10:57 -050036 p.setColorFilter(cf1->makeComposed(cf0));
Mike Reed07c5f522021-01-23 12:23:23 -050037 canvas->drawImage(img, 256, 256, sampling, &p);
Mike Reedbdf6c622017-07-05 22:40:23 -040038
39 p.setColorFilter(cf2);
Mike Reed07c5f522021-01-23 12:23:23 -050040 canvas->drawImage(img, 0, 512, sampling, &p);
Mike Reed19d7bd62018-02-19 14:10:57 -050041 p.setColorFilter(cf2->makeComposed(cf0));
Mike Reed07c5f522021-01-23 12:23:23 -050042 canvas->drawImage(img, 256, 512, sampling, &p);
Mike Reedbdf6c622017-07-05 22:40:23 -040043}