mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-22 05:04:46 +03:00
Replaced tabs with spaces
This commit is contained in:
parent
4ff47705a7
commit
644e7c0c69
|
@ -5,15 +5,15 @@
|
||||||
* a fast, suspendable GIF decoder
|
* a fast, suspendable GIF decoder
|
||||||
*
|
*
|
||||||
* history:
|
* history:
|
||||||
* 95-09-03 fl Created
|
* 95-09-03 fl Created
|
||||||
* 95-09-05 fl Fixed sign problem on 16-bit platforms
|
* 95-09-05 fl Fixed sign problem on 16-bit platforms
|
||||||
* 95-09-13 fl Added some storage shortcuts
|
* 95-09-13 fl Added some storage shortcuts
|
||||||
* 96-03-28 fl Revised API, integrated with PIL
|
* 96-03-28 fl Revised API, integrated with PIL
|
||||||
* 96-12-10 fl Added interlace support
|
* 96-12-10 fl Added interlace support
|
||||||
* 96-12-16 fl Fixed premature termination bug introduced by last fix
|
* 96-12-16 fl Fixed premature termination bug introduced by last fix
|
||||||
* 97-01-05 fl Don't mess up on bogus configuration
|
* 97-01-05 fl Don't mess up on bogus configuration
|
||||||
* 97-01-17 fl Don't mess up on very small, interlaced files
|
* 97-01-17 fl Don't mess up on very small, interlaced files
|
||||||
* 99-02-07 fl Minor speedups
|
* 99-02-07 fl Minor speedups
|
||||||
*
|
*
|
||||||
* Copyright (c) Secret Labs AB 1997-99.
|
* Copyright (c) Secret Labs AB 1997-99.
|
||||||
* Copyright (c) Fredrik Lundh 1995-97.
|
* Copyright (c) Fredrik Lundh 1995-97.
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <memory.h> /* memcpy() */
|
#include <memory.h> /* memcpy() */
|
||||||
|
|
||||||
#include "Gif.h"
|
#include "Gif.h"
|
||||||
|
|
||||||
|
@ -34,23 +34,23 @@
|
||||||
state->x = 0;\
|
state->x = 0;\
|
||||||
state->y += context->step;\
|
state->y += context->step;\
|
||||||
while (state->y >= state->ysize)\
|
while (state->y >= state->ysize)\
|
||||||
switch (context->interlace) {\
|
switch (context->interlace) {\
|
||||||
case 1:\
|
case 1:\
|
||||||
context->repeat = state->y = 4;\
|
context->repeat = state->y = 4;\
|
||||||
context->interlace = 2;\
|
context->interlace = 2;\
|
||||||
break;\
|
break;\
|
||||||
case 2:\
|
case 2:\
|
||||||
context->step = 4;\
|
context->step = 4;\
|
||||||
context->repeat = state->y = 2;\
|
context->repeat = state->y = 2;\
|
||||||
context->interlace = 3;\
|
context->interlace = 3;\
|
||||||
break;\
|
break;\
|
||||||
case 3:\
|
case 3:\
|
||||||
context->step = 2;\
|
context->step = 2;\
|
||||||
context->repeat = state->y = 1;\
|
context->repeat = state->y = 1;\
|
||||||
context->interlace = 0;\
|
context->interlace = 0;\
|
||||||
break;\
|
break;\
|
||||||
default:\
|
default:\
|
||||||
return -1;\
|
return -1;\
|
||||||
}\
|
}\
|
||||||
if (state->y < state->ysize)\
|
if (state->y < state->ysize)\
|
||||||
out = im->image8[state->y + state->yoff] + state->xoff;\
|
out = im->image8[state->y + state->yoff] + state->xoff;\
|
||||||
|
@ -70,231 +70,231 @@ ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes)
|
||||||
|
|
||||||
if (!state->state) {
|
if (!state->state) {
|
||||||
|
|
||||||
/* Initialise state */
|
/* Initialise state */
|
||||||
if (context->bits < 0 || context->bits > 12) {
|
if (context->bits < 0 || context->bits > 12) {
|
||||||
state->errcode = IMAGING_CODEC_CONFIG;
|
state->errcode = IMAGING_CODEC_CONFIG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear code */
|
/* Clear code */
|
||||||
context->clear = 1 << context->bits;
|
context->clear = 1 << context->bits;
|
||||||
|
|
||||||
/* End code */
|
/* End code */
|
||||||
context->end = context->clear + 1;
|
context->end = context->clear + 1;
|
||||||
|
|
||||||
/* Interlace */
|
/* Interlace */
|
||||||
if (context->interlace) {
|
if (context->interlace) {
|
||||||
context->interlace = 1;
|
context->interlace = 1;
|
||||||
context->step = context->repeat = 8;
|
context->step = context->repeat = 8;
|
||||||
} else
|
} else
|
||||||
context->step = 1;
|
context->step = 1;
|
||||||
|
|
||||||
state->state = 1;
|
state->state = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
out = im->image8[state->y + state->yoff] + state->xoff + state->x;
|
out = im->image8[state->y + state->yoff] + state->xoff + state->x;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
if (state->state == 1) {
|
if (state->state == 1) {
|
||||||
|
|
||||||
/* First free entry in table */
|
/* First free entry in table */
|
||||||
context->next = context->clear + 2;
|
context->next = context->clear + 2;
|
||||||
|
|
||||||
/* Initial code size */
|
/* Initial code size */
|
||||||
context->codesize = context->bits + 1;
|
context->codesize = context->bits + 1;
|
||||||
context->codemask = (1 << context->codesize) - 1;
|
context->codemask = (1 << context->codesize) - 1;
|
||||||
|
|
||||||
/* Buffer pointer. We fill the buffer from right, which
|
/* Buffer pointer. We fill the buffer from right, which
|
||||||
allows us to return all of it in one operation. */
|
allows us to return all of it in one operation. */
|
||||||
context->bufferindex = GIFBUFFER;
|
context->bufferindex = GIFBUFFER;
|
||||||
|
|
||||||
state->state = 2;
|
state->state = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context->bufferindex < GIFBUFFER) {
|
if (context->bufferindex < GIFBUFFER) {
|
||||||
|
|
||||||
/* Return whole buffer in one chunk */
|
/* Return whole buffer in one chunk */
|
||||||
i = GIFBUFFER - context->bufferindex;
|
i = GIFBUFFER - context->bufferindex;
|
||||||
p = &context->buffer[context->bufferindex];
|
p = &context->buffer[context->bufferindex];
|
||||||
|
|
||||||
context->bufferindex = GIFBUFFER;
|
context->bufferindex = GIFBUFFER;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Get current symbol */
|
/* Get current symbol */
|
||||||
|
|
||||||
while (context->bitcount < context->codesize) {
|
while (context->bitcount < context->codesize) {
|
||||||
|
|
||||||
if (context->blocksize > 0) {
|
if (context->blocksize > 0) {
|
||||||
|
|
||||||
/* Read next byte */
|
/* Read next byte */
|
||||||
c = *ptr++; bytes--;
|
c = *ptr++; bytes--;
|
||||||
|
|
||||||
context->blocksize--;
|
context->blocksize--;
|
||||||
|
|
||||||
/* New bits are shifted in from from the left. */
|
/* New bits are shifted in from from the left. */
|
||||||
context->bitbuffer |= (INT32) c << context->bitcount;
|
context->bitbuffer |= (INT32) c << context->bitcount;
|
||||||
context->bitcount += 8;
|
context->bitcount += 8;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* New GIF block */
|
/* New GIF block */
|
||||||
|
|
||||||
/* We don't start decoding unless we have a full block */
|
/* We don't start decoding unless we have a full block */
|
||||||
if (bytes < 1)
|
if (bytes < 1)
|
||||||
return ptr - buffer;
|
return ptr - buffer;
|
||||||
c = *ptr;
|
c = *ptr;
|
||||||
if (bytes < c+1)
|
if (bytes < c+1)
|
||||||
return ptr - buffer;
|
return ptr - buffer;
|
||||||
|
|
||||||
context->blocksize = c;
|
context->blocksize = c;
|
||||||
|
|
||||||
ptr++; bytes--;
|
ptr++; bytes--;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract current symbol from bit buffer. */
|
/* Extract current symbol from bit buffer. */
|
||||||
c = (int) context->bitbuffer & context->codemask;
|
c = (int) context->bitbuffer & context->codemask;
|
||||||
|
|
||||||
/* Adjust buffer */
|
/* Adjust buffer */
|
||||||
context->bitbuffer >>= context->codesize;
|
context->bitbuffer >>= context->codesize;
|
||||||
context->bitcount -= context->codesize;
|
context->bitcount -= context->codesize;
|
||||||
|
|
||||||
/* If c is less than "clear", it's a data byte. Otherwise,
|
/* If c is less than "clear", it's a data byte. Otherwise,
|
||||||
it's either clear/end or a code symbol which should be
|
it's either clear/end or a code symbol which should be
|
||||||
expanded. */
|
expanded. */
|
||||||
|
|
||||||
if (c == context->clear) {
|
if (c == context->clear) {
|
||||||
if (state->state != 2)
|
if (state->state != 2)
|
||||||
state->state = 1;
|
state->state = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == context->end)
|
if (c == context->end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
i = 1;
|
i = 1;
|
||||||
p = &context->lastdata;
|
p = &context->lastdata;
|
||||||
|
|
||||||
if (state->state == 2) {
|
if (state->state == 2) {
|
||||||
|
|
||||||
/* First valid symbol after clear; use as is */
|
/* First valid symbol after clear; use as is */
|
||||||
if (c > context->clear) {
|
if (c > context->clear) {
|
||||||
state->errcode = IMAGING_CODEC_BROKEN;
|
state->errcode = IMAGING_CODEC_BROKEN;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
context->lastdata = context->lastcode = c;
|
context->lastdata = context->lastcode = c;
|
||||||
state->state = 3;
|
state->state = 3;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
thiscode = c;
|
thiscode = c;
|
||||||
|
|
||||||
if (c > context->next) {
|
if (c > context->next) {
|
||||||
state->errcode = IMAGING_CODEC_BROKEN;
|
state->errcode = IMAGING_CODEC_BROKEN;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == context->next) {
|
if (c == context->next) {
|
||||||
|
|
||||||
/* c == next is allowed. not sure why. */
|
/* c == next is allowed. not sure why. */
|
||||||
|
|
||||||
if (context->bufferindex <= 0) {
|
if (context->bufferindex <= 0) {
|
||||||
state->errcode = IMAGING_CODEC_BROKEN;
|
state->errcode = IMAGING_CODEC_BROKEN;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
context->buffer[--context->bufferindex] =
|
context->buffer[--context->bufferindex] =
|
||||||
context->lastdata;
|
context->lastdata;
|
||||||
|
|
||||||
c = context->lastcode;
|
c = context->lastcode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (c >= context->clear) {
|
while (c >= context->clear) {
|
||||||
|
|
||||||
/* Copy data string to buffer (beginning from right) */
|
/* Copy data string to buffer (beginning from right) */
|
||||||
|
|
||||||
if (context->bufferindex <= 0 || c >= GIFTABLE) {
|
if (context->bufferindex <= 0 || c >= GIFTABLE) {
|
||||||
state->errcode = IMAGING_CODEC_BROKEN;
|
state->errcode = IMAGING_CODEC_BROKEN;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
context->buffer[--context->bufferindex] =
|
context->buffer[--context->bufferindex] =
|
||||||
context->data[c];
|
context->data[c];
|
||||||
|
|
||||||
c = context->link[c];
|
c = context->link[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
context->lastdata = c;
|
context->lastdata = c;
|
||||||
|
|
||||||
if (context->next < GIFTABLE) {
|
if (context->next < GIFTABLE) {
|
||||||
|
|
||||||
/* We'll only add this symbol if we have room
|
/* We'll only add this symbol if we have room
|
||||||
for it (take advise, Netscape!) */
|
for it (take advise, Netscape!) */
|
||||||
context->data[context->next] = c;
|
context->data[context->next] = c;
|
||||||
context->link[context->next] = context->lastcode;
|
context->link[context->next] = context->lastcode;
|
||||||
|
|
||||||
if (context->next == context->codemask &&
|
if (context->next == context->codemask &&
|
||||||
context->codesize < GIFBITS) {
|
context->codesize < GIFBITS) {
|
||||||
|
|
||||||
/* Expand code size */
|
/* Expand code size */
|
||||||
context->codesize++;
|
context->codesize++;
|
||||||
context->codemask = (1 << context->codesize) - 1;
|
context->codemask = (1 << context->codesize) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
context->next++;
|
context->next++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context->lastcode = thiscode;
|
context->lastcode = thiscode;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the bytes into the image */
|
/* Copy the bytes into the image */
|
||||||
if (state->y >= state->ysize) {
|
if (state->y >= state->ysize) {
|
||||||
state->errcode = IMAGING_CODEC_OVERRUN;
|
state->errcode = IMAGING_CODEC_OVERRUN;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* To squeeze some extra pixels out of this loop, we test for
|
/* To squeeze some extra pixels out of this loop, we test for
|
||||||
some common cases and handle them separately. */
|
some common cases and handle them separately. */
|
||||||
|
|
||||||
/* If we have transparency, we need to use the regular loop. */
|
/* If we have transparency, we need to use the regular loop. */
|
||||||
if(context->transparency == -1)
|
if(context->transparency == -1)
|
||||||
{
|
{
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
if (state->x < state->xsize-1) {
|
if (state->x < state->xsize-1) {
|
||||||
/* Single pixel, not at the end of the line. */
|
/* Single pixel, not at the end of the line. */
|
||||||
*out++ = p[0];
|
*out++ = p[0];
|
||||||
state->x++;
|
state->x++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (state->x + i <= state->xsize) {
|
} else if (state->x + i <= state->xsize) {
|
||||||
/* This string fits into current line. */
|
/* This string fits into current line. */
|
||||||
memcpy(out, p, i);
|
memcpy(out, p, i);
|
||||||
out += i;
|
out += i;
|
||||||
state->x += i;
|
state->x += i;
|
||||||
if (state->x == state->xsize) {
|
if (state->x == state->xsize) {
|
||||||
NEWLINE(state, context);
|
NEWLINE(state, context);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No shortcut, copy pixel by pixel */
|
/* No shortcut, copy pixel by pixel */
|
||||||
for (c = 0; c < i; c++) {
|
for (c = 0; c < i; c++) {
|
||||||
if(p[c] != context->transparency)
|
if(p[c] != context->transparency)
|
||||||
*out = p[c];
|
*out = p[c];
|
||||||
out++;
|
out++;
|
||||||
if (++state->x >= state->xsize) {
|
if (++state->x >= state->xsize) {
|
||||||
NEWLINE(state, context);
|
NEWLINE(state, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ptr - buffer;
|
return ptr - buffer;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user