Fix #1240: Regression: Option to open new full-function window directly is missing
[geeqie.git] / src / image-load.h
1 /*
2  * Copyright (C) 2004 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
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 #ifndef IMAGE_LOAD_H
23 #define IMAGE_LOAD_H
24
25 #include <memory>
26
27 #include <gdk-pixbuf/gdk-pixbuf.h>
28 #include <glib-object.h>
29 #include <glib.h>
30
31 struct FileData;
32
33 #define TYPE_IMAGE_LOADER               (image_loader_get_type())
34
35 struct ImageLoaderBackend
36 {
37 public:
38         virtual ~ImageLoaderBackend() = default;
39
40         using AreaUpdatedCb = void (*)(gpointer, guint, guint, guint, guint, gpointer);
41         using SizePreparedCb = void (*)(gpointer, gint, gint, gpointer);
42         using AreaPreparedCb = void (*)(gpointer, gpointer);
43
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; };
54 };
55
56 enum ImageLoaderPreview {
57         IMAGE_LOADER_PREVIEW_NONE = 0,
58         IMAGE_LOADER_PREVIEW_EXIF = 1,
59         IMAGE_LOADER_PREVIEW_LIBRAW = 2
60 };
61
62
63 struct ImageLoader
64 {
65         GObject parent;
66
67         /*< private >*/
68         GdkPixbuf *pixbuf;
69         FileData *fd;
70         gchar *path;
71
72         gsize bytes_read;
73         gsize bytes_total;
74
75         ImageLoaderPreview preview;
76
77         gint requested_width;
78         gint requested_height;
79
80         gint actual_width;
81         gint actual_height;
82
83         gboolean shrunk;
84
85         gboolean done;
86         guint idle_id; /**< event source id */
87         gint idle_priority;
88
89         GError *error;
90         std::unique_ptr<ImageLoaderBackend> backend;
91
92         guint idle_done_id; /**< event source id */
93         GList *area_param_list;
94         GList *area_param_delayed_list;
95
96         gboolean delay_area_ready;
97
98         GMutex *data_mutex;
99         gboolean stopping;
100         gboolean can_destroy;
101         GCond *can_destroy_cond;
102         gboolean thread;
103
104         guchar *mapped_file;
105         gsize read_buffer_size;
106         guint idle_read_loop_count;
107 };
108
109 struct ImageLoaderClass {
110         GObjectClass parent;
111
112         /* class members */
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);
117 };
118
119 GType image_loader_get_type();
120
121 ImageLoader *image_loader_new(FileData *fd);
122
123 void image_loader_free(ImageLoader *il);
124
125 /**
126  * @headerfile image_loader_delay_area_ready
127  * delay area_ready signals
128  */
129 void image_loader_delay_area_ready(ImageLoader *il, gboolean enable);
130
131 /**
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..
136  */
137 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height);
138
139 void image_loader_set_buffer_size(ImageLoader *il, guint count);
140
141 /**
142  * @headerfile image_loader_set_priority
143  * this only has effect if used before image_loader_start()
144  * default is G_PRIORITY_DEFAULT_IDLE
145  */
146 void image_loader_set_priority(ImageLoader *il, gint priority);
147
148 gboolean image_loader_start(ImageLoader *il);
149
150
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);
157
158 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height);
159
160 #endif
161 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */