2 * Copyright (C) 2004 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
5 * Author: Vladimir Nadvornik
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.
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.
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.
22 #include "image-load-gdk.h"
24 #include <gdk-pixbuf/gdk-pixbuf.h>
25 #include <glib-object.h>
29 #include "image-load.h"
34 struct ImageLoaderGdk : public ImageLoaderBackend
37 ~ImageLoaderGdk() override;
39 void init(AreaUpdatedCb area_updated_cb, SizePreparedCb size_prepared_cb, AreaPreparedCb area_prepared_cb, gpointer data) override;
40 void set_size(int width, int height) override;
41 gboolean write(const guchar *buf, gsize &chunk_size, gsize count, GError **error) override;
42 GdkPixbuf *get_pixbuf() override;
43 gboolean close(GError **error) override;
44 gchar *get_format_name() override;
45 gchar **get_format_mime_types() override;
48 GdkPixbufLoader *loader;
51 gchar *ImageLoaderGdk::get_format_name()
53 GdkPixbufFormat *format;
55 format = gdk_pixbuf_loader_get_format(loader);
58 return gdk_pixbuf_format_get_name(format);
64 gchar **ImageLoaderGdk::get_format_mime_types()
66 return gdk_pixbuf_format_get_mime_types(gdk_pixbuf_loader_get_format(loader));
69 void ImageLoaderGdk::init(AreaUpdatedCb area_updated_cb, SizePreparedCb size_prepared_cb, AreaPreparedCb area_prepared_cb, gpointer data)
71 auto il = static_cast<ImageLoader *>(data);
73 /** @FIXME gdk-pixbuf-loader does not recognize .xbm files unless
74 * the mime type is given. There should be a general case */
75 if (g_ascii_strncasecmp(il->fd->extension, ".xbm", 4) == 0)
77 loader = gdk_pixbuf_loader_new_with_mime_type("image/x-xbitmap", nullptr);
81 loader = gdk_pixbuf_loader_new();
84 g_signal_connect(G_OBJECT(loader), "area_updated", G_CALLBACK(area_updated_cb), data);
85 g_signal_connect(G_OBJECT(loader), "size_prepared", G_CALLBACK(size_prepared_cb), data);
86 g_signal_connect(G_OBJECT(loader), "area_prepared", G_CALLBACK(area_prepared_cb), data);
89 void ImageLoaderGdk::set_size(int width, int height)
91 gdk_pixbuf_loader_set_size(loader, width, height);
94 gboolean ImageLoaderGdk::write(const guchar *buf, gsize &chunk_size, gsize, GError **error)
96 return gdk_pixbuf_loader_write(loader, buf, chunk_size, error);
99 GdkPixbuf *ImageLoaderGdk::get_pixbuf()
101 return gdk_pixbuf_loader_get_pixbuf(loader);
104 gboolean ImageLoaderGdk::close(GError **error)
106 return gdk_pixbuf_loader_close(loader, error);
109 ImageLoaderGdk::~ImageLoaderGdk()
111 g_object_unref(G_OBJECT(loader));
116 std::unique_ptr<ImageLoaderBackend> get_image_loader_backend_default()
118 return std::make_unique<ImageLoaderGdk>();
121 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */