Chromium Code Reviews| Index: src/codec/SkGifInterlaceIter.cpp |
| diff --git a/src/codec/SkGifInterlaceIter.cpp b/src/codec/SkGifInterlaceIter.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..64911d78f5f1882e91b28798a38562617a73e446 |
| --- /dev/null |
| +++ b/src/codec/SkGifInterlaceIter.cpp |
| @@ -0,0 +1,49 @@ |
| +/* |
| + * Copyright 2015 The Android Open Source Project |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "SkGifInterlaceIter.h" |
| + |
| +static const uint8_t kStartingInterlaceYValue[] = { 0, 4, 2, 1 }; |
|
scroggo
2015/03/25 19:44:49
nit: Values, plural.
msarett
2015/03/26 19:15:57
Done.
|
| +static const uint8_t kDeltaInterlaceYValue[] = { 8, 8, 4, 2 }; |
| + |
| +SkGifInterlaceIter::SkGifInterlaceIter(int height) : fHeight(height) { |
| + fStartYPtr = kStartingInterlaceYValue; |
| + fDeltaYPtr = kDeltaInterlaceYValue; |
| + |
| + fCurrY = *fStartYPtr++; |
| + fDeltaY = *fDeltaYPtr++; |
| +} |
| + |
| +void SkGifInterlaceIter::prepareY() { |
| + uint32_t y = fCurrY + fDeltaY; |
| + |
| + // We went from an if statement to a while loop so that we iterate |
|
scroggo
2015/03/25 19:44:49
Are you saying that the old decoder trashed memory
msarett
2015/03/26 19:15:57
This comment is straight from the old decoder. I
|
| + // through fStartYPtr until a valid row is found. This is so that |
| + // images that are smaller than 5x5 will not trash memory. |
| + while (y >= fHeight) { |
| + if (kStartingInterlaceYValue + |
| + SK_ARRAY_COUNT(kStartingInterlaceYValue) == fStartYPtr) { |
| + // Now we have iterated over the entire image. Forbid any |
| + // subsequent calls to nextY(). |
| + SkDEBUGCODE(fStartYPtr = NULL;) |
| + SkDEBUGCODE(fDeltaYPtr = NULL;) |
| + y = 0; |
| + } else { |
| + y = *fStartYPtr++; |
| + fDeltaY = *fDeltaYPtr++; |
| + } |
| + } |
| + fCurrY = y; |
| +} |
| + |
| +uint32_t SkGifInterlaceIter::nextY() { |
| + SkASSERT(fStartYPtr); |
| + SkASSERT(fDeltaYPtr); |
| + uint32_t y = fCurrY; |
| + prepareY(); |
| + return y; |
| +} |