From 22f673d42087853a151fcd5e95c129be83065cdc Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Wed, 30 May 2018 15:33:46 -0400 Subject: 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 Reviewed-by: Mike Klein --- src/codec/SkCodecImageGenerator.h | 2 -- src/codec/SkColorTable.cpp | 19 +++++++++++++-- src/codec/SkColorTable.h | 50 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 src/codec/SkColorTable.h (limited to 'src/codec') 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 fCodec; sk_sp fData; - sk_sp 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(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 -- cgit v1.2.3