aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec/SkGifInterlaceIter.cpp
blob: 268a142e8678b35e71573c9b58199c87bcb873ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * 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 kStartingInterlaceYValues[] = { 0, 4, 2, 1 };
static const uint8_t kDeltaInterlaceYValues[] = { 8, 8, 4, 2 };

SkGifInterlaceIter::SkGifInterlaceIter(int height) : fHeight(height) {
    fStartYPtr = kStartingInterlaceYValues;
    fDeltaYPtr = kDeltaInterlaceYValues;

    fCurrY = *fStartYPtr++;
    fDeltaY = *fDeltaYPtr++;
}

void SkGifInterlaceIter::prepareY() {
    int32_t y = fCurrY + fDeltaY;

    // Iterate through fStartYPtr until a valid row is found.
    // This ensures that we do not move past the height of the small images.
    while (y >= fHeight) {
        if (kStartingInterlaceYValues +
                SK_ARRAY_COUNT(kStartingInterlaceYValues) == 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;
}

int32_t SkGifInterlaceIter::nextY() {
    SkASSERT(fStartYPtr);
    SkASSERT(fDeltaYPtr);
    int32_t y = fCurrY;
    prepareY();
    return y;
}