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 "SkData.h" |
9 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
10 #include "SkScaledBitmapSampler.h" | 11 #include "SkScaledBitmapSampler.h" |
11 #include "SkStream.h" | 12 #include "SkStream.h" |
12 #include "SkStreamPriv.h" | 13 #include "SkStreamPriv.h" |
13 #include "SkTextureCompressor.h" | 14 #include "SkTextureCompressor.h" |
14 #include "SkTypes.h" | 15 #include "SkTypes.h" |
15 | 16 |
16 #include "etc1.h" | 17 #include "etc1.h" |
17 | 18 |
18 class SkPKMImageDecoder : public SkImageDecoder { | 19 class SkPKMImageDecoder : public SkImageDecoder { |
19 public: | 20 public: |
20 SkPKMImageDecoder() { } | 21 SkPKMImageDecoder() { } |
21 | 22 |
22 Format getFormat() const override { | 23 Format getFormat() const override { |
23 return kPKM_Format; | 24 return kPKM_Format; |
24 } | 25 } |
25 | 26 |
26 protected: | 27 protected: |
27 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override; | 28 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override; |
28 | 29 |
29 private: | 30 private: |
30 typedef SkImageDecoder INHERITED; | 31 typedef SkImageDecoder INHERITED; |
31 }; | 32 }; |
32 | 33 |
33 ////////////////////////////////////////////////////////////////////////////////
///////// | 34 ////////////////////////////////////////////////////////////////////////////////
///////// |
34 | 35 |
35 SkImageDecoder::Result SkPKMImageDecoder::onDecode(SkStream* stream, SkBitmap* b
m, Mode mode) { | 36 SkImageDecoder::Result SkPKMImageDecoder::onDecode(SkStream* stream, SkBitmap* b
m, Mode mode) { |
36 SkAutoMalloc autoMal; | 37 SkAutoTUnref<SkData> data(SkCopyStreamToData(stream)); |
37 const size_t length = SkCopyStreamToStorage(&autoMal, stream); | 38 if (!data || !data->size()) { |
38 if (0 == length) { | |
39 return kFailure; | 39 return kFailure; |
40 } | 40 } |
41 | 41 |
42 unsigned char* buf = (unsigned char*)autoMal.get(); | 42 unsigned char* buf = (unsigned char*) data->data(); |
43 | 43 |
44 // Make sure original PKM header is there... | 44 // Make sure original PKM header is there... |
45 SkASSERT(etc1_pkm_is_valid(buf)); | 45 SkASSERT(etc1_pkm_is_valid(buf)); |
46 | 46 |
47 const unsigned short width = etc1_pkm_get_width(buf); | 47 const unsigned short width = etc1_pkm_get_width(buf); |
48 const unsigned short height = etc1_pkm_get_height(buf); | 48 const unsigned short height = etc1_pkm_get_height(buf); |
49 | 49 |
50 // Setup the sampler... | 50 // Setup the sampler... |
51 SkScaledBitmapSampler sampler(width, height, this->getSampleSize()); | 51 SkScaledBitmapSampler sampler(width, height, this->getSampleSize()); |
52 | 52 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 static SkImageDecoder_DecodeReg gReg(sk_libpkm_dfactory); | 119 static SkImageDecoder_DecodeReg gReg(sk_libpkm_dfactory); |
120 | 120 |
121 static SkImageDecoder::Format get_format_pkm(SkStreamRewindable* stream) { | 121 static SkImageDecoder::Format get_format_pkm(SkStreamRewindable* stream) { |
122 if (is_pkm(stream)) { | 122 if (is_pkm(stream)) { |
123 return SkImageDecoder::kPKM_Format; | 123 return SkImageDecoder::kPKM_Format; |
124 } | 124 } |
125 return SkImageDecoder::kUnknown_Format; | 125 return SkImageDecoder::kUnknown_Format; |
126 } | 126 } |
127 | 127 |
128 static SkImageDecoder_FormatReg gFormatReg(get_format_pkm); | 128 static SkImageDecoder_FormatReg gFormatReg(get_format_pkm); |
OLD | NEW |