hornetseye-xorg 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ Hornetseye-Xorg
2
+ ======
3
+ This Ruby extension provides graphical output under X.Org.
4
+
data/Rakefile ADDED
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env ruby
2
+ require 'date'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/loaders/makefile'
7
+ require 'rbconfig'
8
+
9
+ PKG_NAME = 'hornetseye-xorg'
10
+ PKG_VERSION = '0.2.0'
11
+ CXX = ENV[ 'CXX' ] || 'g++'
12
+ STRIP = ENV[ 'STRIP' ] || 'strip'
13
+ RB_FILES = FileList[ 'lib/**/*.rb' ]
14
+ CC_FILES = FileList[ 'ext/*.cc' ]
15
+ HH_FILES = FileList[ 'ext/*.hh' ] + FileList[ 'ext/*.tcc' ]
16
+ TC_FILES = FileList[ 'test/tc_*.rb' ]
17
+ TS_FILES = FileList[ 'test/ts_*.rb' ]
18
+ SO_FILE = "ext/#{PKG_NAME.tr '\-', '_'}.so"
19
+ PKG_FILES = [ 'Rakefile', 'README.md', 'COPYING', '.document' ] +
20
+ RB_FILES + CC_FILES + HH_FILES + TS_FILES + TC_FILES
21
+ BIN_FILES = [ 'README.md', 'COPYING', '.document', SO_FILE ] +
22
+ RB_FILES + TS_FILES + TC_FILES
23
+ SUMMARY = %q{Graphical output under X.Org}
24
+ DESCRIPTION = %q{This Ruby extension provides graphical output under X.Org.}
25
+ AUTHOR = %q{Jan Wedekind}
26
+ EMAIL = %q{jan@wedesoft.de}
27
+ HOMEPAGE = %q{http://wedesoft.github.com/hornetseye-xorg/}
28
+
29
+ OBJ = CC_FILES.ext 'o'
30
+ $CXXFLAGS = ENV[ 'CXXFLAGS' ] || ''
31
+ $CXXFLAGS = "#{$CXXFLAGS} -fPIC -DNDEBUG"
32
+ if RbConfig::CONFIG[ 'rubyhdrdir' ]
33
+ $CXXFLAGS = "#{$CXXFLAGS} -I#{RbConfig::CONFIG[ 'rubyhdrdir' ]} " +
34
+ "-I#{RbConfig::CONFIG[ 'rubyhdrdir' ]}/#{RbConfig::CONFIG[ 'arch' ]}"
35
+ else
36
+ $CXXFLAGS = "#{$CXXFLAGS} -I#{RbConfig::CONFIG[ 'archdir' ]}"
37
+ end
38
+ $LIBRUBYARG = RbConfig::CONFIG[ 'LIBRUBYARG' ]
39
+ $SITELIBDIR = RbConfig::CONFIG[ 'sitelibdir' ]
40
+ $SITEARCHDIR = RbConfig::CONFIG[ 'sitearchdir' ]
41
+
42
+ task :default => :all
43
+
44
+ desc 'Compile Ruby extension (default)'
45
+ task :all => [ SO_FILE ]
46
+
47
+ file SO_FILE => OBJ do |t|
48
+ sh "#{CXX} -shared -o #{t.name} #{OBJ} -lX11 -lXv #{$LIBRUBYARG}"
49
+ # sh "#{STRIP} --strip-all #{t.name}"
50
+ end
51
+
52
+ task :test => [ SO_FILE ]
53
+
54
+ desc 'Install Ruby extension'
55
+ task :install => :all do
56
+ verbose true do
57
+ for f in RB_FILES do
58
+ FileUtils.mkdir_p "#{$SITELIBDIR}/#{File.dirname f.gsub( /^lib\//, '' )}"
59
+ FileUtils.cp_r f, "#{$SITELIBDIR}/#{f.gsub( /^lib\//, '' )}"
60
+ end
61
+ FileUtils.mkdir_p $SITEARCHDIR
62
+ FileUtils.cp SO_FILE, "#{$SITEARCHDIR}/#{File.basename SO_FILE}"
63
+ end
64
+ end
65
+
66
+ desc 'Uninstall Ruby extension'
67
+ task :uninstall do
68
+ verbose true do
69
+ for f in RB_FILES do
70
+ FileUtils.rm_f "#{$SITELIBDIR}/#{f.gsub /^lib\//, ''}"
71
+ end
72
+ FileUtils.rm_f "#{$SITEARCHDIR}/#{File.basename SO_FILE}"
73
+ end
74
+ end
75
+
76
+ Rake::TestTask.new do |t|
77
+ t.libs << 'ext'
78
+ t.test_files = TC_FILES
79
+ end
80
+
81
+ begin
82
+ require 'yard'
83
+ YARD::Rake::YardocTask.new :yard do |y|
84
+ y.options << '--no-private'
85
+ y.files << FileList[ 'lib/**/*.rb' ]
86
+ end
87
+ rescue LoadError
88
+ STDERR.puts 'Please install \'yard\' if you want to generate documentation'
89
+ end
90
+
91
+ Rake::PackageTask.new PKG_NAME, PKG_VERSION do |p|
92
+ p.need_tar = true
93
+ p.package_files = PKG_FILES
94
+ end
95
+
96
+ begin
97
+ require 'rubygems'
98
+ require 'rubygems/builder'
99
+ $SPEC = Gem::Specification.new do |s|
100
+ s.name = PKG_NAME
101
+ s.version = PKG_VERSION
102
+ s.platform = Gem::Platform::RUBY
103
+ s.date = Date.today.to_s
104
+ s.summary = SUMMARY
105
+ s.description = DESCRIPTION
106
+ s.author = AUTHOR
107
+ s.email = EMAIL
108
+ s.homepage = HOMEPAGE
109
+ s.files = PKG_FILES
110
+ s.test_files = TC_FILES
111
+ s.require_paths = [ 'lib', 'ext' ]
112
+ s.rubyforge_project = %q{hornetseye}
113
+ s.extensions = %w{Rakefile}
114
+ s.has_rdoc = 'yard'
115
+ s.extra_rdoc_files = []
116
+ s.rdoc_options = %w{--no-private}
117
+ s.add_dependency %<malloc>, [ '~> 1.1' ]
118
+ s.add_dependency %<multiarray>, [ '~> 0.6' ]
119
+ s.add_dependency %<hornetseye-frame>, [ '~> 0.3' ]
120
+ s.add_development_dependency %q{rake}
121
+ end
122
+ GEM_SOURCE = "#{PKG_NAME}-#{PKG_VERSION}.gem"
123
+ $BINSPEC = Gem::Specification.new do |s|
124
+ s.name = PKG_NAME
125
+ s.version = PKG_VERSION
126
+ s.platform = Gem::Platform::CURRENT
127
+ s.date = Date.today.to_s
128
+ s.summary = SUMMARY
129
+ s.description = DESCRIPTION
130
+ s.author = AUTHOR
131
+ s.email = EMAIL
132
+ s.homepage = HOMEPAGE
133
+ s.files = BIN_FILES
134
+ s.test_files = TC_FILES
135
+ s.require_paths = [ 'lib', 'ext' ]
136
+ s.rubyforge_project = %q{hornetseye}
137
+ s.has_rdoc = 'yard'
138
+ s.extra_rdoc_files = []
139
+ s.rdoc_options = %w{--no-private}
140
+ s.add_dependency %<malloc>, [ '~> 1.1' ]
141
+ s.add_dependency %<multiarray>, [ '~> 0.6' ]
142
+ s.add_dependency %<hornetseye-frame>, [ '~> 0.3' ]
143
+ end
144
+ GEM_BINARY = "#{PKG_NAME}-#{PKG_VERSION}-#{$BINSPEC.platform}.gem"
145
+ desc "Build the gem file #{GEM_SOURCE}"
146
+ task :gem => [ "pkg/#{GEM_SOURCE}" ]
147
+ file "pkg/#{GEM_SOURCE}" => [ 'pkg' ] + $SPEC.files do
148
+ when_writing 'Creating GEM' do
149
+ Gem::Builder.new( $SPEC ).build
150
+ verbose true do
151
+ FileUtils.mv GEM_SOURCE, "pkg/#{GEM_SOURCE}"
152
+ end
153
+ end
154
+ end
155
+ desc "Build the gem file #{GEM_BINARY}"
156
+ task :gem_binary => [ "pkg/#{GEM_BINARY}" ]
157
+ file "pkg/#{GEM_BINARY}" => [ 'pkg' ] + $BINSPEC.files do
158
+ when_writing 'Creating binary GEM' do
159
+ Gem::Builder.new( $BINSPEC ).build
160
+ verbose true do
161
+ FileUtils.mv GEM_BINARY, "pkg/#{GEM_BINARY}"
162
+ end
163
+ end
164
+ end
165
+ rescue LoadError
166
+ STDERR.puts 'Please install \'rubygems\' if you want to create Gem packages'
167
+ end
168
+
169
+ rule '.o' => '.cc' do |t|
170
+ sh "#{CXX} #{$CXXFLAGS} -c -o #{t.name} #{t.source}"
171
+ end
172
+
173
+ file ".depends.mf" do |t|
174
+ sh "makedepend -f- -- #{$CXXFLAGS} -- #{CC_FILES.join ' '} > #{t.name}"
175
+ end
176
+ CC_FILES.each do |t|
177
+ file t.ext(".o") => t
178
+ end
179
+ import ".depends.mf"
180
+
181
+ CLEAN.include 'ext/*.o'
182
+ CLOBBER.include SO_FILE, 'doc', '.yardoc', '.depends.mf'
183
+
data/ext/error.hh ADDED
@@ -0,0 +1,50 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifndef ERROR_HH
17
+ #define ERROR_HH
18
+
19
+ #include <exception>
20
+ #include <sstream>
21
+
22
+ class Error: public std::exception
23
+ {
24
+ public:
25
+ Error(void) {}
26
+ Error( Error &e ): std::exception( e )
27
+ { m_message << e.m_message.str(); }
28
+ virtual ~Error(void) throw() {}
29
+ template< typename T >
30
+ std::ostream &operator<<( const T &t )
31
+ { m_message << t; return m_message; }
32
+ std::ostream &operator<<( std::ostream& (*__pf)(std::ostream&) )
33
+ { (*__pf)( m_message ); return m_message; }
34
+ virtual const char* what(void) const throw() {
35
+ temp = m_message.str();
36
+ return temp.c_str();
37
+ }
38
+ protected:
39
+ std::ostringstream m_message;
40
+ mutable std::string temp;
41
+ };
42
+
43
+ #define ERRORMACRO( condition, class, params, message ) \
44
+ if ( !( condition ) ) { \
45
+ class _e params; \
46
+ _e << message; \
47
+ throw _e; \
48
+ };
49
+
50
+ #endif
data/ext/frame.cc ADDED
@@ -0,0 +1,69 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #include "frame.hh"
17
+
18
+ using namespace std;
19
+
20
+ Frame::Frame( const string &typecode, int width, int height, char *data ):
21
+ m_frame( Qnil )
22
+ {
23
+ VALUE mModule = rb_define_module( "Hornetseye" );
24
+ VALUE cMalloc = rb_define_class_under( mModule, "Malloc", rb_cObject );
25
+ VALUE cFrame = rb_define_class_under( mModule, "Frame", rb_cObject );
26
+ VALUE rbSize = rb_funcall( cFrame, rb_intern( "storage_size" ), 3,
27
+ rb_const_get( mModule, rb_intern( typecode.c_str() ) ),
28
+ INT2NUM( width ), INT2NUM( height ) );
29
+ VALUE rbMemory;
30
+ if ( data != NULL ) {
31
+ rbMemory = Data_Wrap_Struct( cMalloc, 0, 0, (void *)data );
32
+ rb_ivar_set( rbMemory, rb_intern( "@size" ), rbSize );
33
+ } else
34
+ rbMemory = rb_funcall( cMalloc, rb_intern( "new" ), 1, rbSize );
35
+ m_frame = rb_funcall( cFrame, rb_intern( "import" ), 4,
36
+ rb_const_get( mModule, rb_intern( typecode.c_str() ) ),
37
+ INT2NUM( width ), INT2NUM( height ), rbMemory );
38
+ }
39
+
40
+ string Frame::typecode(void)
41
+ {
42
+ VALUE rbString = rb_funcall( rb_funcall( m_frame, rb_intern( "typecode" ), 0 ),
43
+ rb_intern( "to_s" ), 0 );
44
+ return StringValuePtr( rbString );
45
+ }
46
+
47
+ int Frame::width(void)
48
+ {
49
+ return NUM2INT( rb_funcall( m_frame, rb_intern( "width" ), 0 ) );
50
+ }
51
+
52
+ int Frame::height(void)
53
+ {
54
+ return NUM2INT( rb_funcall( m_frame, rb_intern( "height" ), 0 ) );
55
+ }
56
+
57
+ char *Frame::data(void)
58
+ {
59
+ VALUE rbMemory = rb_funcall( m_frame, rb_intern( "memory" ), 0 );
60
+ char *ptr;
61
+ Data_Get_Struct( rbMemory, char, ptr );
62
+ return ptr;
63
+ }
64
+
65
+ void Frame::markRubyMember(void)
66
+ {
67
+ rb_gc_mark( m_frame );
68
+ }
69
+
data/ext/frame.hh ADDED
@@ -0,0 +1,41 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifndef FRAME_HH
17
+ #define FRAME_HH
18
+
19
+ #include <boost/smart_ptr.hpp>
20
+ #include "rubyinc.hh"
21
+ #include <string>
22
+
23
+ class Frame
24
+ {
25
+ public:
26
+ Frame( const std::string &typecode, int width, int height, char *data = NULL );
27
+ Frame( VALUE rbFrame ): m_frame( rbFrame ) {}
28
+ virtual ~Frame(void) {}
29
+ std::string typecode(void);
30
+ int width(void);
31
+ int height(void);
32
+ char *data(void);
33
+ VALUE rubyObject(void) { return m_frame; }
34
+ void markRubyMember(void);
35
+ protected:
36
+ VALUE m_frame;
37
+ };
38
+
39
+ typedef boost::shared_ptr< Frame > FramePtr;
40
+
41
+ #endif
data/ext/init.cc ADDED
@@ -0,0 +1,48 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #include "rubyinc.hh"
17
+ #include "x11output.hh"
18
+ #include "ximagepainter.hh"
19
+ #include "xvideoimagepainter.hh"
20
+ #include "x11display.hh"
21
+ #include "x11window.hh"
22
+
23
+ #ifdef WIN32
24
+ #define DLLEXPORT __declspec(dllexport)
25
+ #define DLLLOCAL
26
+ #else
27
+ #define DLLEXPORT __attribute__ ((visibility("default")))
28
+ #define DLLLOCAL __attribute__ ((visibility("hidden")))
29
+ #endif
30
+
31
+ extern "C" DLLEXPORT void Init_hornetseye_xorg(void);
32
+
33
+ extern "C" {
34
+
35
+ void Init_hornetseye_xorg(void)
36
+ {
37
+ // XInitThreads();
38
+ rb_require( "hornetseye_frame" );
39
+ VALUE rbHornetseye = rb_define_module( "Hornetseye" );
40
+ X11Output::registerRubyClass( rbHornetseye );
41
+ XImagePainter::registerRubyClass( rbHornetseye, X11Output::cRubyClass );
42
+ XVideoImagePainter::registerRubyClass( rbHornetseye, X11Output::cRubyClass );
43
+ X11Display::registerRubyClass( rbHornetseye );
44
+ X11Window::registerRubyClass( rbHornetseye );
45
+ rb_require( "hornetseye_xorg_ext.rb" );
46
+ }
47
+
48
+ }
data/ext/rubyinc.hh ADDED
@@ -0,0 +1,54 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifndef HORNETSEYE_RUBYINC_HH
17
+ #define HORNETSEYE_RUBYINC_HH
18
+
19
+ #ifdef RSHIFT
20
+ #undef RSHIFT
21
+ #endif
22
+
23
+ #define gettimeofday rubygettimeofday
24
+ #define timezone rubygettimezone
25
+ #include <ruby.h>
26
+ // #include <version.h>
27
+ #undef timezone
28
+ #undef gettimeofday
29
+ #ifdef read
30
+ #undef read
31
+ #endif
32
+ #ifdef write
33
+ #undef write
34
+ #endif
35
+ #ifdef RGB
36
+ #undef RGB
37
+ #endif
38
+
39
+ #ifndef RUBY_VERSION_NUMBER
40
+ #define RUBY_VERSION_NUMBER ( RUBY_VERSION_MAJOR * 10000 + \
41
+ RUBY_VERSION_MINOR * 100 + \
42
+ RUBY_VERSION_TEENY )
43
+ #endif
44
+
45
+ #ifndef RUBY_METHOD_FUNC
46
+ #define RUBY_METHOD_FUNC(func) ((VALUE (*)(ANYARGS))func)
47
+ #endif
48
+
49
+ #ifndef xfree
50
+ #define xfree free
51
+ #endif
52
+
53
+ #endif
54
+