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 "SkBitmapRegionCanvas.h" | |
9 #include "SkBitmapRegionCodec.h" | 8 #include "SkBitmapRegionCodec.h" |
10 #include "SkBitmapRegionDecoder.h" | 9 #include "SkBitmapRegionDecoder.h" |
11 #include "SkAndroidCodec.h" | 10 #include "SkAndroidCodec.h" |
12 #include "SkCodec.h" | 11 #include "SkCodec.h" |
13 #include "SkCodecPriv.h" | 12 #include "SkCodecPriv.h" |
14 | 13 |
15 SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( | 14 SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( |
16 SkData* data, Strategy strategy) { | 15 SkData* data, Strategy strategy) { |
17 return SkBitmapRegionDecoder::Create(new SkMemoryStream(data), | 16 return SkBitmapRegionDecoder::Create(new SkMemoryStream(data), |
18 strategy); | 17 strategy); |
19 } | 18 } |
20 | 19 |
21 SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( | 20 SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( |
22 SkStreamRewindable* stream, Strategy strategy) { | 21 SkStreamRewindable* stream, Strategy strategy) { |
23 SkAutoTDelete<SkStreamRewindable> streamDeleter(stream); | 22 SkAutoTDelete<SkStreamRewindable> streamDeleter(stream); |
24 switch (strategy) { | 23 switch (strategy) { |
25 case kCanvas_Strategy: { | |
26 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(streamDeleter.re
lease())); | |
27 if (nullptr == codec) { | |
28 SkCodecPrintf("Error: Failed to create decoder.\n"); | |
29 return nullptr; | |
30 } | |
31 | |
32 SkEncodedFormat format = codec->getEncodedFormat(); | |
33 switch (format) { | |
34 case SkEncodedFormat::kJPEG_SkEncodedFormat: | |
35 case SkEncodedFormat::kPNG_SkEncodedFormat: | |
36 break; | |
37 default: | |
38 // FIXME: Support webp using a special case. Webp does not
support | |
39 // scanline decoding. | |
40 return nullptr; | |
41 } | |
42 | |
43 // If the image is a jpeg or a png, the scanline ordering should alw
ays be | |
44 // kTopDown or kNone. It is relevant to check because this implemen
tation | |
45 // only supports these two scanline orderings. | |
46 SkASSERT(SkCodec::kTopDown_SkScanlineOrder == codec->getScanlineOrde
r() || | |
47 SkCodec::kNone_SkScanlineOrder == codec->getScanlineOrder())
; | |
48 | |
49 return new SkBitmapRegionCanvas(codec.release()); | |
50 } | |
51 case kAndroidCodec_Strategy: { | 24 case kAndroidCodec_Strategy: { |
52 SkAutoTDelete<SkAndroidCodec> codec = | 25 SkAutoTDelete<SkAndroidCodec> codec = |
53 SkAndroidCodec::NewFromStream(streamDeleter.release()); | 26 SkAndroidCodec::NewFromStream(streamDeleter.release()); |
54 if (nullptr == codec) { | 27 if (nullptr == codec) { |
55 SkCodecPrintf("Error: Failed to create codec.\n"); | 28 SkCodecPrintf("Error: Failed to create codec.\n"); |
56 return NULL; | 29 return NULL; |
57 } | 30 } |
58 | 31 |
59 SkEncodedFormat format = codec->getEncodedFormat(); | 32 SkEncodedFormat format = codec->getEncodedFormat(); |
60 switch (format) { | 33 switch (format) { |
61 case SkEncodedFormat::kJPEG_SkEncodedFormat: | 34 case SkEncodedFormat::kJPEG_SkEncodedFormat: |
62 case SkEncodedFormat::kPNG_SkEncodedFormat: | 35 case SkEncodedFormat::kPNG_SkEncodedFormat: |
63 case SkEncodedFormat::kWEBP_SkEncodedFormat: | 36 case SkEncodedFormat::kWEBP_SkEncodedFormat: |
64 break; | 37 break; |
65 default: | 38 default: |
66 return nullptr; | 39 return nullptr; |
67 } | 40 } |
68 | 41 |
69 return new SkBitmapRegionCodec(codec.release()); | 42 return new SkBitmapRegionCodec(codec.release()); |
70 } | 43 } |
71 default: | 44 default: |
72 SkASSERT(false); | 45 SkASSERT(false); |
73 return nullptr; | 46 return nullptr; |
74 } | 47 } |
75 } | 48 } |
OLD | NEW |