SkColorTable.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  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. #ifndef SkColorTable_DEFINED
  8. #define SkColorTable_DEFINED
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkRefCnt.h"
  11. /** \class SkColorTable
  12. SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by
  13. 8-bit bitmaps, where the bitmap bytes are interpreted as indices into the colortable.
  14. SkColorTable is thread-safe.
  15. */
  16. class SkColorTable : public SkRefCnt {
  17. public:
  18. /** Copy up to 256 colors into a new SkColorTable.
  19. */
  20. SkColorTable(const SkPMColor colors[], int count);
  21. ~SkColorTable() override;
  22. /** Returns the number of colors in the table.
  23. */
  24. int count() const { return fCount; }
  25. /** Returns the specified color from the table. In the debug build, this asserts that
  26. * the index is in range (0 <= index < count).
  27. */
  28. SkPMColor operator[](int index) const {
  29. SkASSERT(fColors != nullptr && (unsigned)index < (unsigned)fCount);
  30. return fColors[index];
  31. }
  32. /** Return the array of colors for reading. */
  33. const SkPMColor* readColors() const { return fColors; }
  34. private:
  35. SkPMColor* fColors;
  36. int fCount;
  37. typedef SkRefCnt INHERITED;
  38. };
  39. #endif