hornetseye-qt4 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ hornetseye-qt4
2
+ ======
3
+ This Ruby extension provides graphical output of images for Qt4.
4
+
data/Rakefile ADDED
@@ -0,0 +1,187 @@
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-qt4'
10
+ PKG_VERSION = '0.1.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 of images for Qt4}
24
+ DESCRIPTION = %q{This Ruby extension provides graphical output of images for Qt4.}
25
+ AUTHOR = %q{Jan Wedekind}
26
+ EMAIL = %q{jan@wedesoft.de}
27
+ HOMEPAGE = %q{http://wedesoft.github.com/hornetseye-qt4/}
28
+
29
+ OBJ = CC_FILES.ext 'o'
30
+ $CXXFLAGS = ENV[ 'CXXFLAGS' ] || ''
31
+ $CXXFLAGS = "#{$CXXFLAGS} -fPIC -DNDEBUG -DQT_SHARED -I/usr/include/qt4"
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 -lQtGui -lQtCore #{$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 %<qtruby4>, [ '~> 2.1' ]
118
+ s.add_dependency %<malloc>, [ '~> 1.1' ]
119
+ s.add_dependency %<multiarray>, [ '~> 0.9' ]
120
+ s.add_dependency %<hornetseye-frame>, [ '~> 0.6' ]
121
+ s.add_development_dependency %q{rake}
122
+ end
123
+ GEM_SOURCE = "#{PKG_NAME}-#{PKG_VERSION}.gem"
124
+ $BINSPEC = Gem::Specification.new do |s|
125
+ s.name = PKG_NAME
126
+ s.version = PKG_VERSION
127
+ s.platform = Gem::Platform::CURRENT
128
+ s.date = Date.today.to_s
129
+ s.summary = SUMMARY
130
+ s.description = DESCRIPTION
131
+ s.author = AUTHOR
132
+ s.email = EMAIL
133
+ s.homepage = HOMEPAGE
134
+ s.files = BIN_FILES
135
+ s.test_files = TC_FILES
136
+ s.require_paths = [ 'lib', 'ext' ]
137
+ s.rubyforge_project = %q{hornetseye}
138
+ s.has_rdoc = 'yard'
139
+ s.extra_rdoc_files = []
140
+ s.rdoc_options = %w{--no-private}
141
+ s.add_dependency %<qtruby4>, [ '~> 2.1' ]
142
+ s.add_dependency %<malloc>, [ '~> 1.1' ]
143
+ s.add_dependency %<multiarray>, [ '~> 0.9' ]
144
+ s.add_dependency %<hornetseye-frame>, [ '~> 0.6' ]
145
+ end
146
+ GEM_BINARY = "#{PKG_NAME}-#{PKG_VERSION}-#{$BINSPEC.platform}.gem"
147
+ desc "Build the gem file #{GEM_SOURCE}"
148
+ task :gem => [ "pkg/#{GEM_SOURCE}" ]
149
+ file "pkg/#{GEM_SOURCE}" => [ 'pkg' ] + $SPEC.files do
150
+ when_writing 'Creating GEM' do
151
+ Gem::Builder.new( $SPEC ).build
152
+ verbose true do
153
+ FileUtils.mv GEM_SOURCE, "pkg/#{GEM_SOURCE}"
154
+ end
155
+ end
156
+ end
157
+ desc "Build the gem file #{GEM_BINARY}"
158
+ task :gem_binary => [ "pkg/#{GEM_BINARY}" ]
159
+ file "pkg/#{GEM_BINARY}" => [ 'pkg' ] + $BINSPEC.files do
160
+ when_writing 'Creating binary GEM' do
161
+ Gem::Builder.new( $BINSPEC ).build
162
+ verbose true do
163
+ FileUtils.mv GEM_BINARY, "pkg/#{GEM_BINARY}"
164
+ end
165
+ end
166
+ end
167
+ rescue LoadError
168
+ STDERR.puts 'Please install \'rubygems\' if you want to create Gem packages'
169
+ end
170
+
171
+ rule '.o' => '.cc' do |t|
172
+ sh "#{CXX} #{$CXXFLAGS} -c -o #{t.name} #{t.source}"
173
+ end
174
+
175
+ file ".depends.mf" do |t|
176
+ sh "g++ -MM #{$CXXFLAGS} #{CC_FILES.join ' '} | " +
177
+ "sed -e :a -e N -e 's/\\n/\\$/g' -e ta | " +
178
+ "sed -e 's/ *\\\\\\$ */ /g' -e 's/\\$/\\n/g' | sed -e 's/^/ext\\//' > #{t.name}"
179
+ end
180
+ CC_FILES.each do |t|
181
+ file t.ext(".o") => t
182
+ end
183
+ import ".depends.mf"
184
+
185
+ CLEAN.include 'ext/*.o'
186
+ CLOBBER.include SO_FILE, 'doc', '.yardoc', '.depends.mf'
187
+
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,81 @@
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 = INT2NUM( storageSize( typecode, width, height ) );
27
+ VALUE rbMemory;
28
+ if ( data != NULL ) {
29
+ rbMemory = Data_Wrap_Struct( cMalloc, 0, 0, (void *)data );
30
+ rb_ivar_set( rbMemory, rb_intern( "@size" ), rbSize );
31
+ } else
32
+ rbMemory = rb_funcall( cMalloc, rb_intern( "new" ), 1, rbSize );
33
+ m_frame = rb_funcall( cFrame, rb_intern( "import" ), 4,
34
+ rb_const_get( mModule, rb_intern( typecode.c_str() ) ),
35
+ INT2NUM( width ), INT2NUM( height ), rbMemory );
36
+ }
37
+
38
+ string Frame::typecode(void)
39
+ {
40
+ VALUE rbString = rb_funcall( rb_funcall( m_frame, rb_intern( "typecode" ), 0 ),
41
+ rb_intern( "to_s" ), 0 );
42
+ return StringValuePtr( rbString );
43
+ }
44
+
45
+ int Frame::width(void)
46
+ {
47
+ return NUM2INT( rb_funcall( m_frame, rb_intern( "width" ), 0 ) );
48
+ }
49
+
50
+ int Frame::height(void)
51
+ {
52
+ return NUM2INT( rb_funcall( m_frame, rb_intern( "height" ), 0 ) );
53
+ }
54
+
55
+ char *Frame::data(void)
56
+ {
57
+ VALUE rbMemory = rb_funcall( m_frame, rb_intern( "memory" ), 0 );
58
+ char *ptr;
59
+ Data_Get_Struct( rbMemory, char, ptr );
60
+ return ptr;
61
+ }
62
+
63
+ bool Frame::rgb(void)
64
+ {
65
+ return rb_funcall( m_frame, rb_intern( "rgb?" ), 0 ) != Qfalse;
66
+ }
67
+
68
+ void Frame::markRubyMember(void)
69
+ {
70
+ rb_gc_mark( m_frame );
71
+ }
72
+
73
+ int Frame::storageSize( const std::string &typecode, int width, int height )
74
+ {
75
+ VALUE mModule = rb_define_module( "Hornetseye" );
76
+ VALUE cFrame = rb_define_class_under( mModule, "Frame", rb_cObject );
77
+ return NUM2INT( rb_funcall( cFrame, rb_intern( "storage_size" ), 3,
78
+ rb_const_get( mModule, rb_intern( typecode.c_str() ) ),
79
+ INT2NUM( width ), INT2NUM( height ) ) );
80
+ }
81
+
data/ext/frame.hh ADDED
@@ -0,0 +1,43 @@
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
+ bool rgb(void);
34
+ VALUE rubyObject(void) { return m_frame; }
35
+ void markRubyMember(void);
36
+ static int storageSize( const std::string &typecode, int width, int height );
37
+ protected:
38
+ VALUE m_frame;
39
+ };
40
+
41
+ typedef boost::shared_ptr< Frame > FramePtr;
42
+
43
+ #endif
data/ext/init.cc ADDED
@@ -0,0 +1,43 @@
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 "xvwidget.hh"
18
+
19
+ #ifdef WIN32
20
+ #define DLLEXPORT __declspec(dllexport)
21
+ #define DLLLOCAL
22
+ #else
23
+ #define DLLEXPORT __attribute__ ((visibility("default")))
24
+ #define DLLLOCAL __attribute__ ((visibility("hidden")))
25
+ #endif
26
+
27
+ extern "C" DLLEXPORT void Init_hornetseye_qt4(void);
28
+
29
+ extern "C" {
30
+
31
+ void Init_hornetseye_qt4(void)
32
+ {
33
+ // XInitThreads();
34
+ rb_require( "hornetseye_frame" );
35
+ rb_require( "Qt4" );
36
+ VALUE rbHornetseye = rb_define_module( "Hornetseye" );
37
+ VALUE rbQt = rb_define_module( "Qt" );
38
+ VALUE cWidget = rb_const_get( rbQt, rb_intern( "Widget" ) );
39
+ XvManager::registerRubyClass( rbHornetseye, cWidget );
40
+ rb_require( "hornetseye_qt4_ext.rb" );
41
+ }
42
+
43
+ }
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
+