OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "SkBitmapRegionCanvas.h" | |
9 #include "SkBitmapRegionCodec.h" | |
10 #include "SkBitmapRegionDecoderInterface.h" | |
11 #include "SkBitmapRegionSampler.h" | |
12 #include "SkAndroidCodec.h" | |
13 #include "SkCodec.h" | |
14 #include "SkCodecPriv.h" | |
15 #include "SkImageDecoder.h" | |
16 | |
17 SkBitmapRegionDecoderInterface* SkBitmapRegionDecoderInterface::CreateBitmapRegi
onDecoder( | |
18 SkData* data, Strategy strategy) { | |
19 return SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(new SkMemor
yStream(data), | |
20 strategy); | |
21 } | |
22 | |
23 SkBitmapRegionDecoderInterface* SkBitmapRegionDecoderInterface::CreateBitmapRegi
onDecoder( | |
24 SkStreamRewindable* stream, Strategy strategy) { | |
25 SkAutoTDelete<SkStreamRewindable> streamDeleter(stream); | |
26 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: { | |
42 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(streamDeleter.de
tach())); | |
43 if (nullptr == codec) { | |
44 SkCodecPrintf("Error: Failed to create decoder.\n"); | |
45 return nullptr; | |
46 } | |
47 | |
48 if (SkEncodedFormat::kWEBP_SkEncodedFormat == codec->getEncodedForma
t()) { | |
49 // FIXME: Support webp using a special case. Webp does not supp
ort | |
50 // scanline decoding. | |
51 return nullptr; | |
52 } | |
53 | |
54 switch (codec->getScanlineOrder()) { | |
55 case SkCodec::kTopDown_SkScanlineOrder: | |
56 case SkCodec::kNone_SkScanlineOrder: | |
57 break; | |
58 default: | |
59 SkCodecPrintf("Error: Scanline ordering not supported.\n"); | |
60 return nullptr; | |
61 } | |
62 return new SkBitmapRegionCanvas(codec.detach()); | |
63 } | |
64 case kAndroidCodec_Strategy: { | |
65 SkAutoTDelete<SkAndroidCodec> codec = | |
66 SkAndroidCodec::NewFromStream(streamDeleter.detach()); | |
67 if (NULL == codec) { | |
68 SkCodecPrintf("Error: Failed to create codec.\n"); | |
69 return NULL; | |
70 } | |
71 return new SkBitmapRegionCodec(codec.detach()); | |
72 } | |
73 default: | |
74 SkASSERT(false); | |
75 return nullptr; | |
76 } | |
77 } | |
OLD | NEW |