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