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()) { |
msarett
2015/10/06 17:38:02
I'm opposed to this.
I think we've both done a si
scroggo
2015/10/06 17:52:41
Ignoring bugs is hard though. If we want to run na
| |
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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 storagePtr += sampleY * rowBytes; | 295 storagePtr += sampleY * rowBytes; |
293 dst = SkTAddOffset<void>(dst, rowBytes); | 296 dst = SkTAddOffset<void>(dst, rowBytes); |
294 } | 297 } |
295 return result; | 298 return result; |
296 } | 299 } |
297 default: | 300 default: |
298 SkASSERT(false); | 301 SkASSERT(false); |
299 return kUnimplemented; | 302 return kUnimplemented; |
300 } | 303 } |
301 } | 304 } |
OLD | NEW |