OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
9 #include "SkScaledCodec.h" | 9 #include "SkScaledCodec.h" |
10 #include "SkStream.h" | 10 #include "SkStream.h" |
11 #include "SkWebpCodec.h" | 11 #include "SkWebpCodec.h" |
12 | 12 |
13 | 13 |
14 SkCodec* SkScaledCodec::NewFromStream(SkStream* stream) { | 14 SkCodec* SkScaledCodec::NewFromStream(SkStream* stream) { |
15 bool isWebp = SkWebpCodec::IsWebp(stream); | |
16 if (!stream->rewind()) { | |
17 return nullptr; | |
18 } | |
19 if (isWebp) { | |
20 // Webp codec supports scaling and subsetting natively | |
21 return SkWebpCodec::NewFromStream(stream); | |
22 } | |
23 | |
24 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream)); | 15 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream)); |
25 if (nullptr == codec) { | 16 if (nullptr == codec) { |
26 return nullptr; | 17 return nullptr; |
27 } | 18 } |
28 | 19 |
29 // wrap in new SkScaledCodec | 20 switch (codec->getEncodedFormat()) { |
30 return new SkScaledCodec(codec.detach()); | 21 case kWEBP_SkEncodedFormat: |
| 22 // Webp codec supports scaling and subsetting natively |
| 23 return codec.detach(); |
| 24 case kPNG_SkEncodedFormat: |
| 25 case kJPEG_SkEncodedFormat: |
| 26 // wrap in new SkScaledCodec |
| 27 return new SkScaledCodec(codec.detach()); |
| 28 default: |
| 29 // FIXME: SkScaledCodec is temporarily disabled for other formats |
| 30 // while focusing on the formats that are supported by |
| 31 // BitmapRegionDecoder. |
| 32 return nullptr; |
| 33 } |
31 } | 34 } |
32 | 35 |
33 SkCodec* SkScaledCodec::NewFromData(SkData* data) { | 36 SkCodec* SkScaledCodec::NewFromData(SkData* data) { |
34 if (!data) { | 37 if (!data) { |
35 return nullptr; | 38 return nullptr; |
36 } | 39 } |
37 return NewFromStream(new SkMemoryStream(data)); | 40 return NewFromStream(new SkMemoryStream(data)); |
38 } | 41 } |
39 | 42 |
40 SkScaledCodec::SkScaledCodec(SkCodec* codec) | 43 SkScaledCodec::SkScaledCodec(SkCodec* codec) |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 storagePtr += sampleY * rowBytes; | 299 storagePtr += sampleY * rowBytes; |
297 dst = SkTAddOffset<void>(dst, rowBytes); | 300 dst = SkTAddOffset<void>(dst, rowBytes); |
298 } | 301 } |
299 return result; | 302 return result; |
300 } | 303 } |
301 default: | 304 default: |
302 SkASSERT(false); | 305 SkASSERT(false); |
303 return kUnimplemented; | 306 return kUnimplemented; |
304 } | 307 } |
305 } | 308 } |
OLD | NEW |