| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { | 143 if (!desiredSubset) { |
| 144 return false; | 144 return false; |
| 145 } | 145 } |
| 146 | 146 |
| 147 SkIRect bounds = SkIRect::MakeSize(this->getInfo().dimensions()); | 147 SkIRect dimensions = SkIRect::MakeSize(this->getInfo().dimensions()); |
| 148 if (!desiredSubset->intersect(bounds)) { | 148 if (!dimensions.contains(*desiredSubset)) { |
| 149 return false; | 149 return false; |
| 150 } | 150 } |
| 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 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // Break out of the switch statement. Continue the loop. | 246 // Break out of the switch statement. Continue the loop. |
| 247 break; | 247 break; |
| 248 default: | 248 default: |
| 249 return kInvalidInput; | 249 return kInvalidInput; |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) | 254 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) |
| 255 : INHERITED(info, stream) {} | 255 : INHERITED(info, stream) {} |
| OLD | NEW |