gdk_pixbuf2 3.0.8 → 3.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/gdk_pixbuf2.rb +11 -69
- data/lib/gdk_pixbuf2/deprecated.rb +160 -0
- data/lib/gdk_pixbuf2/loader.rb +51 -0
- data/lib/gdk_pixbuf2/pixbuf-loader.rb +24 -0
- data/lib/gdk_pixbuf2/pixbuf.rb +282 -0
- data/lib/gdk_pixbuf2/version.rb +33 -0
- data/sample/anim.rb +2 -2
- data/sample/composite.rb +41 -11
- data/sample/flip.rb +2 -2
- data/sample/format.rb +2 -4
- data/sample/loader.rb +3 -3
- data/sample/rotate.rb +4 -4
- data/sample/save.rb +3 -3
- data/sample/scale.rb +14 -6
- data/sample/simpleanim.rb +10 -4
- data/sample/utils.rb +7 -4
- data/sample/xpm.rb +9 -9
- data/test/fixture/floppybuddy.gif +0 -0
- data/test/fixture/gnome-logo-icon.png +0 -0
- data/test/fixture/image.gresource +0 -0
- data/test/fixture/image.gresource.xml +6 -0
- data/test/gdk_pixbuf2-test-utils.rb +11 -0
- data/test/run-test.rb +6 -3
- data/test/test-animation.rb +30 -0
- data/test/test-loader.rb +31 -0
- data/test/test-pixbuf.rb +334 -0
- metadata +18 -25
- data/README +0 -29
- data/ext/gdk_pixbuf2/depend +0 -11
- data/ext/gdk_pixbuf2/extconf.rb +0 -68
- data/ext/gdk_pixbuf2/gdk_pixbuf2.def +0 -2
- data/ext/gdk_pixbuf2/rbgdk-pixbuf-format.c +0 -179
- data/ext/gdk_pixbuf2/rbgdk-pixbuf-loader.c +0 -164
- data/ext/gdk_pixbuf2/rbgdk-pixbuf.c +0 -737
- data/ext/gdk_pixbuf2/rbgdk-pixbuf.h +0 -41
- data/ext/gdk_pixbuf2/rbgdk-pixbuf2conversions.h +0 -42
- data/ext/gdk_pixbuf2/rbgdk-pixbuf2private.h +0 -35
- data/ext/gdk_pixbuf2/rbgdk-pixbufanimation.c +0 -93
- data/ext/gdk_pixbuf2/rbgdk-pixbufanimationiter.c +0 -71
- data/ext/gdk_pixbuf2/rbgdk-pixbufsimpleanim.c +0 -53
- data/ext/gdk_pixbuf2/rbgdk-pixdata.c +0 -213
- data/extconf.rb +0 -49
- data/sample/inline.rb +0 -37
- data/sample/pixdata.rb +0 -39
- data/test/test-version.rb +0 -47
@@ -1,737 +0,0 @@
|
|
1
|
-
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
-
/*
|
3
|
-
* Copyright (C) 2011 Ruby-GNOME2 Project Team
|
4
|
-
* Copyright (C) 2002-2004 Masao Mutoh
|
5
|
-
* Copyright (C) 2000 Yasushi Shoji
|
6
|
-
*
|
7
|
-
* This library is free software; you can redistribute it and/or
|
8
|
-
* modify it under the terms of the GNU Lesser General Public
|
9
|
-
* License as published by the Free Software Foundation; either
|
10
|
-
* version 2.1 of the License, or (at your option) any later version.
|
11
|
-
*
|
12
|
-
* This library 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 GNU
|
15
|
-
* Lesser General Public License for more details.
|
16
|
-
*
|
17
|
-
* You should have received a copy of the GNU Lesser General Public
|
18
|
-
* License along with this library; if not, write to the Free Software
|
19
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
20
|
-
* MA 02110-1301 USA
|
21
|
-
*/
|
22
|
-
|
23
|
-
#include "rbgdk-pixbuf2private.h"
|
24
|
-
#include <string.h>
|
25
|
-
|
26
|
-
#define RG_TARGET_NAMESPACE cPixbuf
|
27
|
-
#define _SELF(s) RVAL2GDKPIXBUF(s)
|
28
|
-
|
29
|
-
#define NOMEM_ERROR(error) g_set_error(error,\
|
30
|
-
GDK_PIXBUF_ERROR,\
|
31
|
-
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,\
|
32
|
-
"Insufficient memory to load image file");
|
33
|
-
|
34
|
-
static ID id_pixdata;
|
35
|
-
|
36
|
-
/****************************************************/
|
37
|
-
/* The GdkPixbuf Structure */
|
38
|
-
static int
|
39
|
-
pixels_size(GdkPixbuf *pixbuf)
|
40
|
-
{
|
41
|
-
int height, width, rowstride, n_channels, bits_per_sample;
|
42
|
-
|
43
|
-
height = gdk_pixbuf_get_height(pixbuf);
|
44
|
-
width = gdk_pixbuf_get_width(pixbuf);
|
45
|
-
rowstride = gdk_pixbuf_get_rowstride(pixbuf);
|
46
|
-
n_channels = gdk_pixbuf_get_n_channels(pixbuf);
|
47
|
-
bits_per_sample = gdk_pixbuf_get_bits_per_sample(pixbuf);
|
48
|
-
|
49
|
-
return ((height - 1) * rowstride +
|
50
|
-
width * ((n_channels * bits_per_sample + 7) / 8));
|
51
|
-
}
|
52
|
-
|
53
|
-
static VALUE
|
54
|
-
get_pixels(VALUE self)
|
55
|
-
{
|
56
|
-
GdkPixbuf *pixbuf = _SELF(self);
|
57
|
-
int size;
|
58
|
-
|
59
|
-
size = pixels_size(pixbuf);
|
60
|
-
return rb_str_new((const char *)gdk_pixbuf_get_pixels(pixbuf), size);
|
61
|
-
}
|
62
|
-
|
63
|
-
static VALUE
|
64
|
-
rg_operator_set_pixels(VALUE self, VALUE pixels)
|
65
|
-
{
|
66
|
-
GdkPixbuf *pixbuf = _SELF(self);
|
67
|
-
int size;
|
68
|
-
int arg_size;
|
69
|
-
|
70
|
-
size = pixels_size(pixbuf);
|
71
|
-
|
72
|
-
StringValue(pixels);
|
73
|
-
arg_size = RSTRING_LEN(pixels);
|
74
|
-
if (arg_size != size)
|
75
|
-
rb_raise(rb_eRangeError,
|
76
|
-
"Pixels are %i bytes, %i bytes supplied.",
|
77
|
-
size, arg_size);
|
78
|
-
|
79
|
-
/* The user currently cannot get a pointer to the actual
|
80
|
-
* pixels, the data is copied to a String. */
|
81
|
-
memcpy(gdk_pixbuf_get_pixels(pixbuf),
|
82
|
-
RSTRING_PTR(pixels), MIN(RSTRING_LEN(pixels), size));
|
83
|
-
|
84
|
-
return pixels;
|
85
|
-
}
|
86
|
-
|
87
|
-
static VALUE
|
88
|
-
rg_get_option(VALUE self, VALUE key)
|
89
|
-
{
|
90
|
-
const gchar* ret = gdk_pixbuf_get_option(_SELF(self), RVAL2CSTR(key));
|
91
|
-
return ret ? CSTR2RVAL(ret) : Qnil;
|
92
|
-
}
|
93
|
-
|
94
|
-
/****************************************************/
|
95
|
-
/* File opening */
|
96
|
-
/* Image Data in Memory */
|
97
|
-
static GdkPixbuf *
|
98
|
-
pixbuf_initialize_by_hash(VALUE self, VALUE arg, GError **error)
|
99
|
-
{
|
100
|
-
GdkPixbuf *buf = NULL;
|
101
|
-
|
102
|
-
VALUE rb_colorspace, rb_has_alpha, rb_bits_per_sample, rb_width, rb_height,
|
103
|
-
rb_data, rb_rowstride, rb_xpm, rb_inline, rb_copy_pixels,
|
104
|
-
rb_src_pixbuf, rb_src_x, rb_src_y,
|
105
|
-
rb_file, rb_scale_width, rb_scale_height, rb_preserve_aspect_ratio;
|
106
|
-
rbg_scan_options(arg,
|
107
|
-
"colorspace", &rb_colorspace,
|
108
|
-
"has_alpha", &rb_has_alpha,
|
109
|
-
"bits_per_sample", &rb_bits_per_sample,
|
110
|
-
"width", &rb_width,
|
111
|
-
"height", &rb_height,
|
112
|
-
"data", &rb_data,
|
113
|
-
"rowstride", &rb_rowstride,
|
114
|
-
"xpm", &rb_xpm,
|
115
|
-
"inline", &rb_inline,
|
116
|
-
"copy_pixels", &rb_copy_pixels,
|
117
|
-
"src_pixbuf", &rb_src_pixbuf,
|
118
|
-
"src_x", &rb_src_x,
|
119
|
-
"src_y", &rb_src_y,
|
120
|
-
"file", &rb_file,
|
121
|
-
"scale_width", &rb_scale_width,
|
122
|
-
"scale_height", &rb_scale_height,
|
123
|
-
"preserve_aspect_ratio", &rb_preserve_aspect_ratio,
|
124
|
-
NULL);
|
125
|
-
|
126
|
-
if (!NIL_P(rb_data)) {
|
127
|
-
buf = gdk_pixbuf_new_from_data((const guchar*)RVAL2CSTR(rb_data),
|
128
|
-
NIL_P(rb_colorspace) ? GDK_COLORSPACE_RGB : RVAL2GDKCOLORSPACE(rb_colorspace),
|
129
|
-
RVAL2CBOOL(rb_has_alpha),
|
130
|
-
NIL_P(rb_bits_per_sample) ? 8 : NUM2INT(rb_bits_per_sample),
|
131
|
-
NUM2INT(rb_width),
|
132
|
-
NUM2INT(rb_height),
|
133
|
-
NUM2INT(rb_rowstride),
|
134
|
-
NULL, NULL);
|
135
|
-
if (buf == NULL)
|
136
|
-
NOMEM_ERROR(error);
|
137
|
-
// Save a reference to the string because the pixbuf doesn't copy it.
|
138
|
-
G_RELATIVE(self, rb_data);
|
139
|
-
} else if (!NIL_P(rb_xpm)) {
|
140
|
-
const gchar **data = RVAL2STRV(rb_xpm);
|
141
|
-
buf = gdk_pixbuf_new_from_xpm_data(data);
|
142
|
-
g_free(data);
|
143
|
-
if (buf == NULL)
|
144
|
-
NOMEM_ERROR(error);
|
145
|
-
} else if (!NIL_P(rb_inline)) {
|
146
|
-
/* TODO: Is this really up to the caller to decide? */
|
147
|
-
long n;
|
148
|
-
guint8 *data = RVAL2GUINT8S(rb_inline, n);
|
149
|
-
buf = gdk_pixbuf_new_from_inline(n, data, RVAL2CBOOL(rb_copy_pixels), error);
|
150
|
-
/* need to manage the returned value */
|
151
|
-
rb_ivar_set(self, id_pixdata, Data_Wrap_Struct(rb_cData, NULL, g_free, data));
|
152
|
-
} else if (!NIL_P(rb_src_pixbuf)) {
|
153
|
-
buf = gdk_pixbuf_new_subpixbuf(_SELF(rb_src_pixbuf),
|
154
|
-
NUM2INT(rb_src_x),
|
155
|
-
NUM2INT(rb_src_y),
|
156
|
-
NUM2INT(rb_width),
|
157
|
-
NUM2INT(rb_height));
|
158
|
-
if (buf == NULL)
|
159
|
-
NOMEM_ERROR(error);
|
160
|
-
} else if (!NIL_P(rb_file)) {
|
161
|
-
if (!NIL_P(rb_width)) {
|
162
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
|
163
|
-
buf = gdk_pixbuf_new_from_file_at_size(RVAL2CSTR(rb_file),
|
164
|
-
NUM2INT(rb_width),
|
165
|
-
NUM2INT(rb_height),
|
166
|
-
error);
|
167
|
-
#else
|
168
|
-
rb_warning("Sizing on load not supported in GTK+ < 2.4.0");
|
169
|
-
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(rb_file), error);
|
170
|
-
#endif
|
171
|
-
} else if (!NIL_P(rb_scale_width)) {
|
172
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,6,0)
|
173
|
-
int width = NUM2INT(rb_scale_width);
|
174
|
-
int height = NUM2INT(rb_scale_height);
|
175
|
-
#if !RBGDK_PIXBUF_CHECK_VERSION(2,8,0)
|
176
|
-
if (width < 0 || height < 0)
|
177
|
-
rb_warning("For scaling on load, a negative value for width or height are not supported in GTK+ < 2.8.0");
|
178
|
-
#endif
|
179
|
-
buf = gdk_pixbuf_new_from_file_at_scale(RVAL2CSTR(rb_file),
|
180
|
-
width, height,
|
181
|
-
NIL_P(rb_preserve_aspect_ratio) ? TRUE : RVAL2CBOOL(rb_preserve_aspect_ratio),
|
182
|
-
error);
|
183
|
-
#else
|
184
|
-
rb_warning("Scaling on load not supported in GTK+ < 2.6.0");
|
185
|
-
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(rb_file), error);
|
186
|
-
#endif
|
187
|
-
} else {
|
188
|
-
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(rb_file), error);
|
189
|
-
}
|
190
|
-
} else {
|
191
|
-
buf = gdk_pixbuf_new(NIL_P(rb_colorspace) ? GDK_COLORSPACE_RGB : RVAL2GDKCOLORSPACE(rb_colorspace),
|
192
|
-
RVAL2CBOOL(rb_has_alpha),
|
193
|
-
NIL_P(rb_bits_per_sample) ? 8 : NUM2INT(rb_bits_per_sample),
|
194
|
-
NUM2INT(rb_width),
|
195
|
-
NUM2INT(rb_height));
|
196
|
-
if (buf == NULL)
|
197
|
-
NOMEM_ERROR(error);
|
198
|
-
}
|
199
|
-
|
200
|
-
return buf;
|
201
|
-
}
|
202
|
-
|
203
|
-
/* TODO: make deprecated */
|
204
|
-
static GdkPixbuf *
|
205
|
-
pixbuf_initialize(VALUE self, int argc, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7, GError **error)
|
206
|
-
{
|
207
|
-
GdkPixbuf* buf;
|
208
|
-
|
209
|
-
if (argc == 7){
|
210
|
-
buf = gdk_pixbuf_new_from_data((const guchar*)RVAL2CSTR(arg1),
|
211
|
-
RVAL2GDKCOLORSPACE(arg2),
|
212
|
-
RVAL2CBOOL(arg3), NUM2INT(arg4),
|
213
|
-
NUM2INT(arg5), NUM2INT(arg6),
|
214
|
-
NUM2INT(arg7), NULL, NULL);
|
215
|
-
if (buf == NULL) NOMEM_ERROR(error);
|
216
|
-
// Save a reference to the string because the pixbuf doesn't copy it.
|
217
|
-
G_RELATIVE(self, arg1);
|
218
|
-
} else if (argc == 5){
|
219
|
-
if (rb_obj_is_kind_of(arg1, GTYPE2CLASS(GDK_TYPE_PIXBUF))){
|
220
|
-
buf = gdk_pixbuf_new_subpixbuf(_SELF(arg1),
|
221
|
-
NUM2INT(arg2), NUM2INT(arg3),
|
222
|
-
NUM2INT(arg4), NUM2INT(arg5));
|
223
|
-
if (buf == NULL) NOMEM_ERROR(error);
|
224
|
-
} else if (rb_obj_is_kind_of(arg1, GTYPE2CLASS(GDK_TYPE_COLORSPACE))){
|
225
|
-
buf = gdk_pixbuf_new(RVAL2GDKCOLORSPACE(arg1),
|
226
|
-
RVAL2CBOOL(arg2), NUM2INT(arg3),
|
227
|
-
NUM2INT(arg4), NUM2INT(arg5));
|
228
|
-
if (buf == NULL) NOMEM_ERROR(error);
|
229
|
-
} else {
|
230
|
-
rb_raise(rb_eArgError, "Wrong type of 1st argument or wrong number of arguments");
|
231
|
-
}
|
232
|
-
} else if (argc == 4) {
|
233
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,6,0)
|
234
|
-
int width = NUM2INT(arg2);
|
235
|
-
int height = NUM2INT(arg3);
|
236
|
-
#if ! RBGDK_PIXBUF_CHECK_VERSION(2,8,0)
|
237
|
-
if (width < 0 || height < 0)
|
238
|
-
rb_warning("For scaling on load, a negative value for width or height are not supported in GTK+ < 2.8.0");
|
239
|
-
#endif
|
240
|
-
buf = gdk_pixbuf_new_from_file_at_scale(RVAL2CSTR(arg1),
|
241
|
-
width, height,
|
242
|
-
RVAL2CBOOL(arg4), error);
|
243
|
-
#else
|
244
|
-
rb_warning("Scaling on load not supported in GTK+ < 2.6.0");
|
245
|
-
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(arg1), error);
|
246
|
-
#endif
|
247
|
-
} else if (argc == 3) {
|
248
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
|
249
|
-
buf = gdk_pixbuf_new_from_file_at_size(RVAL2CSTR(arg1),
|
250
|
-
NUM2INT(arg2), NUM2INT(arg3), error);
|
251
|
-
#else
|
252
|
-
rb_warning("Sizing on load not supported in GTK+ < 2.4.0");
|
253
|
-
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(arg1), error);
|
254
|
-
#endif
|
255
|
-
} else if (argc == 2) {
|
256
|
-
/* TODO: Is this really up to the caller to decide? */
|
257
|
-
gboolean copy_pixels = RVAL2CBOOL(arg2);
|
258
|
-
long n;
|
259
|
-
guint8 *data = RVAL2GUINT8S(arg1, n);
|
260
|
-
buf = gdk_pixbuf_new_from_inline(n, data, copy_pixels, error);
|
261
|
-
/* need to manage the returned value */
|
262
|
-
rb_ivar_set(self, id_pixdata, Data_Wrap_Struct(rb_cData, NULL, g_free, data));
|
263
|
-
} else if (argc == 1){
|
264
|
-
if (TYPE(arg1) == T_STRING) {
|
265
|
-
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(arg1), error);
|
266
|
-
} else if (TYPE(arg1) == T_ARRAY) {
|
267
|
-
const gchar **data = RVAL2STRV(arg1);
|
268
|
-
buf = gdk_pixbuf_new_from_xpm_data(data);
|
269
|
-
g_free(data);
|
270
|
-
if (buf == NULL)
|
271
|
-
NOMEM_ERROR(error);
|
272
|
-
} else if (TYPE(arg1) == T_HASH) {
|
273
|
-
buf = pixbuf_initialize_by_hash(self, arg1, error);
|
274
|
-
} else {
|
275
|
-
rb_raise(rb_eArgError, "Wrong type of 1st argument or wrong number of arguments");
|
276
|
-
}
|
277
|
-
} else {
|
278
|
-
rb_raise(rb_eArgError, "Wrong number of arguments");
|
279
|
-
}
|
280
|
-
|
281
|
-
return buf;
|
282
|
-
}
|
283
|
-
|
284
|
-
static VALUE
|
285
|
-
rg_initialize(int argc, VALUE *argv, VALUE self)
|
286
|
-
{
|
287
|
-
VALUE arg1, arg2, arg3, arg4, arg5, arg6, arg7;
|
288
|
-
GdkPixbuf *buf;
|
289
|
-
GError *error = NULL;
|
290
|
-
|
291
|
-
rb_scan_args(argc, argv, "16", &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7);
|
292
|
-
buf = pixbuf_initialize(self, argc, arg1, arg2, arg3, arg4, arg5, arg6, arg7, &error);
|
293
|
-
if (buf == NULL) {
|
294
|
-
rb_gc();
|
295
|
-
g_error_free(error);
|
296
|
-
error = NULL;
|
297
|
-
buf = pixbuf_initialize(self, argc, arg1, arg2, arg3, arg4, arg5, arg6, arg7, &error);
|
298
|
-
}
|
299
|
-
if (error || !buf)
|
300
|
-
RAISE_GERROR(error);
|
301
|
-
|
302
|
-
G_INITIALIZE(self, buf);
|
303
|
-
return Qnil;
|
304
|
-
}
|
305
|
-
|
306
|
-
static VALUE
|
307
|
-
rg_dup(VALUE self)
|
308
|
-
{
|
309
|
-
VALUE ret;
|
310
|
-
GdkPixbuf* dest = gdk_pixbuf_copy(_SELF(self));
|
311
|
-
if (dest == NULL)
|
312
|
-
return Qnil;
|
313
|
-
ret = GOBJ2RVAL(dest);
|
314
|
-
g_object_unref(dest);
|
315
|
-
return ret;
|
316
|
-
}
|
317
|
-
|
318
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
|
319
|
-
static VALUE
|
320
|
-
rg_s_get_file_info(G_GNUC_UNUSED VALUE self, VALUE filename)
|
321
|
-
{
|
322
|
-
gint width, height;
|
323
|
-
|
324
|
-
GdkPixbufFormat* format = gdk_pixbuf_get_file_info(RVAL2CSTR(filename),
|
325
|
-
&width, &height);
|
326
|
-
return format ? rb_ary_new3(3, GDKPIXBUFFORMAT2RVAL(format), INT2NUM(width), INT2NUM(height)) : Qnil;
|
327
|
-
}
|
328
|
-
|
329
|
-
#endif
|
330
|
-
|
331
|
-
static VALUE
|
332
|
-
save_to(VALUE self, const gchar *filename, const gchar *type, VALUE options)
|
333
|
-
{
|
334
|
-
VALUE result = self;
|
335
|
-
GError *error = NULL;
|
336
|
-
gchar **keys = NULL;
|
337
|
-
gchar **values = NULL;
|
338
|
-
|
339
|
-
if (!NIL_P(options)) {
|
340
|
-
VALUE ary, key, value;
|
341
|
-
ID to_s;
|
342
|
-
gint len, i;
|
343
|
-
|
344
|
-
Check_Type(options, T_HASH);
|
345
|
-
to_s = rb_intern("to_s");
|
346
|
-
|
347
|
-
ary = rb_funcall(options, rb_intern("to_a"), 0);
|
348
|
-
len = RARRAY_LEN(ary);
|
349
|
-
keys = ALLOCA_N(gchar *, len + 1);
|
350
|
-
values = ALLOCA_N(gchar *, len + 1);
|
351
|
-
for (i = 0; i < len; i++) {
|
352
|
-
key = RARRAY_PTR(RARRAY_PTR(ary)[i])[0];
|
353
|
-
if (SYMBOL_P(key)) {
|
354
|
-
const char *const_key;
|
355
|
-
const_key = rb_id2name(SYM2ID(key));
|
356
|
-
keys[i] = (gchar *)const_key;
|
357
|
-
} else {
|
358
|
-
keys[i] = (gchar *)RVAL2CSTR(key);
|
359
|
-
}
|
360
|
-
value = rb_funcall(RARRAY_PTR(RARRAY_PTR(ary)[i])[1], to_s, 0);
|
361
|
-
values[i] = (gchar *)RVAL2CSTR(value);
|
362
|
-
}
|
363
|
-
keys[len] = NULL;
|
364
|
-
values[len] = NULL;
|
365
|
-
}
|
366
|
-
|
367
|
-
if (filename) {
|
368
|
-
gdk_pixbuf_savev(_SELF(self), filename, type, keys, values, &error);
|
369
|
-
}
|
370
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
|
371
|
-
else {
|
372
|
-
gchar *buffer;
|
373
|
-
gsize buffer_size;
|
374
|
-
if (gdk_pixbuf_save_to_bufferv(_SELF(self), &buffer, &buffer_size,
|
375
|
-
type, keys, values, &error))
|
376
|
-
result = rb_str_new(buffer, buffer_size);
|
377
|
-
}
|
378
|
-
#endif
|
379
|
-
|
380
|
-
if (error)
|
381
|
-
RAISE_GERROR(error);
|
382
|
-
|
383
|
-
return result;
|
384
|
-
}
|
385
|
-
|
386
|
-
/****************************************************/
|
387
|
-
/* File saving */
|
388
|
-
static VALUE
|
389
|
-
rg_save(int argc, VALUE *argv, VALUE self)
|
390
|
-
{
|
391
|
-
VALUE filename, type, options;
|
392
|
-
|
393
|
-
rb_scan_args(argc, argv, "21", &filename, &type, &options);
|
394
|
-
|
395
|
-
return save_to(self, RVAL2CSTR(filename), RVAL2CSTR(type), options);
|
396
|
-
}
|
397
|
-
|
398
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
|
399
|
-
/* XXX
|
400
|
-
gboolean gdk_pixbuf_save_to_callbackv (GdkPixbuf *pixbuf,
|
401
|
-
GdkPixbufSaveFunc save_func,
|
402
|
-
gpointer user_data,
|
403
|
-
const char *type,
|
404
|
-
char **option_keys,
|
405
|
-
char **option_values,
|
406
|
-
GError **error);
|
407
|
-
*/
|
408
|
-
|
409
|
-
static VALUE
|
410
|
-
rg_save_to_buffer(int argc, VALUE *argv, VALUE self)
|
411
|
-
{
|
412
|
-
VALUE type, options;
|
413
|
-
|
414
|
-
rb_scan_args(argc, argv, "11", &type, &options);
|
415
|
-
|
416
|
-
return save_to(self, NULL, RVAL2CSTR(type), options);
|
417
|
-
}
|
418
|
-
#endif
|
419
|
-
|
420
|
-
/****************************************************/
|
421
|
-
/* Scaling */
|
422
|
-
static VALUE
|
423
|
-
rg_scale(int argc, VALUE *argv, VALUE self)
|
424
|
-
{
|
425
|
-
GdkPixbuf* dest;
|
426
|
-
VALUE dest_width, dest_height, interp_type, ret;
|
427
|
-
GdkInterpType type = GDK_INTERP_BILINEAR;
|
428
|
-
|
429
|
-
rb_scan_args(argc, argv, "21", &dest_width, &dest_height,
|
430
|
-
&interp_type);
|
431
|
-
|
432
|
-
if (!NIL_P(interp_type))
|
433
|
-
type = RVAL2GDKINTERPTYPE(interp_type);
|
434
|
-
|
435
|
-
dest = gdk_pixbuf_scale_simple(_SELF(self),
|
436
|
-
NUM2INT(dest_width),
|
437
|
-
NUM2INT(dest_height),
|
438
|
-
type);
|
439
|
-
if (dest == NULL)
|
440
|
-
return Qnil;
|
441
|
-
|
442
|
-
ret = GOBJ2RVAL(dest);
|
443
|
-
g_object_unref(dest);
|
444
|
-
return ret;
|
445
|
-
}
|
446
|
-
|
447
|
-
static VALUE
|
448
|
-
rg_scale_bang(int argc, VALUE *argv, VALUE self)
|
449
|
-
{
|
450
|
-
GdkInterpType type = GDK_INTERP_BILINEAR;
|
451
|
-
|
452
|
-
VALUE src, src_x, src_y, src_width, src_height;
|
453
|
-
VALUE offset_x, offset_y, scale_x, scale_y, interp_type;
|
454
|
-
|
455
|
-
rb_scan_args(argc, argv, "91", &src, &src_x, &src_y,
|
456
|
-
&src_width, &src_height, &offset_x, &offset_y,
|
457
|
-
&scale_x, &scale_y, &interp_type);
|
458
|
-
|
459
|
-
if (!NIL_P(interp_type))
|
460
|
-
type = RVAL2GDKINTERPTYPE(interp_type);
|
461
|
-
|
462
|
-
gdk_pixbuf_scale(_SELF(src), _SELF(self),
|
463
|
-
NUM2INT(src_x), NUM2INT(src_y),
|
464
|
-
NUM2INT(src_width), NUM2INT(src_height),
|
465
|
-
NUM2DBL(offset_x), NUM2DBL(offset_y),
|
466
|
-
NUM2DBL(scale_x), NUM2DBL(scale_y), type);
|
467
|
-
return self;
|
468
|
-
}
|
469
|
-
|
470
|
-
static VALUE
|
471
|
-
rg_composite(VALUE self, VALUE dest_width, VALUE dest_height, VALUE interp_type, VALUE overall_alpha, VALUE check_size, VALUE color1, VALUE color2)
|
472
|
-
{
|
473
|
-
GdkPixbuf* dest;
|
474
|
-
VALUE ret;
|
475
|
-
GdkInterpType type = GDK_INTERP_BILINEAR;
|
476
|
-
|
477
|
-
if (!NIL_P(interp_type))
|
478
|
-
type = RVAL2GDKINTERPTYPE(interp_type);
|
479
|
-
|
480
|
-
dest = gdk_pixbuf_composite_color_simple(
|
481
|
-
_SELF(self), NUM2INT(dest_width), NUM2INT(dest_height),
|
482
|
-
type, NUM2INT(overall_alpha), NUM2INT(check_size),
|
483
|
-
NUM2UINT(color1), NUM2UINT(color2));
|
484
|
-
|
485
|
-
if (dest == NULL)
|
486
|
-
return Qnil;
|
487
|
-
|
488
|
-
ret = GOBJ2RVAL(dest);
|
489
|
-
g_object_unref(dest);
|
490
|
-
return ret;
|
491
|
-
}
|
492
|
-
|
493
|
-
static VALUE
|
494
|
-
rg_composite_bang(int argc, VALUE *argv, VALUE self)
|
495
|
-
{
|
496
|
-
VALUE ret;
|
497
|
-
VALUE args[16];
|
498
|
-
GdkInterpType interp_type = GDK_INTERP_BILINEAR;
|
499
|
-
|
500
|
-
rb_scan_args(argc, argv, "97",
|
501
|
-
&args[0], &args[1], &args[2], &args[3], &args[4],
|
502
|
-
&args[5], &args[6], &args[7], &args[8], &args[9],
|
503
|
-
&args[10], &args[11], &args[12], &args[13], &args[14],
|
504
|
-
&args[15]);
|
505
|
-
|
506
|
-
switch (argc) {
|
507
|
-
case 11:
|
508
|
-
if (!NIL_P(args[9]))
|
509
|
-
interp_type = RVAL2GDKINTERPTYPE(args[9]);
|
510
|
-
|
511
|
-
gdk_pixbuf_composite(_SELF(args[0]), _SELF(self),
|
512
|
-
NUM2INT(args[1]), NUM2INT(args[2]),
|
513
|
-
NUM2INT(args[3]), NUM2INT(args[4]),
|
514
|
-
NUM2DBL(args[5]), NUM2DBL(args[6]),
|
515
|
-
NUM2DBL(args[7]), NUM2DBL(args[8]),
|
516
|
-
interp_type, NUM2INT(args[10]));
|
517
|
-
ret = self;
|
518
|
-
break;
|
519
|
-
case 16:
|
520
|
-
if (!NIL_P(args[9]))
|
521
|
-
interp_type = RVAL2GDKINTERPTYPE(args[9]);
|
522
|
-
|
523
|
-
gdk_pixbuf_composite_color(_SELF(args[0]), _SELF(self),
|
524
|
-
NUM2INT(args[1]), NUM2INT(args[2]),
|
525
|
-
NUM2INT(args[3]), NUM2INT(args[4]),
|
526
|
-
NUM2DBL(args[5]), NUM2DBL(args[6]),
|
527
|
-
NUM2DBL(args[7]), NUM2DBL(args[8]),
|
528
|
-
interp_type, NUM2INT(args[10]),
|
529
|
-
NUM2INT(args[11]), NUM2INT(args[12]),
|
530
|
-
NUM2INT(args[13]), NUM2UINT(args[14]),
|
531
|
-
NUM2UINT(args[15]));
|
532
|
-
ret = self;
|
533
|
-
break;
|
534
|
-
default:
|
535
|
-
rb_raise(rb_eArgError, "Wrong number of arguments: %d", argc);
|
536
|
-
break;
|
537
|
-
}
|
538
|
-
return ret;
|
539
|
-
}
|
540
|
-
|
541
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,6,0)
|
542
|
-
static VALUE
|
543
|
-
rg_rotate(VALUE self, VALUE angle)
|
544
|
-
{
|
545
|
-
VALUE ret;
|
546
|
-
GdkPixbuf* dest = gdk_pixbuf_rotate_simple(_SELF(self), RVAL2GDKPIXBUFROTATION(angle));
|
547
|
-
if (dest == NULL)
|
548
|
-
return Qnil;
|
549
|
-
ret = GOBJ2RVAL(dest);
|
550
|
-
g_object_unref(dest);
|
551
|
-
return ret;
|
552
|
-
}
|
553
|
-
|
554
|
-
static VALUE
|
555
|
-
rg_flip(VALUE self, VALUE horizontal)
|
556
|
-
{
|
557
|
-
VALUE ret;
|
558
|
-
GdkPixbuf* dest = gdk_pixbuf_flip(_SELF(self), RVAL2CBOOL(horizontal));
|
559
|
-
if (dest == NULL)
|
560
|
-
return Qnil;
|
561
|
-
ret = GOBJ2RVAL(dest);
|
562
|
-
g_object_unref(dest);
|
563
|
-
return ret;
|
564
|
-
}
|
565
|
-
#endif
|
566
|
-
|
567
|
-
static VALUE
|
568
|
-
rg_add_alpha(VALUE self, VALUE substitute_color, VALUE r, VALUE g, VALUE b)
|
569
|
-
{
|
570
|
-
VALUE ret;
|
571
|
-
GdkPixbuf* dest = gdk_pixbuf_add_alpha(_SELF(self),
|
572
|
-
RVAL2CBOOL(substitute_color),
|
573
|
-
FIX2INT(r), FIX2INT(g), FIX2INT(b));
|
574
|
-
if (dest == NULL)
|
575
|
-
return Qnil;
|
576
|
-
ret = GOBJ2RVAL(dest);
|
577
|
-
g_object_unref(dest);
|
578
|
-
return ret;
|
579
|
-
}
|
580
|
-
|
581
|
-
static VALUE
|
582
|
-
rg_copy_area(VALUE self, VALUE src_x, VALUE src_y, VALUE width, VALUE height, VALUE dest, VALUE dest_x, VALUE dest_y)
|
583
|
-
{
|
584
|
-
gdk_pixbuf_copy_area(_SELF(self), NUM2INT(src_x), NUM2INT(src_y),
|
585
|
-
NUM2INT(width), NUM2INT(height),
|
586
|
-
_SELF(dest), NUM2INT(dest_x), NUM2INT(dest_y));
|
587
|
-
return dest;
|
588
|
-
}
|
589
|
-
|
590
|
-
static VALUE
|
591
|
-
rg_saturate_and_pixelate(VALUE self, VALUE staturation, VALUE pixelate)
|
592
|
-
{
|
593
|
-
GdkPixbuf* dest = gdk_pixbuf_copy(_SELF(self));
|
594
|
-
gdk_pixbuf_saturate_and_pixelate(_SELF(self), dest,
|
595
|
-
NUM2DBL(staturation), RVAL2CBOOL(pixelate));
|
596
|
-
return GOBJ2RVAL(dest);
|
597
|
-
}
|
598
|
-
|
599
|
-
static VALUE
|
600
|
-
rg_fill_bang(VALUE self, VALUE pixel)
|
601
|
-
{
|
602
|
-
gdk_pixbuf_fill(_SELF(self), NUM2UINT(pixel));
|
603
|
-
return self;
|
604
|
-
}
|
605
|
-
|
606
|
-
/* From Module Interface */
|
607
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,2,0)
|
608
|
-
static VALUE
|
609
|
-
rg_s_formats(G_GNUC_UNUSED VALUE self)
|
610
|
-
{
|
611
|
-
return GSLIST2ARY2(gdk_pixbuf_get_formats(), GDK_TYPE_PIXBUF_FORMAT);
|
612
|
-
}
|
613
|
-
|
614
|
-
#ifdef HAVE_GDK_PIXBUF_SET_OPTION
|
615
|
-
static VALUE
|
616
|
-
rg_set_option(VALUE self, VALUE key, VALUE value)
|
617
|
-
{
|
618
|
-
return CBOOL2RVAL(gdk_pixbuf_set_option(_SELF(self),
|
619
|
-
RVAL2CSTR(key), RVAL2CSTR(value)));
|
620
|
-
}
|
621
|
-
#else
|
622
|
-
static VALUE
|
623
|
-
rg_set_option(G_GNUC_UNUSED VALUE self, G_GNUC_UNUSED VALUE key, G_GNUC_UNUSED VALUE value)
|
624
|
-
{
|
625
|
-
rb_warning("not supported in this version of GTK+");
|
626
|
-
return Qfalse;
|
627
|
-
}
|
628
|
-
#endif
|
629
|
-
#endif
|
630
|
-
|
631
|
-
extern void Init_gdk_pixbuf2(void);
|
632
|
-
|
633
|
-
void
|
634
|
-
Init_gdk_pixbuf2(void)
|
635
|
-
{
|
636
|
-
VALUE mGdk = rb_define_module("Gdk");
|
637
|
-
VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(GDK_TYPE_PIXBUF, "Pixbuf", mGdk);
|
638
|
-
|
639
|
-
id_pixdata = rb_intern("pixdata");
|
640
|
-
|
641
|
-
/*
|
642
|
-
gdk_rgb_init();*/ /* initialize it anyway */
|
643
|
-
|
644
|
-
/*
|
645
|
-
* Initialization and Versions
|
646
|
-
*/
|
647
|
-
/* Removed. This crashes Ruby/GTK on Windows + GTK+-2.4.x.
|
648
|
-
Pointed out by Laurent.
|
649
|
-
#ifdef HAVE_GDK_PIXBUF_VERSION
|
650
|
-
rb_define_const(RG_TARGET_NAMESPACE, "VERSION", CSTR2RVAL(gdk_pixbuf_version));
|
651
|
-
#endif
|
652
|
-
*/
|
653
|
-
rb_define_const(RG_TARGET_NAMESPACE, "MAJOR", INT2FIX(GDK_PIXBUF_MAJOR));
|
654
|
-
rb_define_const(RG_TARGET_NAMESPACE, "MINOR", INT2FIX(GDK_PIXBUF_MINOR));
|
655
|
-
rb_define_const(RG_TARGET_NAMESPACE, "MICRO", INT2FIX(GDK_PIXBUF_MICRO));
|
656
|
-
|
657
|
-
/*
|
658
|
-
* The GdkPixbuf Structure
|
659
|
-
*/
|
660
|
-
G_REPLACE_GET_PROPERTY(RG_TARGET_NAMESPACE, "pixels", get_pixels, 0);
|
661
|
-
RG_DEF_METHOD_OPERATOR("pixels=", set_pixels, 1);
|
662
|
-
RG_DEF_METHOD(get_option, 1);
|
663
|
-
|
664
|
-
/* GdkPixbufError */
|
665
|
-
G_DEF_ERROR(GDK_PIXBUF_ERROR, "PixbufError", mGdk, rb_eRuntimeError, GDK_TYPE_PIXBUF_ERROR);
|
666
|
-
|
667
|
-
/* GdkColorspace */
|
668
|
-
G_DEF_CLASS(GDK_TYPE_COLORSPACE, "ColorSpace", RG_TARGET_NAMESPACE);
|
669
|
-
G_DEF_CONSTANTS(RG_TARGET_NAMESPACE, GDK_TYPE_COLORSPACE, "GDK_");
|
670
|
-
|
671
|
-
/* GdkPixbufAlphaMode */
|
672
|
-
G_DEF_CLASS(GDK_TYPE_PIXBUF_ALPHA_MODE, "AlphaMode", RG_TARGET_NAMESPACE);
|
673
|
-
G_DEF_CONSTANTS(RG_TARGET_NAMESPACE, GDK_TYPE_PIXBUF_ALPHA_MODE, "GDK_PIXBUF_");
|
674
|
-
|
675
|
-
/*
|
676
|
-
* File Loading, Image Data in Memory
|
677
|
-
*/
|
678
|
-
RG_DEF_METHOD(initialize, -1);
|
679
|
-
RG_DEF_METHOD(dup, 0);
|
680
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
|
681
|
-
RG_DEF_SMETHOD(get_file_info, 1);
|
682
|
-
#endif
|
683
|
-
|
684
|
-
/*
|
685
|
-
* File saving
|
686
|
-
*/
|
687
|
-
RG_DEF_METHOD(save, -1);
|
688
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
|
689
|
-
RG_DEF_METHOD(save_to_buffer, -1);
|
690
|
-
#endif
|
691
|
-
|
692
|
-
/*
|
693
|
-
* Scaling
|
694
|
-
*/
|
695
|
-
RG_DEF_METHOD(scale, -1);
|
696
|
-
RG_DEF_METHOD_BANG(scale, -1);
|
697
|
-
RG_DEF_METHOD(composite, 7);
|
698
|
-
RG_DEF_METHOD_BANG(composite, -1);
|
699
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,6,0)
|
700
|
-
RG_DEF_METHOD(rotate, 1);
|
701
|
-
RG_DEF_METHOD(flip, 1);
|
702
|
-
#endif
|
703
|
-
|
704
|
-
/* GdkInterpType */
|
705
|
-
G_DEF_CLASS(GDK_TYPE_INTERP_TYPE, "InterpType", RG_TARGET_NAMESPACE);
|
706
|
-
G_DEF_CONSTANTS(RG_TARGET_NAMESPACE, GDK_TYPE_INTERP_TYPE, "GDK_");
|
707
|
-
|
708
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,6,0)
|
709
|
-
/* GdkPixbufRotation */
|
710
|
-
G_DEF_CLASS(GDK_TYPE_PIXBUF_ROTATION, "GdkPixbufRotation", RG_TARGET_NAMESPACE);
|
711
|
-
G_DEF_CONSTANTS(RG_TARGET_NAMESPACE, GDK_TYPE_PIXBUF_ROTATION, "GDK_PIXBUF_");
|
712
|
-
#endif
|
713
|
-
/*
|
714
|
-
* Utilities
|
715
|
-
*/
|
716
|
-
RG_DEF_METHOD(add_alpha, 4);
|
717
|
-
RG_DEF_METHOD(copy_area, 7);
|
718
|
-
RG_DEF_METHOD(saturate_and_pixelate, 2);
|
719
|
-
RG_DEF_METHOD_BANG(fill, 1);
|
720
|
-
|
721
|
-
/*
|
722
|
-
* Module Interface
|
723
|
-
*/
|
724
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,2,0)
|
725
|
-
RG_DEF_SMETHOD(formats, 0);
|
726
|
-
RG_DEF_METHOD(set_option, 2);
|
727
|
-
#endif
|
728
|
-
|
729
|
-
Init_gdk_pixbuf_animation(mGdk);
|
730
|
-
Init_gdk_pixbuf_animation_iter(mGdk);
|
731
|
-
#if RBGDK_PIXBUF_CHECK_VERSION(2,8,0)
|
732
|
-
Init_gdk_pixbuf_simpleanim(mGdk);
|
733
|
-
#endif
|
734
|
-
Init_gdk_pixdata(mGdk);
|
735
|
-
Init_gdk_pixbuf_loader(mGdk);
|
736
|
-
Init_gdk_pixbuf_format(mGdk);
|
737
|
-
}
|