OLD | NEW |
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 "SkScaledBitmapSampler.h" | 10 #include "SkScaledBitmapSampler.h" |
11 #include "SkStream.h" | 11 #include "SkStream.h" |
12 #include "SkStreamPriv.h" | 12 #include "SkStreamPriv.h" |
13 #include "SkTextureCompressor.h" | |
14 #include "SkTypes.h" | 13 #include "SkTypes.h" |
15 | 14 |
16 #include "etc1.h" | 15 #include "etc1.h" |
17 | 16 |
18 class SkPKMImageDecoder : public SkImageDecoder { | 17 class SkPKMImageDecoder : public SkImageDecoder { |
19 public: | 18 public: |
20 SkPKMImageDecoder() { } | 19 SkPKMImageDecoder() { } |
21 | 20 |
22 virtual Format getFormat() const SK_OVERRIDE { | 21 virtual Format getFormat() const SK_OVERRIDE { |
23 return kPKM_Format; | 22 return kPKM_Format; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) { | 73 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) { |
75 return false; | 74 return false; |
76 } | 75 } |
77 | 76 |
78 // Advance buffer past the header | 77 // Advance buffer past the header |
79 buf += ETC_PKM_HEADER_SIZE; | 78 buf += ETC_PKM_HEADER_SIZE; |
80 | 79 |
81 // ETC1 Data is encoded as RGB pixels, so we should extract it as such | 80 // ETC1 Data is encoded as RGB pixels, so we should extract it as such |
82 int nPixels = width * height; | 81 int nPixels = width * height; |
83 SkAutoMalloc outRGBData(nPixels * 3); | 82 SkAutoMalloc outRGBData(nPixels * 3); |
84 uint8_t *outRGBDataPtr = reinterpret_cast<uint8_t *>(outRGBData.get()); | 83 etc1_byte *outRGBDataPtr = reinterpret_cast<etc1_byte *>(outRGBData.get()); |
85 | 84 |
86 // Decode ETC1 | 85 // Decode ETC1 |
87 if (!SkTextureCompressor::DecompressBufferFromFormat( | 86 if (etc1_decode_image(buf, outRGBDataPtr, width, height, 3, width*3)) { |
88 outRGBDataPtr, width*3, buf, width, height, SkTextureCompressor::kET
C1_Format)) { | |
89 return false; | 87 return false; |
90 } | 88 } |
91 | 89 |
92 // Set each of the pixels... | 90 // Set each of the pixels... |
93 const int srcRowBytes = width * 3; | 91 const int srcRowBytes = width * 3; |
94 const int dstHeight = sampler.scaledHeight(); | 92 const int dstHeight = sampler.scaledHeight(); |
95 const uint8_t *srcRow = reinterpret_cast<uint8_t *>(outRGBDataPtr); | 93 const uint8_t *srcRow = reinterpret_cast<uint8_t *>(outRGBDataPtr); |
96 srcRow += sampler.srcY0() * srcRowBytes; | 94 srcRow += sampler.srcY0() * srcRowBytes; |
97 for (int y = 0; y < dstHeight; ++y) { | 95 for (int y = 0; y < dstHeight; ++y) { |
98 sampler.next(srcRow); | 96 sampler.next(srcRow); |
(...skipping 27 matching lines...) Expand all Loading... |
126 static SkImageDecoder_DecodeReg gReg(sk_libpkm_dfactory); | 124 static SkImageDecoder_DecodeReg gReg(sk_libpkm_dfactory); |
127 | 125 |
128 static SkImageDecoder::Format get_format_pkm(SkStreamRewindable* stream) { | 126 static SkImageDecoder::Format get_format_pkm(SkStreamRewindable* stream) { |
129 if (is_pkm(stream)) { | 127 if (is_pkm(stream)) { |
130 return SkImageDecoder::kPKM_Format; | 128 return SkImageDecoder::kPKM_Format; |
131 } | 129 } |
132 return SkImageDecoder::kUnknown_Format; | 130 return SkImageDecoder::kUnknown_Format; |
133 } | 131 } |
134 | 132 |
135 static SkImageDecoder_FormatReg gFormatReg(get_format_pkm); | 133 static SkImageDecoder_FormatReg gFormatReg(get_format_pkm); |
OLD | NEW |