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

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Sat Mar 27 18:35:58 EDT 2010


Author: matju
Date: Sat Mar 27 18:35:57 2010
New Revision: 5189

Log:
adding YUYV support (palette 8)

Modified:
    trunk/src/videodev.cxx

Modified: trunk/src/videodev.cxx
==============================================================================
--- trunk/src/videodev.cxx (original)
+++ trunk/src/videodev.cxx Sat Mar 27 18:35:57 2010
@@ -347,6 +347,9 @@
 #define YUV2U(Y,U,V) clip(((             293*(U-128)              )>>8)+128)
 #define YUV2V(Y,U,V) clip(((                           293*(V-128))>>8)+128)
 #define YUV2YUV(b,Y,U,V) (b)[0]=YUV2Y(Y,U,V); (b)[1]=YUV2U(Y,U,V); (b)[2]=YUV2V(Y,U,V);
+// these are other macros specific to frame_finished
+#define GET420P(x) do {Y1=bufy[(x)+0]; U=bufu[(x)/2]; Y2=bufy[(x)+1]; V=bufv[(x)/2];} while (0)
+#define GETYUYV(x) do {Y1=bufy[(x)+0]; U=bufy[(x)+1]; Y2=bufy[(x)+2]; V=bufy[(x)+3];} while (0)
 void FormatVideoDev::frame_finished (uint8 *buf) {
 	string cs = colorspace->s_name;
 	int downscale = cs=="magic";
@@ -356,44 +359,51 @@
 	int bs = dim->prod(1); if (downscale) bs/=2;
 	uint8 b2[bs];
 	//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;
-		#define GET420(x) do {Y1=bufy[x+0]; U=bufu[x/2]; Y2=bufy[x+1]; V=bufv[x/2];} while (0)
-		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        ;}
+	if (vp.palette==VIDEO_PALETTE_YUYV) {
+		uint8 *bufy = buf;
 		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 x=0,xx=0; x<sx; x+=2,xx+=2) {
-					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);
+		    for(int y=0; y<sy; bufy+=sx, y++) {
+			for (int x=0,xx=0; x<sx; x+=2,xx+=4) {
+				b2[xx+0]=YUV2Y(bufy[x+0],0,0);
+				b2[xx+1]=YUV2Y(bufy[x+2],0,0);
+			}
+			out.send(bs,b2);
+		    }
 		} 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) {GET420(x); YUV2RGB(b2+xx,Y1,U,V); YUV2RGB(b2+xx+3,Y2,U,V);}
-			    out.send(bs,b2);
-			}
+		    for(int y=0; y<sy; bufy+=sx*2, y++) {int Y1,Y2,U,V;
+			for (int x=0,xx=0; x<sx; x+=4,xx+=6) {GETYUYV(x); YUV2RGB(b2+xx,Y1,U,V); YUV2RGB(b2+xx+3,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 Y1,Y2,U,V;
-			    for (int x=0,xx=0; x<sx; x+=2,xx+=6) {GET420(x); YUV2YUV(b2+xx,Y1,U,V); YUV2YUV(b2+xx+3,Y2,U,V);}
-			    out.send(bs,b2);
-			}
+		    for(int y=0; y<sy; bufy+=sx*2, y++) {int Y1,Y2,U,V;
+			for (int x=0,xx=0; x<sx; x+=4,xx+=6) {GETYUYV(x); YUV2YUV(b2+xx,Y1,U,V); YUV2YUV(b2+xx+3,Y2,U,V);}
+			out.send(bs,b2);}
 		} else if (cs=="magic") {
-			if (vp.palette==VIDEO_PALETTE_YUYV) RAISE("can't convert YUYV (YUV422) to magic");
-			int sx2 = sx/2;
-			for(int y=0; y<sy/2; bufy+=2*sx, bufu+=sx2, bufv+=sx2, y++) {
- 				for (int x=0,xx=0; x<sx2; x++,xx+=3) {
-					b2[xx+0]=bufy[x+x];
-					b2[xx+1]=bufu[x];
-					b2[xx+2]=bufv[x];
-				}
-				out.send(bs,b2);
-			}
+		    int sx2 = sx/2;
+		    for(int y=0; y<sy/2; bufy+=2*sx, y++) {
+ 			for (int x=0,xx=0; x<sx2; x+=3,xx+=3) {b2[xx+0]=bufy[x+0]; b2[xx+1]=bufy[x+1]; b2[xx+2]=bufy[x+3];}
+			out.send(bs,b2);
+		    }
+		}
+	} else if (vp.palette==VIDEO_PALETTE_YUV420P) {
+		uint8 *bufy = buf, *bufu = buf+sx*sy, *bufv = buf+sx*sy*5/4;
+		GridOutlet out(this,0,cs=="magic"?new Dim(sy>>downscale,sx>>downscale,3):(Dim *)dim,cast);
+		if (cs=="y") {
+		    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) {GET420P(x); YUV2RGB(b2+xx,Y1,U,V); YUV2RGB(b2+xx+3,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 Y1,Y2,U,V;
+			for (int x=0,xx=0; x<sx; x+=2,xx+=6) {GET420P(x); YUV2YUV(b2+xx,Y1,U,V); YUV2YUV(b2+xx+3,Y2,U,V);}
+			out.send(bs,b2);}
+		} else if (cs=="magic") {
+		    int sx2 = sx/2;
+		    for(int y=0; y<sy/2; bufy+=2*sx, bufu+=sx2, bufv+=sx2, y++) {
+ 			for (int x=0,xx=0; x<sx2; x++,xx+=3) {b2[xx+0]=bufy[x+x]; b2[xx+1]=bufu[x]; b2[xx+2]=bufv[x];}
+			out.send(bs,b2);
+		    }
 		}
 	} else if (vp.palette==VIDEO_PALETTE_RGB32 || vp.palette==VIDEO_PALETTE_RGB24 || vp.palette==VIDEO_PALETTE_RGB565) {
 		GridOutlet out(this,0,dim,cast);
@@ -411,7 +421,7 @@
 		} else if (cs=="rgb") {
 			for(int y=0; y<sy; y++) {
 			        bit_packing->unpack(sx,buf+y*sx*bit_packing->bytes,rgb);
-				out.send(bs,rgb);
+			 	out.send(bs,rgb);
 			}
 		} else if (cs=="yuv") {
 			for(int y=0; y<sy; y++) {



More information about the Gridflow-cvs mailing list