Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Unified Diff: src/images/SkImageDecoder_ktx.cpp

Issue 1373683003: change pixel-serializer to support reencoding existing data Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: I hate this warning Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkImage.cpp ('k') | src/images/SkImageEncoder.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/images/SkImageDecoder_ktx.cpp
diff --git a/src/images/SkImageDecoder_ktx.cpp b/src/images/SkImageDecoder_ktx.cpp
index a95ab6f602d3610918b5874b10de50a76fd894de..f903b3fd5671a6446444c17ee4df7bf0ed6e73c4 100644
--- a/src/images/SkImageDecoder_ktx.cpp
+++ b/src/images/SkImageDecoder_ktx.cpp
@@ -252,34 +252,40 @@ SkImageDecoder::Result SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* b
class SkKTXImageEncoder : public SkImageEncoder {
protected:
bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) override;
+ SkData* onReencodeData(SkData*) override;
private:
virtual bool encodePKM(SkWStream* stream, const SkData *data);
typedef SkImageEncoder INHERITED;
};
+SkData* SkKTXImageEncoder::onReencodeData(SkData* encoded) {
+ const uint8_t* bytes = encoded->bytes();
+ if (etc1_pkm_is_valid(bytes)) {
+ SkDynamicMemoryWStream stream;
+ if (this->encodePKM(&stream, encoded)) {
+ return stream.copyToData();
+ }
+ }
+ // Is it a KTX file??
+ if (SkKTXFile::is_ktx(bytes)) {
+ return SkRef(encoded);
+ }
+ return nullptr;
+}
+
bool SkKTXImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int) {
if (!bitmap.pixelRef()) {
return false;
}
- SkAutoDataUnref 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);
- }
- // Is it a KTX file??
- if (SkKTXFile::is_ktx(bytes)) {
- return stream->write(bytes, data->size());
+ SkAutoDataUnref encoded(bitmap.pixelRef()->refEncodedData());
+ if (encoded) {
+ SkAutoDataUnref reencoded(this->onReencodeData(encoded));
+ if (reencoded) {
+ return stream->write(reencoded->bytes(), reencoded->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);
}
« no previous file with comments | « src/image/SkImage.cpp ('k') | src/images/SkImageEncoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698