OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkColorTable_DEFINED | 10 #ifndef SkColorTable_DEFINED |
11 #define SkColorTable_DEFINED | 11 #define SkColorTable_DEFINED |
12 | 12 |
13 #include "SkColor.h" | 13 #include "SkColor.h" |
14 #include "SkFlattenable.h" | 14 #include "SkFlattenable.h" |
15 #include "SkImageInfo.h" | 15 #include "SkImageInfo.h" |
16 | 16 |
17 /** \class SkColorTable | 17 /** \class SkColorTable |
18 | 18 |
19 SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by | 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 co
lortable. | 20 8-bit bitmaps, where the bitmap bytes are interpreted as indices into the co
lortable. |
21 */ | 21 */ |
22 class SK_API SkColorTable : public SkRefCnt { | 22 class SK_API SkColorTable : public SkRefCnt { |
23 public: | 23 public: |
24 SK_DECLARE_INST_COUNT(SkColorTable) | 24 SK_DECLARE_INST_COUNT(SkColorTable) |
25 | 25 |
26 /** Makes a deep copy of colors. | 26 /** Makes a deep copy of colors. |
27 */ | 27 */ |
28 SkColorTable(const SkColorTable& src); | 28 SkColorTable(const SkColorTable& src); |
29 SkColorTable(const SkPMColor colors[], int count, | 29 SkColorTable(const SkPMColor colors[], int count); |
30 SkAlphaType alphaType = kPremul_SkAlphaType); | |
31 virtual ~SkColorTable(); | 30 virtual ~SkColorTable(); |
32 | 31 |
33 SkAlphaType alphaType() const { return (SkAlphaType)fAlphaType; } | |
34 | |
35 bool isOpaque() const { | |
36 return SkAlphaTypeIsOpaque(this->alphaType()); | |
37 } | |
38 | |
39 /** Returns the number of colors in the table. | 32 /** Returns the number of colors in the table. |
40 */ | 33 */ |
41 int count() const { return fCount; } | 34 int count() const { return fCount; } |
42 | 35 |
43 /** Returns the specified color from the table. In the debug build, this ass
erts that | 36 /** Returns the specified color from the table. In the debug build, this ass
erts that |
44 the index is in range (0 <= index < count). | 37 the index is in range (0 <= index < count). |
45 */ | 38 */ |
46 SkPMColor operator[](int index) const { | 39 SkPMColor operator[](int index) const { |
47 SkASSERT(fColors != NULL && (unsigned)index < fCount); | 40 SkASSERT(fColors != NULL && (unsigned)index < (unsigned)fCount); |
48 return fColors[index]; | 41 return fColors[index]; |
49 } | 42 } |
50 | 43 |
51 /** | 44 /** |
52 * Return the array of colors for reading. This must be balanced by a call | 45 * Return the array of colors for reading. This must be balanced by a call |
53 * to unlockColors(). | 46 * to unlockColors(). |
54 */ | 47 */ |
55 const SkPMColor* lockColors() { | 48 const SkPMColor* lockColors() { |
56 SkDEBUGCODE(sk_atomic_inc(&fColorLockCount);) | 49 SkDEBUGCODE(sk_atomic_inc(&fColorLockCount);) |
57 return fColors; | 50 return fColors; |
(...skipping 16 matching lines...) Expand all Loading... |
74 SkASSERT(f16BitCacheLockCount > 0); | 67 SkASSERT(f16BitCacheLockCount > 0); |
75 SkDEBUGCODE(f16BitCacheLockCount -= 1); | 68 SkDEBUGCODE(f16BitCacheLockCount -= 1); |
76 } | 69 } |
77 | 70 |
78 explicit SkColorTable(SkReadBuffer&); | 71 explicit SkColorTable(SkReadBuffer&); |
79 void writeToBuffer(SkWriteBuffer&) const; | 72 void writeToBuffer(SkWriteBuffer&) const; |
80 | 73 |
81 private: | 74 private: |
82 SkPMColor* fColors; | 75 SkPMColor* fColors; |
83 uint16_t* f16BitCache; | 76 uint16_t* f16BitCache; |
84 uint16_t fCount; | 77 int fCount; |
85 uint8_t fAlphaType; | |
86 SkDEBUGCODE(int fColorLockCount;) | 78 SkDEBUGCODE(int fColorLockCount;) |
87 SkDEBUGCODE(int f16BitCacheLockCount;) | 79 SkDEBUGCODE(int f16BitCacheLockCount;) |
88 | 80 |
| 81 void init(const SkPMColor* colors, int count); |
| 82 |
89 void inval16BitCache(); | 83 void inval16BitCache(); |
90 | 84 |
91 typedef SkRefCnt INHERITED; | 85 typedef SkRefCnt INHERITED; |
92 }; | 86 }; |
93 | 87 |
94 #endif | 88 #endif |
OLD | NEW |