2 * Copyright (C) 2004 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
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.
27 #include <gdk-pixbuf/gdk-pixbuf.h>
28 #include <glib-object.h>
33 #define TYPE_IMAGE_LOADER (image_loader_get_type())
35 struct ImageLoaderBackend
38 virtual ~ImageLoaderBackend() = default;
40 using AreaUpdatedCb = void (*)(gpointer, guint, guint, guint, guint, gpointer);
41 using SizePreparedCb = void (*)(gpointer, gint, gint, gpointer);
42 using AreaPreparedCb = void (*)(gpointer, gpointer);
44 virtual void init(AreaUpdatedCb area_updated_cb, SizePreparedCb size_prepared_cb, AreaPreparedCb area_prepared_cb, gpointer data) = 0;
45 virtual void set_size(int /*width*/, int /*height*/) {};
46 virtual gboolean write(const guchar *buf, gsize &chunk_size, gsize count, GError **error) = 0;
47 virtual GdkPixbuf *get_pixbuf() = 0;
48 virtual gboolean close(GError **/*error*/) { return TRUE; };
49 virtual void abort() {};
50 virtual gchar *get_format_name() = 0;
51 virtual gchar **get_format_mime_types() = 0;
52 virtual void set_page_num(gint /*page_num*/) {};
53 virtual gint get_page_total() { return 0; };
56 enum ImageLoaderPreview {
57 IMAGE_LOADER_PREVIEW_NONE = 0,
58 IMAGE_LOADER_PREVIEW_EXIF = 1,
59 IMAGE_LOADER_PREVIEW_LIBRAW = 2
75 ImageLoaderPreview preview;
78 gint requested_height;
86 guint idle_id; /**< event source id */
90 std::unique_ptr<ImageLoaderBackend> backend;
92 guint idle_done_id; /**< event source id */
93 GList *area_param_list;
94 GList *area_param_delayed_list;
96 gboolean delay_area_ready;
100 gboolean can_destroy;
101 GCond *can_destroy_cond;
105 gsize read_buffer_size;
106 guint idle_read_loop_count;
109 struct ImageLoaderClass {
113 void (*area_ready)(ImageLoader *, guint x, guint y, guint w, guint h, gpointer);
114 void (*error)(ImageLoader *, gpointer);
115 void (*done)(ImageLoader *, gpointer);
116 void (*percent)(ImageLoader *, gdouble, gpointer);
119 GType image_loader_get_type();
121 ImageLoader *image_loader_new(FileData *fd);
123 void image_loader_free(ImageLoader *il);
126 * @headerfile image_loader_delay_area_ready
127 * delay area_ready signals
129 void image_loader_delay_area_ready(ImageLoader *il, gboolean enable);
132 * @headerfile image_loader_set_requested_size
133 * Speed up loading when you only need at most width x height size image,
134 * only the jpeg GdkPixbuf loader benefits from it - so there is no
135 * guarantee that the image will scale down to the requested size..
137 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height);
139 void image_loader_set_buffer_size(ImageLoader *il, guint count);
142 * @headerfile image_loader_set_priority
143 * this only has effect if used before image_loader_start()
144 * default is G_PRIORITY_DEFAULT_IDLE
146 void image_loader_set_priority(ImageLoader *il, gint priority);
148 gboolean image_loader_start(ImageLoader *il);
151 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il);
152 gdouble image_loader_get_percent(ImageLoader *il);
153 gboolean image_loader_get_is_done(ImageLoader *il);
154 FileData *image_loader_get_fd(ImageLoader *il);
155 gboolean image_loader_get_shrunk(ImageLoader *il);
156 const gchar *image_loader_get_error(ImageLoader *il);
158 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height);
161 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */