aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkColorLookUpTable.h
blob: f7d62452e77c7c93f0fd1d4fdc05c4475643fd9d (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
/*
 * 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 SkColorLookUpTable_DEFINED
#define SkColorLookUpTable_DEFINED

#include "SkNx.h"
#include "SkRefCnt.h"
#include "SkTemplates.h"

// TODO: scope inside SkColorLookUpTable
static constexpr uint8_t kMaxColorChannels = 4;

class SkColorLookUpTable : public SkRefCnt {
public:
    static constexpr uint8_t kOutputChannels = 3;

    SkColorLookUpTable(uint8_t inputChannels, const uint8_t limits[]);

    int  inputChannels() const { return  fInputChannels; }
    int outputChannels() const { return kOutputChannels; }

    // TODO: Rename to somethingBetter(int)?
    int gridPoints(int dimension) const {
        SkASSERT(dimension >= 0 && dimension < inputChannels());
        return fLimits[dimension];
    }

    // Objects of this type are created in a custom fashion using sk_malloc_throw
    // and therefore must be sk_freed.
    void* operator new(size_t size) = delete;
    void* operator new(size_t, void* p) { return p; }
    void operator delete(void* p) { sk_free(p); }

    const float* table() const {
        return SkTAddOffset<const float>(this, sizeof(SkColorLookUpTable));
    }

private:
    uint8_t fInputChannels;
    uint8_t fLimits[kMaxColorChannels];
};

#endif