3 * Copyright 2012 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkColorTable_DEFINED
11 #define SkColorTable_DEFINED
14 #include "SkFlattenable.h"
15 #include "SkImageInfo.h"
17 /** \class SkColorTable
19 SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by
20 8-bit bitmaps, where the bitmap bytes are interpreted as indices into the colortable.
22 class SK_API SkColorTable : public SkRefCnt {
24 SK_DECLARE_INST_COUNT(SkColorTable)
26 /** Makes a deep copy of colors.
28 SkColorTable(const SkColorTable& src);
29 SkColorTable(const SkPMColor colors[], int count);
30 virtual ~SkColorTable();
32 /** Returns the number of colors in the table.
34 int count() const { return fCount; }
36 /** Returns the specified color from the table. In the debug build, this asserts that
37 the index is in range (0 <= index < count).
39 SkPMColor operator[](int index) const {
40 SkASSERT(fColors != NULL && (unsigned)index < (unsigned)fCount);
41 return fColors[index];
45 * Return the array of colors for reading. This must be balanced by a call
48 const SkPMColor* lockColors() {
49 SkDEBUGCODE(sk_atomic_inc(&fColorLockCount);)
54 * Balancing call to lockColors().
58 /** Similar to lockColors(), lock16BitCache() returns the array of
59 RGB16 colors that mirror the 32bit colors. However, this function
60 will return null if kColorsAreOpaque_Flag is not set.
61 Also, unlike lockColors(), the returned array here cannot be modified.
63 const uint16_t* lock16BitCache();
64 /** Balancing call to lock16BitCache().
66 void unlock16BitCache() {
67 SkASSERT(f16BitCacheLockCount > 0);
68 SkDEBUGCODE(f16BitCacheLockCount -= 1);
71 explicit SkColorTable(SkReadBuffer&);
72 void writeToBuffer(SkWriteBuffer&) const;
76 uint16_t* f16BitCache;
78 SkDEBUGCODE(int fColorLockCount;)
79 SkDEBUGCODE(int f16BitCacheLockCount;)
81 void init(const SkPMColor* colors, int count);
83 void inval16BitCache();
85 typedef SkRefCnt INHERITED;