summaryrefslogtreecommitdiffstats
path: root/skia/ext/skia_utils.h
blob: 769d9d4e07034395e4349c294a45724c23a3eb11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SKIA_EXT_SKIA_UTILS_H_
#define SKIA_EXT_SKIA_UTILS_H_

#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkShader.h"

namespace skia {

struct HSL {
  double h;
  double s;
  double l;
};

// Creates a vertical gradient shader. The caller owns the shader.
// Example usage to avoid leaks:
//   paint.setShader(gfx::CreateGradientShader(0, 10, red, blue))->safeUnref();
//
// (The old shader in the paint, if any, needs to be freed, and safeUnref will
// handle the NULL case.)
SkShader* CreateGradientShader(int start_point,
                               int end_point,
                               SkColor start_color,
                               SkColor end_color);

// Convert an SkColor to a HSL value.
void SkColorToHSL(SkColor c, HSL& hsl);

// Convert a HSL color to an SkColor.
SkColor HSLToSkColor(U8CPU alpha, HSL hsl);

// HSL-Shift an SkColor. The shift values are in the range of 0-1, with the 
// option to specify -1 for 'no change'. The shift values are defined as:
// hsl_shift[0] (hue): The absolute hue value - 0 and 1 map
//    to 0 and 360 on the hue color wheel (red).
// hsl_shift[1] (saturation): A saturation shift, with the
//    following key values:
//    0 = remove all color.
//    0.5 = leave unchanged.
//    1 = fully saturate the image.
// hsl_shift[2] (lightness): A lightness shift, with the
//    following key values:
//    0 = remove all lightness (make all pixels black).
//    0.5 = leave unchanged.
//    1 = full lightness (make all pixels white).
SkColor HSLShift(SkColor color, skia::HSL shift);

}  // namespace skia

#endif  // SKIA_EXT_SKIA_UTILS_H_