• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #if 0  // Disabled until updated to use current API.
2 // Copyright 2019 Google LLC.
3 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4 #include "tools/fiddle/examples.h"
5 // HASH=22df72732e898a11773fbfe07388a546
6 REG_FIDDLE(ImageInfo_gammaCloseToSRGB, 256, 144, false, 0) {
7 void draw(SkCanvas* canvas) {
8     const int width = 256;
9     const int height = 64;
10     auto drawLabel = [=](const char* what, bool closeToSRGB) -> void {
11         SkString string;
12         string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not ");
13         SkPaint paint;
14         paint.setAntiAlias(true);
15         canvas->drawString(string, 20, 56, paint);
16     };
17     SkColor  gradColors[] = { 0xFFFF7F00, 0xFF00FF7F,  0xFF0000FF, 0xFF7F7FFF };
18     SkPoint  gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } };
19     SkPaint gradPaint;
20     gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
21                     std::size(gradColors), SkShader::kClamp_TileMode));
22     canvas->drawRect(SkRect::MakeWH(width, height), gradPaint);
23     drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB());
24     SkBitmap bitmap;
25     SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType);
26     bitmap.allocPixels(offscreenInfo);
27     SkCanvas sRGBOffscreen(bitmap);
28     sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
29     canvas->translate(0, 80);
30     canvas->drawBitmap(bitmap, 0, 0);
31     drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB());
32 }
33 }  // END FIDDLE
34 #endif  // Disabled until updated to use current API.
35