hornetseye-xorg 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
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.5.0'
10
+ PKG_VERSION = '0.5.1'
11
11
  CFG = RbConfig::CONFIG
12
12
  CXX = ENV[ 'CXX' ] || 'g++'
13
13
  RB_FILES = FileList[ 'lib/**/*.rb' ]
@@ -27,7 +27,7 @@ EMAIL = %q{jan@wedesoft.de}
27
27
  HOMEPAGE = %q{http://wedesoft.github.com/hornetseye-xorg/}
28
28
 
29
29
  OBJ = CC_FILES.ext 'o'
30
- $CXXFLAGS = "-DNDEBUG #{CFG[ 'CPPFLAGS' ]} #{CFG[ 'CFLAGS' ]}"
30
+ $CXXFLAGS = "-DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONSTANT_MACROS #{CFG[ 'CPPFLAGS' ]} #{CFG[ 'CFLAGS' ]}"
31
31
  if CFG[ 'rubyhdrdir' ]
32
32
  $CXXFLAGS = "#{$CXXFLAGS} -I#{CFG[ 'rubyhdrdir' ]} " +
33
33
  "-I#{CFG[ 'rubyhdrdir' ]}/#{CFG[ 'arch' ]}"
@@ -46,7 +46,7 @@ desc 'Compile Ruby extension (default)'
46
46
  task :all => [ SO_FILE ]
47
47
 
48
48
  file SO_FILE => OBJ do |t|
49
- sh "#{CXX} -shared -o #{t.name} #{OBJ} -lGLU -lGL -lX11 -lXv -lXpm #{$LIBRUBYARG}"
49
+ sh "#{CXX} -shared -o #{t.name} #{OBJ} -lswscale -lGLU -lGL -lX11 -lXv -lXpm #{$LIBRUBYARG}"
50
50
  end
51
51
 
52
52
  task :test => [ SO_FILE ]
@@ -73,6 +73,45 @@ task :uninstall do
73
73
  end
74
74
  end
75
75
 
76
+ desc 'Create config.h'
77
+ task :config_h => 'ext/config.h'
78
+
79
+ def check_program
80
+ f_base_name = 'rakeconf'
81
+ begin
82
+ File.open( "#{f_base_name}.cc", 'w' ) { |f| yield f }
83
+ `#{CXX} -S #{$CXXFLAGS} -c -o #{f_base_name}.o #{f_base_name}.cc 2>&1 >> rake.log`
84
+ $?.exitstatus == 0
85
+ ensure
86
+ File.delete *Dir.glob( "#{f_base_name}.*" )
87
+ end
88
+ end
89
+
90
+ def check_c_header( name )
91
+ check_program do |c|
92
+ c.puts <<EOS
93
+ extern "C" {
94
+ #include <#{name}>
95
+ }
96
+ int main(void) { return 0; }
97
+ EOS
98
+ end
99
+ end
100
+
101
+ file 'ext/config.h' do |t|
102
+ s = "/* config.h. Generated from Rakefile by rake. */\n"
103
+ # need to compile with -D__STDC_CONSTANT_MACROS
104
+ if check_c_header 'libswscale/swscale.h'
105
+ s << "#define HAVE_LIBSWSCALE_INCDIR 1\n"
106
+ else
107
+ unless check_c_header 'ffmpeg/swscale.h'
108
+ raise 'Cannot find swscale.h header file'
109
+ end
110
+ s << "#undef HAVE_LIBSWSCALE_INCDIR\n"
111
+ end
112
+ File.open( t.name, 'w' ) { |f| f.puts s }
113
+ end
114
+
76
115
  Rake::TestTask.new do |t|
77
116
  t.libs << 'ext'
78
117
  t.test_files = TC_FILES
@@ -170,7 +209,7 @@ rule '.o' => '.cc' do |t|
170
209
  sh "#{CXX} #{$CXXFLAGS} -c -o #{t.name} #{t.source}"
171
210
  end
172
211
 
173
- file ".depends.mf" do |t|
212
+ file ".depends.mf" => :config_h do |t|
174
213
  sh "g++ -MM #{CC_FILES.join ' '} | " +
175
214
  "sed -e :a -e N -e 's/\\n/\\$/g' -e ta | " +
176
215
  "sed -e 's/ *\\\\\\$ */ /g' -e 's/\\$/\\n/g' | sed -e 's/^/ext\\//' > #{t.name}"
@@ -181,5 +220,5 @@ end
181
220
  import ".depends.mf"
182
221
 
183
222
  CLEAN.include 'ext/*.o'
184
- CLOBBER.include SO_FILE, 'doc', '.yardoc', '.depends.mf'
223
+ CLOBBER.include SO_FILE, 'doc', '.yardoc', '.depends.mf', 'ext/config.h'
185
224
 
data/ext/ximagepainter.cc CHANGED
@@ -32,11 +32,21 @@
32
32
  * License along with this library; if not, write to the Free
33
33
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34
34
  */
35
+ #ifdef HAVE_CONFIG_H
36
+ #include "config.h"
37
+ #endif
35
38
  #include <boost/shared_array.hpp>
36
39
  #include <errno.h>
37
40
  #ifndef NDEBUG
38
41
  #include <iostream>
39
42
  #endif
43
+ extern "C" {
44
+ #ifndef HAVE_LIBSWSCALE_INCDIR
45
+ #include <ffmpeg/swscale.h>
46
+ #else
47
+ #include <libswscale/swscale.h>
48
+ #endif
49
+ }
40
50
  #include "ximagepainter.hh"
41
51
  #include "rubytools.hh"
42
52
  #include "x11window.hh"
@@ -63,53 +73,36 @@ void XImagePainter::paint( bool ) throw (Error)
63
73
  FramePtr frame = m_imageSource->frame();
64
74
 
65
75
  if ( frame ) {
66
- // Create scaled BGRA data.
67
- int
68
- newWidth = m_window->width(),
69
- newHeight = m_window->height();
70
76
  boost::shared_array< unsigned char > array
71
- ( new unsigned char[ newWidth * newHeight * 4 ] );
72
- const char *p = frame->data();
73
- int
74
- fw = frame->width(),
75
- dx = ( frame->width() << 16 ) / newWidth,
76
- dy = ( frame->height() << 16 ) / newHeight,
77
- py = 0;
78
- unsigned char *d = array.get();
79
- for ( int y=0; y<newHeight; y++ ) {
80
- int t = fw * ( py >> 16 );
81
- const char *s = p + ( t << 1 ) + t;/* 3 * t */
82
- int
83
- ox = 0,
84
- px = 0;
85
- for ( int x=0; x<newWidth; x++ ) {
86
- px += dx;
87
- *d++ = s[2];
88
- *d++ = s[1];
89
- *d++ = s[0];
90
- *d++ = '\000';
91
- t = ( px - ox ) >> 16;
92
- ox += t << 16;
93
- s += ( t << 1 ) + t;// s += 3 * t
94
- }
95
- py += dy;
96
- };
97
-
98
- // Display the scaled BGRA data.
77
+ ( new unsigned char[ m_window->width() * m_window->height() * 4 ] );
78
+ SwsContext *swsContext =
79
+ sws_getContext( frame->width(), frame->height(), PIX_FMT_RGB24,
80
+ m_window->width(), m_window->height(), PIX_FMT_BGRA,
81
+ SWS_FAST_BILINEAR, 0, 0, 0 );
82
+ uint8_t *sourceData[4];
83
+ int sourceLineSize[4];
84
+ sourceData[0] = (uint8_t *)frame->data();
85
+ sourceLineSize[0] = 3 * frame->width();
86
+ uint8_t *destData[4];
87
+ int destLineSize[4];
88
+ destData[0] = (uint8_t *)array.get();
89
+ destLineSize[0] = 4 * m_window->width();
90
+ sws_scale( swsContext, sourceData, sourceLineSize, 0,
91
+ frame->height(), destData, destLineSize );
92
+ sws_freeContext( swsContext );
99
93
  XImage *xImage = XCreateImage( m_display->get(), m_visualInfo.visual,
100
- 24, ZPixmap, 0,
101
- (char *)array.get(),
102
- newWidth, newHeight,
103
- 32, newWidth * 4 );
94
+ 24, ZPixmap, 0, (char *)array.get(),
95
+ m_window->width(), m_window->height(),
96
+ 32, m_window->width() * 4 );
104
97
  ERRORMACRO( xImage != NULL, Error, ,
105
98
  "Failed to create X11-image" );
106
99
  xImage->byte_order = LSBFirst;
107
100
  #ifndef NDEBUG
108
- cerr << "Window size is " << newWidth << 'x'
109
- << newHeight << endl;
101
+ cerr << "Window size is " << m_window->width() << 'x'
102
+ << m_window->height() << endl;
110
103
  #endif
111
104
  XPutImage( m_display->get(), m_window->get(), m_window->gc(),
112
- xImage, 0, 0, 0, 0, newWidth, newHeight );
105
+ xImage, 0, 0, 0, 0, m_window->width(), m_window->height() );
113
106
  xImage->data = (char *)NULL;
114
107
  XDestroyImage( xImage );
115
108
  };
@@ -117,7 +110,6 @@ void XImagePainter::paint( bool ) throw (Error)
117
110
  };
118
111
  }
119
112
 
120
-
121
113
  XVisualInfo *XImagePainter::visualInfo( X11DisplayPtr display )
122
114
  throw (Error)
123
115
  {
@@ -13,6 +13,16 @@
13
13
 
14
14
  You should have received a copy of the GNU General Public License
15
15
  along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifdef HAVE_CONFIG_H
17
+ #include "config.h"
18
+ #endif
19
+ extern "C" {
20
+ #ifndef HAVE_LIBSWSCALE_INCDIR
21
+ #include <ffmpeg/swscale.h>
22
+ #else
23
+ #include <libswscale/swscale.h>
24
+ #endif
25
+ }
16
26
  #ifndef NDEBUG
17
27
  #include <iostream>
18
28
  #include <iomanip>
@@ -115,7 +125,7 @@ void XVideoImagePainter::paint( bool x11Event ) throw (Error)
115
125
  m_xvImage->data = (char *)frame->data();
116
126
 
117
127
  if ( frame->typecode() == "YV12" ) {
118
- // YV12 requires alignment for X video output.
128
+ // YV12 may require alignment for X video output.
119
129
  frame = alignYV12( frame );
120
130
  m_xvImage->data = (char *)frame->data();
121
131
  };
@@ -151,38 +161,28 @@ FramePtr XVideoImagePainter::alignYV12( FramePtr frame )
151
161
  #endif
152
162
  FramePtr dest( new Frame( "YV12",
153
163
  m_xvImage->width, m_xvImage->height ) );
154
- const char
155
- *src_y = frame->data();
156
- const signed char
157
- *src_v = (const signed char *)src_y + widtha * height,
158
- *src_u = src_v + width2a * height2;
159
- unsigned char
160
- *dest_y = (unsigned char *)dest->data();
161
- signed char
162
- *dest_v = (signed char *)dest_y + m_xvImage->offsets[1],
163
- *dest_u = (signed char *)dest_y + m_xvImage->offsets[2];
164
- for ( int y=0; y<height; y+=2 ) {
165
- for ( int x=0; x<width; x+=2 ) {
166
- dest_y[ 0] = src_y[ 0];
167
- dest_y[ 1] = src_y[ 1];
168
- dest_y[m_xvImage->pitches[0] ] = src_y[widtha ];
169
- dest_y[m_xvImage->pitches[0]+1] = src_y[widtha+1];
170
- *dest_v = *src_v;
171
- *dest_u = *src_u;
172
- src_y += 2;
173
- src_u++;
174
- src_v++;
175
- dest_y += 2;
176
- dest_u++;
177
- dest_v++;
178
- };
179
- src_y += 2 * widtha - width;
180
- src_v += width2a - width2;
181
- src_u += width2a - width2;
182
- dest_y += 2 * m_xvImage->pitches[0] - width;
183
- dest_v += m_xvImage->pitches[1] - width2;
184
- dest_u += m_xvImage->pitches[2] - width2;
185
- };
164
+ uint8_t *sourceData[4];
165
+ int sourceLineSize[4];
166
+ sourceData[0] = (uint8_t *)frame->data();
167
+ sourceData[2] = (uint8_t *)frame->data() + widtha * height;
168
+ sourceData[1] = (uint8_t *)sourceData[2] + width2a * height2;
169
+ sourceLineSize[0] = widtha;
170
+ sourceLineSize[1] = width2a;
171
+ sourceLineSize[2] = width2a;
172
+ uint8_t *destData[4];
173
+ int destLineSize[4];
174
+ destData[0] = (uint8_t *)dest->data();
175
+ destData[2] = (uint8_t *)dest->data() + m_xvImage->offsets[1];
176
+ destData[1] = (uint8_t *)dest->data() + m_xvImage->offsets[2];
177
+ destLineSize[0] = m_xvImage->pitches[0];
178
+ destLineSize[1] = m_xvImage->pitches[2];
179
+ destLineSize[2] = m_xvImage->pitches[1];
180
+ SwsContext *swsContext = sws_getContext( width, height, PIX_FMT_YUV420P,
181
+ width, height, PIX_FMT_YUV420P,
182
+ SWS_FAST_BILINEAR, 0, 0, 0 );
183
+ sws_scale( swsContext, sourceData, sourceLineSize, 0,
184
+ height, destData, destLineSize );
185
+ sws_freeContext( swsContext );
186
186
  retVal = dest;
187
187
  } else
188
188
  retVal = frame;
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 0
9
- version: 0.5.0
8
+ - 1
9
+ version: 0.5.1
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-12-20 00:00:00 +00:00
17
+ date: 2010-12-21 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency