hornetseye-xorg 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +6 -6
- data/ext/frame.cc +5 -0
- data/ext/frame.hh +1 -0
- data/ext/init.cc +2 -0
- data/ext/openglimagepainter.cc +175 -0
- data/ext/openglimagepainter.hh +44 -0
- data/lib/hornetseye-xorg/opengloutput.rb +31 -0
- data/lib/hornetseye-xorg/ximageoutput.rb +1 -3
- data/lib/hornetseye_xorg_ext.rb +1 -0
- metadata +11 -8
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ require 'rake/loaders/makefile'
|
|
7
7
|
require 'rbconfig'
|
8
8
|
|
9
9
|
PKG_NAME = 'hornetseye-xorg'
|
10
|
-
PKG_VERSION = '0.
|
10
|
+
PKG_VERSION = '0.3.0'
|
11
11
|
CXX = ENV[ 'CXX' ] || 'g++'
|
12
12
|
STRIP = ENV[ 'STRIP' ] || 'strip'
|
13
13
|
RB_FILES = FileList[ 'lib/**/*.rb' ]
|
@@ -45,7 +45,7 @@ desc 'Compile Ruby extension (default)'
|
|
45
45
|
task :all => [ SO_FILE ]
|
46
46
|
|
47
47
|
file SO_FILE => OBJ do |t|
|
48
|
-
sh "#{CXX} -shared -o #{t.name} #{OBJ} -lX11 -lXv #{$LIBRUBYARG}"
|
48
|
+
sh "#{CXX} -shared -o #{t.name} #{OBJ} -lGLU -lGL -lX11 -lXv #{$LIBRUBYARG}"
|
49
49
|
# sh "#{STRIP} --strip-all #{t.name}"
|
50
50
|
end
|
51
51
|
|
@@ -115,8 +115,8 @@ begin
|
|
115
115
|
s.extra_rdoc_files = []
|
116
116
|
s.rdoc_options = %w{--no-private}
|
117
117
|
s.add_dependency %<malloc>, [ '~> 1.1' ]
|
118
|
-
s.add_dependency %<multiarray>, [ '~> 0.
|
119
|
-
s.add_dependency %<hornetseye-frame>, [ '~> 0.
|
118
|
+
s.add_dependency %<multiarray>, [ '~> 0.9' ]
|
119
|
+
s.add_dependency %<hornetseye-frame>, [ '~> 0.6' ]
|
120
120
|
s.add_development_dependency %q{rake}
|
121
121
|
end
|
122
122
|
GEM_SOURCE = "#{PKG_NAME}-#{PKG_VERSION}.gem"
|
@@ -138,8 +138,8 @@ begin
|
|
138
138
|
s.extra_rdoc_files = []
|
139
139
|
s.rdoc_options = %w{--no-private}
|
140
140
|
s.add_dependency %<malloc>, [ '~> 1.1' ]
|
141
|
-
s.add_dependency %<multiarray>, [ '~> 0.
|
142
|
-
s.add_dependency %<hornetseye-frame>, [ '~> 0.
|
141
|
+
s.add_dependency %<multiarray>, [ '~> 0.9' ]
|
142
|
+
s.add_dependency %<hornetseye-frame>, [ '~> 0.6' ]
|
143
143
|
end
|
144
144
|
GEM_BINARY = "#{PKG_NAME}-#{PKG_VERSION}-#{$BINSPEC.platform}.gem"
|
145
145
|
desc "Build the gem file #{GEM_SOURCE}"
|
data/ext/frame.cc
CHANGED
data/ext/frame.hh
CHANGED
data/ext/init.cc
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
#include "rubyinc.hh"
|
17
17
|
#include "x11output.hh"
|
18
18
|
#include "ximagepainter.hh"
|
19
|
+
#include "openglimagepainter.hh"
|
19
20
|
#include "xvideoimagepainter.hh"
|
20
21
|
#include "x11display.hh"
|
21
22
|
#include "x11window.hh"
|
@@ -39,6 +40,7 @@ extern "C" {
|
|
39
40
|
VALUE rbHornetseye = rb_define_module( "Hornetseye" );
|
40
41
|
X11Output::registerRubyClass( rbHornetseye );
|
41
42
|
XImagePainter::registerRubyClass( rbHornetseye, X11Output::cRubyClass );
|
43
|
+
OpenGLImagePainter::registerRubyClass( rbHornetseye, X11Output::cRubyClass );
|
42
44
|
XVideoImagePainter::registerRubyClass( rbHornetseye, X11Output::cRubyClass );
|
43
45
|
X11Display::registerRubyClass( rbHornetseye );
|
44
46
|
X11Window::registerRubyClass( rbHornetseye );
|
@@ -0,0 +1,175 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009 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
|
+
#define GLX_GLXEXT_PROTOTYPES
|
17
|
+
#include <GL/glu.h>
|
18
|
+
#include <GL/glx.h>
|
19
|
+
#ifndef NDEBUG
|
20
|
+
#include <iostream>
|
21
|
+
#endif
|
22
|
+
#include "openglimagepainter.hh"
|
23
|
+
#include "rubytools.hh"
|
24
|
+
#include "x11window.hh"
|
25
|
+
#include "x11output.hh"
|
26
|
+
|
27
|
+
using namespace boost;
|
28
|
+
using namespace std;
|
29
|
+
|
30
|
+
VALUE OpenGLImagePainter::cRubyClass = Qnil;
|
31
|
+
|
32
|
+
OpenGLImagePainter::~OpenGLImagePainter(void)
|
33
|
+
{
|
34
|
+
// Seems to be deallocated by X11 or GLX.
|
35
|
+
// if ( m_visualInfo != NULL )
|
36
|
+
// XFree( m_visualInfo );
|
37
|
+
}
|
38
|
+
|
39
|
+
void OpenGLImagePainter::paint( bool ) throw (Error)
|
40
|
+
{
|
41
|
+
#ifndef NDEBUG
|
42
|
+
cerr << "OpenGLImagePainter::paint()" << endl;
|
43
|
+
#endif
|
44
|
+
|
45
|
+
assert( m_window != NULL );
|
46
|
+
|
47
|
+
if ( m_imageSource != NULL ) {
|
48
|
+
|
49
|
+
#ifndef NDEBUG
|
50
|
+
cerr << "Requesting image." << endl;
|
51
|
+
#endif
|
52
|
+
FramePtr frame = m_imageSource->frame();
|
53
|
+
|
54
|
+
if ( frame ) {
|
55
|
+
// Create OpenGL rendering context for on-screen rendering.
|
56
|
+
// Direct rendering is enabled (GL_TRUE). Try GL_FALSE if there
|
57
|
+
// are problems with your graphics card and/or driver.
|
58
|
+
// It's also possible to disable direct rendering using an
|
59
|
+
// environment variable "export LIBGL_ALWAYS_INDIRECT=1".
|
60
|
+
GLXContext context =
|
61
|
+
glXCreateContext( m_window->display()->get(),
|
62
|
+
m_window->visualInfo(), 0, GL_TRUE );
|
63
|
+
// Check success.
|
64
|
+
glWrap( context != NULL, "Error creating GLX-context" );
|
65
|
+
|
66
|
+
// Attach context to the window.
|
67
|
+
glWrap( glXMakeCurrent( m_window->display()->get(),
|
68
|
+
m_window->get(), context ),
|
69
|
+
"Error switching GLX-context" );
|
70
|
+
|
71
|
+
// Initialise coordinate system.
|
72
|
+
glLoadIdentity();
|
73
|
+
glViewport( 0, 0, m_window->width(), m_window->height() );
|
74
|
+
glOrtho( 0, m_window->width(), m_window->height(), 0, -1.0, 1.0 );
|
75
|
+
|
76
|
+
// Set up parameters for image transfer.
|
77
|
+
glDisable( GL_DITHER );
|
78
|
+
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
79
|
+
glRasterPos2i( 0, 0 );
|
80
|
+
glPixelZoom( (float)m_window->width() / frame->width() ,
|
81
|
+
-(float)m_window->height() / frame->height() );
|
82
|
+
|
83
|
+
// Wait for vertical retrace
|
84
|
+
// http://www.inb.uni-luebeck.de/~boehme/xvideo_sync.html
|
85
|
+
// The code is commented out for the moment, because it does
|
86
|
+
// not compile on some platforms.
|
87
|
+
// http://rubyforge.org/tracker/index.php?func=detail&aid=11164&group_id=2714&atid=10403
|
88
|
+
|
89
|
+
// unsigned int retraceCount;
|
90
|
+
// glXGetVideoSyncSGI( &retraceCount );
|
91
|
+
// glXWaitVideoSyncSGI( 2, ( retraceCount + 1 ) % 2, &retraceCount );
|
92
|
+
|
93
|
+
#ifndef NDEBUG
|
94
|
+
cerr << "Drawing " << frame->width() << 'x' << frame->height()
|
95
|
+
<< " image." << endl;
|
96
|
+
#endif
|
97
|
+
if ( frame->rgb() ) {
|
98
|
+
glDrawPixels( frame->width(), frame->height(),
|
99
|
+
GL_RGB, GL_UNSIGNED_BYTE, frame->data() );
|
100
|
+
} else {
|
101
|
+
glDrawPixels( frame->width(), frame->height(),
|
102
|
+
GL_LUMINANCE, GL_UNSIGNED_BYTE, frame->data() );
|
103
|
+
};
|
104
|
+
glEnable(GL_DITHER);
|
105
|
+
|
106
|
+
// Finalise.
|
107
|
+
glFinish();
|
108
|
+
glXDestroyContext( m_window->display()->get(), context );
|
109
|
+
};
|
110
|
+
|
111
|
+
};
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
void OpenGLImagePainter::unregisterWindow(void)
|
116
|
+
{
|
117
|
+
XFree( m_visualInfo );
|
118
|
+
X11Painter::unregisterWindow();
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
XVisualInfo *OpenGLImagePainter::visualInfo( X11DisplayPtr display )
|
123
|
+
throw (Error)
|
124
|
+
{
|
125
|
+
assert( m_visualInfo == NULL );
|
126
|
+
int attributes[] =
|
127
|
+
{ GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
|
128
|
+
GLX_DEPTH_SIZE, 0, None };
|
129
|
+
m_visualInfo =
|
130
|
+
glXChooseVisual( display->get(), DefaultScreen( display->get() ),
|
131
|
+
attributes );
|
132
|
+
ERRORMACRO( m_visualInfo != NULL, Error, ,
|
133
|
+
"Error choosing desired X11 visual." );
|
134
|
+
m_display = display;
|
135
|
+
return m_visualInfo;
|
136
|
+
}
|
137
|
+
|
138
|
+
void OpenGLImagePainter::glWrap( bool condition, const char *message )
|
139
|
+
throw (Error)
|
140
|
+
{
|
141
|
+
if ( !condition ) {
|
142
|
+
Error e;
|
143
|
+
e << message;
|
144
|
+
bool first = true;
|
145
|
+
GLenum error;
|
146
|
+
while ( ( error = glGetError() ) != GL_NO_ERROR ) {
|
147
|
+
e << ( first ? ": " : "; " ) << gluErrorString( error );
|
148
|
+
first = false;
|
149
|
+
};
|
150
|
+
throw e;
|
151
|
+
};
|
152
|
+
}
|
153
|
+
|
154
|
+
VALUE OpenGLImagePainter::registerRubyClass( VALUE module,
|
155
|
+
VALUE cX11Output )
|
156
|
+
{
|
157
|
+
cRubyClass = rb_define_class_under( module, "OpenGLOutput", cX11Output );
|
158
|
+
rb_define_singleton_method( cRubyClass, "new",
|
159
|
+
RUBY_METHOD_FUNC( wrapNew ), 0 );
|
160
|
+
return cRubyClass;
|
161
|
+
}
|
162
|
+
|
163
|
+
VALUE OpenGLImagePainter::wrapNew( VALUE rbClass )
|
164
|
+
{
|
165
|
+
VALUE retVal = Qnil;
|
166
|
+
X11PainterPtr painter( new OpenGLImagePainter );
|
167
|
+
X11OutputPtr ptr( new X11Output( painter ) );
|
168
|
+
retVal = Data_Wrap_Struct( rbClass,
|
169
|
+
X11Output::markRubyObject,
|
170
|
+
X11Output::deleteRubyObject,
|
171
|
+
new X11OutputPtr( ptr ) );
|
172
|
+
return retVal;
|
173
|
+
}
|
174
|
+
|
175
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009 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_OPENGLIMAGEPAINTER_HH
|
17
|
+
#define HORNETSEYE_OPENGLIMAGEPAINTER_HH
|
18
|
+
|
19
|
+
#include <boost/shared_ptr.hpp>
|
20
|
+
#include "x11painter.hh"
|
21
|
+
#include "x11display.hh"
|
22
|
+
|
23
|
+
class X11Window;
|
24
|
+
|
25
|
+
class OpenGLImagePainter: public X11Painter
|
26
|
+
{
|
27
|
+
public:
|
28
|
+
OpenGLImagePainter(void): m_visualInfo(NULL) {}
|
29
|
+
virtual ~OpenGLImagePainter(void);
|
30
|
+
virtual void paint( bool x11Event ) throw (Error);
|
31
|
+
virtual XVisualInfo *visualInfo( X11DisplayPtr display ) throw (Error);
|
32
|
+
virtual void unregisterWindow(void);
|
33
|
+
static VALUE cRubyClass;
|
34
|
+
static VALUE registerRubyClass( VALUE module, VALUE cX11Output );
|
35
|
+
static VALUE wrapNew( VALUE rbClass );
|
36
|
+
protected:
|
37
|
+
void glWrap( bool condition, const char *message ) throw (Error);
|
38
|
+
XVisualInfo *m_visualInfo;
|
39
|
+
X11DisplayPtr m_display;
|
40
|
+
};
|
41
|
+
|
42
|
+
typedef boost::shared_ptr< OpenGLImagePainter > OpenGLImagePainterPtr;
|
43
|
+
|
44
|
+
#endif
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# hornetseye-xorg - Graphical output under X.Org
|
2
|
+
# Copyright (C) 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
|
+
|
17
|
+
# Namespace of Hornetseye computer vision library
|
18
|
+
module Hornetseye
|
19
|
+
|
20
|
+
class OpenGLOutput
|
21
|
+
|
22
|
+
def write( frame )
|
23
|
+
target = frame.rgb? ? UBYTERGB : UBYTE
|
24
|
+
frame = frame.to_type target unless frame.typecode == target
|
25
|
+
super frame
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
data/lib/hornetseye_xorg_ext.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jan Wedekind
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-12 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -41,8 +41,8 @@ dependencies:
|
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
segments:
|
43
43
|
- 0
|
44
|
-
-
|
45
|
-
version: "0.
|
44
|
+
- 9
|
45
|
+
version: "0.9"
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
48
|
- !ruby/object:Gem::Dependency
|
@@ -55,8 +55,8 @@ dependencies:
|
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
segments:
|
57
57
|
- 0
|
58
|
-
-
|
59
|
-
version: "0.
|
58
|
+
- 6
|
59
|
+
version: "0.6"
|
60
60
|
type: :runtime
|
61
61
|
version_requirements: *id003
|
62
62
|
- !ruby/object:Gem::Dependency
|
@@ -90,9 +90,11 @@ files:
|
|
90
90
|
- lib/hornetseye-xorg/ximageoutput.rb
|
91
91
|
- lib/hornetseye-xorg/node.rb
|
92
92
|
- lib/hornetseye-xorg/x11display.rb
|
93
|
+
- lib/hornetseye-xorg/opengloutput.rb
|
93
94
|
- lib/hornetseye_xorg_ext.rb
|
94
95
|
- ext/xvideoimagepainter.cc
|
95
96
|
- ext/x11output.cc
|
97
|
+
- ext/openglimagepainter.cc
|
96
98
|
- ext/timer.cc
|
97
99
|
- ext/x11window.cc
|
98
100
|
- ext/init.cc
|
@@ -103,6 +105,7 @@ files:
|
|
103
105
|
- ext/frame.hh
|
104
106
|
- ext/rubytools.hh
|
105
107
|
- ext/x11display.hh
|
108
|
+
- ext/openglimagepainter.hh
|
106
109
|
- ext/ximagepainter.hh
|
107
110
|
- ext/timer.hh
|
108
111
|
- ext/x11output.hh
|