summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Fox <dyntryx@gmail.com>2008-08-23 21:28:31 +0000
committerSean Fox <dyntryx@gmail.com>2008-08-23 21:28:31 +0000
commitf8fe88a2cd688b62f50ae5b00eb74a5e5500e019 (patch)
tree7a8cf55c76b78c3e04468250745f546013f54ab1
parent480304fbb190cd0dbfea23b1a84fe8d85e414579 (diff)
downloadlibnsgif-f8fe88a2cd688b62f50ae5b00eb74a5e5500e019.tar.gz
libnsgif-f8fe88a2cd688b62f50ae5b00eb74a5e5500e019.tar.bz2
- LOG now prints to stderr, so it won't disrupt the gif decoding example, which reads from stdout
- Correct the way block data is skipped when processing extensions - Remove a lot of code that was apparently rendered useless with previous commits and was causing problems when displaying some gif animations svn path=/trunk/libnsgif/; revision=5187
-rw-r--r--libnsgif.c28
-rw-r--r--utils/log.h12
2 files changed, 9 insertions, 31 deletions
diff --git a/libnsgif.c b/libnsgif.c
index ae89f99..93fa4ac 100644
--- a/libnsgif.c
+++ b/libnsgif.c
@@ -112,6 +112,7 @@
#define GIF_EXTENSION_COMMENT 0xfe
#define GIF_EXTENSION_PLAIN_TEXT 0x01
#define GIF_EXTENSION_APPLICATION 0xff
+#define GIF_BLOCK_TERMINATOR 0x00
#define GIF_TRAILER 0x3b
/* Internal GIF routines
@@ -694,12 +695,13 @@ static gif_result gif_initialise_frame_extensions(gif_animation *gif, const int
*/
gif_bytes = (gif_end - gif_data);
block_size = 0;
- while (block_size != 1) {
+ while (gif_data[0] != GIF_BLOCK_TERMINATOR) {
block_size = gif_data[0] + 1;
if ((gif_bytes -= block_size) < 0)
return GIF_INSUFFICIENT_FRAME_DATA;
gif_data += block_size;
}
+ ++gif_data;
}
/* Set buffer position and return
@@ -732,7 +734,6 @@ gif_result gif_decode_frame(gif_animation *gif, unsigned int frame) {
unsigned int save_buffer_position;
unsigned int return_value = 0;
unsigned int x, y, decode_y, burst_bytes;
- unsigned int block_size;
int last_undisposed_frame = (frame - 1);
register unsigned char colour;
@@ -881,6 +882,7 @@ gif_result gif_decode_frame(gif_animation *gif, unsigned int frame) {
*/
if ((frame == 0) || (gif->decoded_frame == GIF_INVALID_FRAME)) {
memset((char*)frame_data, GIF_TRANSPARENT_COLOUR, gif->width * gif->height * sizeof(int));
+ gif->decoded_frame = frame;
/* The line below would fill the image with its background color, but because GIFs support
* transparency we likely wouldn't want to do that. */
/* memset((char*)frame_data, colour_table[gif->background_index], gif->width * gif->height * sizeof(int)); */
@@ -974,27 +976,8 @@ gif_result gif_decode_frame(gif_animation *gif, unsigned int frame) {
memset(frame_scanline, colour_table[gif->background_index], width * 4);
}
}
-
- /* Repeatedly skip blocks until we get a zero block or run out of data
- */
- gif_bytes = gif->buffer_size - gif->buffer_position;
- gif_data = gif->gif_data + gif->buffer_size;
- block_size = 0;
- while (block_size != 1) {
- block_size = gif_data[0] + 1;
- if ((gif_bytes -= block_size) < 0) {
- return_value = GIF_INSUFFICIENT_FRAME_DATA;
- goto gif_decode_frame_exit;
- }
- gif_data += block_size;
- }
}
gif_decode_frame_exit:
- /* Check for end of data
- */
- gif->buffer_position++;
- gif_bytes = gif->buffer_size - gif->buffer_position;
- gif_data = gif->gif_data + gif->buffer_position;
/* Check if we should test for optimisation
*/
@@ -1064,12 +1047,13 @@ static gif_result gif_skip_frame_extensions(gif_animation *gif) {
*/
gif_bytes = (gif_end - gif_data);
block_size = 0;
- while (block_size != 1) {
+ while (gif_data[0] != GIF_BLOCK_TERMINATOR) {
block_size = gif_data[0] + 1;
if ((gif_bytes -= block_size) < 0)
return GIF_INSUFFICIENT_FRAME_DATA;
gif_data += block_size;
}
+ ++gif_data;
}
/* Set buffer position and return
diff --git a/utils/log.h b/utils/log.h
index d204ec9..d70a44b 100644
--- a/utils/log.h
+++ b/utils/log.h
@@ -25,13 +25,7 @@
#ifdef NDEBUG
# define LOG(x) ((void) 0)
#else
-# ifdef __GNUC__
-# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
-# elif defined(__CC_NORCROFT)
-# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
-# else
-# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
-# endif
-#endif
+# define LOG(x) do { fprintf(stderr, x), fputc('\n', stderr); } while (0)
+#endif /* NDEBUG */
-#endif
+#endif /* _LIBNSGIF_LOG_H_ */