[gthumb: 6/40] fixed shirnk_wrap regression with two steps loading
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 6/40] fixed shirnk_wrap regression with two steps loading
- Date: Fri, 10 Sep 2010 16:56:42 +0000 (UTC)
commit 13ccd19ffe8b1322883073eccca4f5d1402fa2d0
Author: Paolo Bacchilega <paobac src gnome org>
Date: Thu Sep 2 20:37:58 2010 +0200
fixed shirnk_wrap regression with two steps loading
extensions/image_viewer/gth-image-viewer-page.c | 47 +++++++------------
extensions/image_viewer/gth-image-viewer-page.h | 24 +++++-----
gthumb/gth-image-loader.c | 9 +++-
gthumb/gth-image-viewer.c | 55 ++++++++++++++++++-----
gthumb/gth-image-viewer.h | 3 +
5 files changed, 84 insertions(+), 54 deletions(-)
---
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index adcc574..93ba68b 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -644,7 +644,6 @@ gth_image_viewer_page_real_view (GthViewerPage *base,
GthFileData *next_file_data = NULL;
GthFileData *next2_file_data = NULL;
GthFileData *prev_file_data = NULL;
- GtkAllocation allocation;
int window_width;
int window_height;
@@ -685,21 +684,9 @@ gth_image_viewer_page_real_view (GthViewerPage *base,
prev_file_data = gth_file_store_get_file (file_store, &iter2);
}
- window_width = -1;
- window_height = -1;
-
- gtk_widget_get_allocation (self->priv->viewer, &allocation);
- if ((allocation.width > 1) && (allocation.height > 1)) {
- window_width = allocation.width;
- window_height = allocation.height;
- }
- else {
- GtkWidget *toplevel;
-
- toplevel = gtk_widget_get_toplevel (self->priv->viewer);
- if (gtk_widget_is_toplevel (toplevel))
- gtk_window_get_size (GTK_WINDOW (toplevel), &window_width, &window_height);
- }
+ gtk_window_get_size (GTK_WINDOW (self->priv->browser),
+ &window_width,
+ &window_height);
gth_image_preloader_load (self->priv->preloader,
self->priv->file_data,
@@ -1230,15 +1217,15 @@ void
gth_image_viewer_page_shrink_wrap (GthImageViewerPage *self,
gboolean activate)
{
- GdkPixbuf *pixbuf;
- int width;
- int height;
- double ratio;
- int other_width;
- int other_height;
- GdkScreen *screen;
- int max_width;
- int max_height;
+ GthFileData *file_data;
+ int width;
+ int height;
+ double ratio;
+ int other_width;
+ int other_height;
+ GdkScreen *screen;
+ int max_width;
+ int max_height;
self->priv->shrink_wrap = activate;
if (! self->priv->shrink_wrap) {
@@ -1260,12 +1247,14 @@ gth_image_viewer_page_shrink_wrap (GthImageViewerPage *self,
return;
}
- pixbuf = gth_image_viewer_page_get_pixbuf (self);
- if (pixbuf == NULL)
+ file_data = gth_browser_get_current_file (self->priv->browser);
+ if (file_data == NULL)
+ return;
+
+ gth_image_viewer_get_original_size (GTH_IMAGE_VIEWER (self->priv->viewer), &width, &height);
+ if ((width <= 0) || (height <= 0))
return;
- width = gdk_pixbuf_get_width (pixbuf);
- height = gdk_pixbuf_get_height (pixbuf);
ratio = (double) width / height;
other_width = 0;
diff --git a/extensions/image_viewer/gth-image-viewer-page.h b/extensions/image_viewer/gth-image-viewer-page.h
index 1471922..2e1f83a 100644
--- a/extensions/image_viewer/gth-image-viewer-page.h
+++ b/extensions/image_viewer/gth-image-viewer-page.h
@@ -46,18 +46,18 @@ struct _GthImageViewerPageClass {
GObjectClass parent_class;
};
-GType gth_image_viewer_page_get_type (void);
-GtkWidget * gth_image_viewer_page_get_image_viewer (GthImageViewerPage *page);
-GdkPixbuf * gth_image_viewer_page_get_pixbuf (GthImageViewerPage *page);
-void gth_image_viewer_page_set_pixbuf (GthImageViewerPage *page,
- GdkPixbuf *pixbuf,
- gboolean add_to_history);
-void gth_image_viewer_page_undo (GthImageViewerPage *page);
-void gth_image_viewer_page_redo (GthImageViewerPage *page);
-GthImageHistory * gth_image_viewer_page_get_history (GthImageViewerPage *self);
-void gth_image_viewer_page_reset (GthImageViewerPage *self);
-void gth_image_viewer_page_shrink_wrap (GthImageViewerPage *self,
- gboolean activate);
+GType gth_image_viewer_page_get_type (void);
+GtkWidget * gth_image_viewer_page_get_image_viewer (GthImageViewerPage *page);
+GdkPixbuf * gth_image_viewer_page_get_pixbuf (GthImageViewerPage *page);
+void gth_image_viewer_page_set_pixbuf (GthImageViewerPage *page,
+ GdkPixbuf *pixbuf,
+ gboolean add_to_history);
+void gth_image_viewer_page_undo (GthImageViewerPage *page);
+void gth_image_viewer_page_redo (GthImageViewerPage *page);
+GthImageHistory * gth_image_viewer_page_get_history (GthImageViewerPage *self);
+void gth_image_viewer_page_reset (GthImageViewerPage *self);
+void gth_image_viewer_page_shrink_wrap (GthImageViewerPage *self,
+ gboolean activate);
G_END_DECLS
diff --git a/gthumb/gth-image-loader.c b/gthumb/gth-image-loader.c
index d2606ba..67ebefa 100644
--- a/gthumb/gth-image-loader.c
+++ b/gthumb/gth-image-loader.c
@@ -841,8 +841,10 @@ gth_image_loader_get_original_size (GthImageLoader *iloader,
int *height)
{
g_mutex_lock (iloader->priv->data_mutex);
- *width = iloader->priv->original_width;
- *height = iloader->priv->original_height;
+ if (width != NULL)
+ *width = iloader->priv->original_width;
+ if (height != NULL)
+ *height = iloader->priv->original_height;
g_mutex_unlock (iloader->priv->data_mutex);
}
@@ -919,6 +921,9 @@ gth_image_loader_load_from_image_loader (GthImageLoader *to,
if ((to->priv->pixbuf == NULL) && (to->priv->animation == NULL))
error = g_error_new_literal (GTH_ERROR, 0, "No image available");
+ to->priv->original_width = from->priv->original_width;
+ to->priv->original_height = from->priv->original_height;
+
g_mutex_unlock (to->priv->data_mutex);
g_mutex_unlock (from->priv->data_mutex);
diff --git a/gthumb/gth-image-viewer.c b/gthumb/gth-image-viewer.c
index 42fbe0a..e7e33f5 100644
--- a/gthumb/gth-image-viewer.c
+++ b/gthumb/gth-image-viewer.c
@@ -233,8 +233,7 @@ get_zoomed_size (GthImageViewer *viewer,
else {
int w, h;
- w = gth_image_viewer_get_image_width (viewer);
- h = gth_image_viewer_get_image_height (viewer);
+ gth_image_viewer_get_original_size (viewer, &w, &h);
*width = (int) floor ((double) w * zoom_level);
*height = (int) floor ((double) h * zoom_level);
@@ -450,6 +449,8 @@ zoom_to_fit (GthImageViewer *viewer)
GtkAllocation allocation;
int gdk_width;
int gdk_height;
+ int original_width;
+ int original_height;
double x_level;
double y_level;
double new_zoom_level;
@@ -459,8 +460,11 @@ zoom_to_fit (GthImageViewer *viewer)
gtk_widget_get_allocation (GTK_WIDGET (viewer), &allocation);
gdk_width = allocation.width - viewer->priv->frame_border2;
gdk_height = allocation.height - viewer->priv->frame_border2;
- x_level = (double) gdk_width / gdk_pixbuf_get_width (pixbuf);
- y_level = (double) gdk_height / gdk_pixbuf_get_height (pixbuf);
+
+ gth_image_viewer_get_original_size (viewer, &original_width, &original_height);
+
+ x_level = (double) gdk_width / original_width;
+ y_level = (double) gdk_height / original_height;
new_zoom_level = (x_level < y_level) ? x_level : y_level;
if (new_zoom_level > 0.0) {
@@ -477,12 +481,16 @@ zoom_to_fit_width (GthImageViewer *viewer)
GdkPixbuf *pixbuf;
GtkAllocation allocation;
int gdk_width;
+ int original_width;
double new_zoom_level;
pixbuf = gth_image_viewer_get_current_pixbuf (viewer);
gtk_widget_get_allocation (GTK_WIDGET (viewer), &allocation);
gdk_width = allocation.width - viewer->priv->frame_border2;
- new_zoom_level = (double) gdk_width / gdk_pixbuf_get_width (pixbuf);
+
+ gth_image_viewer_get_original_size (viewer, &original_width, NULL);
+
+ new_zoom_level = (double) gdk_width / original_width;
if (new_zoom_level > 0.0) {
viewer->priv->doing_zoom_fit = TRUE;
@@ -497,7 +505,10 @@ gth_image_viewer_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GthImageViewer *viewer;
- int gdk_width, gdk_height;
+ int gdk_width;
+ int gdk_height;
+ int original_width;
+ int original_height;
GdkPixbuf *current_pixbuf;
viewer = GTH_IMAGE_VIEWER (widget);
@@ -512,6 +523,8 @@ gth_image_viewer_size_allocate (GtkWidget *widget,
current_pixbuf = gth_image_viewer_get_current_pixbuf (viewer);
+ gth_image_viewer_get_original_size (viewer, &original_width, &original_height);
+
/* If a fit type is active update the zoom level. */
if (! viewer->priv->is_void && (current_pixbuf != NULL)) {
@@ -521,9 +534,7 @@ gth_image_viewer_size_allocate (GtkWidget *widget,
break;
case GTH_FIT_SIZE_IF_LARGER:
- if ((gdk_width < gdk_pixbuf_get_width (current_pixbuf))
- || (gdk_height < gdk_pixbuf_get_height (current_pixbuf)))
- {
+ if ((gdk_width < original_width) || (gdk_height < original_height)) {
zoom_to_fit (viewer);
}
else {
@@ -538,7 +549,7 @@ gth_image_viewer_size_allocate (GtkWidget *widget,
break;
case GTH_FIT_WIDTH_IF_LARGER:
- if (gdk_width < gdk_pixbuf_get_width (current_pixbuf)) {
+ if (gdk_width < original_width) {
zoom_to_fit_width (viewer);
}
else {
@@ -1994,6 +2005,26 @@ gth_image_viewer_get_image_height (GthImageViewer *viewer)
}
+void
+gth_image_viewer_get_original_size (GthImageViewer *viewer,
+ int *width,
+ int *height)
+{
+ if (width != NULL)
+ *width = -1;
+ if (height != NULL)
+ *height = -1;
+
+ if (viewer->priv->loader != NULL)
+ gth_image_loader_get_original_size (viewer->priv->loader, width, height);
+
+ if ((width != NULL) && (*width == -1))
+ *width = gth_image_viewer_get_image_width (viewer);
+ if ((height != NULL) && (*height == -1))
+ *height = gth_image_viewer_get_image_height (viewer);
+}
+
+
int
gth_image_viewer_get_image_bps (GthImageViewer *viewer)
{
@@ -2530,11 +2561,13 @@ gth_image_viewer_paint (GthImageViewer *viewer,
int height,
int interp_type)
{
+ int original_width;
double zoom_level;
int bits_per_sample;
GdkColorspace color_space;
- zoom_level = viewer->priv->zoom_level;
+ gth_image_viewer_get_original_size (viewer, &original_width, NULL);
+ zoom_level = viewer->priv->zoom_level * ((double) original_width / gdk_pixbuf_get_width (pixbuf));
color_space = gdk_pixbuf_get_colorspace (pixbuf);
bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf);
diff --git a/gthumb/gth-image-viewer.h b/gthumb/gth-image-viewer.h
index 9d1124b..f23067b 100644
--- a/gthumb/gth-image-viewer.h
+++ b/gthumb/gth-image-viewer.h
@@ -174,6 +174,9 @@ int gth_image_viewer_get_image_height (GthImageViewer *vi
int gth_image_viewer_get_image_bps (GthImageViewer *viewer);
gboolean gth_image_viewer_get_has_alpha (GthImageViewer *viewer);
GdkPixbuf * gth_image_viewer_get_current_pixbuf (GthImageViewer *viewer);
+void gth_image_viewer_get_original_size (GthImageViewer *viewer,
+ int *width,
+ int *height);
/* animation. */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]