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

Side by Side Diff: src/images/SkImageDecoder_ktx.cpp

Issue 440783004: Add support for all compressed formats in KTX file format (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix boolean stuff Created 6 years, 4 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 unified diff | Download patch
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | src/utils/SkTextureCompressor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 // If we've made it this far, then we know how to grok the data. 100 // If we've made it this far, then we know how to grok the data.
101 if (!this->allocPixelRef(bm, NULL)) { 101 if (!this->allocPixelRef(bm, NULL)) {
102 return false; 102 return false;
103 } 103 }
104 104
105 // Lock the pixels, since we're about to write to them... 105 // Lock the pixels, since we're about to write to them...
106 SkAutoLockPixels alp(*bm); 106 SkAutoLockPixels alp(*bm);
107 107
108 if (ktxFile.isETC1()) { 108 if (ktxFile.isCompressedFormat(SkTextureCompressor::kETC1_Format)) {
109 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) { 109 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) {
110 return false; 110 return false;
111 } 111 }
112 112
113 // ETC1 Data is encoded as RGB pixels, so we should extract it as such 113 // ETC1 Data is encoded as RGB pixels, so we should extract it as such
114 int nPixels = width * height; 114 int nPixels = width * height;
115 SkAutoMalloc outRGBData(nPixels * 3); 115 SkAutoMalloc outRGBData(nPixels * 3);
116 etc1_byte *outRGBDataPtr = reinterpret_cast<etc1_byte *>(outRGBData.get( )); 116 uint8_t *outRGBDataPtr = reinterpret_cast<uint8_t *>(outRGBData.get());
117 117
118 // Decode ETC1 118 // Decode ETC1
119 const etc1_byte *buf = reinterpret_cast<const etc1_byte *>(ktxFile.pixel Data()); 119 const uint8_t *buf = reinterpret_cast<const uint8_t *>(ktxFile.pixelData ());
120 if (etc1_decode_image(buf, outRGBDataPtr, width, height, 3, width*3)) { 120 if (!SkTextureCompressor::DecompressBufferFromFormat(
121 outRGBDataPtr, width*3, buf, width, height, SkTextureCompressor: :kETC1_Format)) {
121 return false; 122 return false;
122 } 123 }
123 124
124 // Set each of the pixels... 125 // Set each of the pixels...
125 const int srcRowBytes = width * 3; 126 const int srcRowBytes = width * 3;
126 const int dstHeight = sampler.scaledHeight(); 127 const int dstHeight = sampler.scaledHeight();
127 const uint8_t *srcRow = reinterpret_cast<uint8_t *>(outRGBDataPtr); 128 const uint8_t *srcRow = reinterpret_cast<uint8_t *>(outRGBDataPtr);
128 srcRow += sampler.srcY0() * srcRowBytes; 129 srcRow += sampler.srcY0() * srcRowBytes;
129 for (int y = 0; y < dstHeight; ++y) { 130 for (int y = 0; y < dstHeight; ++y) {
130 sampler.next(srcRow); 131 sampler.next(srcRow);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 return SkImageDecoder::kUnknown_Format; 272 return SkImageDecoder::kUnknown_Format;
272 } 273 }
273 274
274 SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) { 275 SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) {
275 return (SkImageEncoder::kKTX_Type == t) ? SkNEW(SkKTXImageEncoder) : NULL; 276 return (SkImageEncoder::kKTX_Type == t) ? SkNEW(SkKTXImageEncoder) : NULL;
276 } 277 }
277 278
278 static SkImageDecoder_DecodeReg gReg(sk_libktx_dfactory); 279 static SkImageDecoder_DecodeReg gReg(sk_libktx_dfactory);
279 static SkImageDecoder_FormatReg gFormatReg(get_format_ktx); 280 static SkImageDecoder_FormatReg gFormatReg(get_format_ktx);
280 static SkImageEncoder_EncodeReg gEReg(sk_libktx_efactory); 281 static SkImageEncoder_EncodeReg gEReg(sk_libktx_efactory);
OLDNEW
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | src/utils/SkTextureCompressor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698