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