[Gridflow-cvs] [svn] commit: r3576 - in /trunk/format: aalib.c jpeg.c netpbm.c png.c sdl.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Wed Apr 16 19:36:15 EDT 2008


Author: matju
Date: Wed Apr 16 19:36:15 2008
New Revision: 3576

Log:
use \constructor

Modified:
    trunk/format/aalib.c
    trunk/format/jpeg.c
    trunk/format/netpbm.c
    trunk/format/png.c
    trunk/format/sdl.c

Modified: trunk/format/aalib.c
==============================================================================
--- trunk/format/aalib.c (original)
+++ trunk/format/aalib.c Wed Apr 16 19:36:15 2008
@@ -35,13 +35,30 @@
 #endif
 AAAttr;
 
+static std::map<string,const aa_driver *> drivers;
+
 \class FormatAALib : Format {
 	aa_context *context;
 	aa_renderparams *rparams;
 	\attr bool autodraw;
 	bool raw_mode;
-	FormatAALib () : context(0), autodraw(1) {}
-	\decl void initialize (t_symbol *mode, string target);
+	/* !@#$ varargs missing here */
+	\constructor (t_symbol *mode, string target) {
+		context=0; autodraw=1;
+		argc-=2; argv+=2;
+		char *argv2[argc];
+		for (int i=0; i<argc; i++) argv2[i] = strdup(string(argv[i]).data());
+		if (mode!=gensym("out")) RAISE("write-only, sorry");
+		aa_parseoptions(0,0,&argc,argv2);
+		for (int i=0; i<argc; i++) free(argv2[i]);
+		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");
+		int32 v[]={context->imgheight,context->imgwidth,1};
+		post("aalib image size: %s",(new Dim(3,v))->to_s());
+	}
 	~FormatAALib () {if (context) aa_close(context);}
 	\decl 0 hidecursor ();
 	\decl 0 print (int y, int x, int a, string text);
@@ -117,26 +134,6 @@
 	}		
 }
 
-static std::map<string,const aa_driver *> drivers;
-
-/* !@#$ varargs missing here */
-\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!=gensym("out")) RAISE("write-only, sorry");
-	aa_parseoptions(0,0,&argc,argv2);
-	for (int i=0; i<argc; i++) free(argv2[i]);
-	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");
-	int32 v[]={context->imgheight,context->imgwidth,1};
-	post("aalib image size: %s",(new Dim(3,v))->to_s());
-}
-
 \end class FormatAALib {
 	const aa_driver *const *p = aa_drivers;
 	for (; *p; p++) drivers[(*p)->shortname] = *p;

Modified: trunk/format/jpeg.c
==============================================================================
--- trunk/format/jpeg.c (original)
+++ trunk/format/jpeg.c Wed Apr 16 19:36:15 2008
@@ -38,7 +38,11 @@
 	struct jpeg_compress_struct cjpeg;
 	struct jpeg_decompress_struct djpeg;
 	struct jpeg_error_mgr jerr;
-	\decl void initialize (t_symbol *mode, string filename);
+	\constructor (t_symbol *mode, string filename) {
+		Format::_0_open(0,0,mode,filename);
+		uint32 mask[3] = {0x0000ff,0x00ff00,0xff0000};
+		bit_packing = new BitPacking(is_le(),3,3,mask);
+	}
 	\decl 0 bang ();
 	\decl 0 quality (short quality);
 	\grin 0 int
@@ -111,13 +115,6 @@
 	jpeg_set_quality(&cjpeg,quality,false);
 }
 
-\def void initialize (t_symbol *mode, string filename) {
-	SUPER;
-	Format::_0_open(0,0,mode,filename);
-	uint32 mask[3] = {0x0000ff,0x00ff00,0xff0000};
-	bit_packing = new BitPacking(is_le(),3,3,mask);
-}
-
 \classinfo {install_format("#io.jpeg",6,"jpeg jpg");}
 \end class FormatJPEG
 void startup_jpeg () {

Modified: trunk/format/netpbm.c
==============================================================================
--- trunk/format/netpbm.c (original)
+++ trunk/format/netpbm.c Wed Apr 16 19:36:15 2008
@@ -29,15 +29,13 @@
 \class FormatNetPBM : Format {
 	struct pam inpam, outpam;
 	\grin 0
-	\decl void initialize(t_symbol *mode, string filename);
+	\constructor (t_symbol *mode, string filename) {
+		Format::_0_open(0,0,mode,filename);
+		memset(& inpam,sizeof(pam),0);
+		memset(&outpam,sizeof(pam),0);
+	}
 	\decl 0 bang ();
 };
-\def void initialize(t_symbol *mode, string filename) {
-	SUPER;
-	Format::_0_open(0,0,mode,filename);
-	memset(& inpam,sizeof(pam),0);
-	memset(&outpam,sizeof(pam),0);
-}
 \def 0 bang () {
 	//inpam.allocation_depth = 3;
 	pnm_readpaminit(f, &inpam, /*PAM_STRUCT_SIZE(tuple_type)*/ sizeof(struct pam));

Modified: trunk/format/png.c
==============================================================================
--- trunk/format/png.c (original)
+++ trunk/format/png.c Wed Apr 16 19:36:15 2008
@@ -33,8 +33,11 @@
 	P<BitPacking> bit_packing;
 	png_structp png;
 	png_infop info;
-	FormatPNG () : bit_packing(0), png(0) {}
-	\decl void initialize (t_symbol *mode, string filename);
+	\constructor (t_symbol *mode, string filename) {
+		Format::_0_open(0,0,mode,filename);
+		uint32 mask[3] = {0x0000ff,0x00ff00,0xff0000};
+		bit_packing = new BitPacking(is_le(),3,3,mask);
+	}
 	\decl 0 bang ();
 	\grin 0 int
 };
@@ -106,13 +109,6 @@
 	png_destroy_read_struct(&png, &info, NULL);
 }
 
-\def void initialize (t_symbol *mode, string filename) {
-	SUPER;
-	Format::_0_open(0,0,mode,filename);
-	uint32 mask[3] = {0x0000ff,0x00ff00,0xff0000};
-	bit_packing = new BitPacking(is_le(),3,3,mask);
-}
-
 \classinfo {install_format("#io.png",4,"png");}
 \end class FormatPNG
 void startup_png () {

Modified: trunk/format/sdl.c
==============================================================================
--- trunk/format/sdl.c (original)
+++ trunk/format/sdl.c Wed Apr 16 19:36:15 2008
@@ -32,6 +32,9 @@
 
 static bool in_use = false;
 
+struct FormatSDL;
+void FormatSDL_call(FormatSDL *self);
+
 \class FormatSDL : Format {
 	SDL_Surface *screen;
 	P<BitPacking> bit_packing;
@@ -39,7 +42,24 @@
 	t_clock *clock;
 	void resize_window (int sx, int sy);
 	void call ();
-	\decl void initialize (t_symbol *mode);
+	\constructor (t_symbol *mode) {
+		dim=0;screen=0;
+		if (in_use) RAISE("only one FormatSDL object at a time; sorry");
+		in_use=true;
+		if (SDL_Init(SDL_INIT_VIDEO)<0) RAISE("SDL_Init() error: %s",SDL_GetError());
+		atexit(SDL_Quit);
+		resize_window(320,240);
+		SDL_PixelFormat *f = screen->format;
+		uint32 mask[3] = {f->Rmask,f->Gmask,f->Bmask};
+		switch (f->BytesPerPixel) {
+		case 1: RAISE("8 bpp not supported"); break;
+		case 2: case 3: case 4:
+			bit_packing = new BitPacking(is_le(),f->BytesPerPixel,3,mask);
+			break;
+		default: RAISE("%d bytes/pixel: how do I deal with that?",f->BytesPerPixel); break;
+		}
+		clock = clock_new(this,(t_method)FormatSDL_call);
+	}
 	\grin 0 int
 	~FormatSDL () {
 		clock_unset(clock);
@@ -86,27 +106,6 @@
 	SDL_UpdateRect(screen,0,0,in->dim->get(1),in->dim->get(0));
 } GRID_END
 
-\def void initialize (t_symbol *mode) {
-	dim=0;screen=0;
-	SUPER;
-	if (in_use) RAISE("only one FormatSDL object at a time; sorry");
-	in_use=true;
-	if (SDL_Init(SDL_INIT_VIDEO)<0)
-		RAISE("SDL_Init() error: %s",SDL_GetError());
-	atexit(SDL_Quit);
-	resize_window(320,240);
-	SDL_PixelFormat *f = screen->format;
-	uint32 mask[3] = {f->Rmask,f->Gmask,f->Bmask};
-	switch (f->BytesPerPixel) {
-	case 1: RAISE("8 bpp not supported"); break;
-	case 2: case 3: case 4:
-		bit_packing = new BitPacking(is_le(),f->BytesPerPixel,3,mask);
-		break;
-	default: RAISE("%d bytes/pixel: how do I deal with that?",f->BytesPerPixel); break;
-	}
-	clock = clock_new(this,(t_method)FormatSDL_call);
-}
-
 \end class FormatSDL {install_format("#io.sdl",2,"");}
 void startup_sdl () {
 	\startall



More information about the Gridflow-cvs mailing list