+ if (context->frame == NULL) {
+ context->frame = g_new (GdkPixbufFrame, 1);
+
+ context->frame->composited = NULL;
+ context->frame->revert = NULL;
+
+ if (context->frame_len == 0 || context->frame_height == 0) {
+ /* An empty frame, we just output a single transparent
+ * pixel at (0, 0).
+ */
+ context->x_offset = 0;
+ context->y_offset = 0;
+ context->frame_len = 1;
+ context->frame_height = 1;
+ context->frame->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
+ if (context->frame->pixbuf) {
+ guchar *pixels;
+
+ pixels = gdk_pixbuf_get_pixels (context->frame->pixbuf);
+ pixels[0] = 0;
+ pixels[1] = 0;
+ pixels[2] = 0;
+ pixels[3] = 0;
+ }
+ } else
+ context->frame->pixbuf =
+ gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+ TRUE,
+ 8,
+ context->frame_len,
+ context->frame_height);
+ if (!context->frame->pixbuf) {
+ g_free (context->frame);
+ g_set_error (context->error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+ _("Not enough memory to load GIF file"));
+ return -2;
+ }
+
+ context->frame->x_offset = context->x_offset;
+ context->frame->y_offset = context->y_offset;
+ context->frame->need_recomposite = TRUE;
+
+ /* GIF delay is in hundredths, we want thousandths */
+ context->frame->delay_time = context->gif89.delay_time * 10;
+
+ /* Some GIFs apparently have delay time of 0,
+ * that crashes everything so set it to "fast".
+ * Also, timeouts less than 20 or so just lock up
+ * the app or make the animation choppy, so fix them.
+ */
+ if (context->frame->delay_time < 20)
+ context->frame->delay_time = 20; /* 20 = "fast" */
+
+ context->frame->elapsed = context->animation->total_time;
+ context->animation->total_time += context->frame->delay_time;
+
+ switch (context->gif89.disposal) {
+ case 0:
+ case 1:
+ context->frame->action = GDK_PIXBUF_FRAME_RETAIN;
+ break;
+ case 2:
+ context->frame->action = GDK_PIXBUF_FRAME_DISPOSE;
+ break;
+ case 3:
+ context->frame->action = GDK_PIXBUF_FRAME_REVERT;
+ break;
+ default:
+ context->frame->action = GDK_PIXBUF_FRAME_RETAIN;
+ break;
+ }
+
+ context->frame->bg_transparent = (context->gif89.transparent == context->background_index);
+
+ context->animation->n_frames ++;
+ context->animation->frames = g_list_append (context->animation->frames, context->frame);
+
+ /* Only call prepare_func for the first frame */
+ if (context->animation->frames->next == NULL) {
+ if (context->prepare_func)
+ (* context->prepare_func) (context->frame->pixbuf,
+ GDK_PIXBUF_ANIMATION (context->animation),
+ context->user_data);
+ } else {
+ /* Otherwise init frame with last frame */
+ GList *link;
+ GdkPixbufFrame *prev_frame;
+ gint x, y, w, h;
+
+ link = g_list_find (context->animation->frames, context->frame);
+
+ prev_frame = link->prev->data;
+
+ gdk_pixbuf_gif_anim_frame_composite (context->animation, prev_frame);
+
+ x = context->frame->x_offset;
+ y = context->frame->y_offset;
+ w = gdk_pixbuf_get_width (context->frame->pixbuf);
+ h = gdk_pixbuf_get_height (context->frame->pixbuf);
+ if (clip_frame (context, &x, &y, &w, &h))
+ gdk_pixbuf_copy_area (prev_frame->composited,
+ x, y, w, h,
+ context->frame->pixbuf,
+ 0, 0);
+ }
+ }
+
+ dest = gdk_pixbuf_get_pixels (context->frame->pixbuf);
+
+ bound_flag = FALSE;
+ lower_bound = upper_bound = context->draw_ypos;
+ first_pass = context->draw_pass;