| 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 "SkColorSpaceXform.h" | 9 #include "SkColorSpaceXform.h" |
| 10 #include "SkWebpCodec.h" | 10 #include "SkWebpCodec.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 break; | 137 break; |
| 138 default: | 138 default: |
| 139 return nullptr; | 139 return nullptr; |
| 140 } | 140 } |
| 141 | 141 |
| 142 SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8); | 142 SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8); |
| 143 return new SkWebpCodec(features.width, features.height, info, std::move(colo
rSpace), | 143 return new SkWebpCodec(features.width, features.height, info, std::move(colo
rSpace), |
| 144 streamDeleter.release(), demux.release(), std::move(d
ata)); | 144 streamDeleter.release(), demux.release(), std::move(d
ata)); |
| 145 } | 145 } |
| 146 | 146 |
| 147 static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo&
src, | |
| 148 SkColorSpaceXform* colorXform) { | |
| 149 if (!valid_alpha(dst.alphaType(), src.alphaType())) { | |
| 150 return false; | |
| 151 } | |
| 152 | |
| 153 switch (dst.colorType()) { | |
| 154 case kRGBA_F16_SkColorType: | |
| 155 return nullptr != colorXform; | |
| 156 case kBGRA_8888_SkColorType: | |
| 157 case kRGBA_8888_SkColorType: | |
| 158 return true; | |
| 159 case kRGB_565_SkColorType: | |
| 160 return nullptr == colorXform && src.alphaType() == kOpaque_SkAlphaTy
pe; | |
| 161 default: | |
| 162 return false; | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const { | 147 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const { |
| 167 SkISize dim = this->getInfo().dimensions(); | 148 SkISize dim = this->getInfo().dimensions(); |
| 168 // SkCodec treats zero dimensional images as errors, so the minimum size | 149 // SkCodec treats zero dimensional images as errors, so the minimum size |
| 169 // that we will recommend is 1x1. | 150 // that we will recommend is 1x1. |
| 170 dim.fWidth = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fWidth)); | 151 dim.fWidth = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fWidth)); |
| 171 dim.fHeight = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fHeight)); | 152 dim.fHeight = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fHeight)); |
| 172 return dim; | 153 return dim; |
| 173 } | 154 } |
| 174 | 155 |
| 175 bool SkWebpCodec::onDimensionsSupported(const SkISize& dim) { | 156 bool SkWebpCodec::onDimensionsSupported(const SkISize& dim) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 205 // decode this exact subset. | 186 // decode this exact subset. |
| 206 // Leave right and bottom unmodified, so we suggest a slightly larger subset
than requested. | 187 // Leave right and bottom unmodified, so we suggest a slightly larger subset
than requested. |
| 207 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; | 188 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; |
| 208 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; | 189 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; |
| 209 return true; | 190 return true; |
| 210 } | 191 } |
| 211 | 192 |
| 212 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
size_t rowBytes, | 193 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
size_t rowBytes, |
| 213 const Options& options, SkPMColor*, int
*, | 194 const Options& options, SkPMColor*, int
*, |
| 214 int* rowsDecodedPtr) { | 195 int* rowsDecodedPtr) { |
| 196 if (!conversion_possible(dstInfo, this->getInfo())) { |
| 197 return kInvalidConversion; |
| 198 } |
| 215 | 199 |
| 216 std::unique_ptr<SkColorSpaceXform> colorXform = nullptr; | 200 std::unique_ptr<SkColorSpaceXform> colorXform = nullptr; |
| 217 if (needs_color_xform(dstInfo, this->getInfo())) { | 201 if (needs_color_xform(dstInfo, this->getInfo())) { |
| 218 colorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace
()), | 202 colorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace
()), |
| 219 sk_ref_sp(dstInfo.colorSpace())); | 203 sk_ref_sp(dstInfo.colorSpace())); |
| 220 } | 204 SkASSERT(colorXform); |
| 221 | |
| 222 if (!webp_conversion_possible(dstInfo, this->getInfo(), colorXform.get())) { | |
| 223 return kInvalidConversion; | |
| 224 } | 205 } |
| 225 | 206 |
| 226 WebPDecoderConfig config; | 207 WebPDecoderConfig config; |
| 227 if (0 == WebPInitDecoderConfig(&config)) { | 208 if (0 == WebPInitDecoderConfig(&config)) { |
| 228 // ABI mismatch. | 209 // ABI mismatch. |
| 229 // FIXME: New enum for this? | 210 // FIXME: New enum for this? |
| 230 return kInvalidInput; | 211 return kInvalidInput; |
| 231 } | 212 } |
| 232 | 213 |
| 233 // Free any memory associated with the buffer. Must be called last, so we de
clare it first. | 214 // Free any memory associated with the buffer. Must be called last, so we de
clare it first. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 return result; | 322 return result; |
| 342 } | 323 } |
| 343 | 324 |
| 344 SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info, | 325 SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info, |
| 345 sk_sp<SkColorSpace> colorSpace, SkStream* stream, WebPD
emuxer* demux, | 326 sk_sp<SkColorSpace> colorSpace, SkStream* stream, WebPD
emuxer* demux, |
| 346 sk_sp<SkData> data) | 327 sk_sp<SkData> data) |
| 347 : INHERITED(width, height, info, stream, std::move(colorSpace)) | 328 : INHERITED(width, height, info, stream, std::move(colorSpace)) |
| 348 , fDemux(demux) | 329 , fDemux(demux) |
| 349 , fData(std::move(data)) | 330 , fData(std::move(data)) |
| 350 {} | 331 {} |
| OLD | NEW |