[Gridflow-cvs] [svn] commit: r3294 - in /trunk/format: jpeg.c main.c main.rb mpeg3.c netpbm.c png.c quicktimeapple.c quicktimehw.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Tue Mar 25 20:21:47 EDT 2008


Author: matju
Date: Tue Mar 25 20:21:46 2008
New Revision: 3294

Log:
"open" methods don't take the "file" argument anymore. [#io:file] merged into GridIO.

Modified:
    trunk/format/jpeg.c
    trunk/format/main.c
    trunk/format/main.rb
    trunk/format/mpeg3.c
    trunk/format/netpbm.c
    trunk/format/png.c
    trunk/format/quicktimeapple.c
    trunk/format/quicktimehw.c

Modified: trunk/format/jpeg.c
==============================================================================
--- trunk/format/jpeg.c (original)
+++ trunk/format/jpeg.c Tue Mar 25 20:21:46 2008
@@ -40,7 +40,7 @@
 	struct jpeg_error_mgr jerr;
 	int fd;
 	FILE *f;
-	\decl void initialize (Symbol mode, Symbol source, String filename);
+	\decl void initialize (Symbol mode, String filename);
 	\decl 0 bang ();
 	\decl 0 quality (short quality);
 	\decl 0 close ();
@@ -120,10 +120,9 @@
 	//if (f) {rb_funcall(stream,SI(close),0); f=0; fd=-1;}
 }
 
-\def void initialize (Symbol mode, Symbol source, String filename) {
+\def void initialize (Symbol mode, String filename) {
 	rb_call_super(argc,argv);
-	if (source!=SYM(file)) RAISE("usage: jpeg file <filename>");
-	rb_funcall(rself,SI(raw_open),3,mode,source,filename);
+	rb_funcall(rself,SI(raw_open),3,mode,filename);
 	Ruby stream = rb_ivar_get(rself,SI(@stream));
 	fd = NUM2INT(rb_funcall(stream,SI(fileno),0));
 	f = fdopen(fd,mode==SYM(in)?"r":"w");

Modified: trunk/format/main.c
==============================================================================
--- trunk/format/main.c (original)
+++ trunk/format/main.c Tue Mar 25 20:21:46 2008
@@ -42,7 +42,7 @@
 	NumberTypeE nt;
 	P<Dim> headerless; // if null: headerful; if Dim: it is the assumed dimensions of received grids
 	\grin 0
-	\decl void initialize(Symbol mode, Symbol source, String filename);
+	\decl void initialize(Symbol mode, String filename);
 	\decl 0 bang ();
 	\decl 0 headerless_m (...);
 	\decl 0 headerful ();
@@ -50,14 +50,14 @@
 	\decl 0 close();
 	\decl void raw_open_gzip_in(String filename);
 	\decl void raw_open_gzip_out(String filename);
-	\decl void raw_open(Symbol mode, Symbol source, String filename);
+	\decl void raw_open(Symbol mode, String filename);
 };
 
-\def void initialize(Symbol mode, Symbol source, String filename) {
+\def void initialize(Symbol mode, String filename) {
 	rb_call_super(argc,argv);
 	strncpy(head.magic,is_le()?"\7fgrid":"\7fGRID",5);
 	head.type = 32;
-	rb_funcall(rself,SI(raw_open),3,mode,source,filename);
+	rb_funcall(rself,SI(raw_open),3,mode,filename);
 	Ruby stream = rb_ivar_get(rself,SI(@stream));
 	fd = NUM2INT(rb_funcall(stream,SI(fileno),0));
 	f = fdopen(fd,mode==SYM(in)?"r":"w");
@@ -137,24 +137,20 @@
 	//if (pid=fork) {GridFlow.subprocesses[pid]=true; r.close; @stream = w;}
 	//else {w.close; STDIN.reopen r; STDOUT.reopen filename, "w"; exec "gzip", "-c";}
 }
-\def void raw_open(Symbol mode, Symbol source, String filename) {
+\def void raw_open(Symbol mode, String filename) {
 	const char *fmode;
 	if (mode==SYM(in))  fmode="r"; else
 	if (mode==SYM(out)) fmode="w"; else
 	RAISE("bad mode");
 	//@stream.close if @stream
-	if (source==SYM(file)) {
-		if (mode==SYM(in)) {filename = rb_funcall(mGridFlow,SI(find_file),1,filename);}
-		RAISE("raw_open code missing here");
-		//@stream = File.open(filename,fmode); break;
-	}
+	if (mode==SYM(in)) {filename = rb_funcall(mGridFlow,SI(find_file),1,filename);}
+	RAISE("raw_open code missing here");
+	//@stream = File.open(filename,fmode); break;
 //	case gzfile:
 //		if (mode==SYM(in)) {filename = GridFlow.find_file(filename);}
 //		if (mode==:in) {raw_open_gzip_in filename; else raw_open_gzip_out filename;}
 //		def self.rewind() raw_open(*@raw_open_args); @frame = 0 end unless @rewind_redefined
 //		@rewind_redefined = true
-//	default: raise "unknown access method '#{source}'"
-//	}
 }
 \def 0 close () {
 	//@stream.close if @stream

Modified: trunk/format/main.rb
==============================================================================
--- trunk/format/main.rb (original)
+++ trunk/format/main.rb Tue Mar 25 20:21:46 2008
@@ -85,8 +85,6 @@
 		}
 	end
 	class<< self
-		attr_reader :symbol_name
-		attr_reader :description
 		attr_reader :flags
 		attr_reader :suffixes
 	end
@@ -116,18 +114,6 @@
 	# "ideal" buffer size or something
 	# the buffer may be bigger than this but usually not by much.
 	def self.buffersize; 16384 end
-	def _0_headerless(*args) #!@#$ goes in FormatGrid ?
-		args=args[0] if Array===args[0]
-		#raise "expecting dimension list..."
-		args.map! {|a|
-			Numeric===a or raise "expecting dimension list..."
-			a.to_i
-		}
-		@headerless = args
-	end
-	def _0_headerful #!@#$ goes in FormatGrid ?
-		@headerless = nil
-	end
 	def _0_type arg
 		#!@#$ goes in FormatGrid ?
 		#!@#$ bug: should not be able to modify this _during_ a transfer
@@ -146,19 +132,35 @@
 		end
 	end
 	def frame; @frame+=1; @frame-1 end
+	def self.install_format(a,b,c,d,e) install(a,b,c); @mode=d; suffixes_are e.split(" ") end
 end
 
 # common parts between GridIn and GridOut
-module GridIO
+class GridIO < GridObject
 	def check_file_open; if not @format then raise "can't do that: file not open" end end
 	def _0_close; (@format.close; @format = nil) if @format end
 	def delete; @format.close if @format; @format = nil; super end
 	attr_reader :format
+	def initialize(*)
+		super
+		@format = nil
+		@timelog = false
+		@framecount = 0
+		@time = Time.new
+	end
 	def _0_open(sym,*a)
-		sym = sym.intern if String===sym
-		if a.length==0 and /\./ =~ sym.to_s then a=[sym]; sym=:file end
-		qlass = GridFlow.fclasses["\#io:#{sym}"]
-		if not qlass then raise "unknown file format identifier: #{sym}" end
+		sym = sym.to_s
+		if a.length==0 and /\./ =~ sym then
+			a = [mode,sym]
+			suf=sym.split(/\./)[-1]
+			#if suf=="gz" then a[1]=:gzfile; suf=file.split(/\./)[-2] end
+			h=Format.suffixes[suf]
+			if not h then raise "unknown suffix '.#{suf}'" end
+			@format = h.new(*a)
+		else
+			qlass = GridFlow.fclasses["\#io:#{sym}"]
+			if not qlass then raise "unknown file format identifier: #{sym}" end
+		end
 		_0_close if @format
 		@format = qlass.new @mode, *a
 		@format.connect 0,self,1
@@ -184,15 +186,10 @@
 	end
 end
 
-GridObject.subclass("#in",1,2) {
+GridIO.subclass("#in",1,2) {
 	install_rgrid 0
-	include GridIO
 	def initialize(*a)
 		super
-		@format = nil
-		@timelog = false
-		@framecount = 0
-		@time = Time.new
 		@mode = :in
 		return if a.length==0
 		_0_open(*a)
@@ -229,18 +226,13 @@
 
 }
 
-GridObject.subclass("#out",1,1) {
-	include GridIO
+GridIO.subclass("#out",1,1) {
 	def initialize(*a)
 		super
-		@format = nil
-		@timelog = false
-		@framecount = 0
-		@time = Time.new
 		@mode = :out
 		return if a.length==0
-		if Integer===a[0] or Float===a[0]
-			_0_open :x11,:here
+		if Numeric===a[0]
+			_0_open :window
 			_0_out_size a[0],a[1]
 		else
 			_0_open(*a)
@@ -265,8 +257,7 @@
 	end
 	def log
 		time = Time.new
-		post("\#out: frame#%04d time: %10.3f s; diff: %5d ms",
-			@framecount, time, ((time- at time)*1000).to_i)
+		post("\#out: frame#%04d time: %10.3f s; diff: %5d ms", @framecount, time, ((time- at time)*1000).to_i)
 		@time = time
 	end
 	install_rgrid 0
@@ -275,20 +266,6 @@
 	alias pack pack2
 	alias unpack unpack2
 end
-
-Format.subclass("#io:file",1,1) {
-	def self.new(mode,file)
-		file=file.to_s
-		a = [mode,:file,file]
-		if not /\./=~file then raise "no filename suffix?" end
-		suf=file.split(/\./)[-1]
-		if suf=="gz" then a[1]=:gzfile; suf=file.split(/\./)[-2] end
-		h=Format.suffixes[suf]
-		if not h then raise "unknown suffix '.#{suf}'" end
-		h.new(*a)
-	end
-	@comment="format autodetection proxy"
-}
 
 =begin
 FormatPPM.subclass("#io:tk",1,1) {

Modified: trunk/format/mpeg3.c
==============================================================================
--- trunk/format/mpeg3.c (original)
+++ trunk/format/mpeg3.c Tue Mar 25 20:21:46 2008
@@ -31,7 +31,7 @@
 	mpeg3_t *mpeg;
 	int track;
 	FormatMPEG3 () : track(0) {}
-	\decl void initialize (Symbol mode, Symbol source, String filename);
+	\decl void initialize (Symbol mode, String filename);
 	\decl 0 seek (int frame);
 	\decl 0 bang ();
 	\decl 0 close ();
@@ -72,10 +72,9 @@
 }
 
 // libmpeg3 may be nice, but it won't take a filehandle, only filename
-\def void initialize (Symbol mode, Symbol source, String filename) {
+\def void initialize (Symbol mode, String filename) {
 	rb_call_super(argc,argv);
 	if (mode!=SYM(in)) RAISE("read-only, sorry");
-	if (source!=SYM(file)) RAISE("usage: mpeg file <filename>");
 	if (TYPE(filename)!=T_STRING) RAISE("PATATE POILUE");
 	filename = rb_funcall(mGridFlow,SI(find_file),1,filename);
 #ifdef MPEG3_UNDEFINED_ERROR

Modified: trunk/format/netpbm.c
==============================================================================
--- trunk/format/netpbm.c (original)
+++ trunk/format/netpbm.c Tue Mar 25 20:21:46 2008
@@ -31,13 +31,12 @@
 	int fd;
 	FILE *f;
 	\grin 0
-	\decl void initialize(Symbol mode, Symbol source, String filename);
+	\decl void initialize(Symbol mode, String filename);
 	\decl 0 bang ();
 };
-\def void initialize(Symbol mode, Symbol source, String filename) {
+\def void initialize(Symbol mode, String filename) {
 	rb_call_super(argc,argv);
-	if (source!=SYM(file)) RAISE("usage: netpbm file <filename>");
-	rb_funcall(rself,SI(raw_open),3,mode,source,filename);
+	rb_funcall(rself,SI(raw_open),3,mode,filename);
 	Ruby stream = rb_ivar_get(rself,SI(@stream));
 	fd = NUM2INT(rb_funcall(stream,SI(fileno),0));
 	f = fdopen(fd,mode==SYM(in)?"r":"w");

Modified: trunk/format/png.c
==============================================================================
--- trunk/format/png.c (original)
+++ trunk/format/png.c Tue Mar 25 20:21:46 2008
@@ -36,7 +36,7 @@
 	int fd;
 	FILE *f;
 	FormatPNG () : bit_packing(0), png(0), f(0) {}
-	\decl void initialize (Symbol mode, Symbol source, String filename);
+	\decl void initialize (Symbol mode, String filename);
 	\decl 0 bang ();
 	\decl 0 close ();
 	\grin 0 int
@@ -111,10 +111,9 @@
 
 \def 0 close () {if (f) {fclose(f); f=0;}}
 
-\def void initialize (Symbol mode, Symbol source, String filename) {
+\def void initialize (Symbol mode, String filename) {
 	rb_call_super(argc,argv);
-	if (source!=SYM(file)) RAISE("usage: png file <filename>");
-	rb_funcall(rself,SI(raw_open),3,mode,source,filename);
+	rb_funcall(rself,SI(raw_open),3,mode,filename);
 	Ruby stream = rb_ivar_get(rself,SI(@stream));
 	fd = NUM2INT(rb_funcall(stream,SI(fileno),0));
 	f = fdopen(fd,mode==SYM(in)?"r":"w");

Modified: trunk/format/quicktimeapple.c
==============================================================================
--- trunk/format/quicktimeapple.c (original)
+++ trunk/format/quicktimeapple.c Tue Mar 25 20:21:46 2008
@@ -191,7 +191,7 @@
   int m_quality;
 //int m_colorspace;
   FormatQuickTimeCamera() : vdc(0) {}
-  \decl void initialize (Symbol mode, Symbol source, String filename);
+  \decl void initialize (Symbol mode, String filename);
   \decl 0 frame ();
   \decl 0 close ();
   \grin 0 int
@@ -201,7 +201,7 @@
 
 static int nn(int c) {return c?c:' ';}
 
-\def void initialize (Symbol mode, Symbol source, String filename) {
+\def void initialize (Symbol mode, String filename) {
 //vdc = SGGetVideoDigitizerComponent(c);
   rb_call_super(argc,argv);
   dim = new Dim(240,320,4);
@@ -347,7 +347,7 @@
 	int nframe, nframes;
 	FormatQuickTimeApple() : movie(0), time(0), movie_file(0), gw(0),
 		buffer(), dim(0), nframe(0), nframes(0) {}
-	\decl void initialize (Symbol mode, Symbol source, String filename);
+	\decl void initialize (Symbol mode, String filename);
 	\decl 0 close ();
 	\decl 0 codec_m (String c);
 	\decl 0 colorspace_m (Symbol c);
@@ -425,22 +425,18 @@
 	rb_call_super(argc,argv);
 }
 
-\def void initialize (Symbol mode, Symbol source, String filename) {
+\def void initialize (Symbol mode, String filename) {
 	int err;
 	rb_call_super(argc,argv);
-	if (source==SYM(file)) {
-		filename = rb_funcall(mGridFlow,SI(find_file),1,filename);
-		FSSpec fss;
-		FSRef fsr;
-		err = FSPathMakeRef((const UInt8 *)rb_str_ptr(filename), &fsr, NULL);
-		if (err) goto err;
-		err = FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, &fss, NULL);
-		if (err) goto err;
-		err = OpenMovieFile(&fss,&movie_file,fsRdPerm);
-		if (err) goto err;
-	} else {
-		RAISE("usage: quicktime [file <filename> | camera bleh]");
-	}
+	filename = rb_funcall(mGridFlow,SI(find_file),1,filename);
+	FSSpec fss;
+	FSRef fsr;
+	err = FSPathMakeRef((const UInt8 *)rb_str_ptr(filename), &fsr, NULL);
+	if (err) goto err;
+	err = FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, &fss, NULL);
+	if (err) goto err;
+	err = OpenMovieFile(&fss,&movie_file,fsRdPerm);
+	if (err) goto err;
 	NewMovieFromFile(&movie, movie_file, NULL, NULL, newMovieActive, NULL);
 	Rect r;
 	GetMovieBox(movie, &r);
@@ -470,13 +466,7 @@
 \classinfo {
 	EnterMovies();
 	install_format("#io:quicktime",1,1,4,"mov");
-IEVAL(rself,
-\ruby
-  def self.new(mode,source,filename)
-    if source==:camera then FormatQuickTimeCamera.new(mode,source,filename) else super end
-  end
-\end ruby
-);}
+}
 \end class FormatQuickTimeApple
 void startup_quicktimeapple () {
 	\startall

Modified: trunk/format/quicktimehw.c
==============================================================================
--- trunk/format/quicktimehw.c (original)
+++ trunk/format/quicktimehw.c Tue Mar 25 20:21:46 2008
@@ -42,7 +42,7 @@
 	int jpeg_quality; // in theory we shouldn't need this, but...
 	FormatQuickTimeHW() : track(0), dim(0), codec(QUICKTIME_RAW), 
 		started(false), force(0), framerate(29.97), bit_packing(0), jpeg_quality(75) {}
-	\decl void initialize (Symbol mode, Symbol source, String filename);
+	\decl void initialize (Symbol mode, String filename);
 	\decl 0 close ();
 	\decl 0 bang ();
 	\decl 0 seek (int frame);
@@ -184,16 +184,14 @@
 }
 
 // libquicktime may be nice, but it won't take a filehandle, only filename
-\def void initialize (Symbol mode, Symbol source, String filename) {
+\def void initialize (Symbol mode, String filename) {
 	rb_call_super(argc,argv);
-	if (source!=SYM(file)) RAISE("usage: quicktime file <filename>");
 	filename = rb_funcall(mGridFlow,SI(find_file),1,filename);
 	anim = quicktime_open(rb_str_ptr(filename),mode==SYM(in),mode==SYM(out));
 	if (!anim) RAISE("can't open file `%s': %s (or some other reason that libquicktime won't tell us)",
 		rb_str_ptr(filename), strerror(errno));
 	if (mode==SYM(in)) {
 		length = quicktime_video_length(anim,track);
-
 		post("quicktime: codec=%s height=%d width=%d depth=%d framerate=%f",
 			quicktime_video_compressor(anim,track),
 			quicktime_video_height(anim,track),



More information about the Gridflow-cvs mailing list