gdk_pixbuf2 0.90.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,74 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'pathname'
4
+ require 'find'
5
+ require 'rubygems'
6
+ require 'rake/extensiontask'
7
+
8
+ @top_dir = Pathname(__FILE__).dirname.parent.expand_path
9
+ @rb_glib2_dir = @top_dir + "glib2"
10
+
11
+ task :default => :build
12
+
13
+ def version
14
+ @version ||= ENV["VERSION"] || guess_version
15
+ end
16
+
17
+ def guess_version
18
+ versions = {}
19
+ rbglib_h_path = @rb_glib2_dir + "ext" + "glib2" + "rbglib.h"
20
+ rbglib_h_path.open do |rbglib_h|
21
+ rbglib_h.each_line do |line|
22
+ if /#define\s+RBGLIB_([A-Z]+)_VERSION\s+(\d+)/ =~ line
23
+ versions[$1.downcase] = $2.to_i
24
+ end
25
+ end
26
+ end
27
+ ["major", "minor", "micro"].collect {|type| versions[type]}.compact.join(".")
28
+ end
29
+
30
+ package_name = "gdk_pixbuf2"
31
+
32
+ spec = Gem::Specification.new do |s|
33
+ s.name = package_name
34
+ s.summary = "Ruby/GdkPixbuf2 is a Ruby binding of GdkPixbuf-2.x."
35
+ s.description = "Ruby/GdkPixbuf2 is a Ruby binding of GdkPixbuf-2.x."
36
+ s.author = "The Ruby-GNOME2 Proejct Team"
37
+ s.email = "ruby-gnome2-devel-en@lists.sourceforge.net"
38
+ s.homepage = "http://ruby-gnome2.sourceforge.jp/"
39
+ s.version = version
40
+ s.platform = Gem::Platform::RUBY
41
+ s.add_dependency("cairo", ">= 1.10.0")
42
+ s.add_dependency("glib2", "= #{version}")
43
+ s.extensions = FileList["ext/#{package_name}/extconf.rb"]
44
+ s.require_paths = ["lib"]
45
+ s.files = FileList["ChangeLog", "README", "Rakefile", "extconf.rb",
46
+ "lib/**/*.rb", "{ext,sample,test}/**/*"]
47
+ end
48
+
49
+ Rake::GemPackageTask.new(spec) do |pkg|
50
+ end
51
+
52
+ Rake::ExtensionTask.new(package_name, spec) do |ext|
53
+ ext.cross_compile = true
54
+ ext.cross_compiling do |spec|
55
+ if /mingw|mswin/ =~ spec.platform.to_s
56
+ win32_dir = File.join("vendor", "local")
57
+ win32_files = []
58
+ Find.find(win32_dir) do |file|
59
+ next if /\.zip\z/ =~ file
60
+ win32_files << file
61
+ end
62
+ spec.files += win32_files
63
+ end
64
+ end
65
+ end
66
+
67
+ namespace :win32 do
68
+ desc "download Windows binaries"
69
+ task :download do
70
+ $LOAD_PATH.unshift((@rb_glib2_dir + "lib").to_s)
71
+ require 'gnome2-win32-binary-downloader'
72
+ GNOME2Win32BinaryDownloader.download(:package => "gtk+")
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ install:
2
+ $(MAKEDIRS) $(libdir)/pkgconfig
3
+ $(INSTALL_DATA) ruby-gdkpixbuf2.pc $(libdir)/pkgconfig
@@ -0,0 +1,61 @@
1
+ =begin
2
+ extconf.rb for Ruby/GdkPixbuf2 extention library
3
+ =end
4
+
5
+ require 'pathname'
6
+
7
+ base_dir = Pathname(__FILE__).dirname.parent.parent.expand_path
8
+ top_dir = base_dir.parent
9
+ top_build_dir = Pathname(".").parent.parent.parent.expand_path
10
+
11
+ mkmf_gnome2_dir = top_dir + "glib2" + 'lib'
12
+ version_suffix = ""
13
+ unless mkmf_gnome2_dir.exist?
14
+ if /(-\d+\.\d+\.\d+)\z/ =~ base_dir.basename.to_s
15
+ version_suffix = $1
16
+ mkmf_gnome2_dir = top_dir + "glib2#{version_suffix}" + 'lib'
17
+ end
18
+ end
19
+
20
+ $LOAD_PATH.unshift(mkmf_gnome2_dir.to_s)
21
+
22
+ module_name = "gdk_pixbuf2"
23
+ package_id = "gdk-pixbuf-2.0"
24
+
25
+ require 'mkmf-gnome2'
26
+
27
+ setup_win32(module_name, base_dir)
28
+
29
+ PKGConfig.have_package(package_id) or exit 1
30
+
31
+ have_func("gdk_pixbuf_set_option", "gdk-pixbuf/gdk-pixbuf.h") do |src|
32
+ "#define GDK_PIXBUF_ENABLE_BACKEND\n#{src}"
33
+ end
34
+ have_header("gdk-pixbuf/gdk-pixbuf-io.h")
35
+
36
+ if PKGConfig.have_package('gdk-2.0')
37
+ options = {}
38
+ rcairo_source_dir_names = ["rcairo"]
39
+ if /mingw|cygwin|mswin32/ =~ RUBY_PLATFORM
40
+ rcairo_source_dir_names.unshift("rcairo.win32")
41
+ end
42
+ rcairo_source_dir_names.each do |rcairo_source_dir_name|
43
+ rcairo_source_dir = top_dir.parent.expand_path + rcairo_source_dir_name
44
+ if rcairo_source_dir.exist?
45
+ options[:rcairo_source_dir] = rcairo_source_dir.to_s
46
+ break
47
+ end
48
+ end
49
+ check_cairo(options)
50
+ end
51
+
52
+ ["glib2"].each do |package|
53
+ directory = "#{package}#{version_suffix}"
54
+ build_dir = "#{directory}/tmp/#{RUBY_PLATFORM}/#{package}/#{RUBY_VERSION}"
55
+ add_depend_package(package, "#{directory}/ext/#{package}",
56
+ top_dir.to_s,
57
+ :top_build_dir => top_build_dir.to_s,
58
+ :target_build_dir => build_dir)
59
+ end
60
+ create_pkg_config_file("Ruby/GdkPixbuf2", package_id)
61
+ create_makefile(module_name)
@@ -0,0 +1,2 @@
1
+ EXPORTS
2
+ Init_gdk_pixbuf2
@@ -0,0 +1,182 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbgdk-pixbuf-format.c -
5
+
6
+ $Author: ggc $
7
+ $Date: 2007/07/13 16:07:28 $
8
+
9
+ Copyright (C) 2004 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbgdk-pixbuf.h"
13
+ #if RBGDK_PIXBUF_CHECK_VERSION(2,2,0)
14
+
15
+ #ifdef HAVE_GDK_PIXBUF_GDK_PIXBUF_IO_H
16
+ #include <gdk-pixbuf/gdk-pixbuf-io.h>
17
+ #endif
18
+
19
+ #define _SELF(r) ((GdkPixbufFormat*)RVAL2BOXED(r, GDK_TYPE_PIXBUF_FORMAT))
20
+
21
+
22
+ /**********************************/
23
+ static GdkPixbufFormat*
24
+ format_copy(const GdkPixbufFormat* val)
25
+ {
26
+ GdkPixbufFormat* new_val;
27
+ g_return_val_if_fail (val != NULL, NULL);
28
+ new_val = g_new(GdkPixbufFormat, 1);
29
+ *new_val = *val;
30
+ return new_val;
31
+ }
32
+
33
+ GType
34
+ gdk_pixbuf_format_get_type(void)
35
+ {
36
+ static GType our_type = 0;
37
+
38
+ if (our_type == 0)
39
+ our_type = g_boxed_type_register_static ("GdkPixbufFormat",
40
+ (GBoxedCopyFunc)format_copy,
41
+ (GBoxedFreeFunc)g_free);
42
+ return our_type;
43
+ }
44
+ /**********************************/
45
+
46
+ /* Move to rbgdk-pixbuf.c
47
+ gboolean gdk_pixbuf_set_option (GdkPixbuf *pixbuf,
48
+ const gchar *key,
49
+ const gchar *value);
50
+ GSList* gdk_pixbuf_get_formats (void);
51
+ */
52
+
53
+ static VALUE
54
+ get_name(self)
55
+ VALUE self;
56
+ {
57
+ return CSTR2RVAL2(gdk_pixbuf_format_get_name(_SELF(self)));
58
+ }
59
+
60
+ static VALUE
61
+ get_description(self)
62
+ VALUE self;
63
+ {
64
+ return CSTR2RVAL2(gdk_pixbuf_format_get_description(_SELF(self)));
65
+ }
66
+
67
+ static VALUE
68
+ get_mime_types(self)
69
+ VALUE self;
70
+ {
71
+ gint i = 0;
72
+ gchar** mime_types = gdk_pixbuf_format_get_mime_types(_SELF(self));
73
+ VALUE array = rb_ary_new();
74
+ while(mime_types[i]){
75
+ rb_ary_push(array, CSTR2RVAL(mime_types[i]));
76
+ i++;
77
+ }
78
+ g_strfreev(mime_types);
79
+ return array;
80
+ }
81
+
82
+ static VALUE
83
+ get_extensions(self)
84
+ VALUE self;
85
+ {
86
+ gint i = 0;
87
+ gchar** extensions = gdk_pixbuf_format_get_extensions(_SELF(self));
88
+ VALUE array = rb_ary_new();
89
+
90
+ while(extensions[i]){
91
+ rb_ary_push(array, CSTR2RVAL(extensions[i]));
92
+ i++;
93
+ }
94
+ g_strfreev(extensions);
95
+ return array;
96
+ }
97
+
98
+ static VALUE
99
+ is_writable(self)
100
+ VALUE self;
101
+ {
102
+ return CBOOL2RVAL(gdk_pixbuf_format_is_writable(_SELF(self)));
103
+ }
104
+
105
+ /* Structure */
106
+ static VALUE
107
+ get_domain(self)
108
+ VALUE self;
109
+ {
110
+ return CSTR2RVAL(_SELF(self)->domain);
111
+ }
112
+
113
+ static VALUE
114
+ get_signature(self)
115
+ VALUE self;
116
+ {
117
+ GdkPixbufModulePattern* signature = _SELF(self)->signature;
118
+
119
+ VALUE array = rb_ary_new();
120
+ int i = 0;
121
+ while(signature[i].prefix){
122
+ rb_ary_push(array, rb_ary_new3(3, CSTR2RVAL((const char*)signature[i].prefix),
123
+ CSTR2RVAL((const char*)signature[i].mask),
124
+ INT2NUM(signature[i].relevance)));
125
+ i++;
126
+ }
127
+ return array;
128
+ }
129
+ #endif
130
+
131
+ #if RBGDK_PIXBUF_CHECK_VERSION(2,6,0)
132
+ static VALUE
133
+ is_scalable(self)
134
+ VALUE self;
135
+ {
136
+ return CBOOL2RVAL(gdk_pixbuf_format_is_scalable(_SELF(self)));
137
+ }
138
+ static VALUE
139
+ is_disabled(self)
140
+ VALUE self;
141
+ {
142
+ return CBOOL2RVAL(gdk_pixbuf_format_is_disabled(_SELF(self)));
143
+ }
144
+ static VALUE
145
+ set_disabled(self, disabled)
146
+ VALUE self, disabled;
147
+ {
148
+ gdk_pixbuf_format_set_disabled(_SELF(self), RVAL2CBOOL(disabled));
149
+ return self;
150
+ }
151
+ static VALUE
152
+ get_license(self)
153
+ VALUE self;
154
+ {
155
+ return CSTR2RVAL(gdk_pixbuf_format_get_license(_SELF(self)));
156
+ }
157
+ #endif
158
+
159
+ void
160
+ Init_gdk_pixbuf_format(VALUE mGdk)
161
+ {
162
+ #if RBGDK_PIXBUF_CHECK_VERSION(2,2,0)
163
+ VALUE format = G_DEF_CLASS(GDK_TYPE_PIXBUF_FORMAT, "PixbufFormat", mGdk);
164
+
165
+ rb_define_method(format, "name", get_name, 0);
166
+ rb_define_method(format, "description", get_description, 0);
167
+ rb_define_method(format, "mime_types", get_mime_types, 0);
168
+ rb_define_method(format, "extensions", get_extensions, 0);
169
+ rb_define_method(format, "writable?", is_writable, 0);
170
+ rb_define_method(format, "domain", get_domain, 0);
171
+ rb_define_method(format, "signature", get_signature, 0);
172
+ #if RBGDK_PIXBUF_CHECK_VERSION(2,6,0)
173
+ rb_define_method(format, "scalable?", is_scalable, 0);
174
+ rb_define_method(format, "disabled?", is_disabled, 0);
175
+ rb_define_method(format, "set_disabled", set_disabled, 1);
176
+ rb_define_method(format, "license", get_license, 0);
177
+
178
+ #endif
179
+ G_DEF_SETTERS(format);
180
+ #endif
181
+ }
182
+
@@ -0,0 +1,164 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbgdk-pixbuf-loader.c -
5
+
6
+ $Author: ggc $
7
+ $Date: 2007/07/13 14:27:06 $
8
+
9
+ Copyright (C) 2004 Masao Mutoh
10
+ Copyright (C) 2003 Geoff Youngs
11
+ ************************************************/
12
+
13
+ #include "rbgdk-pixbuf.h"
14
+
15
+ #define _SELF(s) GDK_PIXBUF_LOADER(RVAL2GOBJ(s))
16
+
17
+ /****************************************************/
18
+ /* File opening */
19
+ /* Image Data in Memory */
20
+ static VALUE
21
+ initialize_loader(argc, argv, self)
22
+ int argc;
23
+ VALUE *argv;
24
+ VALUE self;
25
+ {
26
+ GdkPixbufLoader* loader;
27
+ GError* error = NULL;
28
+ VALUE arg1, is_mime_type;
29
+
30
+ rb_scan_args(argc, argv, "02", &arg1, &is_mime_type);
31
+
32
+ if (NIL_P(arg1)) {
33
+ loader = gdk_pixbuf_loader_new();
34
+ } else {
35
+ if (is_mime_type == Qtrue) {
36
+ #if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
37
+ loader = gdk_pixbuf_loader_new_with_mime_type(RVAL2CSTR(arg1), &error);
38
+ #else
39
+ rb_warning("Not supported GTK+-2.0/2.2.");
40
+ loader = gdk_pixbuf_loader_new();
41
+ #endif
42
+ } else {
43
+ /* Default behavior */
44
+ loader = gdk_pixbuf_loader_new_with_type(RVAL2CSTR(arg1), &error);
45
+ }
46
+ if(error) RAISE_GERROR(error);
47
+ }
48
+
49
+ G_INITIALIZE(self, loader);
50
+ return Qnil;
51
+ }
52
+
53
+ #if RBGDK_PIXBUF_CHECK_VERSION(2,2,0)
54
+ static VALUE
55
+ loader_get_format(self)
56
+ VALUE self;
57
+ {
58
+ GdkPixbufFormat* format = gdk_pixbuf_loader_get_format(_SELF(self));
59
+ return BOXED2RVAL(format, GDK_TYPE_PIXBUF_FORMAT);
60
+ }
61
+ #endif
62
+
63
+ static VALUE
64
+ loader_write(self, data)
65
+ VALUE self;
66
+ VALUE data;
67
+ {
68
+ GError *error = NULL;
69
+ gboolean res;
70
+
71
+ res = gdk_pixbuf_loader_write(_SELF(self), (const guchar*)RVAL2CSTR(data),
72
+ RSTRING_LEN(data), &error);
73
+ if (error)
74
+ RAISE_GERROR(error);
75
+ return CBOOL2RVAL(res);
76
+ }
77
+
78
+ static VALUE
79
+ last_write(self, data)
80
+ VALUE self;
81
+ VALUE data;
82
+ {
83
+ GError *error = NULL;
84
+ gboolean res;
85
+
86
+ res = gdk_pixbuf_loader_write(_SELF(self), (const guchar*)RVAL2CSTR(data),
87
+ RSTRING_LEN(data), &error);
88
+ if (error)
89
+ RAISE_GERROR(error);
90
+
91
+ res = gdk_pixbuf_loader_close(_SELF(self), &error);
92
+ if (error)
93
+ RAISE_GERROR(error);
94
+
95
+ return CBOOL2RVAL(res);
96
+ }
97
+
98
+ #if RBGDK_PIXBUF_CHECK_VERSION(2,2,0)
99
+ static VALUE
100
+ loader_set_size(self, width, height)
101
+ VALUE self, width, height;
102
+ {
103
+ gdk_pixbuf_loader_set_size(_SELF(self), NUM2INT(width), NUM2INT(height));
104
+ return self;
105
+ }
106
+ #endif
107
+
108
+ static VALUE
109
+ loader_close(self)
110
+ VALUE self;
111
+ {
112
+ GError *error = NULL;
113
+ gboolean res;
114
+
115
+ res = gdk_pixbuf_loader_close(_SELF(self), &error);
116
+ if(error)
117
+ RAISE_GERROR(error);
118
+
119
+ return CBOOL2RVAL(res);
120
+ }
121
+
122
+ /****************************************************/
123
+ /* Creating image */
124
+ static VALUE
125
+ get_pixbuf(self)
126
+ VALUE self;
127
+ {
128
+ return GOBJ2RVAL(gdk_pixbuf_loader_get_pixbuf(_SELF(self)));
129
+ }
130
+
131
+ /* Creating animation */
132
+ static VALUE
133
+ get_animation(self)
134
+ VALUE self;
135
+ {
136
+ return GOBJ2RVAL(gdk_pixbuf_loader_get_animation(_SELF(self)));
137
+ }
138
+
139
+
140
+ void
141
+ Init_gdk_pixbuf_loader(VALUE mGdk)
142
+ {
143
+ VALUE gdkPixbufLoader;
144
+ /* initialize it */
145
+ gdkPixbufLoader = G_DEF_CLASS(GDK_TYPE_PIXBUF_LOADER, "PixbufLoader", mGdk);
146
+
147
+ /*
148
+ * File Loading, Image Data in Memory
149
+ */
150
+ rb_define_method(gdkPixbufLoader, "initialize", initialize_loader, -1);
151
+
152
+ rb_undef_method(gdkPixbufLoader, "dup");
153
+ #if RBGDK_PIXBUF_CHECK_VERSION(2,2,0)
154
+ rb_define_method(gdkPixbufLoader, "format", loader_get_format, 0);
155
+ #endif
156
+ rb_define_method(gdkPixbufLoader, "write", loader_write, 1);
157
+ rb_define_method(gdkPixbufLoader, "last_write", last_write, 1);
158
+ #if RBGDK_PIXBUF_CHECK_VERSION(2,2,0)
159
+ rb_define_method(gdkPixbufLoader, "set_size", loader_set_size, 2);
160
+ #endif
161
+ rb_define_method(gdkPixbufLoader, "close", loader_close, 0);
162
+ rb_define_method(gdkPixbufLoader, "pixbuf", get_pixbuf, 0);
163
+ rb_define_method(gdkPixbufLoader, "animation", get_animation, 0);
164
+ }