* -2 -> failure; abort the load
* -3 -> control needs to be passed back to the main loop
* \_ (most of the time returning 0 will get this, but not always)
+ *
* >1 -> for functions that get a guchar, the char will be returned.
*
* -jrb (11/03/1999)
int frame_len;
int frame_height;
int frame_interlace;
+ int x_offset;
+ int y_offset;
/* Static read only */
FILE *file;
/* progressive read, only. */
ModulePreparedNotifyFunc prepare_func;
ModuleUpdatedNotifyFunc update_func;
+ ModuleFrameDoneNotifyFunc frame_done_func;
+ ModuleAnimationDoneNotifyFunc anim_done_func;
gpointer user_data;
guchar *buf;
guint ptr;
return retval;
} else {
#ifdef IO_GIFDEBUG
-// g_print ("\tlooking for %d bytes. size == %d, ptr == %d\n", len, context->size, context->ptr);
+/* g_print ("\tlooking for %d bytes. size == %d, ptr == %d\n", len, context->size, context->ptr); */
#endif
if ((context->size - context->ptr) >= len) {
#ifdef IO_GIFDEBUG
if ((context->block_buf[0] & 0x1) != 0) {
context->gif89.transparent = context->block_buf[3];
} else {
- context->gif89.transparent = FALSE;
+ context->gif89.transparent = -1;
}
}
GetDataBlock (GifContext *context,
unsigned char *buf)
{
-// unsigned char count;
+/* unsigned char count; */
if (!gif_read (context, &context->block_count, 1)) {
/*g_message (_("GIF: error in getting DataBlock size\n"));*/
{
guchar *pixel = NULL;
- if (context->gif89.transparent) {
+ if (context->gif89.transparent != -1) {
pixel = dest + (context->draw_ypos + offset) * gdk_pixbuf_get_rowstride (context->pixbuf) + context->draw_xpos * 4;
*pixel = context->color_map [0][(guchar) v];
*(pixel+1) = context->color_map [1][(guchar) v];
gint v;
if (context->pixbuf == NULL) {
- g_print ("making a new pixbuf\n");
context->pixbuf = gdk_pixbuf_new (ART_PIX_RGB,
- context->gif89.transparent,
+ context->gif89.transparent != -1,
8,
context->width,
context->height);
if (context->prepare_func)
(* context->prepare_func) (context->pixbuf, context->user_data);
- if (context->animation) {
+ if (context->animation || context->frame_done_func) {
context->frame = g_new (GdkPixbufFrame, 1);
- context->frame->x_offset = 0;
- context->frame->y_offset = 0;
+ context->frame->x_offset = context->x_offset;
+ context->frame->y_offset = context->y_offset;;
context->frame->delay_time = context->gif89.delay_time;
switch (context->gif89.disposal) {
case 0:
break;
}
context->frame->pixbuf = context->pixbuf;
- context->animation->n_frames ++;
- context->animation->frames = g_list_append (context->animation->frames, context->frame);
+ if (context->animation) {
+ context->animation->n_frames ++;
+ context->animation->frames = g_list_append (context->animation->frames, context->frame);
+ }
}
}
dest = gdk_pixbuf_get_pixels (context->pixbuf);
}
bound_flag = TRUE;
- if (context->gif89.transparent) {
+ if (context->gif89.transparent != -1) {
temp = dest + context->draw_ypos * gdk_pixbuf_get_rowstride (context->pixbuf) + context->draw_xpos * 4;
*temp = context->color_map [0][(guchar) v];
*(temp+1) = context->color_map [1][(guchar) v];
if (lower_bound <= upper_bound && first_pass == context->draw_pass) {
(* context->update_func)
(context->pixbuf,
- context->user_data,
0, lower_bound,
gdk_pixbuf_get_width (context->pixbuf),
- upper_bound - lower_bound);
+ upper_bound - lower_bound,
+ context->user_data);
} else {
if (lower_bound <= upper_bound) {
(* context->update_func)
(context->pixbuf,
- context->user_data,
0, 0,
gdk_pixbuf_get_width (context->pixbuf),
- gdk_pixbuf_get_height (context->pixbuf));
+ gdk_pixbuf_get_height (context->pixbuf),
+ context->user_data);
} else {
(* context->update_func)
(context->pixbuf,
- context->user_data,
0, 0,
gdk_pixbuf_get_width (context->pixbuf),
- upper_bound);
+ upper_bound,
+ context->user_data);
(* context->update_func)
(context->pixbuf,
- context->user_data,
0, lower_bound,
gdk_pixbuf_get_width (context->pixbuf),
- gdk_pixbuf_get_height (context->pixbuf));
+ gdk_pixbuf_get_height (context->pixbuf),
+ context->user_data);
}
}
}
if (context->animation && context->state == GIF_GET_NEXT_STEP) {
+ if (context->frame_done_func)
+ (* context->frame_done_func) (context->frame,
+ context->user_data);
+ if (context->frame_done_func)
+ gdk_pixbuf_unref (context->pixbuf);
context->pixbuf = NULL;
context->frame = NULL;
}
/* Okay, we got all the info we need. Lets record it */
context->frame_len = LM_to_uint (buf[4], buf[5]);
context->frame_height = LM_to_uint (buf[6], buf[7]);
- if (context->frame) {
- context->frame->x_offset = LM_to_uint (buf[0], buf[1]);
- context->frame->y_offset = LM_to_uint (buf[2], buf[3]);
- }
+ context->x_offset = LM_to_uint (buf[0], buf[1]);
+ context->y_offset = LM_to_uint (buf[2], buf[3]);
+
if (context->frame_height > context->height) {
/* we don't want to resize things. So we exit */
context->state = GIF_DONE;
GifContext *context;
context = g_new0 (GifContext, 1);
+
context->pixbuf = NULL;
context->file = NULL;
context->state = GIF_START;
context->prepare_func = NULL;
context->update_func = NULL;
+ context->frame_done_func = NULL;
+ context->anim_done_func = NULL;
context->user_data = NULL;
context->buf = NULL;
context->amount_needed = 0;
context->gif89.delay_time = -1;
context->gif89.input_flag = -1;
context->gif89.disposal = -1;
+
return context;
}
/* Shared library entry point */
GdkPixbuf *
-image_load (FILE *file)
+gdk_pixbuf__gif_image_load (FILE *file)
{
GifContext *context;
+ GdkPixbuf *pixbuf;
g_return_val_if_fail (file != NULL, NULL);
gif_main_loop (context);
- return context->pixbuf;
+ pixbuf = context->pixbuf;
+ g_free (context);
+
+ return pixbuf;
}
gpointer
-image_begin_load (ModulePreparedNotifyFunc prepare_func,
- ModuleUpdatedNotifyFunc update_func,
- gpointer user_data)
+gdk_pixbuf__gif_image_begin_load (ModulePreparedNotifyFunc prepare_func,
+ ModuleUpdatedNotifyFunc update_func,
+ ModuleFrameDoneNotifyFunc frame_done_func,
+ ModuleAnimationDoneNotifyFunc anim_done_func,
+ gpointer user_data)
{
GifContext *context;
context = new_context ();
context->prepare_func = prepare_func;
context->update_func = update_func;
+ context->frame_done_func = frame_done_func;
+ context->anim_done_func = anim_done_func;
context->user_data = user_data;
return (gpointer) context;
}
void
-image_stop_load (gpointer data)
+gdk_pixbuf__gif_image_stop_load (gpointer data)
{
GifContext *context = (GifContext *) data;
+ /* FIXME: free the animation data */
+
if (context->pixbuf)
gdk_pixbuf_unref (context->pixbuf);
-// g_free (context->buf);
+ if (context->animation)
+ gdk_pixbuf_animation_unref (context->animation);
+/* g_free (context->buf);*/
g_free (context);
}
gboolean
-image_load_increment (gpointer data, guchar *buf, guint size)
+gdk_pixbuf__gif_image_load_increment (gpointer data, guchar *buf, guint size)
{
gint retval;
GifContext *context = (GifContext *) data;
}
GdkPixbufAnimation *
-image_load_animation (FILE *file)
+gdk_pixbuf__gif_image_load_animation (FILE *file)
{
GifContext *context;
+ GdkPixbufAnimation *animation;
g_return_val_if_fail (file != NULL, NULL);
context = new_context ();
context->animation = g_new (GdkPixbufAnimation, 1);
+ context->animation->ref_count = 1;
context->animation->n_frames = 0;
context->animation->frames = NULL;
context->file = file;
gif_main_loop (context);
-
- return context->animation;
+
+ animation = context->animation;
+ g_free (context);
+ return animation;
}