[Gridflow-cvs] [svn] commit: r3289 - in /trunk/format: dc1394.c jpeg.c png.c videodev.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Tue Mar 25 17:07:09 EDT 2008


Author: matju
Date: Tue Mar 25 17:07:09 2008
New Revision: 3289

Log:
adapt to new source_filter and use inlet 0 for format methods

Modified:
    trunk/format/dc1394.c
    trunk/format/jpeg.c
    trunk/format/png.c
    trunk/format/videodev.c

Modified: trunk/format/dc1394.c
==============================================================================
--- trunk/format/dc1394.c (original)
+++ trunk/format/dc1394.c Tue Mar 25 17:07:09 2008
@@ -305,10 +305,9 @@
 \end ruby
 ;
 
-\class FormatDC1394 < Format
-struct FormatDC1394 : Format {
+\class FormatDC1394 : Format {
 	\decl void initialize (Symbol mode);
-	\decl void frame ();
+	\decl 0 bang ();
 };
 
 \def void initialize(Symbol mode) {
@@ -330,12 +329,12 @@
 	dc1394_destroy_handle(rh);
 }
 
-\def void frame () {
+\def 0 bang () {
 	gfpost("i'd like to get a frame from the cam, but how?");
 }
 
 \classinfo {
-	IEVAL(rself,"install '#io:dc1394',1,1;@flags=4;@comment='Video4linux 1.x'");
+	install_format("#io:dc1394",1,1,4,"");
 	//IEVAL(rself,ruby_code);
 	rb_funcall(rself,SI(instance_eval),3,rb_str_new2(ruby_code),
 		rb_str_new2(__FILE__),INT2NUM(ruby_lineno+3));

Modified: trunk/format/jpeg.c
==============================================================================
--- trunk/format/jpeg.c (original)
+++ trunk/format/jpeg.c Tue Mar 25 17:07:09 2008
@@ -33,18 +33,17 @@
 #include <jpeglib.h>
 };
 
-\class FormatJPEG < Format
-struct FormatJPEG : Format {
+\class FormatJPEG < Format {
 	P<BitPacking> bit_packing;
 	struct jpeg_compress_struct cjpeg;
 	struct jpeg_decompress_struct djpeg;
 	struct jpeg_error_mgr jerr;
 	int fd;
 	FILE *f;
-	\decl Ruby frame ();
-	\decl void quality (short quality);
 	\decl void initialize (Symbol mode, Symbol source, String filename);
-	\decl void close ();
+	\decl 0 bang ();
+	\decl 0 quality (short quality);
+	\decl 0 close ();
 	\grin 0 int
 };
 
@@ -70,7 +69,7 @@
 	uint8 *rows[1] = { row };
 	while (n) {
 		bit_packing->pack(in->dim->get(1),data,row);
-		jpeg_write_scanlines(&cjpeg,rows,1);		
+		jpeg_write_scanlines(&cjpeg,rows,1);
 		n-=rowsize; data+=rowsize;
 	}
 } GRID_FINISH {
@@ -87,10 +86,10 @@
 	return cur==end;
 }
 
-\def Ruby frame () {
+\def 0 bang () {
 	off_t off = NUM2LONG(rb_funcall(rb_ivar_get(rself,SI(@stream)),SI(tell),0));
 	fseek(f,off,SEEK_SET);
-	if (gfeof(f)) return Qfalse;
+	if (gfeof(f)) {outlet_bang(bself->out[1]); return;}
 	djpeg.err = jpeg_std_error(&jerr);
 	jpeg_create_decompress(&djpeg);
 	jpeg_stdio_src(&djpeg,f);
@@ -107,17 +106,16 @@
 	}
 	jpeg_finish_decompress(&djpeg);
 	jpeg_destroy_decompress(&djpeg);
-	return Qnil;
 }
 
-\def void quality (short quality) {
+\def 0 quality (short quality) {
 	quality = min(max((int)quality,0),100);
 	// should the last arg ("baseline") be set to true ?
 	// and what is it for? is it for accuracy of the DC component?
 	jpeg_set_quality(&cjpeg,quality,false);
 }
 
-\def void close () {
+\def 0 close () {
 	if (f) {fclose(f); f=0;}
 	//if (f) {rb_funcall(stream,SI(close),0); f=0; fd=-1;}
 }
@@ -133,11 +131,7 @@
 	bit_packing = new BitPacking(is_le(),3,3,mask);
 }
 
-\classinfo {
-	IEVAL(rself,
-	"install '#io:jpeg',1,1;@mode=6;"
-	"include GridFlow::EventIO; suffixes_are'jpeg','jpg'");
-}
+\classinfo {install_format("#io:jpeg",1,1,6,"jpeg jpg");}
 \end class FormatJPEG
 void startup_jpeg () {
 	\startall

Modified: trunk/format/png.c
==============================================================================
--- trunk/format/png.c (original)
+++ trunk/format/png.c Tue Mar 25 17:07:09 2008
@@ -29,17 +29,16 @@
 #include <libpng12/png.h>
 };
 
-\class FormatPNG < Format
-struct FormatPNG : Format {
+\class FormatPNG : Format {
 	P<BitPacking> bit_packing;
 	png_structp png;
 	png_infop info;
 	int fd;
 	FILE *f;
 	FormatPNG () : bit_packing(0), png(0), f(0) {}
-	\decl Ruby frame ();
 	\decl void initialize (Symbol mode, Symbol source, String filename);
-	\decl void close ();
+	\decl 0 bang ();
+	\decl 0 close ();
 	\grin 0 int
 };
 
@@ -61,9 +60,9 @@
 } GRID_FINISH {
 } GRID_END
 
-\def Ruby frame () {
+\def 0 bang () {
 	uint8 sig[8];
-	if (!fread(sig, 1, 8, f)) return Qfalse;
+	if (!fread(sig, 1, 8, f)) {outlet_bang(bself->out[1]); return;}
 	if (!png_check_sig(sig, 8)) RAISE("bad signature");
 	png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 	if (!png) RAISE("!png");
@@ -108,10 +107,9 @@
 	out.send(rowbytes*height,image_data);
 	delete[] image_data;
 	png_destroy_read_struct(&png, &info, NULL);
-	return Qnil;
 }
 
-\def void close () {if (f) {fclose(f); f=0;}}
+\def 0 close () {if (f) {fclose(f); f=0;}}
 
 \def void initialize (Symbol mode, Symbol source, String filename) {
 	rb_call_super(argc,argv);
@@ -124,10 +122,7 @@
 	bit_packing = new BitPacking(is_le(),3,3,mask);
 }
 
-\classinfo {
-	IEVAL(rself,
-	"install '#io:png',1,1;@mode=4;include GridFlow::EventIO; suffixes_are'png'");
-}
+\classinfo { install_format("#io:png",1,1,4,"png"); }
 \end class FormatPNG
 void startup_png () {
 	\startall

Modified: trunk/format/videodev.c
==============================================================================
--- trunk/format/videodev.c (original)
+++ trunk/format/videodev.c Tue Mar 25 17:07:09 2008
@@ -141,7 +141,6 @@
 	if (!*foo) strcat(foo,"0");
 	return strdup(foo);
 }
-
 static char *choice_to_s(int value, int n, const char **table) {
 	if (value < 0 || value >= n) {
 		char foo[64];
@@ -151,7 +150,6 @@
 		return strdup(table[value]);
 	}
 }
-
 static void gfpost(VideoChannel *self) {
 	char buf[256] = "[VideoChannel] ";
 	WH(channel,"%d");
@@ -162,7 +160,6 @@
 	WH(norm,"%d");
 	post("%s",buf);
 }
-
 static void gfpost(VideoTuner *self) {
 	char buf[256] = "[VideoTuner] ";
 	WH(tuner,"%d");
@@ -174,7 +171,6 @@
 	WH(signal,"%d");
 	post("%s",buf);
 }
-
 static void gfpost(VideoCapability *self) {
 	char buf[256] = "[VideoCapability] ";
 	WH(name,"\"%.32s\"");
@@ -185,7 +181,6 @@
 	WHYX(minsize,minheight,minwidth);
 	post("%s",buf);
 }
-
 static void gfpost(VideoWindow *self) {
 	char buf[256] = "[VideoWindow] ";
 	WHYX(pos,y,x);
@@ -195,7 +190,6 @@
 	WH(clipcount,"%d");
 	post("%s",buf);
 }
-
 static void gfpost(VideoPicture *self) {
 	char buf[256] = "[VideoPicture] ";
 	WH(brightness,"%d");
@@ -206,7 +200,6 @@
 	WHCHOICE(palette,video_palette_choice);
 	post("%s",buf);
 }
-
 static void gfpost(VideoMbuf *self) {
 	char buf[256] = "[VideoMBuf] ";
 	WH(size,"%d");
@@ -219,7 +212,6 @@
 	}
 	post("%s",buf);
 }
-
 static void gfpost(VideoMmap *self) {
 	char buf[256] = "[VideoMMap] ";
 	WH(frame,"%u");
@@ -230,8 +222,7 @@
 
 /* **************************************************************** */
 
-\class FormatVideoDev < Format
-struct FormatVideoDev : Format {
+\class FormatVideoDev : Format {
 	VideoCapability vcaps;
 	VideoPicture vp;
 	VideoMbuf vmbuf;
@@ -249,21 +240,21 @@
 	FormatVideoDev () : queuesize(0), queuemax(2), next_frame(0), use_mmap(true), use_pwc(false), bit_packing(0), dim(0) {}
 	void frame_finished (uint8 * buf);
 
+	void alloc_image ();
+	void dealloc_image ();
+	void frame_ask ();
 	\decl void initialize (Symbol mode, String filename, Symbol option=Qnil);
 	\decl void initialize2 ();
-	\decl void close ();
-	\decl void alloc_image ();
-	\decl void dealloc_image ();
-	\decl void frame ();
-	\decl void frame_ask ();
+	\decl 0 close ();
+	\decl 0 bang ();
 	\grin 0 int
 
-	\decl void _0_size (int sy, int sx);
-	\decl void _0_norm (int value);
-	\decl void _0_tuner (int value);
-	\decl void _0_channel (int value);
-	\decl void _0_transfer (Symbol sym, int queuemax=2);
-	\decl void _0_colorspace (Symbol c);
+	\decl 0 size (int sy, int sx);
+	\decl 0 norm (int value);
+	\decl 0 tuner (int value);
+	\decl 0 channel (int value);
+	\decl 0 transfer (Symbol sym, int queuemax=2);
+	\decl 0 colorspace (Symbol c);
 	\attr long   frequency();
 	\attr uint16 brightness();
 	\attr uint16 hue();
@@ -295,7 +286,7 @@
 
 #define GETFD NUM2INT(rb_funcall(rb_ivar_get(rself,SI(@stream)),SI(fileno),0))
 
-\def void _0_size (int sy, int sx) {
+\def 0 size (int sy, int sx) {
 	VideoWindow grab_win;
 	// !@#$ bug here: won't flush the frame queue
 	dim = new Dim(sy,sx,3);
@@ -313,7 +304,7 @@
 	if (debug) gfpost(&grab_win);
 }
 
-\def void dealloc_image () {
+void FormatVideoDev::dealloc_image () {
 	if (!image) return;
 	if (use_mmap) {
 		munmap(image, vmbuf.size);
@@ -323,7 +314,7 @@
 	}
 }
 
-\def void alloc_image () {
+void FormatVideoDev::alloc_image () {
 	if (use_mmap) {
 		WIOCTL2(fd, VIDIOCGMBUF, &vmbuf);
 		//gfpost(&vmbuf);
@@ -335,7 +326,7 @@
 	}
 }
 
-\def void frame_ask () {
+void FormatVideoDev::frame_ask () {
 	if (queuesize>=queuemax) RAISE("queue is full (queuemax=%d)",queuemax);
 	if (queuesize>=vmbuf.frames) RAISE("queue is full (vmbuf.frames=%d)",vmbuf.frames);
 	vmmap.frame = queue[queuesize++] = next_frame;
@@ -474,7 +465,7 @@
 	return n;
 }
 
-\def void frame () {
+\def 0 bang () {
 	if (!image) rb_funcall(rself,SI(alloc_image),0);
 	if (!use_mmap) {
 		/* picture is read at once by frame() to facilitate debugging. */
@@ -485,7 +476,7 @@
 		if (n < tot) RAISE("unexpectedly short picture: %d of %d",n,tot);
 		return;
 	}
-	while(queuesize<queuemax) rb_funcall(rself,SI(frame_ask),0);
+	while(queuesize<queuemax) frame_ask();
 	vmmap.frame = queue[0];
 	//uint64 t0 = gf_timeofday();
 	WIOCTL2(fd, VIDIOCSYNC, &vmmap);
@@ -494,7 +485,7 @@
 	frame_finished(image+vmbuf.offsets[queue[0]]);
 	queuesize--;
 	for (int i=0; i<queuesize; i++) queue[i]=queue[i+1];
-	rb_funcall(rself,SI(frame_ask),0);
+	frame_ask();
 }
 
 GRID_INLET(FormatVideoDev,0) {
@@ -503,7 +494,7 @@
 } GRID_FINISH {
 } GRID_END
 
-\def void _0_norm (int value) {
+\def 0 norm (int value) {
 	VideoTuner vtuner;
 	vtuner.tuner = current_tuner;
 	if (value<0 || value>3) RAISE("norm must be in range 0..3");
@@ -516,7 +507,7 @@
 	}
 }
 
-\def void _0_tuner (int value) {
+\def 0 tuner (int value) {
 	VideoTuner vtuner;
 	vtuner.tuner = current_tuner = value;
 	if (0> IOCTL(fd, VIDIOCGTUNER, &vtuner)) RAISE("no tuner #%d", value);
@@ -527,7 +518,7 @@
 
 #define warn(fmt,stuff...) post("warning: " fmt,stuff)
 
-\def void _0_channel (int value) {
+\def 0 channel (int value) {
 	VideoChannel vchan;
 	vchan.channel = value;
 	current_channel = value;
@@ -537,7 +528,7 @@
 	if (vcaps.type & VID_TYPE_TUNER) rb_funcall(rself,SI(_0_tuner),1,INT2NUM(0));
 }
 
-\def void _0_transfer (Symbol sym, int queuemax=2) {
+\def 0 transfer (Symbol sym, int queuemax=2) {
 	if (sym == SYM(read)) {
 		rb_funcall(rself,SI(dealloc_image),0);
 		use_mmap = false;
@@ -563,31 +554,31 @@
 	/*gfpost("getting %s=%d",#_name_,vp._name_);*/ \
 	return vp._name_;}
 
-\def uint16    brightness ()                 {PICTURE_ATTRGET(brightness)}
-\def void   _0_brightness (uint16 brightness){PICTURE_ATTR(   brightness)}
-\def uint16    hue        ()                 {PICTURE_ATTRGET(hue)}
-\def void   _0_hue        (uint16 hue)       {PICTURE_ATTR(   hue)}
-\def uint16    colour     ()                 {PICTURE_ATTRGET(colour)}
-\def void   _0_colour     (uint16 colour)    {PICTURE_ATTR(   colour)}
-\def uint16    contrast   ()                 {PICTURE_ATTRGET(contrast)}
-\def void   _0_contrast   (uint16 contrast)  {PICTURE_ATTR(   contrast)}
-\def uint16    whiteness  ()                 {PICTURE_ATTRGET(whiteness)}
-\def void   _0_whiteness  (uint16 whiteness) {PICTURE_ATTR(   whiteness)}
+\def uint16 brightness ()                 {PICTURE_ATTRGET(brightness)}
+\def 0      brightness (uint16 brightness){PICTURE_ATTR(   brightness)}
+\def uint16 hue        ()                 {PICTURE_ATTRGET(hue)}
+\def 0      hue        (uint16 hue)       {PICTURE_ATTR(   hue)}
+\def uint16 colour     ()                 {PICTURE_ATTRGET(colour)}
+\def 0      colour     (uint16 colour)    {PICTURE_ATTR(   colour)}
+\def uint16 contrast   ()                 {PICTURE_ATTRGET(contrast)}
+\def 0      contrast   (uint16 contrast)  {PICTURE_ATTR(   contrast)}
+\def uint16 whiteness  ()                 {PICTURE_ATTRGET(whiteness)}
+\def 0      whiteness  (uint16 whiteness) {PICTURE_ATTR(   whiteness)}
 \def long frequency  () {
 	long value;
 	WIOCTL(fd, VIDIOCGFREQ, &value);
 	return value;
 }
-\def void _0_frequency (long frequency) {
+\def 0 frequency (long frequency) {
 	WIOCTL(fd, VIDIOCSFREQ, &frequency);
 }
 
-\def void close () {
+\def 0 close () {
 	if (image) rb_funcall(rself,SI(dealloc_image),0);
 	rb_call_super(argc,argv);
 }
 
-\def void _0_colorspace (Symbol c) { /* y yuv rgb */
+\def 0 colorspace (Symbol c) { /* y yuv rgb */
 	if      (c==SYM(y)) {}
 	else if (c==SYM(yuv)) {}
 	else if (c==SYM(rgb)) {}
@@ -620,8 +611,8 @@
 	dim = new Dim(dim->v[0],dim->v[1],c==SYM(y)?1:3);
 }
 
-\def bool    pwc ()         {return use_pwc;}
-\def void _0_pwc (bool pwc) {use_pwc=pwc;}
+\def bool pwc ()         {return use_pwc;}
+\def 0    pwc (bool pwc) {use_pwc=pwc;}
 
 void set_pan_and_tilt(int fd, char what, int pan, int tilt) { /*unused*/
 	// if (!use_pwc) return;
@@ -640,7 +631,7 @@
 	return (vwin.flags & PWC_FPS_MASK) >> PWC_FPS_SHIFT;
 }
 
-\def void _0_framerate(uint16 framerate) {
+\def 0 framerate(uint16 framerate) {
 	if (!use_pwc) return;
 	struct video_window vwin;
 	WIOCTL(fd, VIDIOCGWIN, &vwin);
@@ -652,8 +643,8 @@
 /* those functions are still mostly unused */
 //void set_compression_preference(int fd, int pref) {if (use_pwc) WIOCTL(fd, VIDIOCPWCSCQUAL, &pref);}
 
-\def uint16 auto_gain() {int auto_gain=0; if (use_pwc) WIOCTL(fd, VIDIOCPWCGAGC, &auto_gain); return auto_gain;}
-\def void _0_auto_gain  (int auto_gain) {if (use_pwc) WIOCTL(fd, VIDIOCPWCSAGC, &auto_gain);}
+\def int auto_gain() {int auto_gain=0; if (use_pwc) WIOCTL(fd, VIDIOCPWCGAGC, &auto_gain); return auto_gain;}
+\def 0   auto_gain   (int auto_gain) {if (use_pwc) WIOCTL(fd, VIDIOCPWCSAGC, &auto_gain);}
 
 //void set_shutter_speed(int fd, int pref) {if (use_pwc) WIOCTL(fd, VIDIOCPWCSSHUTTER, &pref);}
 
@@ -666,7 +657,7 @@
 	return 2;
 }
 
-\def void _0_white_mode (uint16 white_mode) {
+\def 0 white_mode (uint16 white_mode) {
 	if (!use_pwc) return;
 	struct pwc_whitebalance pwcwb;
 	WIOCTL(fd, VIDIOCPWCGAWB, &pwcwb);
@@ -682,10 +673,10 @@
 	struct pwc_whitebalance pwcwb; WIOCTL(fd, VIDIOCPWCGAWB, &pwcwb); return pwcwb.manual_red;}
 \def uint16 white_blue() {if (!use_pwc) return 0;
 	struct pwc_whitebalance pwcwb; WIOCTL(fd, VIDIOCPWCGAWB, &pwcwb); return pwcwb.manual_blue;}
-\def void _0_white_red(uint16 white_red) {if (!use_pwc) return;
+\def 0 white_red(uint16 white_red) {if (!use_pwc) return;
 	struct pwc_whitebalance pwcwb; WIOCTL(fd, VIDIOCPWCGAWB, &pwcwb);
 	pwcwb.manual_red = white_red;  WIOCTL(fd, VIDIOCPWCSAWB, &pwcwb);}
-\def void _0_white_blue(uint16 white_blue) {if (!use_pwc) return;
+\def 0 white_blue(uint16 white_blue) {if (!use_pwc) return;
 	struct pwc_whitebalance pwcwb; WIOCTL(fd, VIDIOCPWCGAWB, &pwcwb);
 	pwcwb.manual_blue = white_blue;WIOCTL(fd, VIDIOCPWCSAWB, &pwcwb);}
 
@@ -693,10 +684,10 @@
 	struct pwc_wb_speed pwcwbs;         WIOCTL(fd, VIDIOCPWCGAWBSPEED, &pwcwbs); return pwcwbs.control_speed;}
 \def uint16 white_delay() {if (!use_pwc) return 0;
 	struct pwc_wb_speed pwcwbs;         WIOCTL(fd, VIDIOCPWCGAWBSPEED, &pwcwbs); return pwcwbs.control_delay;}
-\def void _0_white_speed(uint16 white_speed) {if (!use_pwc) return;
+\def 0 white_speed(uint16 white_speed) {if (!use_pwc) return;
 	struct pwc_wb_speed pwcwbs;         WIOCTL(fd, VIDIOCPWCGAWBSPEED, &pwcwbs);
 	pwcwbs.control_speed = white_speed; WIOCTL(fd, VIDIOCPWCSAWBSPEED, &pwcwbs);}
-\def void _0_white_delay(uint16 white_delay) {if (!use_pwc) return;
+\def 0 white_delay(uint16 white_delay) {if (!use_pwc) return;
 	struct pwc_wb_speed pwcwbs;         WIOCTL(fd, VIDIOCPWCGAWBSPEED, &pwcwbs);
 	pwcwbs.control_delay = white_delay; WIOCTL(fd, VIDIOCPWCSAWBSPEED, &pwcwbs);}
 
@@ -716,7 +707,7 @@
 	WIOCTL(fd, VIDIOCPWCGDYNNOISE, &noise_reduction);
 	return noise_reduction;
 }
-\def void _0_noise_reduction(int noise_reduction) {
+\def 0 noise_reduction(int noise_reduction) {
 	if (!use_pwc) return;
 	WIOCTL(fd, VIDIOCPWCSDYNNOISE, &noise_reduction);
 }
@@ -726,7 +717,7 @@
 	WIOCTL(fd, VIDIOCPWCSCQUAL, &compression);
 	return compression;
 }
-\def void _0_compression(int compression) {
+\def 0 compression(int compression) {
 	if (!use_pwc) return;
 	WIOCTL(fd, VIDIOCPWCGCQUAL, &compression);
 }
@@ -766,10 +757,7 @@
 	rb_funcall(rself,SI(initialize2),0);
 }
 
-\classinfo {
-	IEVAL(rself,"install '#io:videodev',1,2;@flags=4;@comment='Video4linux 1.x'");
-}
-\end class FormatVideoDev
+\end class FormatVideoDev {install_format("#io:videodev",1,2,4,"");}
 void startup_videodev () {
 	\startall
 }



More information about the Gridflow-cvs mailing list