[Gridflow-cvs] [svn] commit: r5377 - in /trunk/src: colorspace.hxx formats.cxx videodev.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Wed Apr 7 21:20:49 EDT 2010


Author: matju
Date: Wed Apr  7 21:20:48 2010
New Revision: 5377

Log:
split away fastclip (renamed from just 'clip') and its lut

Added:
    trunk/src/colorspace.hxx
Modified:
    trunk/src/formats.cxx
    trunk/src/videodev.cxx

Modified: trunk/src/formats.cxx
==============================================================================
--- trunk/src/formats.cxx (original)
+++ trunk/src/formats.cxx Wed Apr  7 21:20:48 2010
@@ -274,6 +274,10 @@
 
 \end class FormatGrid {install_format("#io.grid",6,"grid");}
 
+// this line goes with colorspace.hxx
+int cliptab[1024];
+
 void startup_format () {
 	\startall
-}
+	for (int i=0; i<1024; i++) cliptab[i] = min(255,max(0,i-384));
+}

Modified: trunk/src/videodev.cxx
==============================================================================
--- trunk/src/videodev.cxx (original)
+++ trunk/src/videodev.cxx Wed Apr  7 21:20:48 2010
@@ -27,6 +27,7 @@
  * apparently not all of them. but I can't tell which. it remains a mystery. */
 
 #include "gridflow.hxx.fcs"
+#include "colorspace.hxx"
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
@@ -337,22 +338,15 @@
 	next_frame = (next_frame+1) % vmbuf.frames;
 }
 
-// YUV2R,G,B formula outputs can go from -317 to 573.
-static int cliptab[1024];
-static uint8 clip(int x) {return cliptab[x+384];} // be careful with this !
-
-//static uint8 clip(int x) {return x<0?0 : x>255?255 : x;}
-//#define clip
-
 // these convert from reduced-range YUV to full-range RGB
-#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)
+#define YUV2R(Y,U,V) fastclip( (298*(Y-16)               + 409*(V-128))>>8)
+#define YUV2G(Y,U,V) fastclip( (298*(Y-16) - 100*(U-128) - 208*(V-128))>>8)
+#define YUV2B(Y,U,V) fastclip( (298*(Y-16) + 516*(U-128)              )>>8)
 #define YUV2RGB(b,Y,U,V) (b)[0]=YUV2R(Y,U,V); (b)[1]=YUV2G(Y,U,V); (b)[2]=YUV2B(Y,U,V);
 // these convert from reduced-range YUV to full-range YUV
-#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)
+#define YUV2Y(Y,U,V) fastclip( (298*(Y-16)                            )>>8)
+#define YUV2U(Y,U,V) fastclip(((             293*(U-128)              )>>8)+128)
+#define YUV2V(Y,U,V) fastclip(((                           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 for reading different memory layouts of YUV
 #define GET420P(x) do {Y1=bufy[(x)+0]; U=bufu[(x)/2]; Y2=bufy[(x)+1]; V=bufv[(x)/2];} while (0)
@@ -451,12 +445,12 @@
 			for(int y=0; y<sy; y++) {
 				bit_packing3->unpack(sx,buf+y*sx*bit_packing3->bytes,rgb);
 				for (int x=0,xx=0; x<sx; x+=2,xx+=6) {
-					b2[xx+0] = clip(    ((  76*rgb[xx+0] + 150*rgb[xx+1] +  29*rgb[xx+2])>>8));
-					b2[xx+1] = clip(128+((- 44*rgb[xx+0] -  85*rgb[xx+1] + 108*rgb[xx+2])>>8));
-					b2[xx+2] = clip(128+(( 128*rgb[xx+0] - 108*rgb[xx+1] -  21*rgb[xx+2])>>8));
-					b2[xx+3] = clip(    ((  76*rgb[xx+3] + 150*rgb[xx+4] +  29*rgb[xx+5])>>8));
-					b2[xx+4] = clip(128+((- 44*rgb[xx+3] -  85*rgb[xx+4] + 108*rgb[xx+5])>>8));
-					b2[xx+5] = clip(128+(( 128*rgb[xx+3] - 108*rgb[xx+4] -  21*rgb[xx+5])>>8));
+					b2[xx+0] = fastclip(    ((  76*rgb[xx+0] + 150*rgb[xx+1] +  29*rgb[xx+2])>>8));
+					b2[xx+1] = fastclip(128+((- 44*rgb[xx+0] -  85*rgb[xx+1] + 108*rgb[xx+2])>>8));
+					b2[xx+2] = fastclip(128+(( 128*rgb[xx+0] - 108*rgb[xx+1] -  21*rgb[xx+2])>>8));
+					b2[xx+3] = fastclip(    ((  76*rgb[xx+3] + 150*rgb[xx+4] +  29*rgb[xx+5])>>8));
+					b2[xx+4] = fastclip(128+((- 44*rgb[xx+3] -  85*rgb[xx+4] + 108*rgb[xx+5])>>8));
+					b2[xx+5] = fastclip(128+(( 128*rgb[xx+3] - 108*rgb[xx+4] -  21*rgb[xx+5])>>8));
 				}
 				out.send(bs,b2);
 			}
@@ -725,5 +719,4 @@
 \end class FormatVideoDev {install_format("#io.videodev",4,"");}
 void startup_videodev () {
 	\startall
-	for (int i=0; i<1024; i++) cliptab[i] = min(255,max(0,i-384));
-}
+}



More information about the Gridflow-cvs mailing list