aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkColorLookUpTable.h
blob: b9eb81acc137fb7e7a9f8f8060a395d0c2ea9616 (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
/*
 * 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 "SkRefCnt.h"
#include "SkTemplates.h"

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

    SkColorLookUpTable(uint8_t inputChannels, const uint8_t gridPoints[3]) {
        SkASSERT(3 == inputChannels);
        memcpy(fGridPoints, gridPoints, 3 * sizeof(uint8_t));   
    }

    void interp3D(float dst[3], float src[3]) const;

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

    uint8_t fGridPoints[3];

public:
    // 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); }
};

#endif