diff options
author | Leon Scroggins III <scroggo@google.com> | 2018-05-30 15:33:46 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-06-01 12:53:25 +0000 |
commit | 22f673d42087853a151fcd5e95c129be83065cdc (patch) | |
tree | e4e711677a1e6a02b261acd9346c587ff260d7a0 /src/codec | |
parent | 9ea47bedb945fe51c7805b4f2defccccb8249865 (diff) |
Move SkColorTable to src/codec
It is no longer needed anywhere else, and simply happens to be an
implementation detail of SkCodec (at least for now).
Remove references to SkColorTable in other classes, and clean up some
includes of SkConvertPixels I found along the way.
Remove unused includes/methods on SkColorTable
Change-Id: I46c8e46f5b77c37710b6cf595d48107d55871d52
Reviewed-on: https://skia-review.googlesource.com/130845
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/codec')
-rw-r--r-- | src/codec/SkCodecImageGenerator.h | 2 | ||||
-rw-r--r-- | src/codec/SkColorTable.cpp | 19 | ||||
-rw-r--r-- | src/codec/SkColorTable.h | 50 |
3 files changed, 67 insertions, 4 deletions
diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h index 2bbf118941..b9c9d3c129 100644 --- a/src/codec/SkCodecImageGenerator.h +++ b/src/codec/SkCodecImageGenerator.h @@ -8,7 +8,6 @@ #define SkCodecImageGenerator_DEFINED #include "SkCodec.h" -#include "SkColorTable.h" #include "SkData.h" #include "SkImageGenerator.h" @@ -38,7 +37,6 @@ private: std::unique_ptr<SkCodec> fCodec; sk_sp<SkData> fData; - sk_sp<SkColorTable> fColorTable; typedef SkImageGenerator INHERITED; }; diff --git a/src/codec/SkColorTable.cpp b/src/codec/SkColorTable.cpp index ae6716b3f6..5699d87c2b 100644 --- a/src/codec/SkColorTable.cpp +++ b/src/codec/SkColorTable.cpp @@ -1,8 +1,23 @@ /* - * Copyright 2018 Google Inc. + * Copyright 2009 The Android Open Source Project * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -// Dummy file to assist in landing https://skia-review.googlesource.com/c/skia/+/130845 +#include "SkColorTable.h" +#include "../private/SkMalloc.h" + +SkColorTable::SkColorTable(const SkPMColor colors[], int count) { + SkASSERT(0 == count || colors); + SkASSERT(count >= 0 && count <= 256); + + fCount = count; + fColors = reinterpret_cast<SkPMColor*>(sk_malloc_throw(count * sizeof(SkPMColor))); + + memcpy(fColors, colors, count * sizeof(SkPMColor)); +} + +SkColorTable::~SkColorTable() { + sk_free(fColors); +} diff --git a/src/codec/SkColorTable.h b/src/codec/SkColorTable.h new file mode 100644 index 0000000000..57681a9049 --- /dev/null +++ b/src/codec/SkColorTable.h @@ -0,0 +1,50 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkColorTable_DEFINED +#define SkColorTable_DEFINED + +#include "SkColor.h" +#include "SkRefCnt.h" + +/** \class SkColorTable + + SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by + 8-bit bitmaps, where the bitmap bytes are interpreted as indices into the colortable. + + SkColorTable is thread-safe. +*/ +class SkColorTable : public SkRefCnt { +public: + /** Copy up to 256 colors into a new SkColorTable. + */ + SkColorTable(const SkPMColor colors[], int count); + ~SkColorTable() override; + + /** Returns the number of colors in the table. + */ + int count() const { return fCount; } + + /** Returns the specified color from the table. In the debug build, this asserts that + * the index is in range (0 <= index < count). + */ + SkPMColor operator[](int index) const { + SkASSERT(fColors != nullptr && (unsigned)index < (unsigned)fCount); + return fColors[index]; + } + + /** Return the array of colors for reading. */ + const SkPMColor* readColors() const { return fColors; } + +private: + SkPMColor* fColors; + int fCount; + + typedef SkRefCnt INHERITED; +}; + +#endif |