[Gridflow-cvs] [svn] commit: r5187 - /trunk/src/videodev.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Sat Mar 27 17:57:59 EDT 2010


Author: matju
Date: Sat Mar 27 17:57:57 2010
New Revision: 5187

Log:
introducing macros YUV2R,etc.

Modified:
    trunk/src/videodev.cxx

Modified: trunk/src/videodev.cxx
==============================================================================
--- trunk/src/videodev.cxx (original)
+++ trunk/src/videodev.cxx Sat Mar 27 17:57:57 2010
@@ -337,6 +337,14 @@
 
 static uint8 clip(int x) {return x<0?0 : x>255?255 : x;}
 
+// these are nonstandard YUV converters for use by frame_finished only
+#define YUV2R(Y,U,V) clip( (298*(Y-16)               + 409*(V-128))>>8)
+#define YUV2G(Y,U,V) clip( (298*(Y-16) - 100*(U-128) - 208*(V-128))>>8)
+#define YUV2B(Y,U,V) clip( (298*(Y-16) + 516*(U-128)              )>>8)
+// these too, from one kind of YUV to another.
+#define YUV2Y(Y,U,V) clip( (298*(Y-16)                            )>>8)
+#define YUV2U(Y,U,V) clip(((             293*(U-128)              )>>8)+128)
+#define YUV2V(Y,U,V) clip(((                           293*(V-128))>>8)+128)
 void FormatVideoDev::frame_finished (uint8 *buf) {
 	string cs = colorspace->s_name;
 	int downscale = cs=="magic";
@@ -348,46 +356,35 @@
 	//post("frame_finished sy=%d sx=%d bs=%d, vp.palette = %d; colorspace = %s",sy,sx,bs,vp.palette,cs.data());
 	if (vp.palette==VIDEO_PALETTE_YUV420P || vp.palette==VIDEO_PALETTE_YUYV) {
 		uint8 *bufy, *bufu, *bufv;
-		bufy = buf; bufu = buf+sx*sy; bufv = buf+sx*sy*5/4;
+		if (vp.palette==VIDEO_PALETTE_YUV420P) {bufy = buf; bufu = buf+sx*sy; bufv = buf+sx*sy*5/4;}
+		else                                   {bufy = buf; bufu = buf+1    ; bufv = buf+3        ;}
 		GridOutlet out(this,0,cs=="magic"?new Dim(sy>>downscale,sx>>downscale,3):(Dim *)dim,cast);
 		if (cs=="y") {
-			for(int y=0; y<sy; bufy+=sx, y++) {
+			/*for(int y=0; y<sy; bufy+=sx, y++) {
 				for (int x=0,xx=0; x<sx; x+=2,xx+=2) {
-					b2[xx+0]=clip(((bufy[x+0]-16)*298)>>8);
-					b2[xx+1]=clip(((bufy[x+1]-16)*298)>>8);
+					b2[xx+0]=YUV2Y(bufy[x+0],0,0);
+					b2[xx+1]=YUV2Y(bufy[x+1],0,0);
 				}
 				out.send(bs,b2);
-			}
-			//out.send(sy*sx,buf);
+			}*/
+			out.send(sy*sx,buf);
 		} else if (cs=="rgb") {
 			for(int y=0; y<sy; bufy+=sx, bufu+=(sx/2)*(y&1), bufv+=(sx/2)*(y&1), y++) {
 				int Y1,Y2,U,V;
 				for (int x=0,xx=0; x<sx; x+=2,xx+=6) {
-					Y1=bufy[x]   - 16;
-					Y2=bufy[x+1] - 16;
-					U=bufu[x/2] - 128;
-					V=bufv[x/2] - 128;
-					b2[xx+0]=clip((298*Y1         + 409*V)>>8);
-					b2[xx+1]=clip((298*Y1 - 100*U - 208*V)>>8);
-					b2[xx+2]=clip((298*Y1 + 516*U        )>>8);
-					b2[xx+3]=clip((298*Y2         + 409*V)>>8);
-					b2[xx+4]=clip((298*Y2 - 100*U - 208*V)>>8);
-					b2[xx+5]=clip((298*Y2 + 516*U        )>>8);
+					Y1=bufy[x+0]; U=bufu[x/2]; Y2=bufy[x+1]; V=bufv[x/2];
+					b2[xx+0]=YUV2R(Y1,U,V); b2[xx+1]=YUV2G(Y1,U,V); b2[xx+2]=YUV2B(Y1,U,V);
+					b2[xx+3]=YUV2R(Y2,U,V); b2[xx+4]=YUV2G(Y2,U,V); b2[xx+5]=YUV2B(Y2,U,V);
 				}
 				out.send(bs,b2);
 			}
 		} else if (cs=="yuv") {
 			for(int y=0; y<sy; bufy+=sx, bufu+=(sx/2)*(y&1), bufv+=(sx/2)*(y&1), y++) {
-				int U,V;
+				int Y1,Y2,U,V;
 				for (int x=0,xx=0; x<sx; x+=2,xx+=6) {
-					U=bufu[x/2];
-					V=bufv[x/2];
-					b2[xx+0]=clip(((bufy[x+0]-16)*298)>>8);
-					b2[xx+1]=clip(128+(((U-128)*293)>>8));
-					b2[xx+2]=clip(128+(((V-128)*293)>>8));
-					b2[xx+3]=clip(((bufy[x+1]-16)*298)>>8);
-					b2[xx+4]=clip(128+(((U-128)*293)>>8));
-					b2[xx+5]=clip(128+(((V-128)*293)>>8));
+					Y1=bufy[x+0]; U=bufu[x/2]; Y2=bufy[x+1]; V=bufv[x/2];
+					b2[xx+0]=YUV2Y(Y1,U,V); b2[xx+1]=YUV2U(Y1,U,V); b2[xx+2]=YUV2V(Y1,U,V);
+					b2[xx+3]=YUV2Y(Y2,U,V); b2[xx+4]=YUV2U(Y2,U,V); b2[xx+5]=YUV2V(Y2,U,V);
 				}
 				out.send(bs,b2);
 			}



More information about the Gridflow-cvs mailing list