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