| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 return MODE_LAST; | 133 return MODE_LAST; |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 // The WebP decoding API allows us to incrementally pass chunks of bytes as we r
eceive them to the | 137 // The WebP decoding API allows us to incrementally pass chunks of bytes as we r
eceive them to the |
| 138 // decoder with WebPIAppend. In order to do so, we need to read chunks from the
SkStream. This size | 138 // decoder with WebPIAppend. In order to do so, we need to read chunks from the
SkStream. This size |
| 139 // is arbitrary. | 139 // is arbitrary. |
| 140 static const size_t BUFFER_SIZE = 4096; | 140 static const size_t BUFFER_SIZE = 4096; |
| 141 | 141 |
| 142 bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const { | 142 bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const { |
| 143 if (!desiredSubset) { | |
| 144 return false; | |
| 145 } | |
| 146 | |
| 147 SkIRect bounds = SkIRect::MakeSize(this->getInfo().dimensions()); | |
| 148 if (!desiredSubset->intersect(bounds)) { | |
| 149 return false; | |
| 150 } | |
| 151 | |
| 152 // As stated below, libwebp snaps to even left and top. Make sure top and le
ft are even, so we | 143 // 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. | 144 // decode this exact subset. |
| 154 // Leave right and bottom unmodified, so we suggest a slightly larger subset
than requested. | 145 // Leave right and bottom unmodified, so we suggest a slightly larger subset
than requested. |
| 155 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; | 146 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; |
| 156 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; | 147 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; |
| 157 return true; | 148 return true; |
| 158 } | 149 } |
| 159 | 150 |
| 160 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
size_t rowBytes, | 151 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
size_t rowBytes, |
| 161 const Options& options, SkPMColor*, int
*, | 152 const Options& options, SkPMColor*, int
*, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // Break out of the switch statement. Continue the loop. | 237 // Break out of the switch statement. Continue the loop. |
| 247 break; | 238 break; |
| 248 default: | 239 default: |
| 249 return kInvalidInput; | 240 return kInvalidInput; |
| 250 } | 241 } |
| 251 } | 242 } |
| 252 } | 243 } |
| 253 | 244 |
| 254 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) | 245 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) |
| 255 : INHERITED(info, stream) {} | 246 : INHERITED(info, stream) {} |
| OLD | NEW |