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 "SkScanlineDecoder.h" | 8 #include "SkScanlineDecoder.h" |
9 #include "SkCodec_libpng.h" | 9 #include "SkCodec_libpng.h" |
10 #include "SkCodec_wbmp.h" | 10 #include "SkCodec_wbmp.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 static const DecoderProc gDecoderProcs[] = { | 21 static const DecoderProc gDecoderProcs[] = { |
22 { SkPngCodec::IsPng, SkPngCodec::NewSDFromStream }, | 22 { SkPngCodec::IsPng, SkPngCodec::NewSDFromStream }, |
23 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK | 23 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK |
24 { SkJpegCodec::IsJpeg, SkJpegCodec::NewSDFromStream }, | 24 { SkJpegCodec::IsJpeg, SkJpegCodec::NewSDFromStream }, |
25 #endif | 25 #endif |
26 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewSDFromStream }, | 26 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewSDFromStream }, |
27 }; | 27 }; |
28 | 28 |
29 SkScanlineDecoder* SkScanlineDecoder::NewFromStream(SkStream* stream) { | 29 SkScanlineDecoder* SkScanlineDecoder::NewFromStream(SkStream* stream) { |
30 if (!stream) { | 30 if (!stream) { |
31 return NULL; | 31 return nullptr; |
32 } | 32 } |
33 | 33 |
34 SkAutoTDelete<SkStream> streamDeleter(stream); | 34 SkAutoTDelete<SkStream> streamDeleter(stream); |
35 | 35 |
36 SkAutoTDelete<SkScanlineDecoder> codec(NULL); | 36 SkAutoTDelete<SkScanlineDecoder> codec(nullptr); |
37 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { | 37 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { |
38 DecoderProc proc = gDecoderProcs[i]; | 38 DecoderProc proc = gDecoderProcs[i]; |
39 const bool correctFormat = proc.IsFormat(stream); | 39 const bool correctFormat = proc.IsFormat(stream); |
40 if (!stream->rewind()) { | 40 if (!stream->rewind()) { |
41 return NULL; | 41 return nullptr; |
42 } | 42 } |
43 if (correctFormat) { | 43 if (correctFormat) { |
44 codec.reset(proc.NewFromStream(streamDeleter.detach())); | 44 codec.reset(proc.NewFromStream(streamDeleter.detach())); |
45 break; | 45 break; |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 // Set the max size at 128 megapixels (512 MB for kN32). | 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 | 50 // This is about 4x smaller than a test image that takes a few minutes for |
51 // dm to decode and draw. | 51 // dm to decode and draw. |
52 const int32_t maxSize = 1 << 27; | 52 const int32_t maxSize = 1 << 27; |
53 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize)
{ | 53 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize)
{ |
54 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); | 54 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); |
55 return NULL; | 55 return nullptr; |
56 } else { | 56 } else { |
57 return codec.detach(); | 57 return codec.detach(); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 SkScanlineDecoder* SkScanlineDecoder::NewFromData(SkData* data) { | 61 SkScanlineDecoder* SkScanlineDecoder::NewFromData(SkData* data) { |
62 if (!data) { | 62 if (!data) { |
63 return NULL; | 63 return nullptr; |
64 } | 64 } |
65 return NewFromStream(new SkMemoryStream(data)); | 65 return NewFromStream(new SkMemoryStream(data)); |
66 } | 66 } |
67 | 67 |
68 | 68 |
69 SkCodec::Result SkScanlineDecoder::start(const SkImageInfo& dstInfo, | 69 SkCodec::Result SkScanlineDecoder::start(const SkImageInfo& dstInfo, |
70 const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) { | 70 const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) { |
71 // Ensure that valid color ptrs are passed in for kIndex8 color type | 71 // Ensure that valid color ptrs are passed in for kIndex8 color type |
72 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 72 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
73 if (NULL == ctable || NULL == ctableCount) { | 73 if (nullptr == ctable || nullptr == ctableCount) { |
74 return SkCodec::kInvalidParameters; | 74 return SkCodec::kInvalidParameters; |
75 } | 75 } |
76 } else { | 76 } else { |
77 if (ctableCount) { | 77 if (ctableCount) { |
78 *ctableCount = 0; | 78 *ctableCount = 0; |
79 } | 79 } |
80 ctableCount = NULL; | 80 ctableCount = nullptr; |
81 ctable = NULL; | 81 ctable = nullptr; |
82 } | 82 } |
83 | 83 |
84 // Set options. | 84 // Set options. |
85 SkCodec::Options optsStorage; | 85 SkCodec::Options optsStorage; |
86 if (NULL == options) { | 86 if (nullptr == options) { |
87 options = &optsStorage; | 87 options = &optsStorage; |
88 } | 88 } |
89 | 89 |
90 const SkCodec::Result result = this->onStart(dstInfo, *options, ctable, ctab
leCount); | 90 const SkCodec::Result result = this->onStart(dstInfo, *options, ctable, ctab
leCount); |
91 if (result != SkCodec::kSuccess) { | 91 if (result != SkCodec::kSuccess) { |
92 return result; | 92 return result; |
93 } | 93 } |
94 | 94 |
95 fCurrScanline = 0; | 95 fCurrScanline = 0; |
96 fDstInfo = dstInfo; | 96 fDstInfo = dstInfo; |
97 return SkCodec::kSuccess; | 97 return SkCodec::kSuccess; |
98 } | 98 } |
99 | 99 |
100 SkCodec::Result SkScanlineDecoder::start(const SkImageInfo& dstInfo) { | 100 SkCodec::Result SkScanlineDecoder::start(const SkImageInfo& dstInfo) { |
101 return this->start(dstInfo, NULL, NULL, NULL); | 101 return this->start(dstInfo, nullptr, nullptr, nullptr); |
102 } | 102 } |
103 | 103 |
OLD | NEW |