1
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef SkColorTable_DEFINED
11#define SkColorTable_DEFINED
12
13#include "../private/SkOnce.h"
14#include "SkColor.h"
15#include "SkFlattenable.h"
16#include "SkImageInfo.h"
17
18/** \class SkColorTable
19
20    SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by
21    8-bit bitmaps, where the bitmap bytes are interpreted as indices into the colortable.
22
23    SkColorTable is thread-safe.
24*/
25class SkColorTable : public SkRefCnt {
26public:
27    /** Copy up to 256 colors into a new SkColorTable.
28     */
29    SkColorTable(const SkPMColor colors[], int count);
30    ~SkColorTable() override;
31
32    /** Returns the number of colors in the table.
33     */
34    int count() const { return fCount; }
35
36    /** Returns the specified color from the table. In the debug build, this asserts that
37     *  the index is in range (0 <= index < count).
38     */
39    SkPMColor operator[](int index) const {
40        SkASSERT(fColors != nullptr && (unsigned)index < (unsigned)fCount);
41        return fColors[index];
42    }
43
44    /** Return the array of colors for reading. */
45    const SkPMColor* readColors() const { return fColors; }
46
47    // may return null
48    static void Skip(SkReadBuffer&);
49
50private:
51    SkPMColor*  fColors;
52    int         fCount;
53
54    typedef SkRefCnt INHERITED;
55};
56
57#endif
58