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 --- BUILD.gn | 1 + gn/core.gni | 1 - src/codec/SkCodecImageGenerator.h | 2 -- src/codec/SkColorTable.cpp | 19 +++++++++++-- src/codec/SkColorTable.h | 50 ++++++++++++++++++++++++++++++++++ src/core/SkBitmap.cpp | 5 ++-- src/core/SkBitmapDevice.cpp | 2 -- src/core/SkColorTable.cpp | 31 --------------------- src/core/SkColorTable.h | 57 --------------------------------------- src/core/SkConvertPixels.cpp | 7 +++-- src/core/SkConvertPixels.h | 2 +- src/core/SkPixmap.cpp | 2 +- src/gpu/GrContext.cpp | 1 - src/gpu/SkGr.cpp | 1 - 14 files changed, 75 insertions(+), 106 deletions(-) create mode 100644 src/codec/SkColorTable.h delete mode 100644 src/core/SkColorTable.cpp delete mode 100644 src/core/SkColorTable.h diff --git a/BUILD.gn b/BUILD.gn index 42cbb293a7..5fa81c0f7e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -860,6 +860,7 @@ component("skia") { "src/codec/SkBmpStandardCodec.cpp", "src/codec/SkCodec.cpp", "src/codec/SkCodecImageGenerator.cpp", + "src/codec/SkColorTable.cpp", "src/codec/SkGifCodec.cpp", "src/codec/SkMaskSwizzler.cpp", "src/codec/SkMasks.cpp", diff --git a/gn/core.gni b/gn/core.gni index 56b335cf0a..abc23b93fc 100644 --- a/gn/core.gni +++ b/gn/core.gni @@ -86,7 +86,6 @@ skia_core_sources = [ "$_src/core/SkColorSpaceXformSteps.cpp", "$_src/core/SkColorSpaceXformer.cpp", "$_src/core/SkColorSpaceXformer.h", - "$_src/core/SkColorTable.cpp", "$_src/core/SkConvertPixels.cpp", "$_src/core/SkConvertPixels.h", "$_src/core/SkCoreBlitters.h", 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 diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 579573367f..1b6b6b2f5a 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -8,7 +8,6 @@ #include "SkAtomics.h" #include "SkBitmap.h" #include "SkColorData.h" -#include "SkColorTable.h" #include "SkConvertPixels.h" #include "SkData.h" #include "SkFilterQuality.h" @@ -502,7 +501,7 @@ bool SkBitmap::writePixels(const SkPixmap& src, int dstX, int dstY, void* dstPixels = this->getAddr(rec.fX, rec.fY); const SkImageInfo dstInfo = this->info().makeWH(rec.fInfo.width(), rec.fInfo.height()); SkConvertPixels(dstInfo, dstPixels, this->rowBytes(), rec.fInfo, rec.fPixels, rec.fRowBytes, - nullptr, behavior); + behavior); this->notifyPixelsChanged(); return true; } @@ -522,7 +521,7 @@ static bool GetBitmapAlpha(const SkBitmap& src, uint8_t* SK_RESTRICT alpha, int return false; } SkConvertPixels(SkImageInfo::MakeA8(pmap.width(), pmap.height()), alpha, alphaRowBytes, - pmap.info(), pmap.addr(), pmap.rowBytes(), nullptr, + pmap.info(), pmap.addr(), pmap.rowBytes(), SkTransferFunctionBehavior::kRespect); return true; } diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 522f016a2d..71b85af268 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -187,8 +187,6 @@ public: } }; -class SkColorTable; - static bool valid_for_bitmap_device(const SkImageInfo& info, SkAlphaType* newAlphaType) { if (info.width() < 0 || info.height() < 0) { diff --git a/src/core/SkColorTable.cpp b/src/core/SkColorTable.cpp deleted file mode 100644 index 022b9f8ae3..0000000000 --- a/src/core/SkColorTable.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -#include "SkColorTable.h" -#include "SkReadBuffer.h" -#include "SkWriteBuffer.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); -} - -void SkColorTable::Skip(SkReadBuffer& buffer) { - const int count = buffer.getArrayCount(); - if (buffer.validate(count >= 0 && count <= 256)) { - buffer.skip(count * sizeof(SkPMColor)); - } -} diff --git a/src/core/SkColorTable.h b/src/core/SkColorTable.h deleted file mode 100644 index c56e6fe917..0000000000 --- a/src/core/SkColorTable.h +++ /dev/null @@ -1,57 +0,0 @@ - -/* - * 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 "../private/SkOnce.h" -#include "SkColor.h" -#include "SkFlattenable.h" -#include "SkImageInfo.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; } - - // may return null - static void Skip(SkReadBuffer&); - -private: - SkPMColor* fColors; - int fCount; - - typedef SkRefCnt INHERITED; -}; - -#endif diff --git a/src/core/SkConvertPixels.cpp b/src/core/SkConvertPixels.cpp index ddc04c06b6..b0d37cd89f 100644 --- a/src/core/SkConvertPixels.cpp +++ b/src/core/SkConvertPixels.cpp @@ -7,7 +7,6 @@ #include "SkColorSpaceXformPriv.h" #include "SkColorSpacePriv.h" -#include "SkColorTable.h" #include "SkConvertPixels.h" #include "SkHalf.h" #include "SkImageInfoPriv.h" @@ -164,7 +163,7 @@ static inline bool apply_color_xform(const SkImageInfo& dstInfo, void* dstPixels // Fast Path 4: Alpha 8 dsts. static void convert_to_alpha8(uint8_t* dst, size_t dstRB, const SkImageInfo& srcInfo, - const void* src, size_t srcRB, SkColorTable* ctable) { + const void* src, size_t srcRB) { if (srcInfo.isOpaque()) { for (int y = 0; y < srcInfo.height(); ++y) { memset(dst, 0xFF, srcInfo.width()); @@ -405,7 +404,7 @@ static bool swizzle_and_multiply_color_type(SkColorType ct) { void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRB, - SkColorTable* ctable, SkTransferFunctionBehavior behavior) { + SkTransferFunctionBehavior behavior) { SkASSERT(dstInfo.dimensions() == srcInfo.dimensions()); SkASSERT(SkImageInfoValidConversion(dstInfo, srcInfo)); @@ -434,7 +433,7 @@ void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, // Fast Path 4: Alpha 8 dsts. if (kAlpha_8_SkColorType == dstInfo.colorType()) { - convert_to_alpha8((uint8_t*) dstPixels, dstRB, srcInfo, srcPixels, srcRB, ctable); + convert_to_alpha8((uint8_t*) dstPixels, dstRB, srcInfo, srcPixels, srcRB); return; } diff --git a/src/core/SkConvertPixels.h b/src/core/SkConvertPixels.h index c825d84aa1..001052b7a8 100644 --- a/src/core/SkConvertPixels.h +++ b/src/core/SkConvertPixels.h @@ -15,7 +15,7 @@ class SkColorTable; void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRowBytes, - SkColorTable* srcCTable, SkTransferFunctionBehavior behavior); + SkTransferFunctionBehavior behavior); static inline void SkRectMemcpy(void* dst, size_t dstRB, const void* src, size_t srcRB, size_t bytesPerRow, int rowCount) { diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp index 852ffb0b33..446f25b2f2 100644 --- a/src/core/SkPixmap.cpp +++ b/src/core/SkPixmap.cpp @@ -89,7 +89,7 @@ bool SkPixmap::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t ds const void* srcPixels = this->addr(rec.fX, rec.fY); const SkImageInfo srcInfo = fInfo.makeWH(rec.fInfo.width(), rec.fInfo.height()); SkConvertPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, srcInfo, srcPixels, this->rowBytes(), - nullptr, behavior); + behavior); return true; } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 3d57f9818d..c9c476fb1a 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -27,7 +27,6 @@ #include "GrTextureStripAtlas.h" #include "GrTracing.h" #include "SkAutoPixmapStorage.h" -#include "SkConvertPixels.h" #include "SkDeferredDisplayList.h" #include "SkGr.h" #include "SkImageInfoPriv.h" diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index a37523fc06..528d133e2d 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -21,7 +21,6 @@ #include "SkBlendModePriv.h" #include "SkCanvas.h" #include "SkColorFilter.h" -#include "SkConvertPixels.h" #include "SkData.h" #include "SkImage_Base.h" #include "SkImageInfoPriv.h" -- cgit v1.2.3