| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 250 } |
| 251 | 251 |
| 252 SkISize dstDimensions = dstInfo.dimensions(); | 252 SkISize dstDimensions = dstInfo.dimensions(); |
| 253 if (bounds.size() != dstDimensions) { | 253 if (bounds.size() != dstDimensions) { |
| 254 // Caller is requesting scaling. | 254 // Caller is requesting scaling. |
| 255 config.options.use_scaling = 1; | 255 config.options.use_scaling = 1; |
| 256 config.options.scaled_width = dstDimensions.width(); | 256 config.options.scaled_width = dstDimensions.width(); |
| 257 config.options.scaled_height = dstDimensions.height(); | 257 config.options.scaled_height = dstDimensions.height(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 // FIXME (msarett): | 260 // Swizzling between RGBA and BGRA is zero cost in a color transform. So wh
en we have a |
| 261 // Lossless webp is encoded as BGRA. In that case, it would be more efficie
nt to | 261 // color transform, we should decode to whatever is easiest for libwebp, and
then let the |
| 262 // to decode BGRA and apply the color xform to a BGRA buffer. | 262 // color transform swizzle if necessary. |
| 263 config.output.colorspace = colorXform ? MODE_RGBA : | 263 // Lossy webp is encoded as YUV (so RGBA and BGRA are the same cost). Lossl
ess webp is |
| 264 // encoded as BGRA. This means decoding to BGRA is either faster or the same
cost as RGBA. |
| 265 config.output.colorspace = colorXform ? MODE_BGRA : |
| 264 webp_decode_mode(dstInfo.colorType(), dstInfo.alphaType() == kPremul
_SkAlphaType); | 266 webp_decode_mode(dstInfo.colorType(), dstInfo.alphaType() == kPremul
_SkAlphaType); |
| 265 config.output.is_external_memory = 1; | 267 config.output.is_external_memory = 1; |
| 266 | 268 |
| 267 // We will decode the entire image and then perform the color transform. li
bwebp | 269 // We will decode the entire image and then perform the color transform. li
bwebp |
| 268 // does not provide a row-by-row API. This is a shame particularly in the F
16 case, | 270 // does not provide a row-by-row API. This is a shame particularly in the F
16 case, |
| 269 // where we need to allocate an extra image-sized buffer. | 271 // where we need to allocate an extra image-sized buffer. |
| 270 SkAutoTMalloc<uint32_t> pixels; | 272 SkAutoTMalloc<uint32_t> pixels; |
| 271 if (kRGBA_F16_SkColorType == dstInfo.colorType()) { | 273 if (kRGBA_F16_SkColorType == dstInfo.colorType()) { |
| 272 pixels.reset(dstDimensions.width() * dstDimensions.height()); | 274 pixels.reset(dstDimensions.width() * dstDimensions.height()); |
| 273 config.output.u.RGBA.rgba = (uint8_t*) pixels.get(); | 275 config.output.u.RGBA.rgba = (uint8_t*) pixels.get(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 299 case VP8_STATUS_SUSPENDED: | 301 case VP8_STATUS_SUSPENDED: |
| 300 WebPIDecGetRGB(idec, rowsDecodedPtr, nullptr, nullptr, nullptr); | 302 WebPIDecGetRGB(idec, rowsDecodedPtr, nullptr, nullptr, nullptr); |
| 301 rowsDecoded = *rowsDecodedPtr; | 303 rowsDecoded = *rowsDecodedPtr; |
| 302 result = kIncompleteInput; | 304 result = kIncompleteInput; |
| 303 break; | 305 break; |
| 304 default: | 306 default: |
| 305 return kInvalidInput; | 307 return kInvalidInput; |
| 306 } | 308 } |
| 307 | 309 |
| 308 if (colorXform) { | 310 if (colorXform) { |
| 309 SkColorSpaceXform::ColorFormat colorFormat = select_xform_format(dstInfo
.colorType()); | 311 SkColorSpaceXform::ColorFormat dstColorFormat = select_xform_format(dstI
nfo.colorType()); |
| 310 SkAlphaType xformAlphaType = select_xform_alpha(dstInfo.alphaType(), | 312 SkAlphaType xformAlphaType = select_xform_alpha(dstInfo.alphaType(), |
| 311 this->getInfo().alphaTyp
e()); | 313 this->getInfo().alphaTyp
e()); |
| 312 | 314 |
| 313 uint32_t* src = (uint32_t*) config.output.u.RGBA.rgba; | 315 uint32_t* src = (uint32_t*) config.output.u.RGBA.rgba; |
| 314 size_t srcRowBytes = config.output.u.RGBA.stride; | 316 size_t srcRowBytes = config.output.u.RGBA.stride; |
| 315 for (int y = 0; y < rowsDecoded; y++) { | 317 for (int y = 0; y < rowsDecoded; y++) { |
| 316 colorXform->apply(dst, src, dstInfo.width(), colorFormat, xformAlpha
Type); | 318 colorXform->apply(dst, src, dstInfo.width(), dstColorFormat, |
| 319 SkColorSpaceXform::kBGRA_8888_ColorFormat, xformAl
phaType); |
| 317 dst = SkTAddOffset<void>(dst, rowBytes); | 320 dst = SkTAddOffset<void>(dst, rowBytes); |
| 318 src = SkTAddOffset<uint32_t>(src, srcRowBytes); | 321 src = SkTAddOffset<uint32_t>(src, srcRowBytes); |
| 319 } | 322 } |
| 320 } | 323 } |
| 321 | 324 |
| 322 return result; | 325 return result; |
| 323 } | 326 } |
| 324 | 327 |
| 325 SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info, | 328 SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info, |
| 326 sk_sp<SkColorSpace> colorSpace, SkStream* stream, WebPD
emuxer* demux, | 329 sk_sp<SkColorSpace> colorSpace, SkStream* stream, WebPD
emuxer* demux, |
| 327 sk_sp<SkData> data) | 330 sk_sp<SkData> data) |
| 328 : INHERITED(width, height, info, stream, std::move(colorSpace)) | 331 : INHERITED(width, height, info, stream, std::move(colorSpace)) |
| 329 , fDemux(demux) | 332 , fDemux(demux) |
| 330 , fData(std::move(data)) | 333 , fData(std::move(data)) |
| 331 {} | 334 {} |
| OLD | NEW |