| 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 "SkData.h" |
| 8 #include "SkEndian.h" | 9 #include "SkEndian.h" |
| 9 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 10 #include "SkImageDecoder.h" | 11 #include "SkImageDecoder.h" |
| 11 #include "SkScaledBitmapSampler.h" | 12 #include "SkScaledBitmapSampler.h" |
| 12 #include "SkStream.h" | 13 #include "SkStream.h" |
| 13 #include "SkStreamPriv.h" | 14 #include "SkStreamPriv.h" |
| 14 #include "SkTypes.h" | 15 #include "SkTypes.h" |
| 15 | 16 |
| 16 #include "SkTextureCompressor.h" | 17 #include "SkTextureCompressor.h" |
| 17 | 18 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 36 | 37 |
| 37 static inline int read_24bit(const uint8_t* buf) { | 38 static inline int read_24bit(const uint8_t* buf) { |
| 38 // Assume everything is little endian... | 39 // Assume everything is little endian... |
| 39 return | 40 return |
| 40 static_cast<int>(buf[0]) | | 41 static_cast<int>(buf[0]) | |
| 41 (static_cast<int>(buf[1]) << 8) | | 42 (static_cast<int>(buf[1]) << 8) | |
| 42 (static_cast<int>(buf[2]) << 16); | 43 (static_cast<int>(buf[2]) << 16); |
| 43 } | 44 } |
| 44 | 45 |
| 45 SkImageDecoder::Result SkASTCImageDecoder::onDecode(SkStream* stream, SkBitmap*
bm, Mode mode) { | 46 SkImageDecoder::Result SkASTCImageDecoder::onDecode(SkStream* stream, SkBitmap*
bm, Mode mode) { |
| 46 SkAutoMalloc autoMal; | 47 SkAutoTUnref<SkData> data(SkCopyStreamToData(stream)); |
| 47 const size_t length = SkCopyStreamToStorage(&autoMal, stream); | 48 if (!data || !data->size()) { |
| 48 if (0 == length) { | |
| 49 return kFailure; | 49 return kFailure; |
| 50 } | 50 } |
| 51 | 51 |
| 52 unsigned char* buf = (unsigned char*)autoMal.get(); | 52 unsigned char* buf = (unsigned char*) data->data(); |
| 53 | 53 |
| 54 // Make sure that the magic header is there... | 54 // Make sure that the magic header is there... |
| 55 SkASSERT(SkEndian_SwapLE32(*(reinterpret_cast<uint32_t*>(buf))) == kASTCMagi
cNumber); | 55 SkASSERT(SkEndian_SwapLE32(*(reinterpret_cast<uint32_t*>(buf))) == kASTCMagi
cNumber); |
| 56 | 56 |
| 57 // Advance past the magic header | 57 // Advance past the magic header |
| 58 buf += 4; | 58 buf += 4; |
| 59 | 59 |
| 60 const int blockDimX = buf[0]; | 60 const int blockDimX = buf[0]; |
| 61 const int blockDimY = buf[1]; | 61 const int blockDimY = buf[1]; |
| 62 const int blockDimZ = buf[2]; | 62 const int blockDimZ = buf[2]; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 static SkImageDecoder_DecodeReg gReg(sk_libastc_dfactory); | 194 static SkImageDecoder_DecodeReg gReg(sk_libastc_dfactory); |
| 195 | 195 |
| 196 static SkImageDecoder::Format get_format_astc(SkStreamRewindable* stream) { | 196 static SkImageDecoder::Format get_format_astc(SkStreamRewindable* stream) { |
| 197 if (is_astc(stream)) { | 197 if (is_astc(stream)) { |
| 198 return SkImageDecoder::kASTC_Format; | 198 return SkImageDecoder::kASTC_Format; |
| 199 } | 199 } |
| 200 return SkImageDecoder::kUnknown_Format; | 200 return SkImageDecoder::kUnknown_Format; |
| 201 } | 201 } |
| 202 | 202 |
| 203 static SkImageDecoder_FormatReg gFormatReg(get_format_astc); | 203 static SkImageDecoder_FormatReg gFormatReg(get_format_astc); |
| OLD | NEW |