| 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 SkColorPalette_DEFINED |
| 9 |
#define SkColorPalette_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkColor.h" |
| 12 |
#include "include/core/SkRefCnt.h" |
| 13 |
#include "include/core/SkTypes.h" |
| 14 |
|
| 15 |
/** \class SkColorPalette |
| 16 |
|
| 17 |
SkColorPalette holds an array of SkPMColors (premultiplied 32-bit colors) used by |
| 18 |
8-bit bitmaps, where the bitmap bytes are interpreted as indices into the colortable. |
| 19 |
|
| 20 |
SkColorPalette is thread-safe. |
| 21 |
*/ |
| 22 |
class SkColorPalette : public SkRefCnt { |
| 23 |
public: |
| 24 |
/** Copy up to 256 colors into a new SkColorPalette. |
| 25 |
*/ |
| 26 |
SkColorPalette(const SkPMColor colors[], int count); |
| 27 |
~SkColorPalette() override; |
| 28 |
|
| 29 |
/** Returns the number of colors in the table. |
| 30 |
*/ |
| 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. */ |
| 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 |