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 "SkCodec.h" | 8 #include "SkCodec.h" |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkCodec_libbmp.h" | 10 #include "SkCodec_libbmp.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, | 25 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, |
26 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, | 26 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, |
27 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, | 27 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, |
28 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } | 28 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } |
29 }; | 29 }; |
30 | 30 |
31 SkCodec* SkCodec::NewFromStream(SkStream* stream) { | 31 SkCodec* SkCodec::NewFromStream(SkStream* stream) { |
32 if (!stream) { | 32 if (!stream) { |
33 return NULL; | 33 return NULL; |
34 } | 34 } |
| 35 |
| 36 SkAutoTDelete<SkStream> streamDeleter(stream); |
35 | 37 |
36 SkCodec* codec = NULL; | 38 SkAutoTDelete<SkCodec> codec(NULL); |
37 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { | 39 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { |
38 DecoderProc proc = gDecoderProcs[i]; | 40 DecoderProc proc = gDecoderProcs[i]; |
39 const bool correctFormat = proc.IsFormat(stream); | 41 const bool correctFormat = proc.IsFormat(stream); |
40 if (!stream->rewind()) { | 42 if (!stream->rewind()) { |
41 return NULL; | 43 return NULL; |
42 } | 44 } |
43 if (correctFormat) { | 45 if (correctFormat) { |
44 codec = proc.NewFromStream(stream); | 46 codec.reset(proc.NewFromStream(streamDeleter.detach())); |
45 break; | 47 break; |
46 } | 48 } |
47 } | 49 } |
48 | 50 |
49 // Set the max size at 128 megapixels (512 MB for kN32). | 51 // Set the max size at 128 megapixels (512 MB for kN32). |
50 // This is about 4x smaller than a test image that takes a few minutes for | 52 // This is about 4x smaller than a test image that takes a few minutes for |
51 // dm to decode and draw. | 53 // dm to decode and draw. |
52 const int32_t maxSize = 1 << 27; | 54 const int32_t maxSize = 1 << 27; |
53 if (codec != NULL && | 55 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize)
{ |
54 codec->getInfo().width() * codec->getInfo().height() > maxSize) { | |
55 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); | 56 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); |
56 return NULL; | 57 return NULL; |
57 } else { | 58 } else { |
58 return codec; | 59 return codec.detach(); |
59 } | 60 } |
60 } | 61 } |
61 | 62 |
62 SkCodec* SkCodec::NewFromData(SkData* data) { | 63 SkCodec* SkCodec::NewFromData(SkData* data) { |
63 if (!data) { | 64 if (!data) { |
64 return NULL; | 65 return NULL; |
65 } | 66 } |
66 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); | 67 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); |
67 } | 68 } |
68 | 69 |
(...skipping 15 matching lines...) Expand all Loading... |
84 return kNoRewindNecessary_RewindState; | 85 return kNoRewindNecessary_RewindState; |
85 } | 86 } |
86 return fStream->rewind() ? kRewound_RewindState | 87 return fStream->rewind() ? kRewound_RewindState |
87 : kCouldNotRewind_RewindState; | 88 : kCouldNotRewind_RewindState; |
88 } | 89 } |
89 | 90 |
90 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { | 91 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { |
91 fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo)); | 92 fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo)); |
92 return fScanlineDecoder.get(); | 93 return fScanlineDecoder.get(); |
93 } | 94 } |
OLD | NEW |