d28af2174441878c3c172b8bd3e5b20bb5cfd8c8
[geeqie.git] / src / image-load-gdk.cc
1 /*
2  * Copyright (C) 2004 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: Vladimir Nadvornik
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include "main.h"
23 #include "image-load.h"
24 #include "image-load-gdk.h"
25
26
27 static gchar* image_loader_gdk_get_format_name(gpointer loader)
28 {
29         GdkPixbufFormat *format;
30
31         format = gdk_pixbuf_loader_get_format(GDK_PIXBUF_LOADER(loader));
32         if (format)
33                 {
34                 return gdk_pixbuf_format_get_name(format);
35                 }
36         else
37                 {
38                 return nullptr;
39                 }
40 }
41 static gchar** image_loader_gdk_get_format_mime_types(gpointer loader)
42 {
43         return gdk_pixbuf_format_get_mime_types(gdk_pixbuf_loader_get_format(GDK_PIXBUF_LOADER(loader)));
44 }
45
46 static gpointer image_loader_gdk_new(ImageLoaderBackendCbAreaUpdated area_updated_cb, ImageLoaderBackendCbSize size_cb, ImageLoaderBackendCbAreaPrepared area_prepared_cb, gpointer data)
47 {
48         auto il = static_cast<ImageLoader *>(data);
49         GdkPixbufLoader *loader;
50
51         /** @FIXME gdk-pixbuf-loader does not recognize .xbm files unless
52          * the mime type is given. There should be a general case */
53         if (g_ascii_strncasecmp(il->fd->extension, ".xbm", 4) == 0)
54                 {
55                 loader = gdk_pixbuf_loader_new_with_mime_type("image/x-xbitmap", nullptr);
56                 }
57         else
58                 {
59                 loader = gdk_pixbuf_loader_new();
60                 }
61
62         g_signal_connect(G_OBJECT(loader), "area_updated", G_CALLBACK(area_updated_cb), data);
63         g_signal_connect(G_OBJECT(loader), "size_prepared", G_CALLBACK(size_cb), data);
64         g_signal_connect(G_OBJECT(loader), "area_prepared", G_CALLBACK(area_prepared_cb), data);
65         return loader;
66 }
67
68 static void image_loader_gdk_abort(gpointer UNUSED(loader))
69 {
70 }
71
72 static void image_loader_gdk_free(gpointer loader)
73 {
74         g_object_unref(G_OBJECT(loader));
75 }
76
77 void image_loader_backend_set_default(ImageLoaderBackend *funcs)
78 {
79         funcs->loader_new = image_loader_gdk_new;
80         funcs->set_size = reinterpret_cast<ImageLoaderBackendFuncSetSize>(gdk_pixbuf_loader_set_size);
81         funcs->load = nullptr;
82         funcs->write = reinterpret_cast<ImageLoaderBackendFuncWrite>(gdk_pixbuf_loader_write);
83         funcs->get_pixbuf = reinterpret_cast<ImageLoaderBackendFuncGetPixbuf>(gdk_pixbuf_loader_get_pixbuf);
84         funcs->close = reinterpret_cast<ImageLoaderBackendFuncClose>(gdk_pixbuf_loader_close);
85         funcs->abort = image_loader_gdk_abort;
86         funcs->free = image_loader_gdk_free;
87
88         funcs->get_format_name = image_loader_gdk_get_format_name;
89         funcs->get_format_mime_types = image_loader_gdk_get_format_mime_types;
90 }
91
92
93 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */