djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 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 | |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 8 | #ifndef SkColorTable_DEFINED |
| 9 | #define SkColorTable_DEFINED |
| 10 | |
| 11 | #include "SkColor.h" |
Leon Scroggins III | 22f673d | 2018-05-30 15:33:46 -0400 | [diff] [blame] | 12 | #include "SkRefCnt.h" |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 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. |
mtklein | cc969c4 | 2014-12-02 10:02:47 -0800 | [diff] [blame] | 18 | |
| 19 | SkColorTable is thread-safe. |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 20 | */ |
Mike Reed | 323ae0e | 2017-07-24 22:05:25 -0400 | [diff] [blame] | 21 | class SkColorTable : public SkRefCnt { |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 22 | public: |
scroggo | b267fd6 | 2015-03-18 08:00:27 -0700 | [diff] [blame] | 23 | /** Copy up to 256 colors into a new SkColorTable. |
| 24 | */ |
reed | c5e15a1 | 2014-09-29 12:10:27 -0700 | [diff] [blame] | 25 | SkColorTable(const SkPMColor colors[], int count); |
Mike Reed | 6b3155c | 2017-04-03 14:41:44 -0400 | [diff] [blame] | 26 | ~SkColorTable() override; |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 27 | |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 28 | /** Returns the number of colors in the table. |
mtklein | 775b819 | 2014-12-02 09:11:25 -0800 | [diff] [blame] | 29 | */ |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 30 | int count() const { return fCount; } |
| 31 | |
| 32 | /** Returns the specified color from the table. In the debug build, this asserts that |
mtklein | 775b819 | 2014-12-02 09:11:25 -0800 | [diff] [blame] | 33 | * the index is in range (0 <= index < count). |
| 34 | */ |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 35 | SkPMColor operator[](int index) const { |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 36 | SkASSERT(fColors != nullptr && (unsigned)index < (unsigned)fCount); |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 37 | return fColors[index]; |
| 38 | } |
| 39 | |
Mike Reed | 323ae0e | 2017-07-24 22:05:25 -0400 | [diff] [blame] | 40 | /** Return the array of colors for reading. */ |
mtklein | cc969c4 | 2014-12-02 10:02:47 -0800 | [diff] [blame] | 41 | const SkPMColor* readColors() const { return fColors; } |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 42 | |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 43 | private: |
Mike Reed | 323ae0e | 2017-07-24 22:05:25 -0400 | [diff] [blame] | 44 | SkPMColor* fColors; |
| 45 | int fCount; |
reed | 4b3d3be | 2015-09-17 13:35:19 -0700 | [diff] [blame] | 46 | |
commit-bot@chromium.org | e0e1da3 | 2013-10-15 20:36:16 +0000 | [diff] [blame] | 47 | typedef SkRefCnt INHERITED; |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | #endif |