1 | /* |
2 | * Copyright 2012 Google Inc. |
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 | |
11 | #include "include/core/SkColor.h" |
12 | #include "include/core/SkRefCnt.h" |
13 | |
14 | /** \class SkColorTable |
15 | |
16 | SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by |
17 | 8-bit bitmaps, where the bitmap bytes are interpreted as indices into the colortable. |
18 | |
19 | SkColorTable is thread-safe. |
20 | */ |
21 | class SkColorTable : public SkRefCnt { |
22 | public: |
23 | /** Copy up to 256 colors into a new SkColorTable. |
24 | */ |
25 | SkColorTable(const SkPMColor colors[], int count); |
26 | ~SkColorTable() override; |
27 | |
28 | /** Returns the number of colors in the table. |
29 | */ |
30 | int count() const { return fCount; } |
31 | |
32 | /** Returns the specified color from the table. In the debug build, this asserts that |
33 | * the index is in range (0 <= index < count). |
34 | */ |
35 | SkPMColor operator[](int index) const { |
36 | SkASSERT(fColors != nullptr && (unsigned)index < (unsigned)fCount); |
37 | return fColors[index]; |
38 | } |
39 | |
40 | /** Return the array of colors for reading. */ |
41 | const SkPMColor* readColors() const { return fColors; } |
42 | |
43 | private: |
44 | SkPMColor* fColors; |
45 | int fCount; |
46 | |
47 | typedef SkRefCnt INHERITED; |
48 | }; |
49 | |
50 | #endif |
51 | |