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/Resources.h" 14 15 DEF_SIMPLE_GM(srgb_colorfilter, canvas, 512, 256*3) { 16 auto img = GetResourceAsImage("images/mandrill_256.png"); 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 = SkColorFilters::Matrix(array); 25 auto cf1 = SkColorFilters::LinearToSRGBGamma(); 26 auto cf2 = SkColorFilters::SRGBToLinearGamma(); 27 28 SkSamplingOptions sampling; 29 SkPaint p; 30 p.setColorFilter(cf0); 31 canvas->drawImage(img, 0, 0); 32 canvas->drawImage(img, 256, 0, sampling, &p); 33 34 p.setColorFilter(cf1); 35 canvas->drawImage(img, 0, 256, sampling, &p); 36 p.setColorFilter(cf1->makeComposed(cf0)); 37 canvas->drawImage(img, 256, 256, sampling, &p); 38 39 p.setColorFilter(cf2); 40 canvas->drawImage(img, 0, 512, sampling, &p); 41 p.setColorFilter(cf2->makeComposed(cf0)); 42 canvas->drawImage(img, 256, 512, sampling, &p); 43 } 44