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 "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
9 #include "SkWebpCodec.h" | 9 #include "SkWebpCodec.h" |
10 #include "SkTemplates.h" | 10 #include "SkTemplates.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 151 |
152 // As stated below, libwebp snaps to even left and top. Make sure top and le
ft are even, so we | 152 // As stated below, libwebp snaps to even left and top. Make sure top and le
ft are even, so we |
153 // decode this exact subset. | 153 // decode this exact subset. |
154 // Leave right and bottom unmodified, so we suggest a slightly larger subset
than requested. | 154 // Leave right and bottom unmodified, so we suggest a slightly larger subset
than requested. |
155 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; | 155 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; |
156 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; | 156 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; |
157 return true; | 157 return true; |
158 } | 158 } |
159 | 159 |
160 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
size_t rowBytes, | 160 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
size_t rowBytes, |
161 const Options& options, SkPMColor*, int
*) { | 161 const Options& options, SkPMColor*, int
*, |
| 162 int* rowsDecoded) { |
162 if (!webp_conversion_possible(dstInfo, this->getInfo())) { | 163 if (!webp_conversion_possible(dstInfo, this->getInfo())) { |
163 return kInvalidConversion; | 164 return kInvalidConversion; |
164 } | 165 } |
165 | 166 |
166 WebPDecoderConfig config; | 167 WebPDecoderConfig config; |
167 if (0 == WebPInitDecoderConfig(&config)) { | 168 if (0 == WebPInitDecoderConfig(&config)) { |
168 // ABI mismatch. | 169 // ABI mismatch. |
169 // FIXME: New enum for this? | 170 // FIXME: New enum for this? |
170 return kInvalidInput; | 171 return kInvalidInput; |
171 } | 172 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &co
nfig)); | 228 SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &co
nfig)); |
228 if (!idec) { | 229 if (!idec) { |
229 return kInvalidInput; | 230 return kInvalidInput; |
230 } | 231 } |
231 | 232 |
232 SkAutoMalloc storage(BUFFER_SIZE); | 233 SkAutoMalloc storage(BUFFER_SIZE); |
233 uint8_t* buffer = static_cast<uint8_t*>(storage.get()); | 234 uint8_t* buffer = static_cast<uint8_t*>(storage.get()); |
234 while (true) { | 235 while (true) { |
235 const size_t bytesRead = stream()->read(buffer, BUFFER_SIZE); | 236 const size_t bytesRead = stream()->read(buffer, BUFFER_SIZE); |
236 if (0 == bytesRead) { | 237 if (0 == bytesRead) { |
237 // FIXME: Maybe this is an incomplete image? How to decide? Based | 238 WebPIDecGetRGB(idec, rowsDecoded, NULL, NULL, NULL); |
238 // on the number of rows decoded? We can know the number of rows | 239 return kIncompleteInput; |
239 // decoded using WebPIDecGetRGB. | |
240 return kInvalidInput; | |
241 } | 240 } |
242 | 241 |
243 switch (WebPIAppend(idec, buffer, bytesRead)) { | 242 switch (WebPIAppend(idec, buffer, bytesRead)) { |
244 case VP8_STATUS_OK: | 243 case VP8_STATUS_OK: |
245 return kSuccess; | 244 return kSuccess; |
246 case VP8_STATUS_SUSPENDED: | 245 case VP8_STATUS_SUSPENDED: |
247 // Break out of the switch statement. Continue the loop. | 246 // Break out of the switch statement. Continue the loop. |
248 break; | 247 break; |
249 default: | 248 default: |
250 return kInvalidInput; | 249 return kInvalidInput; |
251 } | 250 } |
252 } | 251 } |
253 } | 252 } |
254 | 253 |
255 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) | 254 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) |
256 : INHERITED(info, stream) {} | 255 : INHERITED(info, stream) {} |
OLD | NEW |