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 | |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 8 | #include "SkBitmap.h" |
| 9 | #include "SkCanvas.h" |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 10 | #include "SkCodecAnimation.h" |
| 11 | #include "SkCodecAnimationPriv.h" |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 12 | #include "SkCodecPriv.h" |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 13 | #include "SkColorSpaceXform.h" |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 14 | #include "SkMakeUnique.h" |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 15 | #include "SkRasterPipeline.h" |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 16 | #include "SkSampler.h" |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 17 | #include "SkStreamPriv.h" |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 18 | #include "SkTemplates.h" |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 19 | #include "SkWebpCodec.h" |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 20 | #include "../jumper/SkJumper.h" |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 21 | |
| 22 | // A WebP decoder on top of (subset of) libwebp |
| 23 | // For more information on WebP image format, and libwebp library, see: |
| 24 | // https://code.google.com/speed/webp/ |
| 25 | // http://www.webmproject.org/code/#libwebp-webp-image-library |
| 26 | // https://chromium.googlesource.com/webm/libwebp |
| 27 | |
| 28 | // If moving libwebp out of skia source tree, path for webp headers must be |
| 29 | // updated accordingly. Here, we enforce using local copy in webp sub-directory. |
| 30 | #include "webp/decode.h" |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 31 | #include "webp/demux.h" |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 32 | #include "webp/encode.h" |
| 33 | |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 34 | bool SkWebpCodec::IsWebp(const void* buf, size_t bytesRead) { |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 35 | // WEBP starts with the following: |
| 36 | // RIFFXXXXWEBPVP |
| 37 | // Where XXXX is unspecified. |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 38 | const char* bytes = static_cast<const char*>(buf); |
| 39 | return bytesRead >= 14 && !memcmp(bytes, "RIFF", 4) && !memcmp(&bytes[8], "WEBPVP", 6); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 42 | static SkAlphaType alpha_type(bool hasAlpha) { |
| 43 | return hasAlpha ? kUnpremul_SkAlphaType : kOpaque_SkAlphaType; |
| 44 | } |
| 45 | |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 46 | // Parse headers of RIFF container, and check for valid Webp (VP8) content. |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 47 | // Returns an SkWebpCodec on success |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 48 | std::unique_ptr<SkCodec> SkWebpCodec::MakeFromStream(std::unique_ptr<SkStream> stream, |
| 49 | Result* result) { |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 50 | // Webp demux needs a contiguous data buffer. |
| 51 | sk_sp<SkData> data = nullptr; |
| 52 | if (stream->getMemoryBase()) { |
| 53 | // It is safe to make without copy because we'll hold onto the stream. |
| 54 | data = SkData::MakeWithoutCopy(stream->getMemoryBase(), stream->getLength()); |
| 55 | } else { |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 56 | data = SkCopyStreamToData(stream.get()); |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 57 | |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 58 | // If we are forced to copy the stream to a data, we can go ahead and delete the stream. |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 59 | stream.reset(nullptr); |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | // It's a little strange that the |demux| will outlive |webpData|, though it needs the |
| 63 | // pointer in |webpData| to remain valid. This works because the pointer remains valid |
| 64 | // until the SkData is freed. |
| 65 | WebPData webpData = { data->bytes(), data->size() }; |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 66 | WebPDemuxState state; |
| 67 | SkAutoTCallVProc<WebPDemuxer, WebPDemuxDelete> demux(WebPDemuxPartial(&webpData, &state)); |
| 68 | switch (state) { |
| 69 | case WEBP_DEMUX_PARSE_ERROR: |
| 70 | *result = kInvalidInput; |
| 71 | return nullptr; |
| 72 | case WEBP_DEMUX_PARSING_HEADER: |
| 73 | *result = kIncompleteInput; |
| 74 | return nullptr; |
| 75 | case WEBP_DEMUX_PARSED_HEADER: |
| 76 | case WEBP_DEMUX_DONE: |
| 77 | SkASSERT(demux); |
| 78 | break; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 81 | const int width = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH); |
| 82 | const int height = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT); |
| 83 | |
| 84 | // Sanity check for image size that's about to be decoded. |
| 85 | { |
| 86 | const int64_t size = sk_64_mul(width, height); |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 87 | // now check that if we are 4-bytes per pixel, we also don't overflow |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 88 | if (!sk_64_isS32(size) || sk_64_asS32(size) > (0x7FFFFFFF >> 2)) { |
| 89 | *result = kInvalidInput; |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 90 | return nullptr; |
| 91 | } |
| 92 | } |
| 93 | |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 94 | WebPChunkIterator chunkIterator; |
| 95 | SkAutoTCallVProc<WebPChunkIterator, WebPDemuxReleaseChunkIterator> autoCI(&chunkIterator); |
| 96 | sk_sp<SkColorSpace> colorSpace = nullptr; |
| 97 | if (WebPDemuxGetChunk(demux, "ICCP", 1, &chunkIterator)) { |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame] | 98 | colorSpace = SkColorSpace::MakeICC(chunkIterator.chunk.bytes, chunkIterator.chunk.size); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 99 | } |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 100 | if (!colorSpace) { |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 101 | colorSpace = SkColorSpace::MakeSRGB(); |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 104 | // Get the first frame and its "features" to determine the color and alpha types. |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 105 | WebPIterator frame; |
| 106 | SkAutoTCallVProc<WebPIterator, WebPDemuxReleaseIterator> autoFrame(&frame); |
| 107 | if (!WebPDemuxGetFrame(demux, 1, &frame)) { |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 108 | *result = kIncompleteInput; |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 109 | return nullptr; |
| 110 | } |
| 111 | |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 112 | WebPBitstreamFeatures features; |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 113 | switch (WebPGetFeatures(frame.fragment.bytes, frame.fragment.size, &features)) { |
| 114 | case VP8_STATUS_OK: |
| 115 | break; |
| 116 | case VP8_STATUS_SUSPENDED: |
| 117 | case VP8_STATUS_NOT_ENOUGH_DATA: |
| 118 | *result = kIncompleteInput; |
| 119 | return nullptr; |
| 120 | default: |
| 121 | *result = kInvalidInput; |
| 122 | return nullptr; |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 125 | const bool hasAlpha = SkToBool(frame.has_alpha) |
| 126 | || frame.width != width || frame.height != height; |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 127 | SkEncodedInfo::Color color; |
| 128 | SkEncodedInfo::Alpha alpha; |
| 129 | switch (features.format) { |
| 130 | case 0: |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 131 | // This indicates a "mixed" format. We could see this for |
| 132 | // animated webps (multiple fragments). |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 133 | // We could also guess kYUV here, but I think it makes more |
| 134 | // sense to guess kBGRA which is likely closer to the final |
| 135 | // output. Otherwise, we might end up converting |
| 136 | // BGRA->YUVA->BGRA. |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 137 | // Fallthrough: |
| 138 | case 2: |
| 139 | // This is the lossless format (BGRA). |
| 140 | if (hasAlpha) { |
| 141 | color = SkEncodedInfo::kBGRA_Color; |
| 142 | alpha = SkEncodedInfo::kUnpremul_Alpha; |
| 143 | } else { |
| 144 | color = SkEncodedInfo::kBGRX_Color; |
| 145 | alpha = SkEncodedInfo::kOpaque_Alpha; |
| 146 | } |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 147 | break; |
| 148 | case 1: |
| 149 | // This is the lossy format (YUV). |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 150 | if (hasAlpha) { |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 151 | color = SkEncodedInfo::kYUVA_Color; |
msarett | c30c418 | 2016-04-20 11:53:35 -0700 | [diff] [blame] | 152 | alpha = SkEncodedInfo::kUnpremul_Alpha; |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 153 | } else { |
| 154 | color = SkEncodedInfo::kYUV_Color; |
| 155 | alpha = SkEncodedInfo::kOpaque_Alpha; |
| 156 | } |
| 157 | break; |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 158 | default: |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 159 | *result = kInvalidInput; |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 160 | return nullptr; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 161 | } |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 162 | |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 163 | *result = kSuccess; |
msarett | ac6c750 | 2016-04-25 09:30:24 -0700 | [diff] [blame] | 164 | SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8); |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 165 | return std::unique_ptr<SkCodec>(new SkWebpCodec(width, height, info, std::move(colorSpace), |
| 166 | std::move(stream), demux.release(), std::move(data))); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 167 | } |
| 168 | |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 169 | SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const { |
| 170 | SkISize dim = this->getInfo().dimensions(); |
msarett | a0c414d | 2015-06-19 07:34:30 -0700 | [diff] [blame] | 171 | // SkCodec treats zero dimensional images as errors, so the minimum size |
| 172 | // that we will recommend is 1x1. |
| 173 | dim.fWidth = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fWidth)); |
| 174 | dim.fHeight = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fHeight)); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 175 | return dim; |
| 176 | } |
| 177 | |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 178 | bool SkWebpCodec::onDimensionsSupported(const SkISize& dim) { |
| 179 | const SkImageInfo& info = this->getInfo(); |
| 180 | return dim.width() >= 1 && dim.width() <= info.width() |
| 181 | && dim.height() >= 1 && dim.height() <= info.height(); |
| 182 | } |
| 183 | |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 184 | static WEBP_CSP_MODE webp_decode_mode(const SkImageInfo& info) { |
| 185 | const bool premultiply = info.alphaType() == kPremul_SkAlphaType; |
| 186 | switch (info.colorType()) { |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 187 | case kBGRA_8888_SkColorType: |
| 188 | return premultiply ? MODE_bgrA : MODE_BGRA; |
| 189 | case kRGBA_8888_SkColorType: |
| 190 | return premultiply ? MODE_rgbA : MODE_RGBA; |
scroggo | 74992b5 | 2015-08-06 13:50:15 -0700 | [diff] [blame] | 191 | case kRGB_565_SkColorType: |
| 192 | return MODE_RGB_565; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 193 | default: |
| 194 | return MODE_LAST; |
| 195 | } |
| 196 | } |
| 197 | |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 198 | SkWebpCodec::Frame* SkWebpCodec::FrameHolder::appendNewFrame(bool hasAlpha) { |
| 199 | const int i = this->size(); |
| 200 | fFrames.emplace_back(i, hasAlpha); |
| 201 | return &fFrames[i]; |
| 202 | } |
| 203 | |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 204 | bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const { |
| 205 | if (!desiredSubset) { |
| 206 | return false; |
| 207 | } |
| 208 | |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 209 | SkIRect dimensions = SkIRect::MakeSize(this->getInfo().dimensions()); |
| 210 | if (!dimensions.contains(*desiredSubset)) { |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 211 | return false; |
| 212 | } |
| 213 | |
| 214 | // As stated below, libwebp snaps to even left and top. Make sure top and left are even, so we |
| 215 | // decode this exact subset. |
| 216 | // Leave right and bottom unmodified, so we suggest a slightly larger subset than requested. |
| 217 | desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; |
| 218 | desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; |
| 219 | return true; |
| 220 | } |
| 221 | |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 222 | int SkWebpCodec::onGetRepetitionCount() { |
| 223 | auto flags = WebPDemuxGetI(fDemux.get(), WEBP_FF_FORMAT_FLAGS); |
| 224 | if (!(flags & ANIMATION_FLAG)) { |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | const int repCount = WebPDemuxGetI(fDemux.get(), WEBP_FF_LOOP_COUNT); |
| 229 | if (0 == repCount) { |
| 230 | return kRepetitionCountInfinite; |
| 231 | } |
| 232 | |
| 233 | return repCount; |
| 234 | } |
| 235 | |
| 236 | int SkWebpCodec::onGetFrameCount() { |
| 237 | auto flags = WebPDemuxGetI(fDemux.get(), WEBP_FF_FORMAT_FLAGS); |
| 238 | if (!(flags & ANIMATION_FLAG)) { |
| 239 | return 1; |
| 240 | } |
| 241 | |
| 242 | const uint32_t oldFrameCount = fFrameHolder.size(); |
| 243 | if (fFailed) { |
| 244 | return oldFrameCount; |
| 245 | } |
| 246 | |
| 247 | const uint32_t frameCount = WebPDemuxGetI(fDemux, WEBP_FF_FRAME_COUNT); |
| 248 | if (oldFrameCount == frameCount) { |
| 249 | // We have already parsed this. |
| 250 | return frameCount; |
| 251 | } |
| 252 | |
| 253 | fFrameHolder.reserve(frameCount); |
| 254 | |
| 255 | for (uint32_t i = oldFrameCount; i < frameCount; i++) { |
| 256 | WebPIterator iter; |
| 257 | SkAutoTCallVProc<WebPIterator, WebPDemuxReleaseIterator> autoIter(&iter); |
| 258 | |
| 259 | if (!WebPDemuxGetFrame(fDemux.get(), i + 1, &iter)) { |
| 260 | fFailed = true; |
| 261 | break; |
| 262 | } |
| 263 | |
| 264 | // libwebp only reports complete frames of an animated image. |
| 265 | SkASSERT(iter.complete); |
| 266 | |
| 267 | Frame* frame = fFrameHolder.appendNewFrame(iter.has_alpha); |
| 268 | frame->setXYWH(iter.x_offset, iter.y_offset, iter.width, iter.height); |
| 269 | frame->setDisposalMethod(iter.dispose_method == WEBP_MUX_DISPOSE_BACKGROUND ? |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 270 | SkCodecAnimation::DisposalMethod::kRestoreBGColor : |
| 271 | SkCodecAnimation::DisposalMethod::kKeep); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 272 | frame->setDuration(iter.duration); |
| 273 | if (WEBP_MUX_BLEND != iter.blend_method) { |
| 274 | frame->setBlend(SkCodecAnimation::Blend::kBG); |
| 275 | } |
| 276 | fFrameHolder.setAlphaAndRequiredFrame(frame); |
| 277 | } |
| 278 | |
| 279 | return fFrameHolder.size(); |
| 280 | |
| 281 | } |
| 282 | |
| 283 | const SkFrame* SkWebpCodec::FrameHolder::onGetFrame(int i) const { |
| 284 | return static_cast<const SkFrame*>(this->frame(i)); |
| 285 | } |
| 286 | |
| 287 | const SkWebpCodec::Frame* SkWebpCodec::FrameHolder::frame(int i) const { |
| 288 | SkASSERT(i >= 0 && i < this->size()); |
| 289 | return &fFrames[i]; |
| 290 | } |
| 291 | |
| 292 | bool SkWebpCodec::onGetFrameInfo(int i, FrameInfo* frameInfo) const { |
| 293 | if (i >= fFrameHolder.size()) { |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | const Frame* frame = fFrameHolder.frame(i); |
| 298 | if (!frame) { |
| 299 | return false; |
| 300 | } |
| 301 | |
| 302 | if (frameInfo) { |
| 303 | frameInfo->fRequiredFrame = frame->getRequiredFrame(); |
| 304 | frameInfo->fDuration = frame->getDuration(); |
| 305 | // libwebp only reports fully received frames for an |
| 306 | // animated image. |
| 307 | frameInfo->fFullyReceived = true; |
| 308 | frameInfo->fAlphaType = alpha_type(frame->hasAlpha()); |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 309 | frameInfo->fDisposalMethod = frame->getDisposalMethod(); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | return true; |
| 313 | } |
| 314 | |
| 315 | static bool is_8888(SkColorType colorType) { |
| 316 | switch (colorType) { |
| 317 | case kRGBA_8888_SkColorType: |
| 318 | case kBGRA_8888_SkColorType: |
| 319 | return true; |
| 320 | default: |
| 321 | return false; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | static void pick_memory_stages(SkColorType ct, SkRasterPipeline::StockStage* load, |
| 326 | SkRasterPipeline::StockStage* store) { |
| 327 | switch(ct) { |
| 328 | case kUnknown_SkColorType: |
| 329 | case kAlpha_8_SkColorType: |
| 330 | case kARGB_4444_SkColorType: |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 331 | case kGray_8_SkColorType: |
| 332 | SkASSERT(false); |
| 333 | break; |
| 334 | case kRGB_565_SkColorType: |
| 335 | if (load) *load = SkRasterPipeline::load_565; |
| 336 | if (store) *store = SkRasterPipeline::store_565; |
| 337 | break; |
| 338 | case kRGBA_8888_SkColorType: |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 339 | if (load) *load = SkRasterPipeline::load_8888; |
| 340 | if (store) *store = SkRasterPipeline::store_8888; |
| 341 | break; |
Mike Klein | c2d2076 | 2017-06-27 19:53:21 -0400 | [diff] [blame] | 342 | case kBGRA_8888_SkColorType: |
| 343 | if (load) *load = SkRasterPipeline::load_bgra; |
| 344 | if (store) *store = SkRasterPipeline::store_bgra; |
| 345 | break; |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 346 | case kRGBA_F16_SkColorType: |
| 347 | if (load) *load = SkRasterPipeline::load_f16; |
| 348 | if (store) *store = SkRasterPipeline::store_f16; |
| 349 | break; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | static void blend_line(SkColorType dstCT, void* dst, |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 354 | SkColorType srcCT, const void* src, |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 355 | bool needsSrgbToLinear, SkAlphaType at, |
| 356 | int width) { |
| 357 | // Setup conversion from the source and dest, which will be the same. |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 358 | SkRasterPipeline_<256> convert_to_linear_premul; |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 359 | if (needsSrgbToLinear) { |
| 360 | convert_to_linear_premul.append_from_srgb(at); |
| 361 | } |
| 362 | if (kUnpremul_SkAlphaType == at) { |
| 363 | // srcover assumes premultiplied inputs. |
| 364 | convert_to_linear_premul.append(SkRasterPipeline::premul); |
| 365 | } |
| 366 | |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 367 | SkJumper_MemoryCtx dst_ctx = { (void*)dst, 0 }, |
| 368 | src_ctx = { (void*)src, 0 }; |
| 369 | |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 370 | SkRasterPipeline_<256> p; |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 371 | SkRasterPipeline::StockStage load_dst, store_dst; |
| 372 | pick_memory_stages(dstCT, &load_dst, &store_dst); |
| 373 | |
| 374 | // Load the final dst. |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 375 | p.append(load_dst, &dst_ctx); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 376 | p.extend(convert_to_linear_premul); |
| 377 | p.append(SkRasterPipeline::move_src_dst); |
| 378 | |
| 379 | // Load the src. |
| 380 | SkRasterPipeline::StockStage load_src; |
| 381 | pick_memory_stages(srcCT, &load_src, nullptr); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 382 | p.append(load_src, &src_ctx); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 383 | p.extend(convert_to_linear_premul); |
| 384 | |
| 385 | p.append(SkRasterPipeline::srcover); |
| 386 | |
| 387 | // Convert back to dst. |
| 388 | if (kUnpremul_SkAlphaType == at) { |
| 389 | p.append(SkRasterPipeline::unpremul); |
| 390 | } |
| 391 | if (needsSrgbToLinear) { |
| 392 | p.append(SkRasterPipeline::to_srgb); |
| 393 | } |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 394 | p.append(store_dst, &dst_ctx); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 395 | |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 396 | p.run(0,0, width,1); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 397 | } |
| 398 | |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 399 | SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 400 | const Options& options, int* rowsDecodedPtr) { |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 401 | const int index = options.fFrameIndex; |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 402 | SkASSERT(0 == index || index < fFrameHolder.size()); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 403 | |
| 404 | const auto& srcInfo = this->getInfo(); |
Matt Sarett | cf3f234 | 2017-03-23 15:32:25 -0400 | [diff] [blame] | 405 | { |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 406 | auto info = srcInfo; |
| 407 | if (index > 0) { |
| 408 | auto alphaType = alpha_type(fFrameHolder.frame(index)->hasAlpha()); |
| 409 | info = info.makeAlphaType(alphaType); |
| 410 | } |
| 411 | if (!conversion_possible(dstInfo, info) || |
| 412 | !this->initializeColorXform(dstInfo, options.fPremulBehavior)) |
| 413 | { |
| 414 | return kInvalidConversion; |
| 415 | } |
| 416 | } |
| 417 | |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 418 | SkASSERT(0 == index || (!options.fSubset && dstInfo.dimensions() == srcInfo.dimensions())); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 419 | |
| 420 | WebPDecoderConfig config; |
| 421 | if (0 == WebPInitDecoderConfig(&config)) { |
| 422 | // ABI mismatch. |
| 423 | // FIXME: New enum for this? |
| 424 | return kInvalidInput; |
| 425 | } |
| 426 | |
| 427 | // Free any memory associated with the buffer. Must be called last, so we declare it first. |
| 428 | SkAutoTCallVProc<WebPDecBuffer, WebPFreeDecBuffer> autoFree(&(config.output)); |
| 429 | |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 430 | WebPIterator frame; |
| 431 | SkAutoTCallVProc<WebPIterator, WebPDemuxReleaseIterator> autoFrame(&frame); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 432 | // If this succeeded in onGetFrameCount(), it should succeed again here. |
| 433 | SkAssertResult(WebPDemuxGetFrame(fDemux, index + 1, &frame)); |
Matt Sarett | 604971e | 2017-02-06 09:51:48 -0500 | [diff] [blame] | 434 | |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 435 | const bool independent = index == 0 ? true : |
| 436 | (fFrameHolder.frame(index)->getRequiredFrame() == kNone); |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 437 | // Get the frameRect. libwebp will have already signaled an error if this is not fully |
| 438 | // contained by the canvas. |
| 439 | auto frameRect = SkIRect::MakeXYWH(frame.x_offset, frame.y_offset, frame.width, frame.height); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 440 | SkASSERT(srcInfo.bounds().contains(frameRect)); |
| 441 | const bool frameIsSubset = frameRect != srcInfo.bounds(); |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 442 | if (independent && frameIsSubset) { |
| 443 | SkSampler::Fill(dstInfo, dst, rowBytes, 0, options.fZeroInitialized); |
Matt Sarett | 604971e | 2017-02-06 09:51:48 -0500 | [diff] [blame] | 444 | } |
| 445 | |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 446 | int dstX = frameRect.x(); |
| 447 | int dstY = frameRect.y(); |
| 448 | int subsetWidth = frameRect.width(); |
| 449 | int subsetHeight = frameRect.height(); |
| 450 | if (options.fSubset) { |
| 451 | SkIRect subset = *options.fSubset; |
| 452 | SkASSERT(this->getInfo().bounds().contains(subset)); |
| 453 | SkASSERT(SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTop)); |
| 454 | SkASSERT(this->getValidSubset(&subset) && subset == *options.fSubset); |
| 455 | |
| 456 | if (!SkIRect::IntersectsNoEmptyCheck(subset, frameRect)) { |
| 457 | return kSuccess; |
| 458 | } |
| 459 | |
| 460 | int minXOffset = SkTMin(dstX, subset.x()); |
| 461 | int minYOffset = SkTMin(dstY, subset.y()); |
| 462 | dstX -= minXOffset; |
| 463 | dstY -= minYOffset; |
| 464 | frameRect.offset(-minXOffset, -minYOffset); |
| 465 | subset.offset(-minXOffset, -minYOffset); |
| 466 | |
| 467 | // Just like we require that the requested subset x and y offset are even, libwebp |
| 468 | // guarantees that the frame x and y offset are even (it's actually impossible to specify |
| 469 | // an odd frame offset). So we can still guarantee that the adjusted offsets are even. |
| 470 | SkASSERT(SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTop)); |
| 471 | |
| 472 | SkIRect intersection; |
| 473 | SkAssertResult(intersection.intersect(frameRect, subset)); |
| 474 | subsetWidth = intersection.width(); |
| 475 | subsetHeight = intersection.height(); |
| 476 | |
| 477 | config.options.use_cropping = 1; |
| 478 | config.options.crop_left = subset.x(); |
| 479 | config.options.crop_top = subset.y(); |
| 480 | config.options.crop_width = subsetWidth; |
| 481 | config.options.crop_height = subsetHeight; |
| 482 | } |
| 483 | |
| 484 | // Ignore the frame size and offset when determining if scaling is necessary. |
| 485 | int scaledWidth = subsetWidth; |
| 486 | int scaledHeight = subsetHeight; |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 487 | SkISize srcSize = options.fSubset ? options.fSubset->size() : srcInfo.dimensions(); |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 488 | if (srcSize != dstInfo.dimensions()) { |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 489 | config.options.use_scaling = 1; |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 490 | |
| 491 | if (frameIsSubset) { |
| 492 | float scaleX = ((float) dstInfo.width()) / srcSize.width(); |
| 493 | float scaleY = ((float) dstInfo.height()) / srcSize.height(); |
| 494 | |
| 495 | // We need to be conservative here and floor rather than round. |
| 496 | // Otherwise, we may find ourselves decoding off the end of memory. |
| 497 | dstX = scaleX * dstX; |
| 498 | scaledWidth = scaleX * scaledWidth; |
| 499 | dstY = scaleY * dstY; |
| 500 | scaledHeight = scaleY * scaledHeight; |
| 501 | if (0 == scaledWidth || 0 == scaledHeight) { |
| 502 | return kSuccess; |
| 503 | } |
| 504 | } else { |
| 505 | scaledWidth = dstInfo.width(); |
| 506 | scaledHeight = dstInfo.height(); |
| 507 | } |
| 508 | |
| 509 | config.options.scaled_width = scaledWidth; |
| 510 | config.options.scaled_height = scaledHeight; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 513 | const bool blendWithPrevFrame = !independent && frame.blend_method == WEBP_MUX_BLEND |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 514 | && frame.has_alpha; |
| 515 | if (blendWithPrevFrame && options.fPremulBehavior == SkTransferFunctionBehavior::kRespect) { |
| 516 | // Blending is done with SkRasterPipeline, which requires a color space that is valid for |
| 517 | // rendering. |
| 518 | const auto* cs = dstInfo.colorSpace(); |
| 519 | if (!cs || (!cs->gammaCloseToSRGB() && !cs->gammaIsLinear())) { |
| 520 | return kInvalidConversion; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | SkBitmap webpDst; |
Leon Scroggins III | ee92f13 | 2017-05-23 15:28:46 -0400 | [diff] [blame] | 525 | auto webpInfo = dstInfo; |
| 526 | if (!frame.has_alpha) { |
| 527 | webpInfo = webpInfo.makeAlphaType(kOpaque_SkAlphaType); |
| 528 | } |
| 529 | if (this->colorXform()) { |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 530 | // Swizzling between RGBA and BGRA is zero cost in a color transform. So when we have a |
| 531 | // color transform, we should decode to whatever is easiest for libwebp, and then let the |
| 532 | // color transform swizzle if necessary. |
| 533 | // Lossy webp is encoded as YUV (so RGBA and BGRA are the same cost). Lossless webp is |
| 534 | // encoded as BGRA. This means decoding to BGRA is either faster or the same cost as RGBA. |
Leon Scroggins III | ee92f13 | 2017-05-23 15:28:46 -0400 | [diff] [blame] | 535 | webpInfo = webpInfo.makeColorType(kBGRA_8888_SkColorType); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 536 | |
Leon Scroggins III | ee92f13 | 2017-05-23 15:28:46 -0400 | [diff] [blame] | 537 | if (webpInfo.alphaType() == kPremul_SkAlphaType) { |
| 538 | webpInfo = webpInfo.makeAlphaType(kUnpremul_SkAlphaType); |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | if ((this->colorXform() && !is_8888(dstInfo.colorType())) || blendWithPrevFrame) { |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 543 | // We will decode the entire image and then perform the color transform. libwebp |
| 544 | // does not provide a row-by-row API. This is a shame particularly when we do not want |
| 545 | // 8888, since we will need to create another image sized buffer. |
Leon Scroggins III | ee92f13 | 2017-05-23 15:28:46 -0400 | [diff] [blame] | 546 | webpDst.allocPixels(webpInfo); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 547 | } else { |
| 548 | // libwebp can decode directly into the output memory. |
Leon Scroggins III | ee92f13 | 2017-05-23 15:28:46 -0400 | [diff] [blame] | 549 | webpDst.installPixels(webpInfo, dst, rowBytes); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 550 | } |
| 551 | |
Leon Scroggins III | ee92f13 | 2017-05-23 15:28:46 -0400 | [diff] [blame] | 552 | config.output.colorspace = webp_decode_mode(webpInfo); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 553 | config.output.is_external_memory = 1; |
| 554 | |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 555 | config.output.u.RGBA.rgba = reinterpret_cast<uint8_t*>(webpDst.getAddr(dstX, dstY)); |
| 556 | config.output.u.RGBA.stride = static_cast<int>(webpDst.rowBytes()); |
| 557 | config.output.u.RGBA.size = webpDst.getSafeSize(); |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 558 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 559 | SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &config)); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 560 | if (!idec) { |
| 561 | return kInvalidInput; |
| 562 | } |
| 563 | |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 564 | int rowsDecoded; |
| 565 | SkCodec::Result result; |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 566 | switch (WebPIUpdate(idec, frame.fragment.bytes, frame.fragment.size)) { |
| 567 | case VP8_STATUS_OK: |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 568 | rowsDecoded = scaledHeight; |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 569 | result = kSuccess; |
| 570 | break; |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 571 | case VP8_STATUS_SUSPENDED: |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 572 | WebPIDecGetRGB(idec, &rowsDecoded, nullptr, nullptr, nullptr); |
| 573 | *rowsDecodedPtr = rowsDecoded + dstY; |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 574 | result = kIncompleteInput; |
| 575 | break; |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 576 | default: |
| 577 | return kInvalidInput; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 578 | } |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 579 | |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 580 | // We're only transforming the new part of the frame, so no need to worry about the |
| 581 | // final composited alpha. |
| 582 | const auto srcAlpha = 0 == index ? srcInfo.alphaType() : alpha_type(frame.has_alpha); |
| 583 | const auto xformAlphaType = select_xform_alpha(dstInfo.alphaType(), srcAlpha); |
| 584 | const bool needsSrgbToLinear = dstInfo.gammaCloseToSRGB() && |
| 585 | options.fPremulBehavior == SkTransferFunctionBehavior::kRespect; |
| 586 | |
| 587 | const size_t dstBpp = SkColorTypeBytesPerPixel(dstInfo.colorType()); |
| 588 | dst = SkTAddOffset<void>(dst, dstBpp * dstX + rowBytes * dstY); |
| 589 | const size_t srcRowBytes = config.output.u.RGBA.stride; |
| 590 | |
| 591 | const auto dstCT = dstInfo.colorType(); |
Matt Sarett | 313c463 | 2016-10-20 12:35:23 -0400 | [diff] [blame] | 592 | if (this->colorXform()) { |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 593 | uint32_t* xformSrc = (uint32_t*) config.output.u.RGBA.rgba; |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 594 | SkBitmap tmp; |
| 595 | void* xformDst; |
| 596 | |
| 597 | if (blendWithPrevFrame) { |
| 598 | // Xform into temporary bitmap big enough for one row. |
| 599 | tmp.allocPixels(dstInfo.makeWH(scaledWidth, 1)); |
| 600 | xformDst = tmp.getPixels(); |
| 601 | } else { |
| 602 | xformDst = dst; |
| 603 | } |
Robert Phillips | b3050b9 | 2017-02-06 13:12:18 +0000 | [diff] [blame] | 604 | for (int y = 0; y < rowsDecoded; y++) { |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 605 | this->applyColorXform(xformDst, xformSrc, scaledWidth, xformAlphaType); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 606 | if (blendWithPrevFrame) { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 607 | blend_line(dstCT, dst, dstCT, xformDst, needsSrgbToLinear, xformAlphaType, |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 608 | scaledWidth); |
| 609 | dst = SkTAddOffset<void>(dst, rowBytes); |
| 610 | } else { |
| 611 | xformDst = SkTAddOffset<void>(xformDst, rowBytes); |
| 612 | } |
Matt Sarett | 5c49617 | 2017-02-07 17:01:16 -0500 | [diff] [blame] | 613 | xformSrc = SkTAddOffset<uint32_t>(xformSrc, srcRowBytes); |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 614 | } |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 615 | } else if (blendWithPrevFrame) { |
| 616 | const uint8_t* src = config.output.u.RGBA.rgba; |
| 617 | |
| 618 | for (int y = 0; y < rowsDecoded; y++) { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 619 | blend_line(dstCT, dst, webpDst.colorType(), src, needsSrgbToLinear, |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 620 | xformAlphaType, scaledWidth); |
| 621 | src = SkTAddOffset<const uint8_t>(src, srcRowBytes); |
| 622 | dst = SkTAddOffset<void>(dst, rowBytes); |
| 623 | } |
msarett | e99883f | 2016-09-08 06:05:35 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | return result; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 627 | } |
| 628 | |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 629 | SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info, |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 630 | sk_sp<SkColorSpace> colorSpace, std::unique_ptr<SkStream> stream, |
| 631 | WebPDemuxer* demux, sk_sp<SkData> data) |
| 632 | : INHERITED(width, height, info, SkColorSpaceXform::kBGRA_8888_ColorFormat, std::move(stream), |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 633 | std::move(colorSpace)) |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 634 | , fDemux(demux) |
| 635 | , fData(std::move(data)) |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 636 | , fFailed(false) |
| 637 | { |
| 638 | fFrameHolder.setScreenSize(width, height); |
| 639 | } |