[gthumb: 69/129] set the TWO_STEPS policy for the image preloader
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 69/129] set the TWO_STEPS policy for the image preloader
- Date: Wed, 27 Apr 2011 20:56:10 +0000 (UTC)
commit 6d596d1b8f0164cd35bbd6acf933cd03ce134767
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Apr 24 12:25:26 2011 +0200
set the TWO_STEPS policy for the image preloader
extensions/cairo_io/cairo-io-jpeg.c | 19 ++++++-
extensions/image_viewer/gth-image-viewer-page.c | 12 +++-
gthumb/gth-browser.c | 2 +-
gthumb/gth-image-viewer.c | 60 ++++++++++++++++-------
gthumb/gth-image-viewer.h | 2 +-
5 files changed, 69 insertions(+), 26 deletions(-)
---
diff --git a/extensions/cairo_io/cairo-io-jpeg.c b/extensions/cairo_io/cairo-io-jpeg.c
index f9445b3..25828b7 100644
--- a/extensions/cairo_io/cairo-io-jpeg.c
+++ b/extensions/cairo_io/cairo-io-jpeg.c
@@ -144,6 +144,7 @@ _cairo_image_surface_create_from_jpeg (GthFileData *file_data,
GError **error)
{
GthImage *image;
+ gboolean load_scaled;
GthTransform orientation;
int destination_width;
int destination_height;
@@ -194,8 +195,9 @@ _cairo_image_surface_create_from_jpeg (GthFileData *file_data,
srcinfo.out_color_space = srcinfo.jpeg_color_space; /* make all the color space conversions manually */
- if (requested_size > 0) {
- for (srcinfo.scale_denom = 16; srcinfo.scale_denom >= 1; srcinfo.scale_denom--) {
+ load_scaled = (requested_size > 0) && (requested_size < srcinfo.image_width) && (requested_size < srcinfo.image_height);
+ if (load_scaled) {
+ for (srcinfo.scale_denom = 1; srcinfo.scale_denom <= 16; srcinfo.scale_denom++) {
jpeg_calc_output_dimensions (&srcinfo);
if ((srcinfo.output_width < requested_size) || (srcinfo.output_height < requested_size)) {
srcinfo.scale_denom += 1;
@@ -205,6 +207,8 @@ _cairo_image_surface_create_from_jpeg (GthFileData *file_data,
if (srcinfo.scale_denom == 0)
srcinfo.scale_denom = srcinfo.scale_num;
+
+ jpeg_calc_output_dimensions (&srcinfo);
}
jpeg_start_decompress (&srcinfo);
@@ -220,6 +224,15 @@ _cairo_image_surface_create_from_jpeg (GthFileData *file_data,
&line_step,
&pixel_step);
+#if 0
+ g_print ("requested: %d, original [%d, %d] ==> load at [%d, %d]\n",
+ requested_size,
+ srcinfo.image_width,
+ srcinfo.image_height,
+ destination_width,
+ destination_height);
+#endif
+
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, destination_width, destination_height);
surface_row = cairo_image_surface_get_data (surface) + line_start;
@@ -454,7 +467,7 @@ _cairo_image_surface_create_from_jpeg (GthFileData *file_data,
if (! g_cancellable_is_cancelled (cancellable)) {
/* Scale to the requested size */
- if (requested_size > 0) {
+ if (load_scaled) {
cairo_surface_t *scaled;
int width;
int height;
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index 77f8ad4..aa358eb 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -322,7 +322,7 @@ image_preloader_requested_ready_cb (GthImagePreloader *preloader,
static void
image_preloader_original_size_ready_cb (GthImagePreloader *preloader,
GthFileData *requested,
- GdkPixbufAnimation *animation,
+ GthImage *image,
int original_width,
int original_height,
GError *error,
@@ -335,7 +335,7 @@ image_preloader_original_size_ready_cb (GthImagePreloader *preloader,
return;
gth_image_viewer_set_better_quality (GTH_IMAGE_VIEWER (self->priv->viewer),
- animation,
+ image,
original_width,
original_height);
gth_image_history_clear (self->priv->history);
@@ -819,6 +819,8 @@ gth_image_viewer_page_real_view (GthViewerPage *base,
GthFileData *next_file_data = NULL;
GthFileData *next2_file_data = NULL;
GthFileData *prev_file_data = NULL;
+ int window_width;
+ int window_height;
self = (GthImageViewerPage*) base;
g_return_if_fail (file_data != NULL);
@@ -858,9 +860,13 @@ gth_image_viewer_page_real_view (GthViewerPage *base,
prev_file_data = gth_file_store_get_file (file_store, &iter2);
}
+ gtk_window_get_size (GTK_WINDOW (self->priv->browser),
+ &window_width,
+ &window_height);
+
gth_image_preloader_load (self->priv->preloader,
self->priv->file_data,
- -1,
+ (gth_image_prelaoder_get_load_policy (self->priv->preloader) == GTH_LOAD_POLICY_TWO_STEPS) ? MAX (window_width, window_height) : -1,
next_file_data,
next2_file_data,
prev_file_data,
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index ebb9078..2dc7ead 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -4355,7 +4355,7 @@ _gth_browser_construct (GthBrowser *browser)
/* the image preloader */
- browser->priv->image_preloader = gth_image_preloader_new (GTH_LOAD_POLICY_ONE_STEP, 4);
+ browser->priv->image_preloader = gth_image_preloader_new (GTH_LOAD_POLICY_TWO_STEPS, 4);
/**/
diff --git a/gthumb/gth-image-viewer.c b/gthumb/gth-image-viewer.c
index 5f752d6..6855536 100644
--- a/gthumb/gth-image-viewer.c
+++ b/gthumb/gth-image-viewer.c
@@ -1659,13 +1659,49 @@ gth_image_viewer_set_animation (GthImageViewer *self,
}
+static void
+_set_surface (GthImageViewer *self,
+ cairo_surface_t *surface,
+ int original_width,
+ int original_height,
+ gboolean better_quality)
+{
+ _cairo_clear_surface (&self->priv->surface);
+ _cairo_clear_surface (&self->priv->iter_surface);
+ _g_clear_object (&self->priv->animation);
+ _g_clear_object (&self->priv->iter);
+
+ self->priv->surface = cairo_surface_reference (surface);
+ self->priv->is_void = (self->priv->surface == NULL);
+ self->priv->is_animation = FALSE;
+ _gth_image_viewer_set_original_size (self, original_width, original_height);
+
+ _gth_image_viewer_content_changed (self, better_quality);
+}
+
+
void
-gth_image_viewer_set_better_quality (GthImageViewer *self,
- GdkPixbufAnimation *animation,
- int original_width,
- int original_height)
+gth_image_viewer_set_better_quality (GthImageViewer *self,
+ GthImage *image,
+ int original_width,
+ int original_height)
{
- _set_animation (self, animation, original_width, original_height, TRUE);
+ if (gth_image_is_animation (image)) {
+ GdkPixbufAnimation *animation;
+
+ animation = gth_image_get_pixbuf_animation (image);
+ _set_animation (self, animation, original_width, original_height, TRUE);
+
+ g_object_unref (animation);
+ }
+ else {
+ cairo_surface_t *surface;
+
+ surface = gth_image_get_cairo_surface (image);
+ _set_surface (self, surface, original_width, original_height, TRUE);
+
+ cairo_surface_destroy (surface);
+ }
}
@@ -1692,19 +1728,7 @@ gth_image_viewer_set_surface (GthImageViewer *self,
int original_width,
int original_height)
{
- g_return_if_fail (self != NULL);
-
- _cairo_clear_surface (&self->priv->surface);
- _cairo_clear_surface (&self->priv->iter_surface);
- _g_clear_object (&self->priv->animation);
- _g_clear_object (&self->priv->iter);
-
- self->priv->surface = cairo_surface_reference (surface);
- self->priv->is_void = (self->priv->surface == NULL);
- self->priv->is_animation = FALSE;
- _gth_image_viewer_set_original_size (self, original_width, original_height);
-
- _gth_image_viewer_content_changed (self, FALSE);
+ _set_surface (self, surface, original_width, original_height, FALSE);
}
diff --git a/gthumb/gth-image-viewer.h b/gthumb/gth-image-viewer.h
index 355178e..bad66a5 100644
--- a/gthumb/gth-image-viewer.h
+++ b/gthumb/gth-image-viewer.h
@@ -171,7 +171,7 @@ void gth_image_viewer_set_image (GthImageViewer *vi
int original_width,
int original_height);
void gth_image_viewer_set_better_quality (GthImageViewer *viewer,
- GdkPixbufAnimation *animation,
+ GthImage *image,
int original_width,
int original_height);
void gth_image_viewer_set_void (GthImageViewer *viewer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]