aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec
diff options
context:
space:
mode:
Diffstat (limited to 'src/codec')
-rw-r--r--src/codec/SkCodecImageGenerator.h2
-rw-r--r--src/codec/SkColorTable.cpp19
-rw-r--r--src/codec/SkColorTable.h50
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