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" |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 38 | #include "SkStream.h" |
| 39 | #include "SkSwizzler.h" |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 40 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 41 | #include <algorithm> |
| 42 | |
| 43 | #define GIF87_STAMP "GIF87a" |
| 44 | #define GIF89_STAMP "GIF89a" |
| 45 | #define GIF_STAMP_LEN 6 |
msarett | 39b2d5a | 2016-02-17 08:26:31 -0800 | [diff] [blame] | 46 | |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 47 | /* |
| 48 | * Checks the start of the stream to see if the image is a gif |
| 49 | */ |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 50 | bool SkGifCodec::IsGif(const void* buf, size_t bytesRead) { |
| 51 | if (bytesRead >= GIF_STAMP_LEN) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 52 | if (memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 || |
bungeman | 0153dea | 2015-08-27 16:43:42 -0700 | [diff] [blame] | 53 | memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) |
| 54 | { |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 55 | return true; |
| 56 | } |
| 57 | } |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | /* |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 62 | * Error function |
| 63 | */ |
bungeman | 0153dea | 2015-08-27 16:43:42 -0700 | [diff] [blame] | 64 | static SkCodec::Result gif_error(const char* msg, SkCodec::Result result = SkCodec::kInvalidInput) { |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 65 | SkCodecPrintf("Gif Error: %s\n", msg); |
| 66 | return result; |
| 67 | } |
| 68 | |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 69 | /* |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 70 | * Assumes IsGif was called and returned true |
| 71 | * Creates a gif decoder |
| 72 | * Reads enough of the stream to determine the image format |
| 73 | */ |
| 74 | SkCodec* SkGifCodec::NewFromStream(SkStream* stream) { |
scroggo | 3d3a65c | 2016-10-24 12:28:30 -0700 | [diff] [blame] | 75 | std::unique_ptr<SkGifImageReader> reader(new SkGifImageReader(stream)); |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 76 | if (!reader->parse(SkGifImageReader::SkGIFSizeQuery)) { |
Leon Scroggins III | 4993b95 | 2016-12-08 11:54:04 -0500 | [diff] [blame^] | 77 | // Fatal error occurred. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 78 | return nullptr; |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 79 | } |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 80 | |
Leon Scroggins III | 4993b95 | 2016-12-08 11:54:04 -0500 | [diff] [blame^] | 81 | // If no images are in the data, or the first header is not yet defined, we cannot |
| 82 | // create a codec. In either case, the width and height are not yet known. |
| 83 | if (0 == reader->imagesCount() || !reader->frameContext(0)->isHeaderDefined()) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 84 | return nullptr; |
| 85 | } |
| 86 | |
Leon Scroggins III | 4993b95 | 2016-12-08 11:54:04 -0500 | [diff] [blame^] | 87 | // isHeaderDefined() will not return true if the screen size is empty. |
| 88 | SkASSERT(reader->screenHeight() > 0 && reader->screenWidth() > 0); |
| 89 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 90 | const auto alpha = reader->firstFrameHasAlpha() ? SkEncodedInfo::kBinary_Alpha |
| 91 | : SkEncodedInfo::kOpaque_Alpha; |
| 92 | // Use kPalette since Gifs are encoded with a color table. |
| 93 | // FIXME: Gifs can actually be encoded with 4-bits per pixel. Using 8 works, but we could skip |
| 94 | // expanding to 8 bits and take advantage of the SkSwizzler to work from 4. |
| 95 | const auto encodedInfo = SkEncodedInfo::Make(SkEncodedInfo::kPalette_Color, alpha, 8); |
| 96 | |
| 97 | // Although the encodedInfo is always kPalette_Color, it is possible that kIndex_8 is |
| 98 | // unsupported if the frame is subset and there is no transparent pixel. |
| 99 | const auto colorType = reader->firstFrameSupportsIndex8() ? kIndex_8_SkColorType |
| 100 | : kN32_SkColorType; |
| 101 | // The choice of unpremul versus premul is arbitrary, since all colors are either fully |
| 102 | // opaque or fully transparent (i.e. kBinary), but we stored the transparent colors as all |
| 103 | // zeroes, which is arguably premultiplied. |
| 104 | const auto alphaType = reader->firstFrameHasAlpha() ? kUnpremul_SkAlphaType |
| 105 | : kOpaque_SkAlphaType; |
Matt Sarett | 7f650bd | 2016-10-30 21:25:34 -0400 | [diff] [blame] | 106 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 107 | const auto imageInfo = SkImageInfo::Make(reader->screenWidth(), reader->screenHeight(), |
Matt Sarett | 7f650bd | 2016-10-30 21:25:34 -0400 | [diff] [blame] | 108 | colorType, alphaType, |
| 109 | SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named)); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 110 | return new SkGifCodec(encodedInfo, imageInfo, reader.release()); |
| 111 | } |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 112 | |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 113 | bool SkGifCodec::onRewind() { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 114 | fReader->clearDecodeState(); |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 115 | return true; |
| 116 | } |
| 117 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 118 | SkGifCodec::SkGifCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imageInfo, |
scroggo | 3d3a65c | 2016-10-24 12:28:30 -0700 | [diff] [blame] | 119 | SkGifImageReader* reader) |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 120 | : INHERITED(encodedInfo, imageInfo, nullptr) |
| 121 | , fReader(reader) |
| 122 | , fTmpBuffer(nullptr) |
| 123 | , fSwizzler(nullptr) |
| 124 | , fCurrColorTable(nullptr) |
| 125 | , fCurrColorTableIsReal(false) |
| 126 | , fFilledBackground(false) |
| 127 | , fFirstCallToIncrementalDecode(false) |
| 128 | , fDst(nullptr) |
| 129 | , fDstRowBytes(0) |
| 130 | , fRowsDecoded(0) |
| 131 | { |
| 132 | reader->setClient(this); |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 133 | } |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 134 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 135 | std::vector<SkCodec::FrameInfo> SkGifCodec::onGetFrameInfo() { |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 136 | fReader->parse(SkGifImageReader::SkGIFFrameCountQuery); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 137 | const size_t size = fReader->imagesCount(); |
| 138 | std::vector<FrameInfo> result(size); |
| 139 | for (size_t i = 0; i < size; i++) { |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 140 | const SkGIFFrameContext* frameContext = fReader->frameContext(i); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 141 | result[i].fDuration = frameContext->delayTime(); |
| 142 | result[i].fRequiredFrame = frameContext->getRequiredFrame(); |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 143 | } |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 144 | return result; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 145 | } |
| 146 | |
scroggo | e71b1a1 | 2016-11-01 08:28:28 -0700 | [diff] [blame] | 147 | int SkGifCodec::onGetRepetitionCount() { |
| 148 | fReader->parse(SkGifImageReader::SkGIFLoopCountQuery); |
| 149 | return fReader->loopCount(); |
| 150 | } |
| 151 | |
Matt Sarett | 562e681 | 2016-11-08 16:13:43 -0500 | [diff] [blame] | 152 | static const SkColorType kXformSrcColorType = kRGBA_8888_SkColorType; |
| 153 | |
Leon Scroggins III | fc49b40 | 2016-10-31 14:08:56 -0400 | [diff] [blame] | 154 | void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, size_t frameIndex) { |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 155 | SkColorType colorTableColorType = dstInfo.colorType(); |
| 156 | if (this->colorXform()) { |
Matt Sarett | 562e681 | 2016-11-08 16:13:43 -0500 | [diff] [blame] | 157 | colorTableColorType = kXformSrcColorType; |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | sk_sp<SkColorTable> currColorTable = fReader->getColorTable(colorTableColorType, frameIndex); |
| 161 | fCurrColorTableIsReal = currColorTable; |
| 162 | if (!fCurrColorTableIsReal) { |
Leon Scroggins III | a049ac4 | 2016-10-27 11:16:11 -0400 | [diff] [blame] | 163 | // This is possible for an empty frame. Create a dummy with one value (transparent). |
| 164 | SkPMColor color = SK_ColorTRANSPARENT; |
| 165 | fCurrColorTable.reset(new SkColorTable(&color, 1)); |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 166 | } else if (this->colorXform() && !fXformOnDecode) { |
| 167 | SkPMColor dstColors[256]; |
Matt Sarett | 562e681 | 2016-11-08 16:13:43 -0500 | [diff] [blame] | 168 | const SkColorSpaceXform::ColorFormat dstFormat = select_xform_format(dstInfo.colorType()); |
| 169 | const SkColorSpaceXform::ColorFormat srcFormat = select_xform_format(kXformSrcColorType); |
| 170 | const SkAlphaType xformAlphaType = select_xform_alpha(dstInfo.alphaType(), |
| 171 | this->getInfo().alphaType()); |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 172 | SkAssertResult(this->colorXform()->apply(dstFormat, dstColors, srcFormat, |
| 173 | currColorTable->readColors(), |
| 174 | currColorTable->count(), xformAlphaType)); |
| 175 | fCurrColorTable.reset(new SkColorTable(dstColors, currColorTable->count())); |
| 176 | } else { |
| 177 | fCurrColorTable = std::move(currColorTable); |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 178 | } |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 179 | } |
| 180 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 181 | |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 182 | SkCodec::Result SkGifCodec::prepareToDecode(const SkImageInfo& dstInfo, SkPMColor* inputColorPtr, |
| 183 | int* inputColorCount, const Options& opts) { |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 184 | // Check for valid input parameters |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 185 | if (!conversion_possible(dstInfo, this->getInfo()) || !this->initializeColorXform(dstInfo)) { |
msarett | 2ecc35f | 2016-09-08 11:55:16 -0700 | [diff] [blame] | 186 | return gif_error("Cannot convert input type to output type.\n", kInvalidConversion); |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 189 | fXformOnDecode = false; |
| 190 | if (this->colorXform()) { |
| 191 | fXformOnDecode = apply_xform_on_decode(dstInfo.colorType(), this->getEncodedInfo().color()); |
| 192 | if (fXformOnDecode) { |
| 193 | fXformBuffer.reset(new uint32_t[dstInfo.width()]); |
| 194 | sk_bzero(fXformBuffer.get(), dstInfo.width() * sizeof(uint32_t)); |
| 195 | } |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 196 | } |
msarett | 5af4e0b | 2015-11-17 11:18:03 -0800 | [diff] [blame] | 197 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 198 | if (opts.fSubset) { |
| 199 | return gif_error("Subsets not supported.\n", kUnimplemented); |
| 200 | } |
| 201 | |
| 202 | const size_t frameIndex = opts.fFrameIndex; |
scroggo | 53f63b6 | 2016-10-27 08:29:13 -0700 | [diff] [blame] | 203 | if (frameIndex > 0) { |
| 204 | switch (dstInfo.colorType()) { |
| 205 | case kIndex_8_SkColorType: |
| 206 | // FIXME: It is possible that a later frame can be decoded to index8, if it does one |
| 207 | // of the following: |
| 208 | // - Covers the entire previous frame |
| 209 | // - Shares a color table (and transparent index) with any prior frames that are |
| 210 | // showing. |
| 211 | // We must support index8 for the first frame to be backwards compatible on Android, |
| 212 | // but we do not (currently) need to support later frames as index8. |
| 213 | return gif_error("Cannot decode multiframe gif (except frame 0) as index 8.\n", |
| 214 | kInvalidConversion); |
| 215 | case kRGB_565_SkColorType: |
| 216 | // FIXME: In theory, we might be able to support this, but it's not clear that it |
| 217 | // is necessary (Chromium does not decode to 565, and Android does not decode |
| 218 | // frames beyond the first). Disabling it because it is somewhat difficult: |
| 219 | // - If there is a transparent pixel, and this frame draws on top of another frame |
| 220 | // (if the frame is independent with a transparent pixel, we should not decode to |
| 221 | // 565 anyway, since it is not opaque), we need to skip drawing the transparent |
| 222 | // pixels (see writeTransparentPixels in haveDecodedRow). We currently do this by |
| 223 | // first swizzling into temporary memory, then copying into the destination. (We |
| 224 | // let the swizzler handle it first because it may need to sample.) After |
| 225 | // swizzling to 565, we do not know which pixels in our temporary memory |
| 226 | // correspond to the transparent pixel, so we do not know what to skip. We could |
| 227 | // special case the non-sampled case (no need to swizzle), but as this is |
| 228 | // currently unused we can just not support it. |
| 229 | return gif_error("Cannot decode multiframe gif (except frame 0) as 565.\n", |
| 230 | kInvalidConversion); |
| 231 | default: |
| 232 | break; |
| 233 | } |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 234 | } |
| 235 | |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 236 | fReader->parse((SkGifImageReader::SkGIFParseQuery) frameIndex); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 237 | |
| 238 | if (frameIndex >= fReader->imagesCount()) { |
| 239 | return gif_error("frame index out of range!\n", kIncompleteInput); |
| 240 | } |
| 241 | |
| 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); |
| 248 | if (inputColorCount) { |
| 249 | *inputColorCount = fCurrColorTable->count(); |
| 250 | } |
| 251 | copy_color_table(dstInfo, fCurrColorTable.get(), inputColorPtr, inputColorCount); |
| 252 | |
msarett | b30d698 | 2016-02-15 10:18:45 -0800 | [diff] [blame] | 253 | return kSuccess; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 254 | } |
| 255 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 256 | void SkGifCodec::initializeSwizzler(const SkImageInfo& dstInfo, size_t frameIndex) { |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 257 | const SkGIFFrameContext* frame = fReader->frameContext(frameIndex); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 258 | // This is only called by prepareToDecode, which ensures frameIndex is in range. |
| 259 | SkASSERT(frame); |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 260 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 261 | const int xBegin = frame->xOffset(); |
| 262 | const int xEnd = std::min(static_cast<int>(frame->xOffset() + frame->width()), |
| 263 | static_cast<int>(fReader->screenWidth())); |
| 264 | |
| 265 | // CreateSwizzler only reads left and right of the frame. We cannot use the frame's raw |
| 266 | // frameRect, since it might extend beyond the edge of the frame. |
| 267 | SkIRect swizzleRect = SkIRect::MakeLTRB(xBegin, 0, xEnd, 0); |
| 268 | |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 269 | SkImageInfo swizzlerInfo = dstInfo; |
| 270 | if (this->colorXform()) { |
Matt Sarett | 562e681 | 2016-11-08 16:13:43 -0500 | [diff] [blame] | 271 | swizzlerInfo = swizzlerInfo.makeColorType(kXformSrcColorType); |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 272 | if (kPremul_SkAlphaType == dstInfo.alphaType()) { |
| 273 | swizzlerInfo = swizzlerInfo.makeAlphaType(kUnpremul_SkAlphaType); |
| 274 | } |
| 275 | } |
| 276 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 277 | // The default Options should be fine: |
| 278 | // - we'll ignore if the memory is zero initialized - unless we're the first frame, this won't |
| 279 | // matter anyway. |
| 280 | // - subsets are not supported for gif |
| 281 | // - the swizzler does not need to know about the frame. |
| 282 | // We may not be able to use the real Options anyway, since getPixels does not store it (due to |
| 283 | // a bug). |
| 284 | fSwizzler.reset(SkSwizzler::CreateSwizzler(this->getEncodedInfo(), |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 285 | fCurrColorTable->readColors(), swizzlerInfo, Options(), &swizzleRect)); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 286 | SkASSERT(fSwizzler.get()); |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /* |
| 290 | * Initiates the gif decode |
| 291 | */ |
| 292 | SkCodec::Result SkGifCodec::onGetPixels(const SkImageInfo& dstInfo, |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 293 | void* pixels, size_t dstRowBytes, |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 294 | const Options& opts, |
| 295 | SkPMColor* inputColorPtr, |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 296 | int* inputColorCount, |
| 297 | int* rowsDecoded) { |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 298 | Result result = this->prepareToDecode(dstInfo, inputColorPtr, inputColorCount, opts); |
| 299 | if (kSuccess != result) { |
| 300 | return result; |
| 301 | } |
| 302 | |
| 303 | if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
| 304 | return gif_error("Scaling not supported.\n", kInvalidScale); |
| 305 | } |
| 306 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 307 | fDst = pixels; |
| 308 | fDstRowBytes = dstRowBytes; |
| 309 | |
| 310 | return this->decodeFrame(true, opts, rowsDecoded); |
| 311 | } |
| 312 | |
| 313 | SkCodec::Result SkGifCodec::onStartIncrementalDecode(const SkImageInfo& dstInfo, |
| 314 | void* pixels, size_t dstRowBytes, |
| 315 | const SkCodec::Options& opts, |
| 316 | SkPMColor* inputColorPtr, |
| 317 | int* inputColorCount) { |
| 318 | Result result = this->prepareToDecode(dstInfo, inputColorPtr, inputColorCount, opts); |
| 319 | if (result != kSuccess) { |
| 320 | return result; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 321 | } |
| 322 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 323 | fDst = pixels; |
| 324 | fDstRowBytes = dstRowBytes; |
| 325 | |
| 326 | fFirstCallToIncrementalDecode = true; |
| 327 | |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 328 | return kSuccess; |
| 329 | } |
| 330 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 331 | SkCodec::Result SkGifCodec::onIncrementalDecode(int* rowsDecoded) { |
| 332 | // It is possible the client has appended more data. Parse, if needed. |
| 333 | const auto& options = this->options(); |
| 334 | const size_t frameIndex = options.fFrameIndex; |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 335 | fReader->parse((SkGifImageReader::SkGIFParseQuery) frameIndex); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 336 | |
| 337 | const bool firstCallToIncrementalDecode = fFirstCallToIncrementalDecode; |
| 338 | fFirstCallToIncrementalDecode = false; |
| 339 | return this->decodeFrame(firstCallToIncrementalDecode, options, rowsDecoded); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 340 | } |
| 341 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 342 | SkCodec::Result SkGifCodec::decodeFrame(bool firstAttempt, const Options& opts, int* rowsDecoded) { |
| 343 | const SkImageInfo& dstInfo = this->dstInfo(); |
| 344 | const size_t frameIndex = opts.fFrameIndex; |
| 345 | SkASSERT(frameIndex < fReader->imagesCount()); |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 346 | const SkGIFFrameContext* frameContext = fReader->frameContext(frameIndex); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 347 | if (firstAttempt) { |
| 348 | // rowsDecoded reports how many rows have been initialized, so a layer above |
| 349 | // can fill the rest. In some cases, we fill the background before decoding |
| 350 | // (or it is already filled for us), so we report rowsDecoded to be the full |
| 351 | // height. |
| 352 | bool filledBackground = false; |
| 353 | if (frameContext->getRequiredFrame() == kNone) { |
| 354 | // We may need to clear to transparent for one of the following reasons: |
| 355 | // - The frameRect does not cover the full bounds. haveDecodedRow will |
| 356 | // only draw inside the frameRect, so we need to clear the rest. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 357 | // - The frame is interlaced. There is no obvious way to fill |
| 358 | // afterwards for an incomplete image. (FIXME: Does the first pass |
| 359 | // cover all rows? If so, we do not have to fill here.) |
scroggo | 8bce117 | 2016-10-25 13:08:40 -0700 | [diff] [blame] | 360 | // - There is no color table for this frame. In that case will not |
| 361 | // draw anything, so we need to fill. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 362 | if (frameContext->frameRect() != this->getInfo().bounds() |
scroggo | 8bce117 | 2016-10-25 13:08:40 -0700 | [diff] [blame] | 363 | || frameContext->interlaced() || !fCurrColorTableIsReal) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 364 | // fill ignores the width (replaces it with the actual, scaled width). |
| 365 | // But we need to scale in Y. |
| 366 | const int scaledHeight = get_scaled_dimension(dstInfo.height(), |
| 367 | fSwizzler->sampleY()); |
| 368 | auto fillInfo = dstInfo.makeWH(0, scaledHeight); |
| 369 | fSwizzler->fill(fillInfo, fDst, fDstRowBytes, this->getFillValue(dstInfo), |
| 370 | opts.fZeroInitialized); |
| 371 | filledBackground = true; |
| 372 | } |
| 373 | } else { |
| 374 | // Not independent |
| 375 | if (!opts.fHasPriorFrame) { |
| 376 | // Decode that frame into pixels. |
| 377 | Options prevFrameOpts(opts); |
| 378 | prevFrameOpts.fFrameIndex = frameContext->getRequiredFrame(); |
| 379 | prevFrameOpts.fHasPriorFrame = false; |
Leon Scroggins III | fc49b40 | 2016-10-31 14:08:56 -0400 | [diff] [blame] | 380 | // The prior frame may have a different color table, so update it and the |
| 381 | // swizzler. |
| 382 | this->initializeColorTable(dstInfo, prevFrameOpts.fFrameIndex); |
| 383 | this->initializeSwizzler(dstInfo, prevFrameOpts.fFrameIndex); |
| 384 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 385 | const Result prevResult = this->decodeFrame(true, prevFrameOpts, nullptr); |
| 386 | switch (prevResult) { |
| 387 | case kSuccess: |
| 388 | // Prior frame succeeded. Carry on. |
| 389 | break; |
| 390 | case kIncompleteInput: |
| 391 | // Prior frame was incomplete. So this frame cannot be decoded. |
| 392 | return kInvalidInput; |
| 393 | default: |
| 394 | return prevResult; |
| 395 | } |
Leon Scroggins III | fc49b40 | 2016-10-31 14:08:56 -0400 | [diff] [blame] | 396 | |
| 397 | // Go back to using the correct color table for this frame. |
| 398 | this->initializeColorTable(dstInfo, frameIndex); |
| 399 | this->initializeSwizzler(dstInfo, frameIndex); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 400 | } |
| 401 | const auto* prevFrame = fReader->frameContext(frameContext->getRequiredFrame()); |
| 402 | if (prevFrame->getDisposalMethod() == SkCodecAnimation::RestoreBGColor_DisposalMethod) { |
| 403 | const SkIRect prevRect = prevFrame->frameRect(); |
| 404 | auto left = get_scaled_dimension(prevRect.fLeft, fSwizzler->sampleX()); |
| 405 | auto top = get_scaled_dimension(prevRect.fTop, fSwizzler->sampleY()); |
| 406 | void* const eraseDst = SkTAddOffset<void>(fDst, top * fDstRowBytes |
| 407 | + left * SkColorTypeBytesPerPixel(dstInfo.colorType())); |
| 408 | auto width = get_scaled_dimension(prevRect.width(), fSwizzler->sampleX()); |
| 409 | auto height = get_scaled_dimension(prevRect.height(), fSwizzler->sampleY()); |
| 410 | // fSwizzler->fill() would fill to the scaled width of the frame, but we want to |
| 411 | // fill to the scaled with of the width of the PRIOR frame, so we do all the scaling |
| 412 | // ourselves and call the static version. |
| 413 | SkSampler::Fill(dstInfo.makeWH(width, height), eraseDst, |
| 414 | fDstRowBytes, this->getFillValue(dstInfo), kNo_ZeroInitialized); |
| 415 | } |
| 416 | filledBackground = true; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 417 | } |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 418 | |
| 419 | fFilledBackground = filledBackground; |
| 420 | if (filledBackground) { |
| 421 | // Report the full (scaled) height, since the client will never need to fill. |
| 422 | fRowsDecoded = get_scaled_dimension(dstInfo.height(), fSwizzler->sampleY()); |
| 423 | } else { |
| 424 | // This will be updated by haveDecodedRow. |
| 425 | fRowsDecoded = 0; |
| 426 | } |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 427 | } |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 428 | |
scroggo | 3d3a65c | 2016-10-24 12:28:30 -0700 | [diff] [blame] | 429 | // Note: there is a difference between the following call to SkGifImageReader::decode |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 430 | // returning false and leaving frameDecoded false: |
| 431 | // - If the method returns false, there was an error in the stream. We still treat this as |
| 432 | // incomplete, since we have already decoded some rows. |
| 433 | // - If frameDecoded is false, that just means that we do not have enough data. If more data |
| 434 | // is supplied, we may be able to continue decoding this frame. We also treat this as |
| 435 | // incomplete. |
| 436 | // FIXME: Ensure that we do not attempt to continue decoding if the method returns false and |
| 437 | // more data is supplied. |
| 438 | bool frameDecoded = false; |
| 439 | if (!fReader->decode(frameIndex, &frameDecoded) || !frameDecoded) { |
| 440 | if (rowsDecoded) { |
| 441 | *rowsDecoded = fRowsDecoded; |
| 442 | } |
| 443 | return kIncompleteInput; |
| 444 | } |
| 445 | |
| 446 | return kSuccess; |
msarett | 10522ff | 2015-09-07 08:54:01 -0700 | [diff] [blame] | 447 | } |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 448 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 449 | uint64_t SkGifCodec::onGetFillValue(const SkImageInfo& dstInfo) const { |
| 450 | // Note: Using fCurrColorTable relies on having called initializeColorTable already. |
| 451 | // This is (currently) safe because this method is only called when filling, after |
| 452 | // initializeColorTable has been called. |
| 453 | // FIXME: Is there a way to make this less fragile? |
| 454 | if (dstInfo.colorType() == kIndex_8_SkColorType && fCurrColorTableIsReal) { |
| 455 | // We only support index 8 for the first frame, for backwards |
| 456 | // compatibity on Android, so we are using the color table for the first frame. |
| 457 | SkASSERT(this->options().fFrameIndex == 0); |
| 458 | // Use the transparent index for the first frame. |
| 459 | const size_t transPixel = fReader->frameContext(0)->transparentPixel(); |
| 460 | if (transPixel < (size_t) fCurrColorTable->count()) { |
| 461 | return transPixel; |
| 462 | } |
| 463 | // Fall through to return SK_ColorTRANSPARENT (i.e. 0). This choice is arbitrary, |
| 464 | // but we have to pick something inside the color table, and this one is as good |
| 465 | // as any. |
| 466 | } |
| 467 | // Using transparent as the fill value matches the behavior in Chromium, |
| 468 | // which ignores the background color. |
| 469 | // If the colorType is kIndex_8, and there was no color table (i.e. |
| 470 | // fCurrColorTableIsReal is false), this value (zero) corresponds to the |
| 471 | // only entry in the dummy color table provided to the client. |
| 472 | return SK_ColorTRANSPARENT; |
| 473 | } |
msarett | 72261c0 | 2015-11-19 15:29:26 -0800 | [diff] [blame] | 474 | |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 475 | void SkGifCodec::applyXformRow(const SkImageInfo& dstInfo, void* dst, const uint8_t* src) const { |
| 476 | if (this->colorXform() && fXformOnDecode) { |
| 477 | fSwizzler->swizzle(fXformBuffer.get(), src); |
| 478 | |
| 479 | const SkColorSpaceXform::ColorFormat dstFormat = select_xform_format(dstInfo.colorType()); |
Matt Sarett | 562e681 | 2016-11-08 16:13:43 -0500 | [diff] [blame] | 480 | const SkColorSpaceXform::ColorFormat srcFormat = select_xform_format(kXformSrcColorType); |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 481 | const SkAlphaType xformAlphaType = select_xform_alpha(dstInfo.alphaType(), |
| 482 | this->getInfo().alphaType()); |
| 483 | const int xformWidth = get_scaled_dimension(dstInfo.width(), fSwizzler->sampleX()); |
| 484 | SkAssertResult(this->colorXform()->apply(dstFormat, dst, srcFormat, fXformBuffer.get(), |
| 485 | xformWidth, xformAlphaType)); |
| 486 | } else { |
| 487 | fSwizzler->swizzle(dst, src); |
| 488 | } |
| 489 | } |
| 490 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 491 | bool SkGifCodec::haveDecodedRow(size_t frameIndex, const unsigned char* rowBegin, |
| 492 | size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels) |
| 493 | { |
scroggo | f9acbe2 | 2016-10-25 12:43:21 -0700 | [diff] [blame] | 494 | const SkGIFFrameContext* frameContext = fReader->frameContext(frameIndex); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 495 | // The pixel data and coordinates supplied to us are relative to the frame's |
| 496 | // origin within the entire image size, i.e. |
| 497 | // (frameContext->xOffset, frameContext->yOffset). There is no guarantee |
| 498 | // that width == (size().width() - frameContext->xOffset), so |
| 499 | // we must ensure we don't run off the end of either the source data or the |
| 500 | // row's X-coordinates. |
| 501 | const size_t width = frameContext->width(); |
| 502 | const int xBegin = frameContext->xOffset(); |
| 503 | const int yBegin = frameContext->yOffset() + rowNumber; |
| 504 | const int xEnd = std::min(static_cast<int>(frameContext->xOffset() + width), |
| 505 | this->getInfo().width()); |
| 506 | const int yEnd = std::min(static_cast<int>(frameContext->yOffset() + rowNumber + repeatCount), |
| 507 | this->getInfo().height()); |
| 508 | // FIXME: No need to make the checks on width/xBegin/xEnd for every row. We could instead do |
| 509 | // this once in prepareToDecode. |
| 510 | if (!width || (xBegin < 0) || (yBegin < 0) || (xEnd <= xBegin) || (yEnd <= yBegin)) |
| 511 | return true; |
| 512 | |
| 513 | // yBegin is the first row in the non-sampled image. dstRow will be the row in the output, |
| 514 | // after potentially scaling it. |
| 515 | int dstRow = yBegin; |
| 516 | |
| 517 | const int sampleY = fSwizzler->sampleY(); |
| 518 | if (sampleY > 1) { |
| 519 | // Check to see whether this row or one that falls in the repeatCount is needed in the |
| 520 | // output. |
| 521 | bool foundNecessaryRow = false; |
| 522 | for (unsigned i = 0; i < repeatCount; i++) { |
| 523 | const int potentialRow = yBegin + i; |
| 524 | if (fSwizzler->rowNeeded(potentialRow)) { |
| 525 | dstRow = potentialRow / sampleY; |
| 526 | const int scaledHeight = get_scaled_dimension(this->dstInfo().height(), sampleY); |
| 527 | if (dstRow >= scaledHeight) { |
| 528 | return true; |
| 529 | } |
| 530 | |
| 531 | foundNecessaryRow = true; |
| 532 | repeatCount -= i; |
| 533 | |
| 534 | repeatCount = (repeatCount - 1) / sampleY + 1; |
| 535 | |
| 536 | // Make sure the repeatCount does not take us beyond the end of the dst |
| 537 | if (dstRow + (int) repeatCount > scaledHeight) { |
| 538 | repeatCount = scaledHeight - dstRow; |
| 539 | SkASSERT(repeatCount >= 1); |
| 540 | } |
| 541 | break; |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | if (!foundNecessaryRow) { |
| 546 | return true; |
| 547 | } |
Matt Sarett | 8a4e9c5 | 2016-10-25 14:24:50 -0400 | [diff] [blame] | 548 | } else { |
| 549 | // Make sure the repeatCount does not take us beyond the end of the dst |
| 550 | SkASSERT(this->dstInfo().height() >= yBegin); |
| 551 | repeatCount = SkTMin(repeatCount, (unsigned) (this->dstInfo().height() - yBegin)); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | if (!fFilledBackground) { |
| 555 | // At this point, we are definitely going to write the row, so count it towards the number |
| 556 | // of rows decoded. |
| 557 | // We do not consider the repeatCount, which only happens for interlaced, in which case we |
| 558 | // have already set fRowsDecoded to the proper value (reflecting that we have filled the |
| 559 | // background). |
| 560 | fRowsDecoded++; |
| 561 | } |
| 562 | |
| 563 | if (!fCurrColorTableIsReal) { |
| 564 | // No color table, so nothing to draw this frame. |
| 565 | // FIXME: We can abort even earlier - no need to decode this frame. |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | // The swizzler takes care of offsetting into the dst width-wise. |
| 570 | void* dstLine = SkTAddOffset<void>(fDst, dstRow * fDstRowBytes); |
| 571 | |
| 572 | // We may or may not need to write transparent pixels to the buffer. |
scroggo | 1285f41 | 2016-10-26 13:48:03 -0700 | [diff] [blame] | 573 | // If we're compositing against a previous image, it's wrong, but if |
| 574 | // we're decoding an interlaced gif and displaying it "Haeberli"-style, |
| 575 | // we must write these for passes beyond the first, or the initial passes |
| 576 | // will "show through" the later ones. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 577 | const auto dstInfo = this->dstInfo(); |
scroggo | 53f63b6 | 2016-10-27 08:29:13 -0700 | [diff] [blame] | 578 | if (writeTransparentPixels) { |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 579 | this->applyXformRow(dstInfo, dstLine, rowBegin); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 580 | } else { |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 581 | sk_bzero(fTmpBuffer.get(), dstInfo.minRowBytes()); |
| 582 | this->applyXformRow(dstInfo, fTmpBuffer.get(), rowBegin); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 583 | |
| 584 | const size_t offsetBytes = fSwizzler->swizzleOffsetBytes(); |
| 585 | switch (dstInfo.colorType()) { |
| 586 | case kBGRA_8888_SkColorType: |
| 587 | case kRGBA_8888_SkColorType: { |
| 588 | uint32_t* dstPixel = SkTAddOffset<uint32_t>(dstLine, offsetBytes); |
| 589 | uint32_t* srcPixel = SkTAddOffset<uint32_t>(fTmpBuffer.get(), offsetBytes); |
| 590 | for (int i = 0; i < fSwizzler->swizzleWidth(); i++) { |
| 591 | // Technically SK_ColorTRANSPARENT is an SkPMColor, and srcPixel would have |
| 592 | // the opposite swizzle for the non-native swizzle, but TRANSPARENT is all |
| 593 | // zeroes, which is the same either way. |
| 594 | if (*srcPixel != SK_ColorTRANSPARENT) { |
| 595 | *dstPixel = *srcPixel; |
| 596 | } |
| 597 | dstPixel++; |
| 598 | srcPixel++; |
| 599 | } |
| 600 | break; |
| 601 | } |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 602 | case kRGBA_F16_SkColorType: { |
| 603 | uint64_t* dstPixel = SkTAddOffset<uint64_t>(dstLine, offsetBytes); |
| 604 | uint64_t* srcPixel = SkTAddOffset<uint64_t>(fTmpBuffer.get(), offsetBytes); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 605 | for (int i = 0; i < fSwizzler->swizzleWidth(); i++) { |
Matt Sarett | 61eedeb | 2016-11-04 13:19:48 -0400 | [diff] [blame] | 606 | if (*srcPixel != 0) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 607 | *dstPixel = *srcPixel; |
| 608 | } |
| 609 | dstPixel++; |
| 610 | srcPixel++; |
| 611 | } |
| 612 | break; |
| 613 | } |
| 614 | default: |
| 615 | SkASSERT(false); |
| 616 | break; |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | // Tell the frame to copy the row data if need be. |
| 621 | if (repeatCount > 1) { |
| 622 | const size_t bytesPerPixel = SkColorTypeBytesPerPixel(this->dstInfo().colorType()); |
| 623 | const size_t bytesToCopy = fSwizzler->swizzleWidth() * bytesPerPixel; |
| 624 | void* copiedLine = SkTAddOffset<void>(dstLine, fSwizzler->swizzleOffsetBytes()); |
| 625 | void* dst = copiedLine; |
| 626 | for (unsigned i = 1; i < repeatCount; i++) { |
| 627 | dst = SkTAddOffset<void>(dst, fDstRowBytes); |
| 628 | memcpy(dst, copiedLine, bytesToCopy); |
msarett | 72261c0 | 2015-11-19 15:29:26 -0800 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
| 632 | return true; |
| 633 | } |