[Gridflow-cvs] [svn] commit: r5853 - /trunk/src/colorspace.hxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Thu Jul 29 21:12:21 EDT 2010


Author: matju
Date: Thu Jul 29 21:12:21 2010
New Revision: 5853

Log:
add parens all over the macros to protect operation order

Modified:
    trunk/src/colorspace.hxx

Modified: trunk/src/colorspace.hxx
==============================================================================
--- trunk/src/colorspace.hxx (original)
+++ trunk/src/colorspace.hxx Thu Jul 29 21:12:21 2010
@@ -25,27 +25,27 @@
 extern int cliptab[1024]; // lut for clipping because YUV2R,G,B formula outputs can go from -317 to 573.
 inline uint8 fastclip(int x) {return cliptab[x+384];} // be careful with this !
 // these convert from reduced-range YUV to full-range RGB
-#define YUV2R(Y,U,V) fastclip( (298*(Y-16)               + 409*(V-128) +128)>>8)
-#define YUV2G(Y,U,V) fastclip( (298*(Y-16) - 100*(U-128) - 208*(V-128) +128)>>8)
-#define YUV2B(Y,U,V) fastclip( (298*(Y-16) + 516*(U-128)               +128)>>8)
+#define YUV2R(Y,U,V) fastclip( (298*((Y)-16)                 + 409*((V)-128) +128)>>8)
+#define YUV2G(Y,U,V) fastclip( (298*((Y)-16) - 100*((U)-128) - 208*((V)-128) +128)>>8)
+#define YUV2B(Y,U,V) fastclip( (298*((Y)-16) + 516*((U)-128)                 +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) fastclip( (298*(Y-16)                             +128)>>8)
-#define YUV2U(Y,U,V) fastclip(((             293*(U-128)               +128)>>8)+128)
-#define YUV2V(Y,U,V) fastclip(((                           293*(V-128) +128)>>8)+128)
+#define YUV2Y(Y,U,V) fastclip( (298*((Y)-16)                                 +128)>>8)
+#define YUV2U(Y,U,V) fastclip(((               293*((U)-128)                 +128)>>8)+128)
+#define YUV2V(Y,U,V) fastclip(((                               293*((V)-128) +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)
 #define GETYUYV(x) do {Y1=bufy[(x)+0]; U=bufy[(x)+1]; Y2=bufy[(x)+2]; V=bufy[(x)+3];} while (0)
 
 // these convert from full-range RGB to full-range YUV
-#define RGB2Y(R,G,B)  fastclip(    ((  76*R + 150*G +  29*B +128)>>8))
-#define RGB2U(R,G,B)  fastclip(128+((- 44*R -  85*G + 108*B +128)>>8))
-#define RGB2V(R,G,B)  fastclip(128+(( 128*R - 108*G -  21*B +128)>>8))
+#define RGB2Y(R,G,B)  fastclip(    ((  76*(R) + 150*(G) +  29*(B) +128)>>8))
+#define RGB2U(R,G,B)  fastclip(128+((- 44*(R) -  85*(G) + 108*(B) +128)>>8))
+#define RGB2V(R,G,B)  fastclip(128+(( 128*(R) - 108*(G) -  21*(B) +128)>>8))
 
 // these convert from full-range RGB to reduced-range YUV
-#define RGB2Y_(R,G,B) fastclip(    ((  66*R + 129*G +  25*B +128)>>8))
-#define RGB2U_(R,G,B) fastclip(128+((- 38*R -  74*G + 112*B +128)>>8))
-#define RGB2V_(R,G,B) fastclip(128+(( 112*R -  94*G -  18*B +128)>>8))
+#define RGB2Y_(R,G,B) fastclip(    ((  66*(R) + 129*(G) +  25*(B) +128)>>8))
+#define RGB2U_(R,G,B) fastclip(128+((- 38*(R) -  74*(G) + 112*(B) +128)>>8))
+#define RGB2V_(R,G,B) fastclip(128+(( 112*(R) -  94*(G) -  18*(B) +128)>>8))
 
 #endif // __COLORSPACE_H



More information about the Gridflow-cvs mailing list