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