175
172
g_object_unref (pixbuf);
175
GthImageFormat preferred_format;
178
176
GthImageLoaderFunc thumbnailer;
180
/* prefer the GTH_IMAGE_FORMAT_CAIRO_SURFACE format to give
181
* priority to the internal loaders. */
183
thumbnailer = gth_main_get_image_loader_func (mime_type, GTH_IMAGE_FORMAT_CAIRO_SURFACE);
178
/* Prefer the internal loader for jpeg images to load rotated
179
* images correctly. */
180
if (strcmp (mime_type, "image/jpeg") == 0)
181
preferred_format = GTH_IMAGE_FORMAT_CAIRO_SURFACE;
183
preferred_format = GTH_IMAGE_FORMAT_GDK_PIXBUF;
184
thumbnailer = gth_main_get_image_loader_func (mime_type, preferred_format);
184
185
if (thumbnailer != NULL)
185
186
image = thumbnailer (istream,
208
208
int requested_size,
209
209
int *original_width,
210
210
int *original_height,
211
gboolean *loaded_original,
212
211
gpointer user_data,
213
212
GCancellable *cancellable,
215
GthImage *image = NULL;
216
219
if (file_data == NULL) {
217
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, "Could not load file");
221
*error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, "Could not load file");
221
return gth_image_new_from_stream (istream,
225
filename = g_file_get_path (file_data->file);
226
pixbuf = gdk_pixbuf_new_from_file (filename, error);
227
if (pixbuf != NULL) {
228
image = gth_image_new_for_pixbuf (pixbuf);
229
g_object_unref (pixbuf);
416
static cairo_surface_t *
417
_cairo_image_surface_scale_for_thumbnail (cairo_surface_t *image,
421
cairo_surface_t *scaled;
423
scaled = _cairo_image_surface_scale (image, new_width, new_height, SCALE_FILTER_GOOD, NULL);
424
_cairo_image_surface_copy_metadata (image, scaled);
431
425
cache_image_ready_cb (GObject *source_object,
432
426
GAsyncResult *res,
433
427
gpointer user_data)
435
LoadData *load_data = user_data;
436
GthThumbLoader *self = load_data->thumb_loader;
437
GthImage *image = NULL;
438
cairo_surface_t *surface;
442
LoadResult *load_result;
429
LoadData *load_data = user_data;
430
GthThumbLoader *self = load_data->thumb_loader;
431
GthImage *image = NULL;
436
LoadResult *load_result;
444
438
if (! gth_image_loader_load_finish (GTH_IMAGE_LOADER (source_object),
452
445
/* error loading the thumbnail from the cache, try to generate
466
459
/* Thumbnail correctly loaded from the cache. Scale if the user wants
467
460
* a different size. */
469
surface = gth_image_get_cairo_surface (image);
471
g_return_if_fail (surface != NULL);
473
width = cairo_image_surface_get_width (surface);
474
height = cairo_image_surface_get_height (surface);
462
pixbuf = gth_image_get_pixbuf (image);
464
g_return_if_fail (pixbuf != NULL);
466
width = gdk_pixbuf_get_width (pixbuf);
467
height = gdk_pixbuf_get_height (pixbuf);
475
468
modified = normalize_thumb (&width,
477
470
self->priv->requested_size,
478
471
self->priv->cache_max_size);
480
cairo_surface_t *tmp = surface;
481
surface = _cairo_image_surface_scale_for_thumbnail (tmp, width, height);
482
cairo_surface_destroy (tmp);
473
GdkPixbuf *tmp = pixbuf;
474
pixbuf = _gdk_pixbuf_scale_simple_safe (tmp, width, height, GDK_INTERP_BILINEAR);
475
g_object_unref (tmp);
485
478
load_result = g_new0 (LoadResult, 1);
486
479
load_result->file_data = g_object_ref (load_data->file_data);
487
load_result->image = surface;
480
load_result->pixbuf = pixbuf;
488
481
g_simple_async_result_set_op_res_gpointer (load_data->simple, load_result, (GDestroyNotify) load_result_unref);
489
482
g_simple_async_result_complete_in_idle (load_data->simple);
520
_gth_thumb_loader_save_to_cache (GthThumbLoader *self,
521
GthFileData *file_data,
522
cairo_surface_t *image,
513
_gth_thumb_loader_save_to_cache (GthThumbLoader *self,
514
GthFileData *file_data,
527
cairo_surface_metadata_t *metadata;
530
if ((self == NULL) || (image == NULL))
519
if ((self == NULL) || (pixbuf == NULL))
533
522
uri = g_file_get_uri (file_data->file);
543
if ((original_width > 0) && (original_height > 0)) {
544
metadata = _cairo_image_surface_get_metadata (image);
545
metadata->thumbnail.image_width = original_width;
546
metadata->thumbnail.image_height = original_height;
548
pixbuf = _gdk_pixbuf_new_from_cairo_surface (image);
552
532
gnome_desktop_thumbnail_factory_save_thumbnail (self->priv->thumb_factory,
555
535
gth_file_data_get_mtime (file_data));
557
g_object_unref (pixbuf);
564
542
original_image_loaded_correctly (GthThumbLoader *self,
565
543
LoadData *load_data,
566
cairo_surface_t *image,
570
cairo_surface_t *local_image;
574
LoadResult *load_result;
576
local_image = cairo_surface_reference (image);
578
width = cairo_image_surface_get_width (local_image);
579
height = cairo_image_surface_get_height (local_image);
546
GdkPixbuf *local_pixbuf;
550
LoadResult *load_result;
552
local_pixbuf = g_object_ref (pixbuf);
554
width = gdk_pixbuf_get_width (local_pixbuf);
555
height = gdk_pixbuf_get_height (local_pixbuf);
581
557
if (self->priv->save_thumbnails) {
582
558
gboolean modified;
591
567
self->priv->cache_max_size,
594
cairo_surface_t *tmp = local_image;
595
local_image = _cairo_image_surface_scale_for_thumbnail (tmp, width, height);
596
cairo_surface_destroy (tmp);
570
GdkPixbuf *tmp = local_pixbuf;
571
local_pixbuf = _gdk_pixbuf_scale_simple_safe (tmp, width, height, GDK_INTERP_BILINEAR);
572
g_object_unref (tmp);
599
_gth_thumb_loader_save_to_cache (self,
600
load_data->file_data,
575
_gth_thumb_loader_save_to_cache (self, load_data->file_data, local_pixbuf);
606
578
/* Scale if the user wants a different size. */
610
582
self->priv->requested_size,
611
583
self->priv->cache_max_size);
613
cairo_surface_t *tmp = local_image;
614
local_image = _cairo_image_surface_scale_for_thumbnail (tmp, width, height);
615
cairo_surface_destroy (tmp);
585
GdkPixbuf *tmp = local_pixbuf;
586
local_pixbuf = _gdk_pixbuf_scale_simple_safe (tmp, width, height, GDK_INTERP_BILINEAR);
587
g_object_unref (tmp);
618
590
load_result = g_new0 (LoadResult, 1);
619
591
load_result->file_data = g_object_ref (load_data->file_data);
620
load_result->image = cairo_surface_reference (local_image);
592
load_result->pixbuf = g_object_ref (local_pixbuf);
621
593
g_simple_async_result_set_op_res_gpointer (load_data->simple, load_result, (GDestroyNotify) load_result_unref);
622
594
g_simple_async_result_complete_in_idle (load_data->simple);
624
cairo_surface_destroy (local_image);
596
g_object_unref (local_pixbuf);
730
702
&load_data->thumbnailer_tmpfile);
732
704
if (pixbuf != NULL) {
733
cairo_surface_t *surface;
735
surface = _cairo_image_surface_create_from_pixbuf (pixbuf);
736
original_image_loaded_correctly (self, load_data, surface, 0, 0);
738
cairo_surface_destroy (surface);
705
original_image_loaded_correctly (self, load_data, pixbuf);
739
706
g_object_unref (pixbuf);
748
715
GAsyncResult *res,
749
716
gpointer user_data)
751
LoadData *load_data = user_data;
752
GthThumbLoader *self = load_data->thumb_loader;
753
GthImage *image = NULL;
756
cairo_surface_t *surface = NULL;
757
GError *error = NULL;
718
LoadData *load_data = user_data;
719
GthThumbLoader *self = load_data->thumb_loader;
720
GthImage *image = NULL;
721
GdkPixbuf *pixbuf = NULL;
722
GError *error = NULL;
759
724
if (! gth_image_loader_load_finish (GTH_IMAGE_LOADER (source_object),
809
surface = gth_image_get_cairo_surface (image);
810
original_image_loaded_correctly (self,
773
pixbuf = gth_image_get_pixbuf (image);
774
original_image_loaded_correctly (self, load_data, pixbuf);
816
cairo_surface_destroy (surface);
776
g_object_unref (pixbuf);
817
777
g_object_unref (image);
818
778
load_data_unref (load_data);