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" | 8 #include "SkBitmapRegionCanvas.h" |
9 #include "SkBitmapRegionCodec.h" | 9 #include "SkBitmapRegionCodec.h" |
10 #include "SkBitmapRegionDecoder.h" | 10 #include "SkBitmapRegionDecoder.h" |
11 #include "SkBitmapRegionSampler.h" | |
12 #include "SkAndroidCodec.h" | 11 #include "SkAndroidCodec.h" |
13 #include "SkCodec.h" | 12 #include "SkCodec.h" |
14 #include "SkCodecPriv.h" | 13 #include "SkCodecPriv.h" |
15 #include "SkImageDecoder.h" | 14 #include "SkImageDecoder.h" |
16 | 15 |
17 SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( | 16 SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( |
18 SkData* data, Strategy strategy) { | 17 SkData* data, Strategy strategy) { |
19 return SkBitmapRegionDecoder::Create(new SkMemoryStream(data), | 18 return SkBitmapRegionDecoder::Create(new SkMemoryStream(data), |
20 strategy); | 19 strategy); |
21 } | 20 } |
22 | 21 |
23 SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( | 22 SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( |
24 SkStreamRewindable* stream, Strategy strategy) { | 23 SkStreamRewindable* stream, Strategy strategy) { |
25 SkAutoTDelete<SkStreamRewindable> streamDeleter(stream); | 24 SkAutoTDelete<SkStreamRewindable> streamDeleter(stream); |
26 switch (strategy) { | 25 switch (strategy) { |
27 case kOriginal_Strategy: { | |
28 SkImageDecoder* decoder = SkImageDecoder::Factory(streamDeleter); | |
29 int width, height; | |
30 if (nullptr == decoder) { | |
31 SkCodecPrintf("Error: Could not create image decoder.\n"); | |
32 return nullptr; | |
33 } | |
34 if (!decoder->buildTileIndex(streamDeleter.detach(), &width, &height
)) { | |
35 SkCodecPrintf("Error: Could not build tile index.\n"); | |
36 delete decoder; | |
37 return nullptr; | |
38 } | |
39 return new SkBitmapRegionSampler(decoder, width, height); | |
40 } | |
41 case kCanvas_Strategy: { | 26 case kCanvas_Strategy: { |
42 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(streamDeleter.de
tach())); | 27 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(streamDeleter.de
tach())); |
43 if (nullptr == codec) { | 28 if (nullptr == codec) { |
44 SkCodecPrintf("Error: Failed to create decoder.\n"); | 29 SkCodecPrintf("Error: Failed to create decoder.\n"); |
45 return nullptr; | 30 return nullptr; |
46 } | 31 } |
47 | 32 |
48 if (SkEncodedFormat::kWEBP_SkEncodedFormat == codec->getEncodedForma
t()) { | 33 if (SkEncodedFormat::kWEBP_SkEncodedFormat == codec->getEncodedForma
t()) { |
49 // FIXME: Support webp using a special case. Webp does not supp
ort | 34 // FIXME: Support webp using a special case. Webp does not supp
ort |
50 // scanline decoding. | 35 // scanline decoding. |
(...skipping 17 matching lines...) Expand all Loading... |
68 SkCodecPrintf("Error: Failed to create codec.\n"); | 53 SkCodecPrintf("Error: Failed to create codec.\n"); |
69 return NULL; | 54 return NULL; |
70 } | 55 } |
71 return new SkBitmapRegionCodec(codec.detach()); | 56 return new SkBitmapRegionCodec(codec.detach()); |
72 } | 57 } |
73 default: | 58 default: |
74 SkASSERT(false); | 59 SkASSERT(false); |
75 return nullptr; | 60 return nullptr; |
76 } | 61 } |
77 } | 62 } |
OLD | NEW |