scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 8 | #include "SkCodecPriv.h" |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 9 | #include "SkColorSpaceXform.h" |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 10 | #include "SkWebpCodec.h" |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 11 | #include "SkStreamPriv.h" |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 12 | #include "SkTemplates.h" |
| 13 | |
| 14 | // A WebP decoder on top of (subset of) libwebp |
| 15 | // For more information on WebP image format, and libwebp library, see: |
| 16 | // https://code.google.com/speed/webp/ |
| 17 | // http://www.webmproject.org/code/#libwebp-webp-image-library |
| 18 | // https://chromium.googlesource.com/webm/libwebp |
| 19 | |
| 20 | // If moving libwebp out of skia source tree, path for webp headers must be |
| 21 | // updated accordingly. Here, we enforce using local copy in webp sub-directory. |
| 22 | #include "webp/decode.h" |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 23 | #include "webp/demux.h" |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 24 | #include "webp/encode.h" |
| 25 | |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 26 | bool SkWebpCodec::IsWebp(const void* buf, size_t bytesRead) { |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 27 | // WEBP starts with the following: |
| 28 | // RIFFXXXXWEBPVP |
| 29 | // Where XXXX is unspecified. |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 30 | const char* bytes = static_cast<const char*>(buf); |
| 31 | return bytesRead >= 14 && !memcmp(bytes, "RIFF", 4) && !memcmp(&bytes[8], "WEBPVP", 6); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 32 | } |
| 33 | |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 34 | // Parse headers of RIFF container, and check for valid Webp (VP8) content. |
| 35 | // NOTE: This calls peek instead of read, since onGetPixels will need these |
| 36 | // bytes again. |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 37 | // Returns an SkWebpCodec on success; |
| 38 | SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { |
| 39 | SkAutoTDelete<SkStream> streamDeleter(stream); |
| 40 | |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 41 | // Webp demux needs a contiguous data buffer. |
| 42 | sk_sp<SkData> data = nullptr; |
| 43 | if (stream->getMemoryBase()) { |
| 44 | // It is safe to make without copy because we'll hold onto the stream. |
| 45 | data = SkData::MakeWithoutCopy(stream->getMemoryBase(), stream->getLength()); |
| 46 | } else { |
| 47 | data = SkCopyStreamToData(stream); |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 48 | |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 49 | // If we are forced to copy the stream to a data, we can go ahead and delete the stream. |
| 50 | streamDeleter.reset(nullptr); |
| 51 | } |
| 52 | |
| 53 | // It's a little strange that the |demux| will outlive |webpData|, though it needs the |
| 54 | // pointer in |webpData| to remain valid. This works because the pointer remains valid |
| 55 | // until the SkData is freed. |
| 56 | WebPData webpData = { data->bytes(), data->size() }; |
| 57 | SkAutoTCallVProc<WebPDemuxer, WebPDemuxDelete> demux(WebPDemuxPartial(&webpData, nullptr)); |
| 58 | if (nullptr == demux) { |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 59 | return nullptr; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 60 | } |
| 61 | |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 62 | WebPChunkIterator chunkIterator; |
| 63 | SkAutoTCallVProc<WebPChunkIterator, WebPDemuxReleaseChunkIterator> autoCI(&chunkIterator); |
| 64 | sk_sp<SkColorSpace> colorSpace = nullptr; |
| 65 | if (WebPDemuxGetChunk(demux, "ICCP", 1, &chunkIterator)) { |
| 66 | colorSpace = SkColorSpace::NewICC(chunkIterator.chunk.bytes, chunkIterator.chunk.size); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 67 | } |
| 68 | |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 69 | if (!colorSpace) { |
| 70 | colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| 71 | } |
| 72 | |
| 73 | // Since we do not yet support animation, we get the |width|, |height|, |color|, and |alpha| |
| 74 | // from the first frame. It's the only frame we will decode. |
| 75 | // |
| 76 | // TODO: |
| 77 | // When we support animation, we'll want to report the canvas width and canvas height instead. |
| 78 | // We can get these from the |demux| directly. |
| 79 | // What |color| and |alpha| will we want to report though? WebP allows different frames |
| 80 | // to be encoded in different ways, making the encoded format difficult to describe. |
| 81 | WebPIterator frame; |
| 82 | SkAutoTCallVProc<WebPIterator, WebPDemuxReleaseIterator> autoFrame(&frame); |
| 83 | if (!WebPDemuxGetFrame(demux, 1, &frame)) { |
| 84 | return nullptr; |
| 85 | } |
| 86 | |
| 87 | // Sanity check for image size that's about to be decoded. |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 88 | { |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 89 | const int64_t size = sk_64_mul(frame.width, frame.height); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 90 | if (!sk_64_isS32(size)) { |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 91 | return nullptr; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 92 | } |
| 93 | // now check that if we are 4-bytes per pixel, we also don't overflow |
| 94 | if (sk_64_asS32(size) > (0x7FFFFFFF >> 2)) { |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 95 | return nullptr; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 99 | // TODO: |
| 100 | // The only reason we actually need to call WebPGetFeatures() is to get the |features.format|. |
| 101 | // This call actually re-reads the frame header. Should we suggest that libwebp expose |
| 102 | // the format on the |frame|? |
| 103 | WebPBitstreamFeatures features; |
| 104 | VP8StatusCode status = WebPGetFeatures(frame.fragment.bytes, frame.fragment.size, &features); |
| 105 | if (VP8_STATUS_OK != status) { |
| 106 | return nullptr; |
| 107 | } |
| 108 | |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 109 | SkEncodedInfo::Color color; |
| 110 | SkEncodedInfo::Alpha alpha; |
| 111 | switch (features.format) { |
| 112 | case 0: |
| 113 | // This indicates a "mixed" format. We would see this for |
| 114 | // animated webps or for webps encoded in multiple fragments. |
| 115 | // I believe that this is a rare case. |
| 116 | // We could also guess kYUV here, but I think it makes more |
| 117 | // sense to guess kBGRA which is likely closer to the final |
| 118 | // output. Otherwise, we might end up converting |
| 119 | // BGRA->YUVA->BGRA. |
| 120 | color = SkEncodedInfo::kBGRA_Color; |
| 121 | alpha = SkEncodedInfo::kUnpremul_Alpha; |
| 122 | break; |
| 123 | case 1: |
| 124 | // This is the lossy format (YUV). |
| 125 | if (SkToBool(features.has_alpha)) { |
| 126 | color = SkEncodedInfo::kYUVA_Color; |
msarett | c30c418 | 2016-04-20 11:53:35 -0700 | [diff] [blame] | 127 | alpha = SkEncodedInfo::kUnpremul_Alpha; |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 128 | } else { |
| 129 | color = SkEncodedInfo::kYUV_Color; |
| 130 | alpha = SkEncodedInfo::kOpaque_Alpha; |
| 131 | } |
| 132 | break; |
| 133 | case 2: |
| 134 | // This is the lossless format (BGRA). |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 135 | color = SkEncodedInfo::kBGRA_Color; |
| 136 | alpha = SkEncodedInfo::kUnpremul_Alpha; |
| 137 | break; |
| 138 | default: |
| 139 | return nullptr; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 140 | } |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 141 | |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 142 | SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8); |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 143 | return new SkWebpCodec(features.width, features.height, info, std::move(colorSpace), |
| 144 | streamDeleter.release(), demux.release(), std::move(data)); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 145 | } |
| 146 | |
msarett | 85c922a | 2016-09-08 10:54:34 -0700 | [diff] [blame] | 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_SkAlphaType; |
| 161 | default: |
| 162 | return false; |
| 163 | } |
| 164 | } |
| 165 | |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 166 | SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const { |
| 167 | SkISize dim = this->getInfo().dimensions(); |
msarett | a0c414d | 2015-06-19 07:34:30 -0700 | [diff] [blame] | 168 | // SkCodec treats zero dimensional images as errors, so the minimum size |
| 169 | // that we will recommend is 1x1. |
| 170 | dim.fWidth = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fWidth)); |
| 171 | dim.fHeight = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fHeight)); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 172 | return dim; |
| 173 | } |
| 174 | |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 175 | bool SkWebpCodec::onDimensionsSupported(const SkISize& dim) { |
| 176 | const SkImageInfo& info = this->getInfo(); |
| 177 | return dim.width() >= 1 && dim.width() <= info.width() |
| 178 | && dim.height() >= 1 && dim.height() <= info.height(); |
| 179 | } |
| 180 | |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 181 | static WEBP_CSP_MODE webp_decode_mode(SkColorType ct, bool premultiply) { |
| 182 | switch (ct) { |
| 183 | case kBGRA_8888_SkColorType: |
| 184 | return premultiply ? MODE_bgrA : MODE_BGRA; |
| 185 | case kRGBA_8888_SkColorType: |
| 186 | return premultiply ? MODE_rgbA : MODE_RGBA; |
scroggo | 74992b5 | 2015-08-06 13:50:15 -0700 | [diff] [blame] | 187 | case kRGB_565_SkColorType: |
| 188 | return MODE_RGB_565; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 189 | default: |
| 190 | return MODE_LAST; |
| 191 | } |
| 192 | } |
| 193 | |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 194 | bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const { |
| 195 | if (!desiredSubset) { |
| 196 | return false; |
| 197 | } |
| 198 | |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 199 | SkIRect dimensions = SkIRect::MakeSize(this->getInfo().dimensions()); |
| 200 | if (!dimensions.contains(*desiredSubset)) { |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 201 | return false; |
| 202 | } |
| 203 | |
| 204 | // As stated below, libwebp snaps to even left and top. Make sure top and left are even, so we |
| 205 | // decode this exact subset. |
| 206 | // Leave right and bottom unmodified, so we suggest a slightly larger subset than requested. |
| 207 | desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; |
| 208 | desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; |
| 209 | return true; |
| 210 | } |
| 211 | |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 212 | SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 213 | const Options& options, SkPMColor*, int*, |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 214 | int* rowsDecodedPtr) { |
| 215 | |
| 216 | std::unique_ptr<SkColorSpaceXform> colorXform = nullptr; |
| 217 | if (needs_color_xform(dstInfo, this->getInfo())) { |
| 218 | colorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()), |
| 219 | sk_ref_sp(dstInfo.colorSpace())); |
msarett | 85c922a | 2016-09-08 10:54:34 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | if (!webp_conversion_possible(dstInfo, this->getInfo(), colorXform.get())) { |
| 223 | return kInvalidConversion; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | WebPDecoderConfig config; |
| 227 | if (0 == WebPInitDecoderConfig(&config)) { |
| 228 | // ABI mismatch. |
| 229 | // FIXME: New enum for this? |
| 230 | return kInvalidInput; |
| 231 | } |
| 232 | |
| 233 | // Free any memory associated with the buffer. Must be called last, so we declare it first. |
| 234 | SkAutoTCallVProc<WebPDecBuffer, WebPFreeDecBuffer> autoFree(&(config.output)); |
| 235 | |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 236 | SkIRect bounds = SkIRect::MakeSize(this->getInfo().dimensions()); |
| 237 | if (options.fSubset) { |
| 238 | // Caller is requesting a subset. |
| 239 | if (!bounds.contains(*options.fSubset)) { |
| 240 | // The subset is out of bounds. |
| 241 | return kInvalidParameters; |
| 242 | } |
| 243 | |
| 244 | bounds = *options.fSubset; |
| 245 | |
| 246 | // This is tricky. libwebp snaps the top and left to even values. We could let libwebp |
| 247 | // do the snap, and return a subset which is a different one than requested. The problem |
| 248 | // with that approach is that the caller may try to stitch subsets together, and if we |
| 249 | // returned different subsets than requested, there would be artifacts at the boundaries. |
| 250 | // Instead, we report that we cannot support odd values for top and left.. |
| 251 | if (!SkIsAlign2(bounds.fLeft) || !SkIsAlign2(bounds.fTop)) { |
| 252 | return kInvalidParameters; |
| 253 | } |
| 254 | |
| 255 | #ifdef SK_DEBUG |
| 256 | { |
| 257 | // Make a copy, since getValidSubset can change its input. |
| 258 | SkIRect subset(bounds); |
| 259 | // That said, getValidSubset should *not* change its input, in this case; otherwise |
| 260 | // getValidSubset does not match the actual subsets we can do. |
| 261 | SkASSERT(this->getValidSubset(&subset) && subset == bounds); |
| 262 | } |
| 263 | #endif |
| 264 | |
| 265 | config.options.use_cropping = 1; |
| 266 | config.options.crop_left = bounds.fLeft; |
| 267 | config.options.crop_top = bounds.fTop; |
| 268 | config.options.crop_width = bounds.width(); |
| 269 | config.options.crop_height = bounds.height(); |
| 270 | } |
| 271 | |
| 272 | SkISize dstDimensions = dstInfo.dimensions(); |
| 273 | if (bounds.size() != dstDimensions) { |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 274 | // Caller is requesting scaling. |
| 275 | config.options.use_scaling = 1; |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 276 | config.options.scaled_width = dstDimensions.width(); |
| 277 | config.options.scaled_height = dstDimensions.height(); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 278 | } |
| 279 | |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 280 | // FIXME (msarett): |
| 281 | // Lossless webp is encoded as BGRA. In that case, it would be more efficient to |
| 282 | // to decode BGRA and apply the color xform to a BGRA buffer. |
| 283 | config.output.colorspace = colorXform ? MODE_RGBA : |
| 284 | webp_decode_mode(dstInfo.colorType(), dstInfo.alphaType() == kPremul_SkAlphaType); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 285 | config.output.is_external_memory = 1; |
| 286 | |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 287 | // We will decode the entire image and then perform the color transform. libwebp |
| 288 | // does not provide a row-by-row API. This is a shame particularly in the F16 case, |
| 289 | // where we need to allocate an extra image-sized buffer. |
| 290 | SkAutoTMalloc<uint32_t> pixels; |
| 291 | if (kRGBA_F16_SkColorType == dstInfo.colorType()) { |
| 292 | pixels.reset(dstDimensions.width() * dstDimensions.height()); |
| 293 | config.output.u.RGBA.rgba = (uint8_t*) pixels.get(); |
| 294 | config.output.u.RGBA.stride = (int) dstDimensions.width() * sizeof(uint32_t); |
| 295 | config.output.u.RGBA.size = config.output.u.RGBA.stride * dstDimensions.height(); |
| 296 | } else { |
| 297 | config.output.u.RGBA.rgba = (uint8_t*) dst; |
| 298 | config.output.u.RGBA.stride = (int) rowBytes; |
| 299 | config.output.u.RGBA.size = dstInfo.getSafeSize(rowBytes); |
| 300 | } |
| 301 | |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 302 | WebPIterator frame; |
| 303 | SkAutoTCallVProc<WebPIterator, WebPDemuxReleaseIterator> autoFrame(&frame); |
| 304 | // If this succeeded in NewFromStream(), it should succeed again here. |
| 305 | SkAssertResult(WebPDemuxGetFrame(fDemux, 1, &frame)); |
| 306 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 307 | SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &config)); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 308 | if (!idec) { |
| 309 | return kInvalidInput; |
| 310 | } |
| 311 | |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 312 | int rowsDecoded; |
| 313 | SkCodec::Result result; |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 314 | switch (WebPIUpdate(idec, frame.fragment.bytes, frame.fragment.size)) { |
| 315 | case VP8_STATUS_OK: |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 316 | rowsDecoded = dstInfo.height(); |
| 317 | result = kSuccess; |
| 318 | break; |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 319 | case VP8_STATUS_SUSPENDED: |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 320 | WebPIDecGetRGB(idec, rowsDecodedPtr, nullptr, nullptr, nullptr); |
| 321 | rowsDecoded = *rowsDecodedPtr; |
| 322 | result = kIncompleteInput; |
| 323 | break; |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 324 | default: |
| 325 | return kInvalidInput; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 326 | } |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 327 | |
| 328 | if (colorXform) { |
| 329 | SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(), |
| 330 | this->getInfo().alphaType()); |
| 331 | |
| 332 | uint32_t* src = (uint32_t*) config.output.u.RGBA.rgba; |
| 333 | size_t srcRowBytes = config.output.u.RGBA.stride; |
| 334 | for (int y = 0; y < rowsDecoded; y++) { |
| 335 | colorXform->apply(dst, src, dstInfo.width(), dstInfo.colorType(), xformAlphaType); |
| 336 | dst = SkTAddOffset<void>(dst, rowBytes); |
| 337 | src = SkTAddOffset<uint32_t>(src, srcRowBytes); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | return result; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 342 | } |
| 343 | |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 344 | SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info, |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 345 | sk_sp<SkColorSpace> colorSpace, SkStream* stream, WebPDemuxer* demux, |
| 346 | sk_sp<SkData> data) |
| 347 | : INHERITED(width, height, info, stream, std::move(colorSpace)) |
| 348 | , fDemux(demux) |
| 349 | , fData(std::move(data)) |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 350 | {} |