1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
/*
* modules.c: Dynamically loading the format handlers for save and load
* operations in Imlib.
*
* Author:
* Miguel de Icaza ([email protected]).
*/
#include <config.h>
#include <glib.h>
#include <gmodule.h>
#include "gdk_imlib.h"
#define id _gdk_imlib_data
#include "gdk_imlib_private.h"
#ifdef USE_GMODULE
static unsigned char *loader_bmp (FILE *f, int *w, int *h, int *t);
static unsigned char *loader_xpm (FILE *f, int *w, int *h, int *t);
static unsigned char *loader_gif (FILE *f, int *w, int *h, int *t);
static unsigned char *loader_tiff (FILE *f, char *n, int *w, int *h, int *t);
static unsigned char *loader_jpeg (FILE *f, int *w, int *h, int *t);
static unsigned char *loader_png (FILE *f, int *w, int *h, int *t);
static unsigned char *loader_ppm (FILE *f, int *w, int *h, int *t);
static gint saver_tiff (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info);
static gint saver_png (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info);
static gint saver_jpeg (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info);
static gint saver_ps (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info);
static gint saver_ppm (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info);
static GdkImlibImage *loader_alpha_png (char *file);
static GdkImlibImage *inline_png (unsigned char *data, int data_size);
#else
# include "io-png.c"
# include "io-bmp.c"
# include "io-gif.c"
# include "io-jpeg.c"
# include "io-ppm.c"
# include "io-ps.c"
# include "io-tiff.c"
# include "io-xpm.c"
#endif
gdk_imlib_loader_fn _gdk_imlib_LoadBMP = loader_bmp;
gdk_imlib_loader_fn _gdk_imlib_LoadXPM = loader_xpm;
gdk_imlib_loader_fn _gdk_imlib_LoadGIF = loader_gif;
gdk_imlib_loader_fn2 _gdk_imlib_LoadTIFF = loader_tiff;
gdk_imlib_loader_fn _gdk_imlib_LoadJPEG = loader_jpeg;
gdk_imlib_loader_fn _gdk_imlib_LoadPNG = loader_png;
gdk_imlib_loader_fn _gdk_imlib_LoadPPM = loader_ppm;
gdk_imlib_saver_fn _gdk_imlib_SaveTIFF = saver_tiff;
gdk_imlib_saver_fn _gdk_imlib_SavePNG = saver_png;
gdk_imlib_saver_fn _gdk_imlib_SaveJPEG = saver_jpeg;
gdk_imlib_saver_fn _gdk_imlib_SavePS = saver_ps;
gdk_imlib_saver_fn _gdk_imlib_SavePPM = saver_ppm;
gdk_imlib_inline_fn _gdk_imlib_inlined_png_to_image = inline_png;
gdk_imlib_load_alpha_fn _gdk_imlib_load_alpha_png = loader_alpha_png;
#ifdef USE_GMODULE
static unsigned char *
load_fail_fn (FILE *f, int *w, int *h, int *t)
{
return NULL;
}
static gint
save_fail_fn (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info)
{
return 0;
}
static gboolean
get_module_loader_saver (char *mod,
void **loader, void *def_loader,
void **saver, void *def_saver)
{
char *path, *modname;
GModule *m;
gboolean v;
void *ptr;
modname = g_strconcat ("imlib-", mod, NULL);
path = g_module_build_path (IMLIB_LIB, modname);
g_free (modname);
m = g_module_open (path, G_MODULE_BIND_LAZY);
g_free (path);
if (!m){
if (loader)
*loader = def_loader;
if (saver)
*saver = def_saver;
return FALSE;
}
if (loader){
char *loader_name;
loader_name = g_strconcat ("loader_", mod, NULL);
v = g_module_symbol (m, loader_name, (void **) &ptr);
if (v)
*loader = ptr;
else
*loader = def_loader;
g_free (loader_name);
}
if (saver){
char *saver_name;
saver_name = g_strconcat ("saver_", mod, NULL);
v = g_module_symbol (m, saver_name, (void **) &ptr);
if (v)
*saver = ptr;
else
*saver = def_saver;
g_free (saver_name);
}
/* Ugly hack, this is an exception */
if (strcmp (mod, "png") == 0){
char *inline_name, *alpha_name;
inline_name = g_strconcat ("inline_", mod, NULL);
v = g_module_symbol (m, inline_name, (void **) &ptr);
if (v)
_gdk_imlib_inlined_png_to_image = ptr;
else
_gdk_imlib_inlined_png_to_image = (gdk_imlib_inline_fn) load_fail_fn;
g_free (inline_name);
alpha_name = g_strconcat ("loader_alpha_", mod, NULL);
v = g_module_symbol (m, alpha_name, (void **) &ptr);
if (v)
_gdk_imlib_load_alpha_png = ptr;
else
_gdk_imlib_load_alpha_png = (gdk_imlib_load_alpha_fn) load_fail_fn;
g_free (alpha_name);
}
return TRUE; /* FIXME: return value is never checked */
}
static unsigned char *
load_module_relay (char *mod, gdk_imlib_loader_fn *lf, gdk_imlib_saver_fn *sf, FILE *f, int *w, int *h, int *t)
{
get_module_loader_saver (mod,
(void **) lf, (void *) load_fail_fn,
(void **) sf, (void *) save_fail_fn);
return (*lf)(f, w, h, t);
}
static gint
save_module_relay (char *mod, gdk_imlib_loader_fn *lf, gdk_imlib_saver_fn *sf,
GdkImlibImage *im, char *fname, GdkImlibSaveInfo *info)
{
get_module_loader_saver (mod,
(void **) lf, (void *) load_fail_fn,
(void **) sf, (void *) save_fail_fn);
return (*sf)(im, fname, info);
}
static unsigned char *
loader_tiff (FILE *f, char *n, int *w, int *h, int *t)
{
get_module_loader_saver ("tiff",
(void **) &_gdk_imlib_LoadTIFF, (void *) load_fail_fn,
(void **) &_gdk_imlib_SaveTIFF, (void *) save_fail_fn);
return _gdk_imlib_LoadTIFF (f, n, w, h, t);
}
static unsigned char *
loader_bmp (FILE *f, int *w, int *h, int *t)
{
return load_module_relay ("bmp", &_gdk_imlib_LoadBMP, NULL, f, w, h, t);
}
static unsigned char *
loader_xpm (FILE *f, int *w, int *h, int *t)
{
return load_module_relay ("xpm", &_gdk_imlib_LoadXPM, NULL, f, w, h, t);
}
static unsigned char *
loader_gif (FILE *f, int *w, int *h, int *t)
{
return load_module_relay ("gif", &_gdk_imlib_LoadGIF, NULL, f, w, h, t);
}
static unsigned char *
loader_jpeg (FILE *f, int *w, int *h, int *t)
{
return load_module_relay ("jpeg",
&_gdk_imlib_LoadJPEG,
&_gdk_imlib_SaveJPEG, f, w, h, t);
}
static unsigned char *
loader_png (FILE *f, int *w, int *h, int *t)
{
return load_module_relay ("png",
&_gdk_imlib_LoadPNG,
&_gdk_imlib_SavePNG, f, w, h, t);
}
static unsigned char *
loader_ppm (FILE *f, int *w, int *h, int *t)
{
return load_module_relay ("ppm",
&_gdk_imlib_LoadPPM,
&_gdk_imlib_SavePPM, f, w, h, t);
}
static gint
saver_tiff (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info)
{
return save_module_relay ("tiff",
(gdk_imlib_loader_fn *) &_gdk_imlib_LoadTIFF,
&_gdk_imlib_SaveTIFF, im, file, info);
}
static gint
saver_png (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info)
{
return save_module_relay ("png",
&_gdk_imlib_LoadPNG,
&_gdk_imlib_SavePNG, im, file, info);
}
static gint
saver_jpeg (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info)
{
return save_module_relay ("jpeg",
&_gdk_imlib_LoadJPEG,
&_gdk_imlib_SaveJPEG, im, file, info);
}
static gint
saver_ps (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info)
{
return save_module_relay ("ps", NULL, &_gdk_imlib_SavePS, im, file, info);
}
static gint
saver_ppm (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info)
{
return save_module_relay ("ppm", &_gdk_imlib_LoadPPM, &_gdk_imlib_SavePPM, im, file, info);
}
static GdkImlibImage *
inline_png (unsigned char *data, int data_size)
{
get_module_loader_saver ("png",
(void **) &_gdk_imlib_LoadPNG, load_fail_fn,
(void **) &_gdk_imlib_SavePNG, save_fail_fn);
return _gdk_imlib_inlined_png_to_image (data, data_size);
}
static GdkImlibImage *
loader_alpha_png (char *file)
{
get_module_loader_saver ("png",
(void **) &_gdk_imlib_LoadPNG, load_fail_fn,
(void **) &_gdk_imlib_SavePNG, save_fail_fn);
return _gdk_imlib_load_alpha_png (file);
}
#endif
GdkImlibImage *
gdk_imlib_inlined_png_to_image(unsigned char *data, int data_size)
{
return _gdk_imlib_inlined_png_to_image (data, data_size);
}
GdkImlibImage *
gdk_imlib_load_alpha (char *file)
{
/* We only support png for now */
return _gdk_imlib_load_alpha_png (file);
}
|