Commit 6d596d1b authored by Paolo Bacchilega's avatar Paolo Bacchilega

set the TWO_STEPS policy for the image preloader

parent f4c2a349
......@@ -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;
......
......@@ -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,
......
......@@ -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);
/**/
......
......@@ -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);
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment