diff options
author | James Bursa <james@netsurf-browser.org> | 2008-08-12 03:49:34 +0000 |
---|---|---|
committer | James Bursa <james@netsurf-browser.org> | 2008-08-12 03:49:34 +0000 |
commit | 33107b160f09bbb301791759b83d772c820c4813 (patch) | |
tree | 2b0a0293ddcc63a44a2d01421db1e3286aa5f753 /gtk/gtk_throbber.c | |
parent | 4c8989a6db25de8b2d3bf7fff07489c05808122b (diff) | |
download | netsurf-33107b160f09bbb301791759b83d772c820c4813.tar.gz netsurf-33107b160f09bbb301791759b83d772c820c4813.tar.bz2 |
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
Diffstat (limited to 'gtk/gtk_throbber.c')
-rw-r--r-- | gtk/gtk_throbber.c | 113 |
1 files changed, 65 insertions, 48 deletions
diff --git a/gtk/gtk_throbber.c b/gtk/gtk_throbber.c index d6b511f89..9070c61ba 100644 --- a/gtk/gtk_throbber.c +++ b/gtk/gtk_throbber.c @@ -1,5 +1,6 @@ /* * Copyright 2008 Rob Kendrick <rjek@netsurf-browser.org> + * Copyright 2008 Sean Fox <dyntryx@gmail.com> * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -19,8 +20,8 @@ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> +#include <libnsgif.h> #include "utils/log.h" -#include "image/gifread.h" #include "gtk/gtk_throbber.h" #include "gtk/gtk_bitmap.h" @@ -98,8 +99,13 @@ bool nsgtk_throbber_initialise_from_gif(const char *fn) /* disect the GIF provided by filename in *fn into a series of * GdkPixbuf for use later. */ - struct gif_animation *gif; /**< structure for gifread.c */ - struct nsgtk_throbber *throb; /**< structure we generate */ + extern gif_bitmap_callback_vt gif_bitmap_callbacks; /**< external structure containing + * bitmap callback functions */ + gif_animation gif; + struct nsgtk_throbber throb; /**< structure we generate */ + int res; + size_t size; + unsigned char *data; int i; FILE *fh = fopen(fn, "rb"); @@ -109,77 +115,88 @@ bool nsgtk_throbber_initialise_from_gif(const char *fn) return false; } - gif = (struct gif_animation *)malloc(sizeof(struct gif_animation)); - throb = (struct nsgtk_throbber *)malloc(sizeof(struct nsgtk_throbber)); - /* discover the size of the data file. */ fseek(fh, 0, SEEK_END); - gif->buffer_size = ftell(fh); + size = ftell(fh); fseek(fh, 0, SEEK_SET); /* allocate a block of sufficient size, and load the data in. */ - gif->gif_data = (unsigned char *)malloc(gif->buffer_size); - fread(gif->gif_data, gif->buffer_size, 1, fh); + data = (unsigned char *)malloc(size); + fread(data, size, 1, fh); fclose(fh); - /* set current position within GIF file to beginning, in order to - * signal to gifread that we're brand new. - */ - gif->buffer_position = 0; + /* create our gif animation */ + gif_create(&gif, &gif_bitmap_callbacks); /* initialise the gif_animation structure. */ - switch (gif_initialise(gif)) - { - case GIF_INSUFFICIENT_FRAME_DATA: - case GIF_FRAME_DATA_ERROR: - case GIF_INSUFFICIENT_DATA: - case GIF_DATA_ERROR: - LOG(("GIF image '%s' appears invalid!", fn)); - free(gif->gif_data); - free(gif); - free(throb); - return false; - break; - case GIF_INSUFFICIENT_MEMORY: - LOG(("Ran out of memory decoding GIF image '%s'!", fn)); - free(gif->gif_data); - free(gif); - free(throb); + do { + res = gif_initialise(&gif, size, data); + if (res != GIF_OK && res != GIF_WORKING) { + switch (res) + { + case GIF_INSUFFICIENT_FRAME_DATA: + case GIF_FRAME_DATA_ERROR: + case GIF_INSUFFICIENT_DATA: + case GIF_DATA_ERROR: + LOG(("GIF image '%s' appears invalid!", fn)); + break; + case GIF_INSUFFICIENT_MEMORY: + LOG(("Ran out of memory decoding GIF image '%s'!", fn)); + break; + } + gif_finalise(&gif); + free(data); + free(&throb); return false; - break; - } + } + } while (res != GIF_OK); - throb->nframes = gif->frame_count; + throb.nframes = gif.frame_count; - if (throb->nframes < 2) + if (throb.nframes < 2) { /* we need at least two frames - one for idle, one for active */ LOG(("Insufficent number of frames in throbber image '%s'!", fn)); LOG(("(GIF contains %d frames, where 2 is a minimum.)", - throb->nframes)); - free(gif->gif_data); - free(gif); - free(throb); + throb.nframes)); + gif_finalise(&gif); + free(data); + free(&throb); return false; } - throb->framedata = (GdkPixbuf **)malloc(sizeof(GdkPixbuf *) - * throb->nframes); + throb.framedata = (GdkPixbuf **)malloc(sizeof(GdkPixbuf *) * throb.nframes); /* decode each frame in turn, extracting the struct bitmap * for each, * and put that in our array of frames. */ - for (i = 0; i < throb->nframes; i++) + for (i = 0; i < throb.nframes; i++) { - gif_decode_frame(gif, i); - throb->framedata[i] = gdk_pixbuf_copy( - gtk_bitmap_get_primary(gif->frame_image)); + res = gif_decode_frame(&gif, i); + if (res != GIF_OK) { + switch (res) + { + case GIF_INSUFFICIENT_FRAME_DATA: + case GIF_FRAME_DATA_ERROR: + case GIF_INSUFFICIENT_DATA: + case GIF_DATA_ERROR: + LOG(("GIF image '%s' appears invalid!", fn)); + break; + case GIF_INSUFFICIENT_MEMORY: + LOG(("Ran out of memory decoding GIF image '%s'!", fn)); + break; + } + gif_finalise(&gif); + free(data); + free(&throb); + return false; + } + throb.framedata[i] = gdk_pixbuf_copy(gtk_bitmap_get_primary(gif.frame_image)); } - gif_finalise(gif); - free(gif->gif_data); - free(gif); + gif_finalise(&gif); + free(data); /* debug code: save out each frame as a PNG to make sure decoding is * working correctly. @@ -191,7 +208,7 @@ bool nsgtk_throbber_initialise_from_gif(const char *fn) } */ - nsgtk_throbber = throb; + nsgtk_throbber = &throb; return true; } |