diff options
author | 2016-11-22 11:57:18 -0700 | |
---|---|---|
committer | 2016-11-22 19:47:21 +0000 | |
commit | e8eed323ef7ea1c3c7057d49f3306b8ff41676e8 (patch) | |
tree | 9c2e0bbb08c91857cc9908715d2b99a4cafff9e2 /src/images | |
parent | fec1dea8098fe09f04fff542efdb83edc1fe8240 (diff) |
remove SkPixelRef::refEncodedData()
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5001
Change-Id: I15dba4f44c762ab69a23eb8a77adff5f63763e30
Reviewed-on: https://skia-review.googlesource.com/5001
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Diffstat (limited to 'src/images')
-rw-r--r-- | src/images/SkKTXImageEncoder.cpp | 61 |
1 files changed, 5 insertions, 56 deletions
diff --git a/src/images/SkKTXImageEncoder.cpp b/src/images/SkKTXImageEncoder.cpp index 7a0ccb3a85..6717bea5f7 100644 --- a/src/images/SkKTXImageEncoder.cpp +++ b/src/images/SkKTXImageEncoder.cpp @@ -24,71 +24,20 @@ // overview, a KTX file contains all of the appropriate values needed to fully specify a // texture in an OpenGL application, including the use of compressed data. // -// This encoder takes a best guess at how to encode the bitmap passed to it. If -// there is an installed discardable pixel ref with existing PKM data, then we -// will repurpose the existing ETC1 data into a KTX file. If the data contains -// KTX data, then we simply return a copy of the same data. For all other files, -// the underlying KTX library tries to do its best to encode the appropriate +// This encoder takes a best guess at how to encode the bitmap passed to it. +// The KTX library tries to do its best to encode the appropriate // data specified by the bitmap based on the config. (i.e. kAlpha8_Config will // be represented as a full resolution 8-bit image dump with the appropriate // OpenGL defines in the header). class SkKTXImageEncoder : public SkImageEncoder { protected: - bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) override; - -private: - virtual bool encodePKM(SkWStream* stream, const SkData *data); - typedef SkImageEncoder INHERITED; -}; - -bool SkKTXImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int) { - if (!bitmap.pixelRef()) { - return false; + bool onEncode(SkWStream* stream, const SkBitmap& bitmap, int) override { + return SkKTXFile::WriteBitmapToKTX(stream, bitmap); } - sk_sp<SkData> data(bitmap.pixelRef()->refEncodedData()); - - // Is this even encoded data? - if (data) { - const uint8_t *bytes = data->bytes(); - if (etc1_pkm_is_valid(bytes)) { - return this->encodePKM(stream, data.get()); - } - - // Is it a KTX file?? - if (SkKTXFile::is_ktx(bytes, data->size())) { - return stream->write(bytes, data->size()); - } - - // If it's neither a KTX nor a PKM, then we need to - // get at the actual pixels, so fall through and decompress... - } - - return SkKTXFile::WriteBitmapToKTX(stream, bitmap); -} - -bool SkKTXImageEncoder::encodePKM(SkWStream* stream, const SkData *data) { - const uint8_t* bytes = data->bytes(); - SkASSERT(etc1_pkm_is_valid(bytes)); - - etc1_uint32 width = etc1_pkm_get_width(bytes); - etc1_uint32 height = etc1_pkm_get_height(bytes); - - // ETC1 Data is stored as compressed 4x4 pixel blocks, so we must make sure - // that our dimensions are valid. - if (width == 0 || (width & 3) != 0 || height == 0 || (height & 3) != 0) { - return false; - } - - // Advance pointer to etc1 data. - bytes += ETC_PKM_HEADER_SIZE; - - return SkKTXFile::WriteETC1ToKTX(stream, bytes, width, height); -} +}; -///////////////////////////////////////////////////////////////////////////////////////// DEFINE_ENCODER_CREATOR(KTXImageEncoder); -///////////////////////////////////////////////////////////////////////////////////////// SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) { return (SkEncodedImageFormat::kKTX == (SkEncodedImageFormat)t) ? new SkKTXImageEncoder : nullptr; |