blob: 57681a90491bdb881fd3a06e81343e11afe046fa [file] [log] [blame]
djsollen@google.com64a0ec32012-06-12 15:17:27 +00001/*
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.com64a0ec32012-06-12 15:17:27 +00008#ifndef SkColorTable_DEFINED
9#define SkColorTable_DEFINED
10
11#include "SkColor.h"
Leon Scroggins III22f673d2018-05-30 15:33:46 -040012#include "SkRefCnt.h"
djsollen@google.com64a0ec32012-06-12 15:17:27 +000013
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.
mtkleincc969c42014-12-02 10:02:47 -080018
19 SkColorTable is thread-safe.
djsollen@google.com64a0ec32012-06-12 15:17:27 +000020*/
Mike Reed323ae0e2017-07-24 22:05:25 -040021class SkColorTable : public SkRefCnt {
djsollen@google.com64a0ec32012-06-12 15:17:27 +000022public:
scroggob267fd62015-03-18 08:00:27 -070023 /** Copy up to 256 colors into a new SkColorTable.
24 */
reedc5e15a12014-09-29 12:10:27 -070025 SkColorTable(const SkPMColor colors[], int count);
Mike Reed6b3155c2017-04-03 14:41:44 -040026 ~SkColorTable() override;
djsollen@google.com64a0ec32012-06-12 15:17:27 +000027
djsollen@google.com64a0ec32012-06-12 15:17:27 +000028 /** Returns the number of colors in the table.
mtklein775b8192014-12-02 09:11:25 -080029 */
djsollen@google.com64a0ec32012-06-12 15:17:27 +000030 int count() const { return fCount; }
31
32 /** Returns the specified color from the table. In the debug build, this asserts that
mtklein775b8192014-12-02 09:11:25 -080033 * the index is in range (0 <= index < count).
34 */
djsollen@google.com64a0ec32012-06-12 15:17:27 +000035 SkPMColor operator[](int index) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -040036 SkASSERT(fColors != nullptr && (unsigned)index < (unsigned)fCount);
djsollen@google.com64a0ec32012-06-12 15:17:27 +000037 return fColors[index];
38 }
39
Mike Reed323ae0e2017-07-24 22:05:25 -040040 /** Return the array of colors for reading. */
mtkleincc969c42014-12-02 10:02:47 -080041 const SkPMColor* readColors() const { return fColors; }
djsollen@google.com64a0ec32012-06-12 15:17:27 +000042
djsollen@google.com64a0ec32012-06-12 15:17:27 +000043private:
Mike Reed323ae0e2017-07-24 22:05:25 -040044 SkPMColor* fColors;
45 int fCount;
reed4b3d3be2015-09-17 13:35:19 -070046
commit-bot@chromium.orge0e1da32013-10-15 20:36:16 +000047 typedef SkRefCnt INHERITED;
djsollen@google.com64a0ec32012-06-12 15:17:27 +000048};
49
50#endif