[Gridflow-cvs] [svn] commit: r3334 - in /trunk/format: aalib.c mpeg3.c quicktimeapple.c quicktimehw.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Fri Mar 28 15:17:32 EDT 2008


Author: matju
Date: Fri Mar 28 15:17:32 2008
New Revision: 3334

Log:
derubify

Modified:
    trunk/format/aalib.c
    trunk/format/mpeg3.c
    trunk/format/quicktimeapple.c
    trunk/format/quicktimehw.c

Modified: trunk/format/aalib.c
==============================================================================
--- trunk/format/aalib.c (original)
+++ trunk/format/aalib.c Fri Mar 28 15:17:32 2008
@@ -24,6 +24,7 @@
 #include "../base/grid.h.fcs"
 #define aa_hardwareparams aa_hardware_params
 #include <aalib.h>
+#include <map>
 
 /* MINNOR is a typo in aalib.h, sorry */
 typedef
@@ -40,10 +41,10 @@
 	\attr bool autodraw;
 	bool raw_mode;
 	FormatAALib () : context(0), autodraw(1) {}
-	\decl void initialize (Symbol mode, Symbol target);
+	\decl void initialize (t_symbol *mode, string target);
 	\decl 0 close ();
 	\decl 0 hidecursor ();
-	\decl 0 print (int y, int x, int a, Symbol text);
+	\decl 0 print (int y, int x, int a, string text);
 	\decl 0 draw ();
 	\decl 0 dump ();
 	\grin 0 int
@@ -105,8 +106,8 @@
 
 \def 0 hidecursor () { aa_hidemouse(context); }
 \def 0 draw () { aa_flush(context); }
-\def 0 print (int y, int x, int a, Symbol text) {
-	aa_puts(context,x,y,(AAAttr)a,(char *)rb_sym_name(text));
+\def 0 print (int y, int x, int a, string text) {
+	aa_puts(context,x,y,(AAAttr)a,(char *)text.data());
 	if (autodraw==1) aa_flush(context);
 }
 
@@ -123,19 +124,19 @@
 	}		
 }
 
+static std::map<string,const aa_driver *> drivers;
+
 /* !@#$ varargs missing here */
-\def void initialize (Symbol mode, Symbol target) {
+\def void initialize (t_symbol *mode, string target) {
 	SUPER;
 	argc-=2; argv+=2;
 	char *argv2[argc];
 	for (int i=0; i<argc; i++) argv2[i] = strdup(rb_str_ptr(rb_funcall(argv[i],SI(to_s),0)));
-	if (mode!=SYM(out)) RAISE("write-only, sorry");
+	if (mode!=gensym("out")) RAISE("write-only, sorry");
 	aa_parseoptions(0,0,&argc,argv2);
 	for (int i=0; i<argc; i++) free(argv2[i]);
-	Ruby drivers = rb_ivar_get(rb_obj_class(rself),SI(@drivers));
-	Ruby driver_address = rb_hash_aref(drivers,target);
-	if (driver_address==Qnil) RAISE("unknown aalib driver '%s'",rb_sym_name(target));
-	aa_driver *driver = FIX2PTR(aa_driver,driver_address);
+	if (drivers.find(target)==drivers.end()) RAISE("unknown aalib driver '%s'",target.data());
+	const aa_driver *driver = drivers[target];
 	context = aa_init(driver,&aa_defparams,0);
 	rparams = aa_getrenderparams();
 	if (!context) RAISE("opening aalib didn't work");
@@ -143,8 +144,11 @@
 	post("aalib image size: %s",(new Dim(3,v))->to_s());
 }
 
-/*const aa_driver *const *p = aa_drivers; for (; *p; p++) rb_hash_aset(drivers,ID2SYM(rb_intern((*p)->shortname)), PTR2FIX(*p));*/
-\end class FormatAALib {install_format("#io.aalib",2,"");}
+\end class FormatAALib {
+	const aa_driver *const *p = aa_drivers;
+	for (; *p; p++) drivers[(*p)->shortname] = *p;
+	install_format("#io.aalib",2,"");
+}
 void startup_aalib () {
 	\startall
 }

Modified: trunk/format/mpeg3.c
==============================================================================
--- trunk/format/mpeg3.c (original)
+++ trunk/format/mpeg3.c Fri Mar 28 15:17:32 2008
@@ -31,7 +31,7 @@
 	mpeg3_t *mpeg;
 	int track;
 	FormatMPEG3 () : track(0) {}
-	\decl void initialize (Symbol mode, String filename);
+	\decl void initialize (t_symbol *mode, string filename);
 	\decl 0 seek (int frame);
 	\decl 0 bang ();
 	\decl 0 close ();
@@ -55,10 +55,7 @@
 	mpeg3_read_frame(mpeg,rows,0,0,sx,sy,sx,sy,MPEG3_RGB888,track);
 	GridOutlet out(this,0,new Dim(sy,sx,channels),cast);
 	int bs = out.dim->prod(1);
-	for(int y=0; y<sy; y++) {
-		uint8 *row = buf+channels*sx*y;
-		out.send(bs,row);
-	}
+	for(int y=0; y<sy; y++) out.send(bs,buf+channels*sx*y);
 	delete[] (uint8 *)buf;
 //	return INT2NUM(nframe);
 }
@@ -69,21 +66,20 @@
 }
 
 // libmpeg3 may be nice, but it won't take a filehandle, only filename
-\def void initialize (Symbol mode, String filename) {
+\def void initialize (t_symbol *mode, string filename) {
 	SUPER;
-	if (mode!=SYM(in)) RAISE("read-only, sorry");
-	if (TYPE(filename)!=T_STRING) RAISE("PATATE POILUE");
-	filename = rb_funcall(mGridFlow,SI(find_file),1,filename);
+	if (mode!=gensym("in")) RAISE("read-only, sorry");
+	filename = gf_find_file(filename);
 #ifdef MPEG3_UNDEFINED_ERROR
 	{
 		int err;
-		mpeg = mpeg3_open(rb_str_ptr(filename),&err);
+		mpeg = mpeg3_open((char *)filename.data(),&err);
 		post("mpeg error code = %d",err);
 	}
 #else
-	mpeg = mpeg3_open(rb_str_ptr(filename));
+	mpeg = mpeg3_open(filename.data());
 #endif
-	if (!mpeg) RAISE("IO Error: can't open file `%s': %s", filename, strerror(errno));
+	if (!mpeg) RAISE("IO Error: can't open file `%s': %s", filename.data(), strerror(errno));
 }
 
 \classinfo {install_format("#io.mpeg",4,"mpg mpeg");}

Modified: trunk/format/quicktimeapple.c
==============================================================================
--- trunk/format/quicktimeapple.c (original)
+++ trunk/format/quicktimeapple.c Fri Mar 28 15:17:32 2008
@@ -191,7 +191,7 @@
   int m_quality;
 //int m_colorspace;
   FormatQuickTimeCamera() : vdc(0) {}
-  \decl void initialize (Symbol mode, String filename);
+  \decl void initialize (t_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, String filename) {
+\def void initialize (t_symbol *mode, string filename) {
 //vdc = SGGetVideoDigitizerComponent(c);
   SUPER;
   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, String filename);
+	\decl void initialize (t_symbol *mode, string filename);
 	\decl 0 close ();
 	\decl 0 codec_m (String c);
 	\decl 0 colorspace_m (Symbol c);
@@ -425,13 +425,13 @@
 	SUPER;
 }
 
-\def void initialize (Symbol mode, String filename) {
+\def void initialize (t_symbol *mode, string filename) {
 	int err;
 	SUPER;
-	filename = rb_funcall(mGridFlow,SI(find_file),1,filename);
+	filename = gf_find_file(filename);
 	FSSpec fss;
 	FSRef fsr;
-	err = FSPathMakeRef((const UInt8 *)rb_str_ptr(filename), &fsr, NULL);
+	err = FSPathMakeRef((const UInt8 *)filename.data(), &fsr, NULL);
 	if (err) goto err;
 	err = FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, &fss, NULL);
 	if (err) goto err;
@@ -458,8 +458,7 @@
 	if (err) goto err;
 	return;
 err:
-	RAISE("can't open file `%s': error #%d (%s)", rb_str_ptr(filename),
-		err,
+	RAISE("can't open file `%s': error #%d (%s)", filename.data(), err,
 		rb_str_ptr(rb_funcall(mGridFlow,SI(macerr),1,INT2NUM(err))));
 }
 

Modified: trunk/format/quicktimehw.c
==============================================================================
--- trunk/format/quicktimehw.c (original)
+++ trunk/format/quicktimehw.c Fri Mar 28 15:17:32 2008
@@ -26,6 +26,11 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <map>
+#include <vector>
+
+static std::map<string,std::vector<string> *> codecs;
+static std::map<string,string> fourccs;
 
 \class FormatQuickTimeHW : Format {
 	quicktime_t *anim;
@@ -47,9 +52,9 @@
 	\decl 0 bang ();
 	\decl 0 seek (int frame);
 	\decl 0 force_size (int32 height, int32 width);
-	\decl 0 codec (String c);
-	\decl 0 colorspace (Symbol c);
-	\decl 0 parameter (Symbol name, int32 value);
+	\decl 0 codec (string c);
+	\decl 0 colorspace (string c);
+	\decl 0 parameter (string name, int32 value);
 	\decl 0 framerate (float64 f);
 	\decl 0 size (int32 height, int32 width);
 	\decl 0 get ();
@@ -89,11 +94,11 @@
 }
 
 //!@#$ should also support symbol values (how?)
-\def 0 parameter (Symbol name, int32 value) {
+\def 0 parameter (string name, int32 value) {
 	int val = value;
-	//post("quicktime_set_parameter %s %d",(char*)rb_sym_name(name), val);
-	quicktime_set_parameter(anim, (char*)rb_sym_name(name), &val);
-	if (name==SYM(jpeg_quality)) jpeg_quality=value;
+	//post("quicktime_set_parameter %s %d",name.data(), val);
+	quicktime_set_parameter(anim, (char *)name.data(), &val);
+	if (name=="jpeg_quality") jpeg_quality=value;
 }
 
 \def 0 framerate (float64 f) {
@@ -140,31 +145,28 @@
 } GRID_FINISH {
 } GRID_END
 
-\def 0 codec (String c) {
-	//fprintf(stderr,"codec = %s\n",rb_str_ptr(rb_inspect(c)));
+\def 0 codec (string c) {
 #ifdef LQT_VERSION
 	char buf[5];
-	strncpy(buf,rb_str_ptr(c),4);
-	for (int i=rb_str_len(c); i<4; i++) buf[i]=' ';
+	strncpy(buf,c.data(),4);
+	for (int i=c.length(); i<4; i++) buf[i]=' ';
 	buf[4]=0;
-	Ruby fourccs = rb_ivar_get(rb_obj_class(rself),SI(@fourccs));
-	if (Qnil==rb_hash_aref(fourccs,rb_str_new2(buf)))
-		RAISE("warning: unknown fourcc '%s' (%s)",
-			buf, rb_str_ptr(rb_inspect(rb_funcall(fourccs,SI(keys),0))));
+	if (fourccs.find(string(buf))==fourccs.end())
+		RAISE("warning: unknown fourcc '%s'" /*" (%s)"*/, buf /*, rb_str_ptr(rb_inspect(rb_funcall(fourccs,SI(keys),0)))*/);
 #endif	
 	codec = strdup(buf);
 }
 
-\def 0 colorspace (Symbol c) {
+\def 0 colorspace (string c) {
 	if (0) {
-	} else if (c==SYM(rgb))     { channels=3; colorspace=BC_RGB888; 
-	} else if (c==SYM(rgba))    { channels=4; colorspace=BC_RGBA8888;
-	} else if (c==SYM(bgr))     { channels=3; colorspace=BC_BGR888;
-	} else if (c==SYM(bgrn))    { channels=4; colorspace=BC_BGR8888;
-//	} else if (c==SYM(yuv))     { channels=3; colorspace=BC_YUV888;
-	} else if (c==SYM(yuva))    { channels=4; colorspace=BC_YUVA8888;
-	} else if (c==SYM(YUV420P)) { channels=3; colorspace=BC_YUV420P;
-	} else RAISE("unknown colorspace '%s' (supported: rgb, rgba, bgr, bgrn, yuv, yuva)",rb_sym_name(c));
+	} else if (c=="rgb")     { channels=3; colorspace=BC_RGB888; 
+	} else if (c=="rgba")    { channels=4; colorspace=BC_RGBA8888;
+	} else if (c=="bgr")     { channels=3; colorspace=BC_BGR888;
+	} else if (c=="bgrn")    { channels=4; colorspace=BC_BGR8888;
+//	} else if (c=="yuv")     { channels=3; colorspace=BC_YUV888;
+	} else if (c=="yuva")    { channels=4; colorspace=BC_YUVA8888;
+	} else if (c=="YUV420P") { channels=3; colorspace=BC_YUV420P;
+	} else RAISE("unknown colorspace '%s' (supported: rgb, rgba, bgr, bgrn, yuv, yuva)",c.data());
 }
 
 \def 0 close () {
@@ -203,7 +205,7 @@
 			      quicktime_video_compressor(anim,track));
 */
 	}
-	_0_colorspace(0,0,SYM(rgb));
+	_0_colorspace(0,0,string("rgb"));
 	quicktime_set_cpus(anim,1);
 	uint32 mask[3] = {0x0000ff,0x00ff00,0xff0000};
 	bit_packing = new BitPacking(is_le(),3,3,mask);
@@ -215,31 +217,27 @@
 #ifdef LQT_VERSION
 	lqt_registry_init();
 	int n = lqt_get_num_video_codecs();
-	Ruby codecs = rb_hash_new();
-	Ruby fourccs = rb_hash_new();
 	for (int i=0; i<n; i++) {
 		const lqt_codec_info_t *s = lqt_get_video_codec_info(i);
 		if (!s->name) {
 			fprintf(stderr,"[#in quicktime]: skipping codec with null name!\n");
 			continue;
 		}
-		Ruby name = rb_str_new2(s->name);
-		Ruby f = rb_ary_new2(s->num_fourccs);
+		string name = string(s->name);
+		std::vector<string> *f = new std::vector<string>(s->num_fourccs);
 		if (!s->fourccs) {
 			post("WARNING: no fourccs (quicktime library is broken?)");
 			goto hell;
 		}
 		//fprintf(stderr,"num_fourccs=%d fourccs=%p\n",s->num_fourccs,s->fourccs);
 		for (int j=0; j<s->num_fourccs; j++) {
-			Ruby fn = rb_str_new2(s->fourccs[j]);
-			rb_ary_push(f,fn);
-			rb_hash_aset(fourccs,fn,name);
+			string fn = string(s->fourccs[j]);
+			f->push_back(fn);
+			fourccs[fn]=name;
 		}
-		rb_hash_aset(codecs,name,f);
+		codecs[name]=f;
 		hell:;
 	}
-	rb_ivar_set(rself,SI(@codecs),codecs);
-	rb_ivar_set(rself,SI(@fourccs),fourccs);
 #endif
 }
 \end class FormatQuickTimeHW



More information about the Gridflow-cvs mailing list