Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: gm/gammacolorfilter.cpp

Issue 2190573002: Add SkGammaColorFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: ?? Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gyp/effects.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 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 "SkGammaColorFilter.h"
10 #include "SkImage.h"
11
12 // Fill a width x height block with a horizontal ramp from 0 to 255
13 static void draw_grey_ramp(SkCanvas* canvas, int width, int height, int numSteps ) {
14 int greyPerStep = SkScalarRoundToInt(255.0f / numSteps);
15 int widthPerStep = SkScalarRoundToInt(width / SkIntToScalar(numSteps));
16
17 SkIRect rect = SkIRect::MakeWH(widthPerStep, height);
18
19 SkPaint paint;
20 int grey = 0;
21 int x = 0;
22 for (int i = 0; i < numSteps-1; ++i) {
23 paint.setColor(SkColorSetARGB(255, grey, grey, grey));
24
25 rect.offsetTo(x, 0);
26 canvas->drawRect(SkRect::Make(rect), paint);
27
28 x += widthPerStep;
29 grey += greyPerStep;
30 }
31
32 paint.setColor(SK_ColorWHITE);
33 rect.setLTRB(x, 0, width, height);
34 canvas->drawRect(SkRect::Make(rect), paint);
35 }
36
37 static sk_sp<SkImage> create_grey_ramp(int width, int height, int numSteps) {
38 SkBitmap bm;
39 bm.allocN32Pixels(width, height);
40 SkCanvas canvas(bm);
41 canvas.clear(0x0);
42
43 draw_grey_ramp(&canvas, width, height, numSteps);
44
45 return SkImage::MakeFromBitmap(bm);
46 }
47
48 namespace skiagm {
49
50 class GammaColorFilterGM : public GM {
51 public:
52 GammaColorFilterGM() {
53 this->setBGColor(SK_ColorBLACK);
54 }
55
56 protected:
57
58 SkString onShortName() override {
59 return SkString("gammacolorfilter");
60 }
61
62 SkISize onISize() override {
63 return SkISize::Make(4 * kCellWidth, kCellHeight);
64 }
65
66 void onDraw(SkCanvas* canvas) override {
67 GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDraw Context();
68 if (!drawContext) {
69 skiagm::GM::DrawGpuOnlyMessage(canvas);
70 return;
71 }
72
73 sk_sp<SkImage> image(create_grey_ramp(kCellWidth, kCellHeight/2, kNumGre ySteps));
74
75 // Leftmost is a non-gamma pair
76 draw_grey_ramp(canvas, kCellWidth, kCellHeight/2, kNumGreySteps);
77 canvas->drawImage(image, 0, kCellHeight/2);
78 canvas->translate(SkIntToScalar(image->width()), 0);
79
80 for (auto gamma : { 1.0f, 1.0f / 1.8f, 1.0f / 2.2f }) {
81 SkPaint paint;
82 paint.setColorFilter(SkGammaColorFilter::Make(gamma));
83
84 draw_grey_ramp(canvas, kCellWidth, kCellHeight/2, kNumGreySteps);
85 canvas->drawImage(image, 0, kCellHeight/2, &paint);
86 canvas->translate(SkIntToScalar(image->width()), 0);
87 }
88 }
89
90 private:
91 static const int kCellWidth = 64;
92 static const int kCellHeight = 64;
93 static const int kNumGreySteps = 16;
94
95 typedef GM INHERITED;
96 };
97
98 //////////////////////////////////////////////////////////////////////////////
99
100 DEF_GM(return new GammaColorFilterGM;)
101 }
OLDNEW
« no previous file with comments | « no previous file | gyp/effects.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698