1 /* 2 * Copyright 2015 The Android Open Source Project 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 8 #include "SkGifInterlaceIter.h" 9 10 static const uint8_t kStartingInterlaceYValues[] = { 0, 4, 2, 1 }; 11 static const uint8_t kDeltaInterlaceYValues[] = { 8, 8, 4, 2 }; 12 SkGifInterlaceIter(int height)13SkGifInterlaceIter::SkGifInterlaceIter(int height) : fHeight(height) { 14 fStartYPtr = kStartingInterlaceYValues; 15 fDeltaYPtr = kDeltaInterlaceYValues; 16 17 fCurrY = *fStartYPtr++; 18 fDeltaY = *fDeltaYPtr++; 19 } 20 prepareY()21void SkGifInterlaceIter::prepareY() { 22 int32_t y = fCurrY + fDeltaY; 23 24 // Iterate through fStartYPtr until a valid row is found. 25 // This ensures that we do not move past the height of the small images. 26 while (y >= fHeight) { 27 if (kStartingInterlaceYValues + 28 SK_ARRAY_COUNT(kStartingInterlaceYValues) == fStartYPtr) { 29 // Now we have iterated over the entire image. Forbid any 30 // subsequent calls to nextY(). 31 SkDEBUGCODE(fStartYPtr = NULL;) 32 SkDEBUGCODE(fDeltaYPtr = NULL;) 33 y = 0; 34 } else { 35 y = *fStartYPtr++; 36 fDeltaY = *fDeltaYPtr++; 37 } 38 } 39 fCurrY = y; 40 } 41 nextY()42int32_t SkGifInterlaceIter::nextY() { 43 SkASSERT(fStartYPtr); 44 SkASSERT(fDeltaYPtr); 45 int32_t y = fCurrY; 46 prepareY(); 47 return y; 48 } 49