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 "SkBmpCodec.h" | 8 #include "SkBmpCodec.h" |
9 #include "SkCodec.h" | 9 #include "SkCodec.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #endif | 31 #endif |
32 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream }, | 32 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream }, |
33 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, | 33 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, |
34 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, | 34 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, |
35 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, | 35 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, |
36 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } | 36 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } |
37 }; | 37 }; |
38 | 38 |
39 SkCodec* SkCodec::NewFromStream(SkStream* stream) { | 39 SkCodec* SkCodec::NewFromStream(SkStream* stream) { |
40 if (!stream) { | 40 if (!stream) { |
41 return NULL; | 41 return nullptr; |
42 } | 42 } |
43 | 43 |
44 SkAutoTDelete<SkStream> streamDeleter(stream); | 44 SkAutoTDelete<SkStream> streamDeleter(stream); |
45 | 45 |
46 SkAutoTDelete<SkCodec> codec(NULL); | 46 SkAutoTDelete<SkCodec> codec(nullptr); |
47 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { | 47 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { |
48 DecoderProc proc = gDecoderProcs[i]; | 48 DecoderProc proc = gDecoderProcs[i]; |
49 const bool correctFormat = proc.IsFormat(stream); | 49 const bool correctFormat = proc.IsFormat(stream); |
50 if (!stream->rewind()) { | 50 if (!stream->rewind()) { |
51 return NULL; | 51 return nullptr; |
52 } | 52 } |
53 if (correctFormat) { | 53 if (correctFormat) { |
54 codec.reset(proc.NewFromStream(streamDeleter.detach())); | 54 codec.reset(proc.NewFromStream(streamDeleter.detach())); |
55 break; | 55 break; |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 // Set the max size at 128 megapixels (512 MB for kN32). | 59 // Set the max size at 128 megapixels (512 MB for kN32). |
60 // This is about 4x smaller than a test image that takes a few minutes for | 60 // This is about 4x smaller than a test image that takes a few minutes for |
61 // dm to decode and draw. | 61 // dm to decode and draw. |
62 const int32_t maxSize = 1 << 27; | 62 const int32_t maxSize = 1 << 27; |
63 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize)
{ | 63 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize)
{ |
64 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); | 64 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); |
65 return NULL; | 65 return nullptr; |
66 } else { | 66 } else { |
67 return codec.detach(); | 67 return codec.detach(); |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 SkCodec* SkCodec::NewFromData(SkData* data) { | 71 SkCodec* SkCodec::NewFromData(SkData* data) { |
72 if (!data) { | 72 if (!data) { |
73 return NULL; | 73 return nullptr; |
74 } | 74 } |
75 return NewFromStream(new SkMemoryStream(data)); | 75 return NewFromStream(new SkMemoryStream(data)); |
76 } | 76 } |
77 | 77 |
78 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) | 78 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) |
79 : fInfo(info) | 79 : fInfo(info) |
80 , fStream(stream) | 80 , fStream(stream) |
81 , fNeedsRewind(false) | 81 , fNeedsRewind(false) |
82 {} | 82 {} |
83 | 83 |
(...skipping 13 matching lines...) Expand all Loading... |
97 } | 97 } |
98 | 98 |
99 return this->onRewind(); | 99 return this->onRewind(); |
100 } | 100 } |
101 | 101 |
102 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes, | 102 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes, |
103 const Options* options, SkPMColor ctable[], i
nt* ctableCount) { | 103 const Options* options, SkPMColor ctable[], i
nt* ctableCount) { |
104 if (kUnknown_SkColorType == info.colorType()) { | 104 if (kUnknown_SkColorType == info.colorType()) { |
105 return kInvalidConversion; | 105 return kInvalidConversion; |
106 } | 106 } |
107 if (NULL == pixels) { | 107 if (nullptr == pixels) { |
108 return kInvalidParameters; | 108 return kInvalidParameters; |
109 } | 109 } |
110 if (rowBytes < info.minRowBytes()) { | 110 if (rowBytes < info.minRowBytes()) { |
111 return kInvalidParameters; | 111 return kInvalidParameters; |
112 } | 112 } |
113 | 113 |
114 if (kIndex_8_SkColorType == info.colorType()) { | 114 if (kIndex_8_SkColorType == info.colorType()) { |
115 if (NULL == ctable || NULL == ctableCount) { | 115 if (nullptr == ctable || nullptr == ctableCount) { |
116 return kInvalidParameters; | 116 return kInvalidParameters; |
117 } | 117 } |
118 } else { | 118 } else { |
119 if (ctableCount) { | 119 if (ctableCount) { |
120 *ctableCount = 0; | 120 *ctableCount = 0; |
121 } | 121 } |
122 ctableCount = NULL; | 122 ctableCount = nullptr; |
123 ctable = NULL; | 123 ctable = nullptr; |
124 } | 124 } |
125 | 125 |
126 { | 126 { |
127 SkAlphaType canonical; | 127 SkAlphaType canonical; |
128 if (!SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &c
anonical) | 128 if (!SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &c
anonical) |
129 || canonical != info.alphaType()) | 129 || canonical != info.alphaType()) |
130 { | 130 { |
131 return kInvalidConversion; | 131 return kInvalidConversion; |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 // Default options. | 135 // Default options. |
136 Options optsStorage; | 136 Options optsStorage; |
137 if (NULL == options) { | 137 if (nullptr == options) { |
138 options = &optsStorage; | 138 options = &optsStorage; |
139 } | 139 } |
140 const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ct
able, ctableCount); | 140 const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ct
able, ctableCount); |
141 | 141 |
142 if ((kIncompleteInput == result || kSuccess == result) && ctableCount) { | 142 if ((kIncompleteInput == result || kSuccess == result) && ctableCount) { |
143 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); | 143 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); |
144 } | 144 } |
145 return result; | 145 return result; |
146 } | 146 } |
147 | 147 |
148 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes) { | 148 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes) { |
149 return this->getPixels(info, pixels, rowBytes, NULL, NULL, NULL); | 149 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); |
150 } | 150 } |
OLD | NEW |