camcapture 0.1.0-i686-linux → 0.2.0-i686-linux

Sign up to get free protection for your applications and to get access to all the features.
@@ -174,7 +174,11 @@ static VALUE cam_capture_create(VALUE class, VALUE device_number, VALUE width, V
174
174
  return Qnil;
175
175
  }
176
176
  vid_chan.channel = 0;
177
- vid_chan.norm = VIDEO_MODE_NTSC;
177
+ if (NUM2INT(palette) & 32) {
178
+ vid_chan.norm = VIDEO_MODE_NTSC;
179
+ } else {
180
+ vid_chan.norm = VIDEO_MODE_PAL;
181
+ }
178
182
  if (ioctl(fd, VIDIOCSCHAN, &(vid_chan)) == -1) {
179
183
  rb_raise(rb_eIOError, "CamCapture : VIDIOCSCHAN");
180
184
  return Qnil;
@@ -196,10 +200,42 @@ static VALUE cam_capture_create(VALUE class, VALUE device_number, VALUE width, V
196
200
  return (VALUE) capture;
197
201
  }
198
202
 
203
+ static VALUE cam_capture_to_bgr(VALUE self)
204
+ {
205
+ VALUE image, image2;
206
+ char *imageData;
207
+ int x, y;
208
+ char r;
209
+ int width,height;
210
+ VALUE rwidth, rheight;
211
+
212
+ rwidth=rb_iv_get(self, "@width");
213
+ width=NUM2INT(rwidth);
214
+ rheight=rb_iv_get(self, "@height");
215
+ height=NUM2INT(rheight);
216
+
217
+ image=rb_iv_get(self, "@image");
218
+ image2=StringValue(image);
219
+ if (RSTRING(image2)->len != width*height*3) {
220
+ rb_raise(rb_eRuntimeError, "image is not correct");
221
+ }
222
+ imageData=RSTRING(image2)->ptr;
223
+ for (y = 0; y < height; y++) {
224
+ for (x = 0; x < width; x++) {
225
+ r = *imageData;
226
+ *imageData = *(imageData + 2);
227
+ *(imageData + 2) = r;
228
+ imageData += 3;
229
+ }
230
+ }
231
+ return self;
232
+ }
233
+
199
234
  void Init_camcapture() {
200
235
  cCamCapture = rb_define_class("CamCapture", rb_cIO);
201
236
  rb_define_singleton_method(cCamCapture, "create", cam_capture_create, 4);
202
237
  rb_define_method(cCamCapture, "save_bmp", cam_capture_save_bmp, 1);
238
+ rb_define_method(cCamCapture, "to_bgr", cam_capture_to_bgr, 0);
203
239
 
204
240
  #define VIDEO_PALETTE_GREY 1 /* Linear greyscale */
205
241
  #define VIDEO_PALETTE_HI240 2 /* High 240 cube (BT848) */
@@ -220,8 +256,9 @@ void Init_camcapture() {
220
256
 
221
257
  rb_define_const(cCamCapture, "GREY", INT2FIX(VIDEO_PALETTE_GREY));
222
258
  rb_define_const(cCamCapture, "RGB24", INT2FIX(VIDEO_PALETTE_RGB24));
223
- rb_define_const(cCamCapture, "RGB32", INT2FIX(VIDEO_PALETTE_RGB32));
224
259
  rb_define_const(cCamCapture, "YUV422", INT2FIX(VIDEO_PALETTE_YUV422));
260
+ rb_define_const(cCamCapture, "PAL", INT2FIX(0));
261
+ rb_define_const(cCamCapture, "NTSC", INT2FIX(32));
225
262
 
226
263
  /* The following definitions are more easily carried out in Ruby */
227
264
  rb_eval_string(
@@ -235,7 +272,7 @@ void Init_camcapture() {
235
272
  "end\n"
236
273
 
237
274
  "def capture\n"
238
- "sysread(@width*@height*3,@image)\n"
275
+ "sysread(@width*@height*3, @image)\n"
239
276
  "end\n"
240
277
 
241
278
  "end\n"
data/lib/camcapture.rb CHANGED
@@ -9,7 +9,7 @@ class CamCapture
9
9
  end
10
10
 
11
11
  def capture
12
- sysread(@width*@height*3,@image)
12
+ sysread(@width*@height*3, @image)
13
13
  end
14
14
  end
15
15
 
data/test/test.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  begin
2
2
  require 'camcapture'
3
+ puts "Successfully loaded module camcapture"
3
4
  rescue LoadError
4
5
  require 'rubygems'
5
- require_gem 'camcapture'
6
+ require 'camcapture'
7
+ puts "Successfully loaded gem camcapture"
6
8
  end
7
9
 
8
- camera=CamCapture.new 0, 320, 240
10
+ camera=CamCapture.new 0, 320, 240
9
11
  puts "Image size is #{camera.width}x#{camera.height}"
10
12
  for i in 1..10 do
11
13
  image=camera.capture
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: camcapture
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2006-10-06 00:00:00 +02:00
6
+ version: 0.2.0
7
+ date: 2007-10-08 00:00:00 +02:00
8
8
  summary: Camera/Webcam capture using Video4Linux interface. Compatible with Ruby Threads.
9
9
  require_paths:
10
10
  - lib