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" |
| 11 #include "SkCodec_libgif.h" |
11 #include "SkCodec_libico.h" | 12 #include "SkCodec_libico.h" |
12 #include "SkCodec_libpng.h" | 13 #include "SkCodec_libpng.h" |
13 #include "SkCodec_wbmp.h" | 14 #include "SkCodec_wbmp.h" |
| 15 #include "SkCodecPriv.h" |
14 #include "SkStream.h" | 16 #include "SkStream.h" |
15 | 17 |
16 struct DecoderProc { | 18 struct DecoderProc { |
17 bool (*IsFormat)(SkStream*); | 19 bool (*IsFormat)(SkStream*); |
18 SkCodec* (*NewFromStream)(SkStream*); | 20 SkCodec* (*NewFromStream)(SkStream*); |
19 }; | 21 }; |
20 | 22 |
21 static const DecoderProc gDecoderProcs[] = { | 23 static const DecoderProc gDecoderProcs[] = { |
22 { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, | 24 { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, |
| 25 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, |
23 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, | 26 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, |
24 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, | 27 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, |
25 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } | 28 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } |
26 }; | 29 }; |
27 | 30 |
28 SkCodec* SkCodec::NewFromStream(SkStream* stream) { | 31 SkCodec* SkCodec::NewFromStream(SkStream* stream) { |
29 if (!stream) { | 32 if (!stream) { |
30 return NULL; | 33 return NULL; |
31 } | 34 } |
| 35 |
| 36 SkCodec* codec = NULL; |
32 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { | 37 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { |
33 DecoderProc proc = gDecoderProcs[i]; | 38 DecoderProc proc = gDecoderProcs[i]; |
34 const bool correctFormat = proc.IsFormat(stream); | 39 const bool correctFormat = proc.IsFormat(stream); |
35 if (!stream->rewind()) { | 40 if (!stream->rewind()) { |
36 return NULL; | 41 return NULL; |
37 } | 42 } |
38 if (correctFormat) { | 43 if (correctFormat) { |
39 return proc.NewFromStream(stream); | 44 codec = proc.NewFromStream(stream); |
| 45 break; |
40 } | 46 } |
41 } | 47 } |
42 return NULL; | 48 |
| 49 // 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 |
| 51 // dm to decode and draw. |
| 52 const int32_t maxSize = 1 << 27; |
| 53 if (codec != NULL && |
| 54 codec->getInfo().width() * codec->getInfo().height() > maxSize) { |
| 55 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); |
| 56 return NULL; |
| 57 } else { |
| 58 return codec; |
| 59 } |
43 } | 60 } |
44 | 61 |
45 SkCodec* SkCodec::NewFromData(SkData* data) { | 62 SkCodec* SkCodec::NewFromData(SkData* data) { |
46 if (!data) { | 63 if (!data) { |
47 return NULL; | 64 return NULL; |
48 } | 65 } |
49 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); | 66 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); |
50 } | 67 } |
51 | 68 |
52 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) | 69 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) |
(...skipping 18 matching lines...) Expand all Loading... |
71 } | 88 } |
72 | 89 |
73 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { | 90 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { |
74 fScanlineDecoder.reset(NULL); | 91 fScanlineDecoder.reset(NULL); |
75 if (!rewindIfNeeded()) { | 92 if (!rewindIfNeeded()) { |
76 return NULL; | 93 return NULL; |
77 } | 94 } |
78 fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo)); | 95 fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo)); |
79 return fScanlineDecoder.get(); | 96 return fScanlineDecoder.get(); |
80 } | 97 } |
OLD | NEW |