aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkColorSpacePriv.h
blob: 47fab647ff19ac5b13564cc0e7b8735a043f6cd0 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkColorSpacePriv_DEFINED
#define SkColorSpacePriv_DEFINED

struct SkGammaCurve {
    bool isValue() const {
        bool result = (0.0f != fValue);
        SkASSERT(!result || (0 == fTableSize));
        return result;
    }

    bool isTable() const {
        bool result = (0 != fTableSize);
        SkASSERT(!result || (0.0f == fValue));
        SkASSERT(!result || fTable);
        return result;
    }

    bool isParametric() const { return false; }

    // We have three different ways to represent gamma.
    // (1) A single value:
    float                    fValue;

    // (2) A lookup table:
    uint32_t                 fTableSize;
    std::unique_ptr<float[]> fTable;

    // (3) Parameters for a curve:
    // FIXME (msarett): Handle parametric curves.

    SkGammaCurve() {
        memset(this, 0, sizeof(struct SkGammaCurve));
    }

    SkGammaCurve(float value)
        : fValue(value)
        , fTableSize(0)
        , fTable(nullptr)
    {}
};

struct SkGammas : public SkRefCnt {
public:
    bool isValues() const {
        return fRed.isValue() && fGreen.isValue() && fBlue.isValue();
    }

    const SkGammaCurve fRed;
    const SkGammaCurve fGreen;
    const SkGammaCurve fBlue;

    SkGammas(float red, float green, float blue)
        : fRed(red)
        , fGreen(green)
        , fBlue(blue)
    {}

    SkGammas(SkGammaCurve red, SkGammaCurve green, SkGammaCurve blue)
        : fRed(std::move(red))
        , fGreen(std::move(green))
        , fBlue(std::move(blue))
    {}

    SkGammas() {}

    friend class SkColorSpace;
};

struct SkColorLookUpTable {
    static const uint8_t kMaxChannels = 16;

    uint8_t                  fInputChannels;
    uint8_t                  fOutputChannels;
    uint8_t                  fGridPoints[kMaxChannels];
    std::unique_ptr<float[]> fTable;

    SkColorLookUpTable() {
        memset(this, 0, sizeof(struct SkColorLookUpTable));
    }
};

#endif