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