From 60c068f3b23d8d7ab428b4c2b1a6829664bfa09b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 15 Mar 2019 13:25:29 +1100 Subject: [PATCH] Fixed indentation --- src/libImaging/GifDecode.c | 404 ++++++++++++++++++------------------- 1 file changed, 202 insertions(+), 202 deletions(-) diff --git a/src/libImaging/GifDecode.c b/src/libImaging/GifDecode.c index 3de4c5386..3febd8454 100644 --- a/src/libImaging/GifDecode.c +++ b/src/libImaging/GifDecode.c @@ -70,231 +70,231 @@ ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes) if (!state->state) { - /* Initialise state */ - if (context->bits < 0 || context->bits > 12) { - state->errcode = IMAGING_CODEC_CONFIG; - return -1; - } + /* Initialise state */ + if (context->bits < 0 || context->bits > 12) { + state->errcode = IMAGING_CODEC_CONFIG; + return -1; + } - /* Clear code */ - context->clear = 1 << context->bits; + /* Clear code */ + context->clear = 1 << context->bits; - /* End code */ - context->end = context->clear + 1; + /* End code */ + context->end = context->clear + 1; - /* Interlace */ - if (context->interlace) { - context->interlace = 1; - context->step = context->repeat = 8; - } else - context->step = 1; + /* Interlace */ + if (context->interlace) { + context->interlace = 1; + context->step = context->repeat = 8; + } else + context->step = 1; - state->state = 1; + state->state = 1; } out = im->image8[state->y + state->yoff] + state->xoff + state->x; for (;;) { - if (state->state == 1) { + if (state->state == 1) { - /* First free entry in table */ - context->next = context->clear + 2; + /* First free entry in table */ + context->next = context->clear + 2; - /* Initial code size */ - context->codesize = context->bits + 1; - context->codemask = (1 << context->codesize) - 1; - - /* Buffer pointer. We fill the buffer from right, which - allows us to return all of it in one operation. */ - context->bufferindex = GIFBUFFER; - - state->state = 2; - } - - if (context->bufferindex < GIFBUFFER) { - - /* Return whole buffer in one chunk */ - i = GIFBUFFER - context->bufferindex; - p = &context->buffer[context->bufferindex]; - - context->bufferindex = GIFBUFFER; - - } else { - - /* Get current symbol */ - - while (context->bitcount < context->codesize) { - - if (context->blocksize > 0) { - - /* Read next byte */ - c = *ptr++; bytes--; - - context->blocksize--; - - /* New bits are shifted in from from the left. */ - context->bitbuffer |= (INT32) c << context->bitcount; - context->bitcount += 8; - - } else { - - /* New GIF block */ - - /* We don't start decoding unless we have a full block */ - if (bytes < 1) - return ptr - buffer; - c = *ptr; - if (bytes < c+1) - return ptr - buffer; - - context->blocksize = c; - - ptr++; bytes--; - - } - } - - /* Extract current symbol from bit buffer. */ - c = (int) context->bitbuffer & context->codemask; - - /* Adjust buffer */ - context->bitbuffer >>= context->codesize; - context->bitcount -= context->codesize; - - /* If c is less than "clear", it's a data byte. Otherwise, - it's either clear/end or a code symbol which should be - expanded. */ - - if (c == context->clear) { - if (state->state != 2) - state->state = 1; - continue; - } - - if (c == context->end) - break; - - i = 1; - p = &context->lastdata; - - if (state->state == 2) { - - /* First valid symbol after clear; use as is */ - if (c > context->clear) { - state->errcode = IMAGING_CODEC_BROKEN; - return -1; - } - - context->lastdata = context->lastcode = c; - state->state = 3; - - } else { - - thiscode = c; - - if (c > context->next) { - state->errcode = IMAGING_CODEC_BROKEN; - return -1; - } - - if (c == context->next) { - - /* c == next is allowed. not sure why. */ - - if (context->bufferindex <= 0) { - state->errcode = IMAGING_CODEC_BROKEN; - return -1; - } - - context->buffer[--context->bufferindex] = - context->lastdata; - - c = context->lastcode; - - } - - while (c >= context->clear) { - - /* Copy data string to buffer (beginning from right) */ - - if (context->bufferindex <= 0 || c >= GIFTABLE) { - state->errcode = IMAGING_CODEC_BROKEN; - return -1; - } - - context->buffer[--context->bufferindex] = - context->data[c]; - - c = context->link[c]; - } - - context->lastdata = c; - - if (context->next < GIFTABLE) { - - /* We'll only add this symbol if we have room - for it (take advise, Netscape!) */ - context->data[context->next] = c; - context->link[context->next] = context->lastcode; - - if (context->next == context->codemask && - context->codesize < GIFBITS) { - - /* Expand code size */ - context->codesize++; + /* Initial code size */ + context->codesize = context->bits + 1; context->codemask = (1 << context->codesize) - 1; + + /* Buffer pointer. We fill the buffer from right, which + allows us to return all of it in one operation. */ + context->bufferindex = GIFBUFFER; + + state->state = 2; + } + + if (context->bufferindex < GIFBUFFER) { + + /* Return whole buffer in one chunk */ + i = GIFBUFFER - context->bufferindex; + p = &context->buffer[context->bufferindex]; + + context->bufferindex = GIFBUFFER; + + } else { + + /* Get current symbol */ + + while (context->bitcount < context->codesize) { + + if (context->blocksize > 0) { + + /* Read next byte */ + c = *ptr++; bytes--; + + context->blocksize--; + + /* New bits are shifted in from from the left. */ + context->bitbuffer |= (INT32) c << context->bitcount; + context->bitcount += 8; + + } else { + + /* New GIF block */ + + /* We don't start decoding unless we have a full block */ + if (bytes < 1) + return ptr - buffer; + c = *ptr; + if (bytes < c+1) + return ptr - buffer; + + context->blocksize = c; + + ptr++; bytes--; + + } } - context->next++; + /* Extract current symbol from bit buffer. */ + c = (int) context->bitbuffer & context->codemask; + /* Adjust buffer */ + context->bitbuffer >>= context->codesize; + context->bitcount -= context->codesize; + + /* If c is less than "clear", it's a data byte. Otherwise, + it's either clear/end or a code symbol which should be + expanded. */ + + if (c == context->clear) { + if (state->state != 2) + state->state = 1; + continue; + } + + if (c == context->end) + break; + + i = 1; + p = &context->lastdata; + + if (state->state == 2) { + + /* First valid symbol after clear; use as is */ + if (c > context->clear) { + state->errcode = IMAGING_CODEC_BROKEN; + return -1; + } + + context->lastdata = context->lastcode = c; + state->state = 3; + + } else { + + thiscode = c; + + if (c > context->next) { + state->errcode = IMAGING_CODEC_BROKEN; + return -1; + } + + if (c == context->next) { + + /* c == next is allowed. not sure why. */ + + if (context->bufferindex <= 0) { + state->errcode = IMAGING_CODEC_BROKEN; + return -1; + } + + context->buffer[--context->bufferindex] = + context->lastdata; + + c = context->lastcode; + + } + + while (c >= context->clear) { + + /* Copy data string to buffer (beginning from right) */ + + if (context->bufferindex <= 0 || c >= GIFTABLE) { + state->errcode = IMAGING_CODEC_BROKEN; + return -1; + } + + context->buffer[--context->bufferindex] = + context->data[c]; + + c = context->link[c]; + } + + context->lastdata = c; + + if (context->next < GIFTABLE) { + + /* We'll only add this symbol if we have room + for it (take advise, Netscape!) */ + context->data[context->next] = c; + context->link[context->next] = context->lastcode; + + if (context->next == context->codemask && + context->codesize < GIFBITS) { + + /* Expand code size */ + context->codesize++; + context->codemask = (1 << context->codesize) - 1; + } + + context->next++; + + } + + context->lastcode = thiscode; + + } } - context->lastcode = thiscode; - + /* Copy the bytes into the image */ + if (state->y >= state->ysize) { + state->errcode = IMAGING_CODEC_OVERRUN; + return -1; } - } - /* Copy the bytes into the image */ - if (state->y >= state->ysize) { - state->errcode = IMAGING_CODEC_OVERRUN; - return -1; - } + /* To squeeze some extra pixels out of this loop, we test for + some common cases and handle them separately. */ - /* To squeeze some extra pixels out of this loop, we test for - some common cases and handle them separately. */ + /* If we have transparency, we need to use the regular loop. */ + if(context->transparency == -1) + { + if (i == 1) { + if (state->x < state->xsize-1) { + /* Single pixel, not at the end of the line. */ + *out++ = p[0]; + state->x++; + continue; + } + } else if (state->x + i <= state->xsize) { + /* This string fits into current line. */ + memcpy(out, p, i); + out += i; + state->x += i; + if (state->x == state->xsize) { + NEWLINE(state, context); + } + continue; + } + } - /* If we have transparency, we need to use the regular loop. */ - if(context->transparency == -1) - { - if (i == 1) { - if (state->x < state->xsize-1) { - /* Single pixel, not at the end of the line. */ - *out++ = p[0]; - state->x++; - continue; + /* No shortcut, copy pixel by pixel */ + for (c = 0; c < i; c++) { + if(p[c] != context->transparency) + *out = p[c]; + out++; + if (++state->x >= state->xsize) { + NEWLINE(state, context); + } } - } else if (state->x + i <= state->xsize) { - /* This string fits into current line. */ - memcpy(out, p, i); - out += i; - state->x += i; - if (state->x == state->xsize) { - NEWLINE(state, context); - } - continue; - } - } - - /* No shortcut, copy pixel by pixel */ - for (c = 0; c < i; c++) { - if(p[c] != context->transparency) - *out = p[c]; - out++; - if (++state->x >= state->xsize) { - NEWLINE(state, context); - } - } } return ptr - buffer;