1 | /* |
2 | * Copyright (C) 2016 Bastien Nocera <hadess@hadess.net> |
3 | * |
4 | * Authors: Bastien Nocera <hadess@hadess.net> |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | * |
20 | */ |
21 | |
22 | #include <string.h> |
23 | #include <glib.h> |
24 | |
25 | #include "gnome-thumbnailer-skeleton.h" |
26 | |
27 | GdkPixbuf * |
28 | file_to_pixbuf (const char *path, |
29 | guint destination_size, |
30 | GError **error) |
31 | { |
32 | GdkPixbuf *pixbuf, *tmp_pixbuf; |
33 | const char *original_width_str, *original_height_str; |
34 | |
35 | pixbuf = gdk_pixbuf_new_from_file_at_size (filename: path, width: destination_size, height: destination_size, error); |
36 | if (pixbuf == NULL) |
37 | return NULL; |
38 | |
39 | /* The GIF codec throws GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION |
40 | * if it's closed without decoding all the frames. Since |
41 | * gdk_pixbuf_new_from_file_at_size only decodes the first |
42 | * frame, this specific error needs to be ignored. |
43 | */ |
44 | if (error != NULL && g_error_matches (error: *error, GDK_PIXBUF_ERROR, code: GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION)) |
45 | g_clear_error (err: error); |
46 | |
47 | tmp_pixbuf = gdk_pixbuf_apply_embedded_orientation (src: pixbuf); |
48 | gdk_pixbuf_copy_options (src_pixbuf: pixbuf, dest_pixbuf: tmp_pixbuf); |
49 | gdk_pixbuf_remove_option (pixbuf: tmp_pixbuf, key: "orientation" ); |
50 | g_object_unref (object: pixbuf); |
51 | pixbuf = tmp_pixbuf; |
52 | |
53 | original_width_str = gdk_pixbuf_get_option (pixbuf, key: "original-width" ); |
54 | original_height_str = gdk_pixbuf_get_option (pixbuf, key: "original-height" ); |
55 | |
56 | if (original_width_str != NULL) |
57 | gdk_pixbuf_set_option (pixbuf, key: "tEXt::Thumb::Image::Width" , value: original_width_str); |
58 | |
59 | if (original_height_str != NULL) |
60 | gdk_pixbuf_set_option (pixbuf, key: "tEXt::Thumb::Image::Height" , value: original_height_str); |
61 | |
62 | return pixbuf; |
63 | } |
64 | |