Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkColorTable.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkColorTable_DEFINED
9#define SkColorTable_DEFINED
10
14
15#include <cstdint>
16
17class SkReadBuffer;
18class SkWriteBuffer;
19
20/**
21 * SkColorTable holds the lookup tables for each channel (ARGB) used to define the filter behavior
22 * of `SkColorFilters::Table`, and provides a way to share the table data between client code and
23 * the returned SkColorFilter. Once created, an SkColorTable is immutable.
24*/
26public:
27 // Creates a new SkColorTable with 'table' used for all four channels. The table is copied into
28 // the SkColorTable.
29 static sk_sp<SkColorTable> Make(const uint8_t table[256]) {
30 return Make(table, table, table, table);
31 }
32
33 // Creates a new SkColorTable with the per-channel lookup tables. Each non-null table is copied
34 // into the SkColorTable. Null parameters are interpreted as the identity table.
35 static sk_sp<SkColorTable> Make(const uint8_t tableA[256],
36 const uint8_t tableR[256],
37 const uint8_t tableG[256],
38 const uint8_t tableB[256]);
39
40 // Per-channel constant value lookup (0-255).
41 const uint8_t* alphaTable() const { return fTable.getAddr8(0, 0); }
42 const uint8_t* redTable() const { return fTable.getAddr8(0, 1); }
43 const uint8_t* greenTable() const { return fTable.getAddr8(0, 2); }
44 const uint8_t* blueTable() const { return fTable.getAddr8(0, 3); }
45
46 void flatten(SkWriteBuffer& buffer) const;
47
48 static sk_sp<SkColorTable> Deserialize(SkReadBuffer& buffer);
49
50private:
51 friend class SkTableColorFilter; // for bitmap()
52
53 SkColorTable(const SkBitmap& table) : fTable(table) {}
54
55 // The returned SkBitmap is immutable; attempting to modify its pixel data will trigger asserts
56 // in debug builds and cause undefined behavior in release builds.
57 const SkBitmap& bitmap() const { return fTable; }
58
59 SkBitmap fTable; // A 256x4 A8 image
60};
61
62#endif // SkColorTable_DEFINED
#define SK_API
Definition SkAPI.h:35
static std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap *src, const SkYUVAPixmaps *srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options)
SI F table(const skcms_Curve *curve, F v)
const uint8_t * redTable() const
const uint8_t * alphaTable() const
static sk_sp< SkColorTable > Make(const uint8_t table[256])
const uint8_t * greenTable() const
const uint8_t * blueTable() const
static const uint8_t buffer[]