Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkColorTable.h
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 
25 class SK_API SkColorTable : public SkRefCnt {
26 public:
29  SkColorTable(const SkPMColor colors[], int count);
30  virtual ~SkColorTable();
31 
34  int count() const { return fCount; }
35 
39  SkPMColor operator[](int index) const {
40  SkASSERT(fColors != NULL && (unsigned)index < (unsigned)fCount);
41  return fColors[index];
42  }
43 
46  const SkPMColor* readColors() const { return fColors; }
47 
50  const uint16_t* read16BitCache() const;
51 
52  void writeToBuffer(SkWriteBuffer&) const;
53 
54  // may return null
55  static SkColorTable* Create(SkReadBuffer&);
56 
57 private:
58  enum AllocatedWithMalloc {
59  kAllocatedWithMalloc
60  };
61  // assumes ownership of colors (assumes it was allocated w/ malloc)
62  SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc);
63 
64  SkPMColor* fColors;
65  mutable uint16_t* f16BitCache = nullptr;
66  mutable SkOnce f16BitCacheOnce;
67  int fCount;
68 
69  void init(const SkPMColor* colors, int count);
70 
71  friend class SkImageGenerator;
72  friend class SkBitmapRegionCodec;
73  // Only call if no other thread or cache has seen this table.
74  void dangerous_overwriteColors(const SkPMColor newColors[], int count) {
75  if (count < 0 || count > fCount) {
76  sk_throw();
77  }
78  // assumes that f16BitCache nas NOT been initialized yet, so we don't try to update it
79  memcpy(fColors, newColors, count * sizeof(SkPMColor));
80  fCount = count; // update fCount, in case count is smaller
81  }
82 
83  typedef SkRefCnt INHERITED;
84 };
85 
86 #endif
SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by 8-bit bitmaps...
Definition: SkColorTable.h:25
An interface that allows a purgeable PixelRef (such as a SkDiscardablePixelRef) to decode and re-deco...
Definition: SkImageGenerator.h:62
Definition: SkRefCnt.h:135
int count() const
Returns the number of colors in the table.
Definition: SkColorTable.h:34
const SkPMColor * readColors() const
Return the array of colors for reading.
Definition: SkColorTable.h:46
uint32_t SkPMColor
32 bit ARGB color value, premultiplied.
Definition: SkColor.h:147
Definition: SkWriteBuffer.h:26
SkPMColor operator[](int index) const
Returns the specified color from the table.
Definition: SkColorTable.h:39
Types and macros for colors.