Updating branch refs/heads/ristretto-0.0 to 58bee9be96336fe2448bae3f8f9906eaa2055169 (commit) from 9a99870c75f66aa963e22434ff4f1c5fc2a521f4 (commit)
commit 58bee9be96336fe2448bae3f8f9906eaa2055169 Author: Stephan Arts <step...@xfce.org> Date: Sat Feb 21 16:08:42 2009 +0100 Add some rudimentary preview support src/image.c | 42 +++++------ src/picture_viewer.c | 199 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 178 insertions(+), 63 deletions(-) diff --git a/src/image.c b/src/image.c index d5d3785..3ca403d 100644 --- a/src/image.c +++ b/src/image.c @@ -401,14 +401,13 @@ rstto_image_load (RsttoImage *image, gboolean empty_cache, GError **error) /*g_signal_connect(image->priv->loader, "area-updated", G_CALLBACK(cb_rstto_image_area_updated), image);*/ g_signal_connect(image->priv->loader, "closed", G_CALLBACK(cb_rstto_image_closed), image); - rstto_image_cache_push_image (cache, image); - g_file_read_async (image->priv->file, 0, NULL, (GAsyncReadyCallback)cb_rstto_image_read_file_ready, image); } else { - rstto_image_cache_push_image (cache, image); + //g_signal_emit(G_OBJECT(image), rstto_image_signals[RSTTO_IMAGE_SIGNAL_UPDATED], 0, image, NULL); } + rstto_image_cache_push_image (cache, image); return TRUE; } @@ -616,8 +615,22 @@ cb_rstto_image_area_prepared (GdkPixbufLoader *loader, RsttoImage *image) { image->priv->iter = NULL; } + + if (image->priv->iter) + { + image->priv->pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (image->priv->iter); + g_object_ref (image->priv->pixbuf); + } + else + { + if (image->priv->loader) + { + image->priv->pixbuf = gdk_pixbuf_loader_get_pixbuf (image->priv->loader); + g_object_ref (image->priv->pixbuf); + } + } + g_signal_emit(G_OBJECT(image), rstto_image_signals[RSTTO_IMAGE_SIGNAL_PREPARED], 0, image, NULL); - g_signal_emit(G_OBJECT(image), rstto_image_signals[RSTTO_IMAGE_SIGNAL_UPDATED], 0, image, NULL); } /** @@ -636,31 +649,12 @@ cb_rstto_image_closed (GdkPixbufLoader *loader, RsttoImage *image) GdkPixbuf *pixbuf = NULL; RsttoImageTransformation *transformation = NULL; - if (image->priv->pixbuf) - { - g_object_unref(image->priv->pixbuf); - image->priv->pixbuf = NULL; - } - - if (image->priv->iter) - { - pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (image->priv->iter); - } - else - { - if (image->priv->loader) - { - pixbuf = gdk_pixbuf_loader_get_pixbuf (image->priv->loader); - } - } - g_object_unref (image->priv->loader); image->priv->loader = NULL; - if (pixbuf != NULL) + if (image->priv->pixbuf != NULL) { - image->priv->pixbuf = pixbuf; /* Get to the bottom of the transformation list */ GList *transform_iter = g_list_last (image->priv->transformations); while (transform_iter != NULL) diff --git a/src/picture_viewer.c b/src/picture_viewer.c index 6a75a07..b4828e4 100644 --- a/src/picture_viewer.c +++ b/src/picture_viewer.c @@ -675,60 +675,179 @@ static gboolean rstto_picture_viewer_refresh(RsttoPictureViewer *viewer) { GtkWidget *widget = GTK_WIDGET(viewer); - GdkPixbuf *src_pixbuf = NULL; + GdkPixbuf *src_pixbuf = NULL, *tmp_pixbuf = NULL; GdkPixbuf *thumb_pixbuf = NULL; gboolean *fit_to_screen = NULL; - gdouble *scale = NULL; + gdouble *scale = NULL; gint width = 0, height = 0; - if (viewer->priv->state == RSTTO_PICTURE_VIEWER_STATE_PREVIEW) + /** + * Get all the required image peripherals + */ + if (viewer->priv->image != NULL) + { + src_pixbuf = rstto_image_get_pixbuf (viewer->priv->image); + thumb_pixbuf = rstto_image_get_thumbnail (viewer->priv->image); + + width = gdk_pixbuf_get_width(src_pixbuf); + height = gdk_pixbuf_get_height(src_pixbuf); + + fit_to_screen = g_object_get_data (G_OBJECT (viewer->priv->image), "viewer-fit-to-screen"); + scale = g_object_get_data (G_OBJECT (viewer->priv->image), "viewer-scale"); + } + + if (scale == NULL) + scale = g_new0 (gdouble, 1); + + if (fit_to_screen == NULL) + fit_to_screen = g_new0 (gboolean, 1); + + /** + * Clean up the destination pixbuf, since we are going to re-create it + * anyway + */ + if(viewer->priv->dst_pixbuf) { - if (viewer->priv->image != NULL); - { - src_pixbuf = rstto_image_get_pixbuf (viewer->priv->image); - thumb_pixbuf = rstto_image_get_thumbnail (viewer->priv->image); + g_object_unref(viewer->priv->dst_pixbuf); + viewer->priv->dst_pixbuf = NULL; + } - if (src_pixbuf) + /** + * If Scale == 0, this means the image has not been rendered before. + * When this is the case, we render the image at 100% unless it is + * larger thenthe dimensions of the picture viewer. + */ + if ((*scale == 0) && (viewer->priv->image)) + { + /* Check if the image fits inside the viewer, + * if not, scale it down to fit + */ + if ((GTK_WIDGET (viewer)->allocation.width < width) || + (GTK_WIDGET (viewer)->allocation.height < height)) + { + *fit_to_screen = TRUE; + /* The image does not fit the picture-viewer, and + * we decided to scale it down to fit. Now we need to check + * which side we need to use as a reference. + * + * We use the one that produces a larger scale difference + * to the viewer. This way we know the image will always fit. + */ + if ((GTK_WIDGET (viewer)->allocation.width / width) > + (GTK_WIDGET (viewer)->allocation.height / height)) + { + *scale = (gdouble)GTK_WIDGET (viewer)->allocation.width / (gdouble)width; + } + else { - width = gdk_pixbuf_get_width (src_pixbuf); - height = gdk_pixbuf_get_height (src_pixbuf); - - /* Check if the image fits inside the viewer, - * if not, scale it down to fit - */ - if ((GTK_WIDGET (viewer)->allocation.width < width) || - (GTK_WIDGET (viewer)->allocation.height < height)) + *scale = (gdouble)GTK_WIDGET (viewer)->allocation.height / (gdouble)height; + } + + } + else + { + /* The image is smaller then the picture-viewer, + * As a result, view it at it's original size. + */ + *scale = 1.0; + *fit_to_screen = FALSE; + } + g_object_set_data (G_OBJECT (viewer->priv->image), "viewer-scale", scale); + g_object_set_data (G_OBJECT (viewer->priv->image), "viewer-fit-to-screen", fit_to_screen); + + } + else + { + switch (viewer->priv->zoom_mode) + { + case RSTTO_ZOOM_MODE_FIT: + *fit_to_screen = TRUE; + g_object_set_data (G_OBJECT (viewer->priv->image), "viewer-fit-to-screen", fit_to_screen); + break; + case RSTTO_ZOOM_MODE_100: + *fit_to_screen = FALSE; + *scale = 1.0; + g_object_set_data (G_OBJECT (viewer->priv->image), "viewer-scale", scale); + break; + case RSTTO_ZOOM_MODE_CUSTOM: + break; + } + + if(*fit_to_screen) + { + gdouble h_scale = (gdouble)GTK_WIDGET(viewer)->allocation.width / (gdouble)width; + gdouble v_scale = (gdouble)GTK_WIDGET(viewer)->allocation.height / (gdouble)height; + if(h_scale < v_scale) + { + if(*scale != h_scale) { - /* The image does not fit the picture-viewer, and - * we decided to scale it down to fit. Now we need to check - * which side we need to use as a reference. - * - * We use the one that produces a larger scale difference - * to the viewer. - */ - if ((GTK_WIDGET (viewer)->allocation.width / width) > - (GTK_WIDGET (viewer)->allocation.height / height)) - { - viewer->priv->scale = GTK_WIDGET (viewer)->allocation.width / width; - } - else - { - viewer->priv->scale = GTK_WIDGET (viewer)->allocation.height / height; - } + *scale = h_scale; } - else + } + else + { + if(*scale != v_scale) { - /* The image is smaller then the picture-viewer, - * As a result, view it at it's original size. - */ - viewer->priv->scale = 1.0; + *scale = v_scale; } } + g_object_set_data (G_OBJECT (viewer->priv->image), "viewer-scale", scale); } } - else + + if (GTK_WIDGET_REALIZED (widget)) { + if (viewer->vadjustment && viewer->hadjustment) + { + viewer->hadjustment->page_size = widget->allocation.width; + viewer->hadjustment->upper = width * (*scale); + viewer->hadjustment->value = 0; + + viewer->vadjustment->page_size = widget->allocation.height; + viewer->vadjustment->upper = height * (*scale); + viewer->vadjustment->value = 0; + + } + + if (viewer->priv->state == RSTTO_PICTURE_VIEWER_STATE_PREVIEW) + { + viewer->priv->dst_pixbuf = gdk_pixbuf_scale_simple (thumb_pixbuf, + (gint)((gdouble)width * (*scale)), + (gint)((gdouble)height * (*scale)), + GDK_INTERP_BILINEAR); + } + else + { + if (src_pixbuf) + { + viewer->priv->dst_pixbuf = gdk_pixbuf_scale_simple (src_pixbuf, + (gint)((gdouble)width * (*scale)), + (gint)((gdouble)height * (*scale)), + GDK_INTERP_BILINEAR); + /* + tmp_pixbuf = gdk_pixbuf_new_subpixbuf(src_pixbuf, + (gint)(viewer->hadjustment->value / (*scale)), + viewer->vadjustment->value / (*scale), + ((widget->allocation.width/(*scale))) < width? + widget->allocation.width/(*scale):width, + ((widget->allocation.height/(*scale)))< height? + widget->allocation.height/(*scale):height); + if(tmp_pixbuf) + { + gint dst_width = gdk_pixbuf_get_width(tmp_pixbuf)*(*scale); + gint dst_height = gdk_pixbuf_get_height(tmp_pixbuf)*(*scale); + viewer->priv->dst_pixbuf = gdk_pixbuf_scale_simple(tmp_pixbuf, + dst_width>0?dst_width:1, + dst_height>0?dst_height:1, + GDK_INTERP_BILINEAR); + g_object_unref(tmp_pixbuf); + tmp_pixbuf = NULL; + } + */ + } + + } } return TRUE; } @@ -1122,10 +1241,10 @@ rstto_picture_viewer_set_image (RsttoPictureViewer *viewer, RsttoImage *image) if (viewer->priv->image) { - rstto_image_load (viewer->priv->image, FALSE, NULL); g_object_ref (viewer->priv->image); g_signal_connect (G_OBJECT (viewer->priv->image), "updated", G_CALLBACK (cb_rstto_picture_viewer_image_updated), viewer); g_signal_connect (G_OBJECT (viewer->priv->image), "prepared", G_CALLBACK (cb_rstto_picture_viewer_image_prepared), viewer); + rstto_image_load (viewer->priv->image, FALSE, NULL); } } @@ -1134,6 +1253,7 @@ cb_rstto_picture_viewer_image_updated (RsttoImage *image, RsttoPictureViewer *vi { if (viewer->priv->state == RSTTO_PICTURE_VIEWER_STATE_PREVIEW) viewer->priv->state = RSTTO_PICTURE_VIEWER_STATE_NONE; + rstto_picture_viewer_refresh (viewer); rstto_picture_viewer_paint (GTK_WIDGET (viewer)); } @@ -1143,6 +1263,7 @@ cb_rstto_picture_viewer_image_prepared (RsttoImage *image, RsttoPictureViewer *v { if (viewer->priv->state == RSTTO_PICTURE_VIEWER_STATE_NONE) viewer->priv->state = RSTTO_PICTURE_VIEWER_STATE_PREVIEW; + rstto_picture_viewer_refresh (viewer); rstto_picture_viewer_paint (GTK_WIDGET (viewer)); } _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits