msarett | 8c8f22a | 2015-04-01 06:58:48 -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 | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 8 | /* |
| 9 | * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 28 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | */ |
| 32 | |
| 33 | #include "SkCodecAnimation.h" |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 34 | #include "SkCodecPriv.h" |
| 35 | #include "SkColorPriv.h" |
| 36 | #include "SkColorTable.h" |
msarett | 1a46467 | 2016-01-07 13:17:19 -0800 | [diff] [blame] | 37 | #include "SkGifCodec.h" |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 38 | #include "SkMakeUnique.h" |
Leon Scroggins III | e43fdb3 | 2017-07-17 19:41:46 -0400 | [diff] [blame] | 39 | #include "SkRasterPipeline.h" |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 40 | #include "SkStream.h" |
| 41 | #include "SkSwizzler.h" |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 42 | #include "../jumper/SkJumper.h" |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 43 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 44 | #include <algorithm> |
| 45 | |
| 46 | #define GIF87_STAMP "GIF87a" |
| 47 | #define GIF89_STAMP "GIF89a" |
| 48 | #define GIF_STAMP_LEN 6 |
msarett | 39b2d5a | 2016-02-17 08:26:31 -0800 | [diff] [blame] | 49 | |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 50 | /* |
| 51 | * Checks the start of the stream to see if the image is a gif |
| 52 | */ |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 53 | bool SkGifCodec::IsGif(const void* buf, size_t bytesRead) { |
| 54 | if (bytesRead >= GIF_STAMP_LEN) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 55 | if (memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 || |
bungeman | 0153dea | 2015-08-27 16:43:42 -0700 | [diff] [blame] | 56 | memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) |
| 57 | { |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 58 | return true; |
| 59 | } |
| 60 | } |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | /* |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 65 | * Error function |
| 66 | */ |
bungeman | 0153dea | 2015-08-27 16:43:42 -0700 | [diff] [blame] | 67 | static SkCodec::Result gif_error(const char* msg, SkCodec::Result result = SkCodec::kInvalidInput) { |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 68 | SkCodecPrintf("Gif Error: %s\n", msg); |
| 69 | return result; |
| 70 | } |
| 71 | |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 72 | std::unique_ptr<SkCodec> SkGifCodec::MakeFromStream(std::unique_ptr<SkStream> stream, |
| 73 | Result* result) { |
| 74 | std::unique_ptr<SkGifImageReader> reader(new SkGifImageReader(std::move(stream))); |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 75 | *result = reader->parse(SkGifImageReader::SkGIFSizeQuery); |
| 76 | if (*result != kSuccess) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 77 | return nullptr; |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 78 | } |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 79 | |
Leon Scroggins III | 4993b95 | 2016-12-08 11:54:04 -0500 | [diff] [blame] | 80 | // If no images are in the data, or the first header is not yet defined, we cannot |
| 81 | // create a codec. In either case, the width and height are not yet known. |
Leon Scroggins III | e726e7c | 2017-07-18 16:22:52 -0400 | [diff] [blame] | 82 | auto* frame = reader->frameContext(0); |
| 83 | if (!frame || !frame->isHeaderDefined()) { |
Leon Scroggins III | 588fb04 | 2017-07-14 16:32:31 -0400 | [diff] [blame] | 84 | *result = kInvalidInput; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 85 | return nullptr; |
| 86 | } |
| 87 | |
Leon Scroggins III | 4993b95 | 2016-12-08 11:54:04 -0500 | [diff] [blame] | 88 | // isHeaderDefined() will not return true if the screen size is empty. |
| 89 | SkASSERT(reader->screenHeight() > 0 && reader->screenWidth() > 0); |
| 90 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 91 | const auto alpha = reader->firstFrameHasAlpha() ? SkEncodedInfo::kBinary_Alpha |
| 92 | : SkEncodedInfo::kOpaque_Alpha; |
| 93 | // Use kPalette since Gifs are encoded with a color table. |
| 94 | // FIXME: Gifs can actually be encoded with 4-bits per pixel. Using 8 works, but we could skip |
| 95 | // expanding to 8 bits and take advantage of the SkSwizzler to work from 4. |
| 96 | const auto encodedInfo = SkEncodedInfo::Make(SkEncodedInfo::kPalette_Color, alpha, 8); |
| 97 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 98 | // The choice of unpremul versus premul is arbitrary, since all colors are either fully |
| 99 | // opaque or fully transparent (i.e. kBinary), but we stored the transparent colors as all |
| 100 | // zeroes, which is arguably premultiplied. |
| 101 | const auto alphaType = reader->firstFrameHasAlpha() ? kUnpremul_SkAlphaType |
| 102 | : kOpaque_SkAlphaType; |
Matt Sarett | 7f650bd | 2016-10-30 21:25:34 -0400 | [diff] [blame] | 103 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 104 | const auto imageInfo = SkImageInfo::Make(reader->screenWidth(), reader->screenHeight(), |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 105 | kN32_SkColorType, alphaType, |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 106 | SkColorSpace::MakeSRGB()); |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 107 | return std::unique_ptr<SkCodec>(new SkGifCodec(encodedInfo, imageInfo, reader.release())); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 108 | } |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 109 | |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 110 | bool SkGifCodec::onRewind() { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 111 | fReader->clearDecodeState(); |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 112 | return true; |
| 113 | } |
| 114 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 115 | SkGifCodec::SkGifCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imageInfo, |
scroggo | 3d3a65c | 2016-10-24 12:28:30 -0700 | [diff] [blame] | 116 | SkGifImageReader* reader) |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 117 | : INHERITED(encodedInfo, imageInfo, SkColorSpaceXform::kRGBA_8888_ColorFormat, nullptr) |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 118 | , fReader(reader) |
| 119 | , fTmpBuffer(nullptr) |
| 120 | , fSwizzler(nullptr) |
| 121 | , fCurrColorTable(nullptr) |
| 122 | , fCurrColorTableIsReal(false) |
| 123 | , fFilledBackground(false) |
| 124 | , fFirstCallToIncrementalDecode(false) |
| 125 | , fDst(nullptr) |
| 126 | , fDstRowBytes(0) |
| 127 | , fRowsDecoded(0) |
| 128 | { |
| 129 | reader->setClient(this); |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 130 | } |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 131 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 132 | int SkGifCodec::onGetFrameCount() { |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 133 | fReader->parse(SkGifImageReader::SkGIFFrameCountQuery); |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 134 | return fReader->imagesCount(); |
| 135 | } |
| 136 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 137 | bool SkGifCodec::onGetFrameInfo(int i, SkCodec::FrameInfo* frameInfo) const { |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 138 | if (i >= fReader->imagesCount()) { |
| 139 | return false; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 140 | } |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 141 | |
| 142 | const SkGIFFrameContext* frameContext = fReader->frameContext(i); |
Leon Scroggins III | e726e7c | 2017-07-18 16:22:52 -0400 | [diff] [blame] | 143 | SkASSERT(frameContext->reachedStartOfData()); |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 144 | |
| 145 | if (frameInfo) { |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 146 | frameInfo->fDuration = frameContext->getDuration(); |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 147 | frameInfo->fRequiredFrame = frameContext->getRequiredFrame(); |
| 148 | frameInfo->fFullyReceived = frameContext->isComplete(); |
| 149 | frameInfo->fAlphaType = frameContext->hasAlpha() ? kUnpremul_SkAlphaType |
| 150 | : kOpaque_SkAlphaType; |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 151 | frameInfo->fDisposalMethod = frameContext->getDisposalMethod(); |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 152 | } |
| 153 | return true; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 154 | } |
| 155 | |
scroggo | e71b1a1 | 2016-11-01 08:28:28 -0700 | [diff] [blame] | 156 | int SkGifCodec::onGetRepetitionCount() { |
| 157 | fReader->parse(SkGifImageReader::SkGIFLoopCountQuery); |
| 158 | return fReader->loopCount(); |
| 159 | } |
| 160 | |
Matt Sarett | 562e681 | 2016-11-08 16:13:43 -0500 | [diff] [blame] | 161 | static const SkColorType kXformSrcColorType = kRGBA_8888_SkColorType; |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 162 | static const SkAlphaType kXformAlphaType = kUnpremul_SkAlphaType; |
Matt Sarett | 562e681 | 2016-11-08 16:13:43 -0500 | [diff] [blame] | 163 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 164 | void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, int frameIndex) { |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 165 | SkColorType colorTableColorType = dstInfo.colorType(); |
| 166 | if (this->colorXform()) { |
Matt Sarett | 562e681 | 2016-11-08 16:13:43 -0500 | [diff] [blame] | 167 | colorTableColorType = kXformSrcColorType; |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | sk_sp<SkColorTable> currColorTable = fReader->getColorTable(colorTableColorType, frameIndex); |
Hal Canary | 9a0e390 | 2017-07-12 11:59:17 -0400 | [diff] [blame] | 171 | fCurrColorTableIsReal = static_cast<bool>(currColorTable); |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 172 | if (!fCurrColorTableIsReal) { |
Leon Scroggins III | a049ac4 | 2016-10-27 11:16:11 -0400 | [diff] [blame] | 173 | // This is possible for an empty frame. Create a dummy with one value (transparent). |
| 174 | SkPMColor color = SK_ColorTRANSPARENT; |
| 175 | fCurrColorTable.reset(new SkColorTable(&color, 1)); |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 176 | } else if (this->colorXform() && !this->xformOnDecode()) { |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 177 | SkPMColor dstColors[256]; |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 178 | this->applyColorXform(dstColors, currColorTable->readColors(), currColorTable->count(), |
| 179 | kXformAlphaType); |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 180 | fCurrColorTable.reset(new SkColorTable(dstColors, currColorTable->count())); |
| 181 | } else { |
| 182 | fCurrColorTable = std::move(currColorTable); |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 183 | } |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 184 | } |
| 185 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 186 | |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 187 | SkCodec::Result SkGifCodec::prepareToDecode(const SkImageInfo& dstInfo, const Options& opts) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 188 | if (opts.fSubset) { |
| 189 | return gif_error("Subsets not supported.\n", kUnimplemented); |
| 190 | } |
| 191 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 192 | const int frameIndex = opts.fFrameIndex; |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 193 | if (frameIndex > 0 && kRGB_565_SkColorType == dstInfo.colorType()) { |
| 194 | // FIXME: In theory, we might be able to support this, but it's not clear that it |
| 195 | // is necessary (Chromium does not decode to 565, and Android does not decode |
| 196 | // frames beyond the first). Disabling it because it is somewhat difficult: |
| 197 | // - If there is a transparent pixel, and this frame draws on top of another frame |
| 198 | // (if the frame is independent with a transparent pixel, we should not decode to |
| 199 | // 565 anyway, since it is not opaque), we need to skip drawing the transparent |
| 200 | // pixels (see writeTransparentPixels in haveDecodedRow). We currently do this by |
| 201 | // first swizzling into temporary memory, then copying into the destination. (We |
| 202 | // let the swizzler handle it first because it may need to sample.) After |
| 203 | // swizzling to 565, we do not know which pixels in our temporary memory |
| 204 | // correspond to the transparent pixel, so we do not know what to skip. We could |
| 205 | // special case the non-sampled case (no need to swizzle), but as this is |
| 206 | // currently unused we can just not support it. |
| 207 | return gif_error("Cannot decode multiframe gif (except frame 0) as 565.\n", |
| 208 | kInvalidConversion); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 211 | const auto* frame = fReader->frameContext(frameIndex); |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 212 | SkASSERT(frame); |
| 213 | if (0 == frameIndex) { |
| 214 | // SkCodec does not have a way to just parse through frame 0, so we |
| 215 | // have to do so manually, here. |
| 216 | fReader->parse((SkGifImageReader::SkGIFParseQuery) 0); |
| 217 | if (!frame->reachedStartOfData()) { |
| 218 | // We have parsed enough to know that there is a color map, but cannot |
| 219 | // parse the map itself yet. Exit now, so we do not build an incorrect |
| 220 | // table. |
| 221 | return gif_error("color map not available yet\n", kIncompleteInput); |
| 222 | } |
| 223 | } else { |
| 224 | // Parsing happened in SkCodec::getPixels. |
| 225 | SkASSERT(frameIndex < fReader->imagesCount()); |
| 226 | SkASSERT(frame->reachedStartOfData()); |
Leon Scroggins III | 3fc97d7 | 2016-12-09 16:39:33 -0500 | [diff] [blame] | 227 | } |
| 228 | |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 229 | const auto at = frame->hasAlpha() ? kUnpremul_SkAlphaType : kOpaque_SkAlphaType; |
| 230 | const auto srcInfo = this->getInfo().makeAlphaType(at); |
| 231 | if (!conversion_possible(dstInfo, srcInfo) || |
| 232 | !this->initializeColorXform(dstInfo, opts.fPremulBehavior)) |
| 233 | { |
| 234 | return gif_error("Cannot convert input type to output type.\n", kInvalidConversion); |
| 235 | } |
| 236 | |
| 237 | if (this->xformOnDecode()) { |
| 238 | fXformBuffer.reset(new uint32_t[dstInfo.width()]); |
| 239 | sk_bzero(fXformBuffer.get(), dstInfo.width() * sizeof(uint32_t)); |
| 240 | } |
| 241 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 242 | fTmpBuffer.reset(new uint8_t[dstInfo.minRowBytes()]); |
| 243 | |
Leon Scroggins III | fc49b40 | 2016-10-31 14:08:56 -0400 | [diff] [blame] | 244 | this->initializeColorTable(dstInfo, frameIndex); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 245 | this->initializeSwizzler(dstInfo, frameIndex); |
Leon Scroggins III | fc49b40 | 2016-10-31 14:08:56 -0400 | [diff] [blame] | 246 | |
| 247 | SkASSERT(fCurrColorTable); |
msarett | b30d698 | 2016-02-15 10:18:45 -0800 | [diff] [blame] | 248 | return kSuccess; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 251 | void SkGifCodec::initializeSwizzler(const SkImageInfo& dstInfo, int frameIndex) { |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 252 | const SkGIFFrameContext* frame = fReader->frameContext(frameIndex); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 253 | // This is only called by prepareToDecode, which ensures frameIndex is in range. |
| 254 | SkASSERT(frame); |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 255 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 256 | const int xBegin = frame->xOffset(); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 257 | const int xEnd = std::min(frame->frameRect().right(), fReader->screenWidth()); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 258 | |
| 259 | // CreateSwizzler only reads left and right of the frame. We cannot use the frame's raw |
| 260 | // frameRect, since it might extend beyond the edge of the frame. |
| 261 | SkIRect swizzleRect = SkIRect::MakeLTRB(xBegin, 0, xEnd, 0); |
| 262 | |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 263 | SkImageInfo swizzlerInfo = dstInfo; |
| 264 | if (this->colorXform()) { |
Matt Sarett | 562e681 | 2016-11-08 16:13:43 -0500 | [diff] [blame] | 265 | swizzlerInfo = swizzlerInfo.makeColorType(kXformSrcColorType); |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 266 | if (kPremul_SkAlphaType == dstInfo.alphaType()) { |
| 267 | swizzlerInfo = swizzlerInfo.makeAlphaType(kUnpremul_SkAlphaType); |
| 268 | } |
| 269 | } |
| 270 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 271 | // The default Options should be fine: |
| 272 | // - we'll ignore if the memory is zero initialized - unless we're the first frame, this won't |
| 273 | // matter anyway. |
| 274 | // - subsets are not supported for gif |
| 275 | // - the swizzler does not need to know about the frame. |
| 276 | // We may not be able to use the real Options anyway, since getPixels does not store it (due to |
| 277 | // a bug). |
| 278 | fSwizzler.reset(SkSwizzler::CreateSwizzler(this->getEncodedInfo(), |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 279 | fCurrColorTable->readColors(), swizzlerInfo, Options(), &swizzleRect)); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 280 | SkASSERT(fSwizzler.get()); |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /* |
| 284 | * Initiates the gif decode |
| 285 | */ |
| 286 | SkCodec::Result SkGifCodec::onGetPixels(const SkImageInfo& dstInfo, |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 287 | void* pixels, size_t dstRowBytes, |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 288 | const Options& opts, |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 289 | int* rowsDecoded) { |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 290 | Result result = this->prepareToDecode(dstInfo, opts); |
Leon Scroggins III | 3fc97d7 | 2016-12-09 16:39:33 -0500 | [diff] [blame] | 291 | switch (result) { |
| 292 | case kSuccess: |
| 293 | break; |
| 294 | case kIncompleteInput: |
| 295 | // onStartIncrementalDecode treats this as incomplete, since it may |
| 296 | // provide more data later, but in this case, no more data will be |
| 297 | // provided, and there is nothing to draw. We also cannot return |
| 298 | // kIncompleteInput, which will make SkCodec attempt to fill |
| 299 | // remaining rows, but that requires an SkSwizzler, which we have |
| 300 | // not created. |
| 301 | return kInvalidInput; |
| 302 | default: |
| 303 | return result; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
| 307 | return gif_error("Scaling not supported.\n", kInvalidScale); |
| 308 | } |
| 309 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 310 | fDst = pixels; |
| 311 | fDstRowBytes = dstRowBytes; |
| 312 | |
| 313 | return this->decodeFrame(true, opts, rowsDecoded); |
| 314 | } |
| 315 | |
| 316 | SkCodec::Result SkGifCodec::onStartIncrementalDecode(const SkImageInfo& dstInfo, |
| 317 | void* pixels, size_t dstRowBytes, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 318 | const SkCodec::Options& opts) { |
| 319 | Result result = this->prepareToDecode(dstInfo, opts); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 320 | if (result != kSuccess) { |
| 321 | return result; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 322 | } |
| 323 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 324 | fDst = pixels; |
| 325 | fDstRowBytes = dstRowBytes; |
| 326 | |
| 327 | fFirstCallToIncrementalDecode = true; |
| 328 | |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 329 | return kSuccess; |
| 330 | } |
| 331 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 332 | SkCodec::Result SkGifCodec::onIncrementalDecode(int* rowsDecoded) { |
| 333 | // It is possible the client has appended more data. Parse, if needed. |
| 334 | const auto& options = this->options(); |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 335 | const int frameIndex = options.fFrameIndex; |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 336 | fReader->parse((SkGifImageReader::SkGIFParseQuery) frameIndex); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 337 | |
| 338 | const bool firstCallToIncrementalDecode = fFirstCallToIncrementalDecode; |
| 339 | fFirstCallToIncrementalDecode = false; |
| 340 | return this->decodeFrame(firstCallToIncrementalDecode, options, rowsDecoded); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 341 | } |
| 342 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 343 | SkCodec::Result SkGifCodec::decodeFrame(bool firstAttempt, const Options& opts, int* rowsDecoded) { |
| 344 | const SkImageInfo& dstInfo = this->dstInfo(); |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 345 | const int frameIndex = opts.fFrameIndex; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 346 | SkASSERT(frameIndex < fReader->imagesCount()); |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 347 | const SkGIFFrameContext* frameContext = fReader->frameContext(frameIndex); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 348 | if (firstAttempt) { |
| 349 | // rowsDecoded reports how many rows have been initialized, so a layer above |
| 350 | // can fill the rest. In some cases, we fill the background before decoding |
| 351 | // (or it is already filled for us), so we report rowsDecoded to be the full |
| 352 | // height. |
| 353 | bool filledBackground = false; |
| 354 | if (frameContext->getRequiredFrame() == kNone) { |
| 355 | // We may need to clear to transparent for one of the following reasons: |
| 356 | // - The frameRect does not cover the full bounds. haveDecodedRow will |
| 357 | // only draw inside the frameRect, so we need to clear the rest. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 358 | // - The frame is interlaced. There is no obvious way to fill |
| 359 | // afterwards for an incomplete image. (FIXME: Does the first pass |
| 360 | // cover all rows? If so, we do not have to fill here.) |
scroggo | 8bce117 | 2016-10-25 13:08:40 -0700 | [diff] [blame] | 361 | // - There is no color table for this frame. In that case will not |
| 362 | // draw anything, so we need to fill. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 363 | if (frameContext->frameRect() != this->getInfo().bounds() |
scroggo | 8bce117 | 2016-10-25 13:08:40 -0700 | [diff] [blame] | 364 | || frameContext->interlaced() || !fCurrColorTableIsReal) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 365 | // fill ignores the width (replaces it with the actual, scaled width). |
| 366 | // But we need to scale in Y. |
| 367 | const int scaledHeight = get_scaled_dimension(dstInfo.height(), |
| 368 | fSwizzler->sampleY()); |
| 369 | auto fillInfo = dstInfo.makeWH(0, scaledHeight); |
| 370 | fSwizzler->fill(fillInfo, fDst, fDstRowBytes, this->getFillValue(dstInfo), |
| 371 | opts.fZeroInitialized); |
| 372 | filledBackground = true; |
| 373 | } |
| 374 | } else { |
Leon Scroggins III | 1f6af6b | 2017-06-12 16:41:09 -0400 | [diff] [blame] | 375 | // Not independent. |
| 376 | // SkCodec ensured that the prior frame has been decoded. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 377 | filledBackground = true; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 378 | } |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 379 | |
| 380 | fFilledBackground = filledBackground; |
| 381 | if (filledBackground) { |
| 382 | // Report the full (scaled) height, since the client will never need to fill. |
| 383 | fRowsDecoded = get_scaled_dimension(dstInfo.height(), fSwizzler->sampleY()); |
| 384 | } else { |
| 385 | // This will be updated by haveDecodedRow. |
| 386 | fRowsDecoded = 0; |
| 387 | } |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 388 | } |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 389 | |
Leon Scroggins III | 3fc97d7 | 2016-12-09 16:39:33 -0500 | [diff] [blame] | 390 | if (!fCurrColorTableIsReal) { |
| 391 | // Nothing to draw this frame. |
| 392 | return kSuccess; |
| 393 | } |
| 394 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 395 | bool frameDecoded = false; |
Leon Scroggins III | 674a184 | 2017-07-06 12:26:09 -0400 | [diff] [blame] | 396 | const bool fatalError = !fReader->decode(frameIndex, &frameDecoded); |
| 397 | if (fatalError || !frameDecoded) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 398 | if (rowsDecoded) { |
| 399 | *rowsDecoded = fRowsDecoded; |
| 400 | } |
Leon Scroggins III | 674a184 | 2017-07-06 12:26:09 -0400 | [diff] [blame] | 401 | if (fatalError) { |
| 402 | return kErrorInInput; |
| 403 | } |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 404 | return kIncompleteInput; |
| 405 | } |
| 406 | |
| 407 | return kSuccess; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 408 | } |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 409 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 410 | uint64_t SkGifCodec::onGetFillValue(const SkImageInfo& dstInfo) const { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 411 | // Using transparent as the fill value matches the behavior in Chromium, |
| 412 | // which ignores the background color. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 413 | return SK_ColorTRANSPARENT; |
| 414 | } |
msarett | 72261c0 | 2015-11-19 15:29:26 -0800 | [diff] [blame] | 415 | |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 416 | void SkGifCodec::applyXformRow(const SkImageInfo& dstInfo, void* dst, const uint8_t* src) const { |
Leon Scroggins III | c6e6a5f | 2017-06-05 15:53:38 -0400 | [diff] [blame] | 417 | if (this->xformOnDecode()) { |
| 418 | SkASSERT(this->colorXform()); |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 419 | fSwizzler->swizzle(fXformBuffer.get(), src); |
| 420 | |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 421 | const int xformWidth = get_scaled_dimension(dstInfo.width(), fSwizzler->sampleX()); |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 422 | this->applyColorXform(dst, fXformBuffer.get(), xformWidth, kXformAlphaType); |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 423 | } else { |
| 424 | fSwizzler->swizzle(dst, src); |
| 425 | } |
| 426 | } |
| 427 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 428 | bool SkGifCodec::haveDecodedRow(int frameIndex, const unsigned char* rowBegin, |
| 429 | int rowNumber, int repeatCount, bool writeTransparentPixels) |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 430 | { |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 431 | const SkGIFFrameContext* frameContext = fReader->frameContext(frameIndex); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 432 | // The pixel data and coordinates supplied to us are relative to the frame's |
| 433 | // origin within the entire image size, i.e. |
| 434 | // (frameContext->xOffset, frameContext->yOffset). There is no guarantee |
| 435 | // that width == (size().width() - frameContext->xOffset), so |
| 436 | // we must ensure we don't run off the end of either the source data or the |
| 437 | // row's X-coordinates. |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 438 | const int width = frameContext->width(); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 439 | const int xBegin = frameContext->xOffset(); |
| 440 | const int yBegin = frameContext->yOffset() + rowNumber; |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 441 | const int xEnd = std::min(xBegin + width, this->getInfo().width()); |
| 442 | const int yEnd = std::min(yBegin + rowNumber + repeatCount, this->getInfo().height()); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 443 | // FIXME: No need to make the checks on width/xBegin/xEnd for every row. We could instead do |
| 444 | // this once in prepareToDecode. |
| 445 | if (!width || (xBegin < 0) || (yBegin < 0) || (xEnd <= xBegin) || (yEnd <= yBegin)) |
| 446 | return true; |
| 447 | |
| 448 | // yBegin is the first row in the non-sampled image. dstRow will be the row in the output, |
| 449 | // after potentially scaling it. |
| 450 | int dstRow = yBegin; |
| 451 | |
| 452 | const int sampleY = fSwizzler->sampleY(); |
| 453 | if (sampleY > 1) { |
| 454 | // Check to see whether this row or one that falls in the repeatCount is needed in the |
| 455 | // output. |
| 456 | bool foundNecessaryRow = false; |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 457 | for (int i = 0; i < repeatCount; i++) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 458 | const int potentialRow = yBegin + i; |
| 459 | if (fSwizzler->rowNeeded(potentialRow)) { |
| 460 | dstRow = potentialRow / sampleY; |
| 461 | const int scaledHeight = get_scaled_dimension(this->dstInfo().height(), sampleY); |
| 462 | if (dstRow >= scaledHeight) { |
| 463 | return true; |
| 464 | } |
| 465 | |
| 466 | foundNecessaryRow = true; |
| 467 | repeatCount -= i; |
| 468 | |
| 469 | repeatCount = (repeatCount - 1) / sampleY + 1; |
| 470 | |
| 471 | // Make sure the repeatCount does not take us beyond the end of the dst |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 472 | if (dstRow + repeatCount > scaledHeight) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 473 | repeatCount = scaledHeight - dstRow; |
| 474 | SkASSERT(repeatCount >= 1); |
| 475 | } |
| 476 | break; |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | if (!foundNecessaryRow) { |
| 481 | return true; |
| 482 | } |
Matt Sarett | 8a4e9c5 | 2016-10-25 14:24:50 -0400 | [diff] [blame] | 483 | } else { |
| 484 | // Make sure the repeatCount does not take us beyond the end of the dst |
| 485 | SkASSERT(this->dstInfo().height() >= yBegin); |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 486 | repeatCount = SkTMin(repeatCount, this->dstInfo().height() - yBegin); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | if (!fFilledBackground) { |
| 490 | // At this point, we are definitely going to write the row, so count it towards the number |
| 491 | // of rows decoded. |
| 492 | // We do not consider the repeatCount, which only happens for interlaced, in which case we |
| 493 | // have already set fRowsDecoded to the proper value (reflecting that we have filled the |
| 494 | // background). |
| 495 | fRowsDecoded++; |
| 496 | } |
| 497 | |
Leon Scroggins III | 3fc97d7 | 2016-12-09 16:39:33 -0500 | [diff] [blame] | 498 | // decodeFrame will early exit if this is false, so this method will not be |
| 499 | // called. |
| 500 | SkASSERT(fCurrColorTableIsReal); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 501 | |
| 502 | // The swizzler takes care of offsetting into the dst width-wise. |
| 503 | void* dstLine = SkTAddOffset<void>(fDst, dstRow * fDstRowBytes); |
| 504 | |
| 505 | // We may or may not need to write transparent pixels to the buffer. |
scroggo | 1285f41 | 2016-10-26 13:48:03 -0700 | [diff] [blame] | 506 | // If we're compositing against a previous image, it's wrong, but if |
| 507 | // we're decoding an interlaced gif and displaying it "Haeberli"-style, |
| 508 | // we must write these for passes beyond the first, or the initial passes |
| 509 | // will "show through" the later ones. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 510 | const auto dstInfo = this->dstInfo(); |
scroggo | 53f63b6 | 2016-10-27 08:29:13 -0700 | [diff] [blame] | 511 | if (writeTransparentPixels) { |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 512 | this->applyXformRow(dstInfo, dstLine, rowBegin); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 513 | } else { |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 514 | this->applyXformRow(dstInfo, fTmpBuffer.get(), rowBegin); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 515 | |
Leon Scroggins III | e43fdb3 | 2017-07-17 19:41:46 -0400 | [diff] [blame] | 516 | size_t offsetBytes = fSwizzler->swizzleOffsetBytes(); |
| 517 | if (dstInfo.colorType() == kRGBA_F16_SkColorType) { |
| 518 | // Account for the fact that post-swizzling we converted to F16, |
| 519 | // which is twice as wide. |
| 520 | offsetBytes *= 2; |
| 521 | } |
| 522 | SkRasterPipeline_<256> p; |
| 523 | SkRasterPipeline::StockStage storeDst; |
| 524 | void* src = SkTAddOffset<void>(fTmpBuffer.get(), offsetBytes); |
| 525 | void* dst = SkTAddOffset<void>(dstLine, offsetBytes); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 526 | |
| 527 | SkJumper_MemoryCtx src_ctx = { src, 0 }, |
| 528 | dst_ctx = { dst, 0 }; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 529 | switch (dstInfo.colorType()) { |
| 530 | case kBGRA_8888_SkColorType: |
Leon Scroggins III | e43fdb3 | 2017-07-17 19:41:46 -0400 | [diff] [blame] | 531 | case kRGBA_8888_SkColorType: |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 532 | p.append(SkRasterPipeline::load_8888_dst, &dst_ctx); |
| 533 | p.append(SkRasterPipeline::load_8888, &src_ctx); |
Leon Scroggins III | e43fdb3 | 2017-07-17 19:41:46 -0400 | [diff] [blame] | 534 | storeDst = SkRasterPipeline::store_8888; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 535 | break; |
Leon Scroggins III | e43fdb3 | 2017-07-17 19:41:46 -0400 | [diff] [blame] | 536 | case kRGBA_F16_SkColorType: |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 537 | p.append(SkRasterPipeline::load_f16_dst, &dst_ctx); |
| 538 | p.append(SkRasterPipeline::load_f16, &src_ctx); |
Leon Scroggins III | e43fdb3 | 2017-07-17 19:41:46 -0400 | [diff] [blame] | 539 | storeDst = SkRasterPipeline::store_f16; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 540 | break; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 541 | default: |
| 542 | SkASSERT(false); |
Leon Scroggins III | e43fdb3 | 2017-07-17 19:41:46 -0400 | [diff] [blame] | 543 | return false; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 544 | break; |
| 545 | } |
Leon Scroggins III | e43fdb3 | 2017-07-17 19:41:46 -0400 | [diff] [blame] | 546 | p.append(SkRasterPipeline::srcover); |
| 547 | p.append(storeDst, &dst); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 548 | p.run(0,0, fSwizzler->swizzleWidth(),1); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | // Tell the frame to copy the row data if need be. |
| 552 | if (repeatCount > 1) { |
| 553 | const size_t bytesPerPixel = SkColorTypeBytesPerPixel(this->dstInfo().colorType()); |
| 554 | const size_t bytesToCopy = fSwizzler->swizzleWidth() * bytesPerPixel; |
| 555 | void* copiedLine = SkTAddOffset<void>(dstLine, fSwizzler->swizzleOffsetBytes()); |
| 556 | void* dst = copiedLine; |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 557 | for (int i = 1; i < repeatCount; i++) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 558 | dst = SkTAddOffset<void>(dst, fDstRowBytes); |
| 559 | memcpy(dst, copiedLine, bytesToCopy); |
msarett | 72261c0 | 2015-11-19 15:29:26 -0800 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
| 563 | return true; |
| 564 | } |