| 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 #include "SkImageDecoder_astc.h" |
| 8 #include "SkColorPriv.h" |
| 8 #include "SkEndian.h" | 9 #include "SkEndian.h" |
| 9 #include "SkColorPriv.h" | |
| 10 #include "SkImageDecoder.h" | |
| 11 #include "SkScaledBitmapSampler.h" | 10 #include "SkScaledBitmapSampler.h" |
| 12 #include "SkStream.h" | 11 #include "SkStream.h" |
| 13 #include "SkStreamPriv.h" | 12 #include "SkStreamPriv.h" |
| 13 #include "SkTextureCompressor.h" |
| 14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 15 | 15 |
| 16 #include "SkTextureCompressor.h" | |
| 17 | |
| 18 class SkASTCImageDecoder : public SkImageDecoder { | 16 class SkASTCImageDecoder : public SkImageDecoder { |
| 19 public: | 17 public: |
| 20 SkASTCImageDecoder() { } | 18 SkASTCImageDecoder() { } |
| 21 | 19 |
| 22 virtual Format getFormat() const SK_OVERRIDE { | 20 virtual Format getFormat() const SK_OVERRIDE { |
| 23 return kASTC_Format; | 21 return kASTC_Format; |
| 24 } | 22 } |
| 25 | 23 |
| 26 protected: | 24 protected: |
| 27 virtual Result onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; | 25 virtual Result onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 const uint8_t *srcRow = reinterpret_cast<uint8_t *>(outRGBADataPtr); | 168 const uint8_t *srcRow = reinterpret_cast<uint8_t *>(outRGBADataPtr); |
| 171 srcRow += sampler.srcY0() * srcRowBytes; | 169 srcRow += sampler.srcY0() * srcRowBytes; |
| 172 for (int y = 0; y < dstHeight; ++y) { | 170 for (int y = 0; y < dstHeight; ++y) { |
| 173 sampler.next(srcRow); | 171 sampler.next(srcRow); |
| 174 srcRow += sampler.srcDY() * srcRowBytes; | 172 srcRow += sampler.srcDY() * srcRowBytes; |
| 175 } | 173 } |
| 176 | 174 |
| 177 return kSuccess; | 175 return kSuccess; |
| 178 } | 176 } |
| 179 | 177 |
| 180 ////////////////////////////////////////////////////////////////////////////////
///////// | 178 SkImageDecoder::Format SkDetectFormatASTCImageDecoder(SkStreamRewindable* stream
) { |
| 181 DEFINE_DECODER_CREATOR(ASTCImageDecoder); | |
| 182 ////////////////////////////////////////////////////////////////////////////////
///////// | |
| 183 | |
| 184 static bool is_astc(SkStreamRewindable* stream) { | |
| 185 // Read the ASTC header and make sure it's valid. | 179 // Read the ASTC header and make sure it's valid. |
| 186 uint32_t magic; | 180 uint32_t magic; |
| 187 if (stream->read((void*)&magic, 4) != 4) { | 181 if (stream->read((void*)&magic, 4) == 4 && |
| 188 return false; | 182 kASTCMagicNumber == SkEndian_SwapLE32(magic)) { |
| 189 } | |
| 190 | |
| 191 return kASTCMagicNumber == SkEndian_SwapLE32(magic); | |
| 192 } | |
| 193 | |
| 194 static SkImageDecoder* sk_libastc_dfactory(SkStreamRewindable* stream) { | |
| 195 if (is_astc(stream)) { | |
| 196 return SkNEW(SkASTCImageDecoder); | |
| 197 } | |
| 198 return NULL; | |
| 199 } | |
| 200 | |
| 201 static SkImageDecoder_DecodeReg gReg(sk_libastc_dfactory); | |
| 202 | |
| 203 static SkImageDecoder::Format get_format_astc(SkStreamRewindable* stream) { | |
| 204 if (is_astc(stream)) { | |
| 205 return SkImageDecoder::kASTC_Format; | 183 return SkImageDecoder::kASTC_Format; |
| 206 } | 184 } |
| 207 return SkImageDecoder::kUnknown_Format; | 185 return SkImageDecoder::kUnknown_Format; |
| 208 } | 186 } |
| 209 | 187 |
| 210 static SkImageDecoder_FormatReg gFormatReg(get_format_astc); | 188 SkImageDecoder* SkCreateASTCImageDecoder(SkImageDecoder::Format format) { |
| 189 SkASSERT(SkImageDecoder::kASTC_Format == format); |
| 190 return SkNEW(SkASTCImageDecoder); |
| 191 } |
| 192 |
| OLD | NEW |