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