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 "SkBitmapRegionDecoderInterface.h" | 10 #include "SkBitmapRegionDecoderInterface.h" |
10 #include "SkBitmapRegionSampler.h" | 11 #include "SkBitmapRegionSampler.h" |
| 12 #include "SkAndroidCodec.h" |
11 #include "SkCodec.h" | 13 #include "SkCodec.h" |
12 #include "SkCodecPriv.h" | 14 #include "SkCodecPriv.h" |
13 #include "SkImageDecoder.h" | 15 #include "SkImageDecoder.h" |
14 | 16 |
15 SkBitmapRegionDecoderInterface* SkBitmapRegionDecoderInterface::CreateBitmapRegi
onDecoder( | 17 SkBitmapRegionDecoderInterface* SkBitmapRegionDecoderInterface::CreateBitmapRegi
onDecoder( |
16 SkStreamRewindable* stream, Strategy strategy) { | 18 SkData* data, Strategy strategy) { |
17 SkAutoTDelete<SkStreamRewindable> streamDeleter(stream); | |
18 switch (strategy) { | 19 switch (strategy) { |
19 case kOriginal_Strategy: { | 20 case kOriginal_Strategy: { |
| 21 SkAutoTDelete<SkStreamRewindable> stream(new SkMemoryStream(data)); |
20 SkImageDecoder* decoder = SkImageDecoder::Factory(stream); | 22 SkImageDecoder* decoder = SkImageDecoder::Factory(stream); |
21 int width, height; | 23 int width, height; |
22 if (nullptr == decoder) { | 24 if (nullptr == decoder) { |
23 SkCodecPrintf("Error: Could not create image decoder.\n"); | 25 SkCodecPrintf("Error: Could not create image decoder.\n"); |
24 return nullptr; | 26 return nullptr; |
25 } | 27 } |
26 if (!decoder->buildTileIndex(streamDeleter.detach(), &width, &height
)) { | 28 if (!decoder->buildTileIndex(stream.detach(), &width, &height)) { |
27 SkCodecPrintf("Error: Could not build tile index.\n"); | 29 SkCodecPrintf("Error: Could not build tile index.\n"); |
28 delete decoder; | 30 delete decoder; |
29 return nullptr; | 31 return nullptr; |
30 } | 32 } |
31 return new SkBitmapRegionSampler(decoder, width, height); | 33 return new SkBitmapRegionSampler(decoder, width, height); |
32 } | 34 } |
33 case kCanvas_Strategy: { | 35 case kCanvas_Strategy: { |
34 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(streamDeleter.de
tach())); | 36 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data)); |
35 if (nullptr == codec) { | 37 if (nullptr == codec) { |
36 SkCodecPrintf("Error: Failed to create decoder.\n"); | 38 SkCodecPrintf("Error: Failed to create decoder.\n"); |
37 return nullptr; | 39 return nullptr; |
38 } | 40 } |
39 switch (codec->getScanlineOrder()) { | 41 switch (codec->getScanlineOrder()) { |
40 case SkCodec::kTopDown_SkScanlineOrder: | 42 case SkCodec::kTopDown_SkScanlineOrder: |
41 case SkCodec::kNone_SkScanlineOrder: | 43 case SkCodec::kNone_SkScanlineOrder: |
42 break; | 44 break; |
43 default: | 45 default: |
44 SkCodecPrintf("Error: Scanline ordering not supported.\n"); | 46 SkCodecPrintf("Error: Scanline ordering not supported.\n"); |
45 return nullptr; | 47 return nullptr; |
46 } | 48 } |
47 return new SkBitmapRegionCanvas(codec.detach()); | 49 return new SkBitmapRegionCanvas(codec.detach()); |
48 } | 50 } |
| 51 case kAndroidCodec_Strategy: { |
| 52 SkAutoTDelete<SkAndroidCodec> codec = SkAndroidCodec::NewFromData(da
ta); |
| 53 if (NULL == codec) { |
| 54 SkCodecPrintf("Error: Failed to create codec.\n"); |
| 55 return NULL; |
| 56 } |
| 57 return new SkBitmapRegionCodec(codec.detach()); |
| 58 } |
49 default: | 59 default: |
50 SkASSERT(false); | 60 SkASSERT(false); |
51 return nullptr; | 61 return nullptr; |
52 } | 62 } |
53 } | 63 } |
OLD | NEW |