[gthumb] jpeg loader: cancel the image loading faster
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] jpeg loader: cancel the image loading faster
- Date: Sun, 30 Jun 2013 08:41:18 +0000 (UTC)
commit 69fe61d039512965faf1c1439af11e9aed392fcb
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Jun 28 16:52:10 2013 +0200
jpeg loader: cancel the image loading faster
added other points where the cancellable is checked
extensions/cairo_io/cairo-image-surface-jpeg.c | 68 +++++++++++++++---------
1 files changed, 42 insertions(+), 26 deletions(-)
---
diff --git a/extensions/cairo_io/cairo-image-surface-jpeg.c b/extensions/cairo_io/cairo-image-surface-jpeg.c
index b8ee828..54985fb 100644
--- a/extensions/cairo_io/cairo-image-surface-jpeg.c
+++ b/extensions/cairo_io/cairo-image-surface-jpeg.c
@@ -273,7 +273,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
while (srcinfo.output_scanline < srcinfo.output_height) {
if (g_cancellable_is_cancelled (cancellable))
- break;
+ goto stop_loading;
n_lines = jpeg_read_scanlines (&srcinfo, buffer, srcinfo.rec_outbuf_height);
@@ -282,6 +282,9 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
p_surface = surface_row;
p_buffer = buffer_row[l];
+ if (g_cancellable_is_cancelled (cancellable))
+ goto stop_loading;
+
for (x = 0; x < srcinfo.output_width; x++) {
if (srcinfo.saw_Adobe_marker) {
c = p_buffer[0];
@@ -318,7 +321,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
{
while (srcinfo.output_scanline < srcinfo.output_height) {
if (g_cancellable_is_cancelled (cancellable))
- break;
+ goto stop_loading;
n_lines = jpeg_read_scanlines (&srcinfo, buffer, srcinfo.rec_outbuf_height);
@@ -327,6 +330,9 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
p_surface = surface_row;
p_buffer = buffer_row[l];
+ if (g_cancellable_is_cancelled (cancellable))
+ goto stop_loading;
+
for (x = 0; x < srcinfo.output_width; x++) {
r = g = b = p_buffer[0];
pixel = CAIRO_RGBA_TO_UINT32 (r, g, b, 0xff);
@@ -347,7 +353,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
{
while (srcinfo.output_scanline < srcinfo.output_height) {
if (g_cancellable_is_cancelled (cancellable))
- break;
+ goto stop_loading;
n_lines = jpeg_read_scanlines (&srcinfo, buffer, srcinfo.rec_outbuf_height);
@@ -356,6 +362,9 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
p_surface = surface_row;
p_buffer = buffer_row[l];
+ if (g_cancellable_is_cancelled (cancellable))
+ goto stop_loading;
+
for (x = 0; x < srcinfo.output_width; x++) {
r = p_buffer[0];
g = p_buffer[1];
@@ -391,7 +400,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
while (srcinfo.output_scanline < srcinfo.output_height) {
if (g_cancellable_is_cancelled (cancellable))
- break;
+ goto stop_loading;
n_lines = jpeg_read_scanlines (&srcinfo, buffer, srcinfo.rec_outbuf_height);
@@ -400,6 +409,9 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
p_surface = surface_row;
p_buffer = buffer_row[l];
+ if (g_cancellable_is_cancelled (cancellable))
+ goto stop_loading;
+
for (x = 0; x < srcinfo.output_width; x++) {
Y = p_buffer[0];
Cb = p_buffer[1];
@@ -443,7 +455,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
while (srcinfo.output_scanline < srcinfo.output_height) {
if (g_cancellable_is_cancelled (cancellable))
- break;
+ goto stop_loading;
n_lines = jpeg_read_scanlines (&srcinfo, buffer, srcinfo.rec_outbuf_height);
@@ -452,6 +464,9 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
p_surface = surface_row;
p_buffer = buffer_row[l];
+ if (g_cancellable_is_cancelled (cancellable))
+ goto stop_loading;
+
for (x = 0; x < srcinfo.output_width; x++) {
Y = p_buffer[0];
Cb = p_buffer[1];
@@ -491,24 +506,11 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
break;
}
- if (! g_cancellable_is_cancelled (cancellable)) {
- cairo_surface_mark_dirty (surface);
-
- /* Scale to the requested size */
-
- if (load_scaled) {
- cairo_surface_t *scaled;
- int width;
- int height;
+ stop_loading:
- width = destination_width;
- height = destination_height;
- scale_keeping_ratio (&width, &height, requested_size, requested_size, TRUE);
- scaled = _cairo_image_surface_scale (surface, width, height, SCALE_FILTER_BEST, NULL);
+ cairo_surface_mark_dirty (surface);
- cairo_surface_destroy (surface);
- surface = scaled;
- }
+ if (! g_cancellable_is_cancelled (cancellable)) {
/* Set the original dimensions */
@@ -528,18 +530,32 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
if (original_height != NULL)
*original_height = srcinfo.image_height;
}
+ jpeg_finish_decompress (&srcinfo);
+ jpeg_destroy_decompress (&srcinfo);
+
+ /* Scale to the requested size */
+
+ if (load_scaled) {
+ cairo_surface_t *scaled;
+ int width;
+ int height;
+
+ width = destination_width;
+ height = destination_height;
+ scale_keeping_ratio (&width, &height, requested_size, requested_size, TRUE);
+ scaled = _cairo_image_surface_scale (surface, width, height, SCALE_FILTER_BEST, NULL);
+
+ cairo_surface_destroy (surface);
+ surface = scaled;
+ }
/*_cairo_image_surface_set_attribute_int (surface, "Image::Rotation", rotation); FIXME*/
-
/* FIXME _cairo_image_surface_set_attribute (surface, "Jpeg::ColorSpace",
jpeg_color_space_name (srcinfo.jpeg_color_space)); */
gth_image_set_cairo_surface (image, surface);
-
- jpeg_finish_decompress (&srcinfo);
- jpeg_destroy_decompress (&srcinfo);
}
else {
- jpeg_destroy ((j_common_ptr) &srcinfo);
+ jpeg_destroy_decompress (&srcinfo);
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CANCELLED, "");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]