[xiph-cvs] cvs commit: w3d yuv.c

Holger Waechtler holger at xiph.org
Wed Mar 28 03:41:38 PST 2001



holger      01/03/28 03:41:37

  Modified:    .        yuv.c
  Log:
  - fix the off-by-one bug.
  - indexed access of arrays should be easier to unroll for the compiler

Revision  Changes    Path
1.3       +34 -31    w3d/yuv.c

Index: yuv.c
===================================================================
RCS file: /usr/local/cvsroot/w3d/yuv.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- yuv.c	2001/02/13 15:38:05	1.2
+++ yuv.c	2001/03/28 11:41:37	1.3
@@ -1,46 +1,49 @@
 #include "yuv.h"
 
-void rgb2yuv (uint8 *rgb, int16 *y, int16 *u, int16 *v, uint32 count, uint32 stride)
+
+void rgb2yuv (uint8 *rgb, int16 *y, int16 *u, int16 *v, uint32 count, uint32 rgbstride)
 {
-   while (count) {
-      count--;
-      rgb += stride;
-      y++; u++; v++;
-
-#ifdef TARKIN_YUV_EXACT
-      *y = ((int16)  77 * rgb [0] + 150 * rgb [1] +  29 * rgb [2]) / 256;
-      *u = ((int16) -44 * rgb [0] -  87 * rgb [1] + 131 * rgb [2]) / 256;
-      *v = ((int16) 131 * rgb [0] - 110 * rgb [1] -  21 * rgb [2]) / 256;
+   int i;
+
+#if defined(TARKIN_YUV_EXACT)
+   for (i=0; i<count; i++, rgb+=rgbstride) {
+      y [i] = ((int16)  77 * rgb [0] + 150 * rgb [1] +  29 * rgb [2]) / 256;
+      u [i] = ((int16) -44 * rgb [0] -  87 * rgb [1] + 131 * rgb [2]) / 256;
+      v [i] = ((int16) 131 * rgb [0] - 110 * rgb [1] -  21 * rgb [2]) / 256;
+   }
 #else
-      *u = rgb [0] - rgb [1];
-      *v = rgb [2] - rgb [1];
-      *y = rgb [1] + ((*u + *v) >> 2);
-#endif
+   for (i=0; i<count; i++, rgb+=rgbstride) {
+      u [i] = rgb [0] - rgb [1];
+      v [i] = rgb [2] - rgb [1];
+      y [i] = rgb [1] + ((u [i] + v [i]) >> 2);
    }
+#endif
 }
 
 
-#define CLAMP(x) x
-#undef CLAMP
-static inline uint8 CLAMP(int16 x) { return  x > 255 ? 255 : x < 0 ? 0 : x; }
+static inline 
+uint8 CLAMP(int16 x)
+{
+   return  ((x > 255) ? 255 : (x < 0) ? 0 : x);
+}
 
 
-void yuv2rgb (int16 *y, int16 *u, int16 *v, uint8 *rgb, uint32 count, uint32 stride)
+void yuv2rgb (int16 *y, int16 *u, int16 *v, uint8 *rgb, uint32 count, uint32 rgbstride)
 {
-   while (count) {
-      count--;
-      rgb += stride;
-      y++; u++; v++;
-
-#ifdef TARKIN_YUV_EXACT
-      rgb [0] = CLAMP(*y + 1.371 * (*v));
-      rgb [1] = CLAMP(*y - 0.698 * (*v) - 0.336 * (*u));
-      rgb [2] = CLAMP(*y + 1.732 * (*u));
+   int i;
+
+#if defined(TARKIN_YUV_EXACT)
+   for (i=0; i<count; i++, rgb+=rgbstride) {
+      rgb [0] = CLAMP(y [i] + 1.371 * v [i]);
+      rgb [1] = CLAMP(y [i] - 0.698 * v [i] - 0.336 * u [i]);
+      rgb [2] = CLAMP(y [i] + 1.732 * u [i]);
+   }
 #else
-      rgb [1] = CLAMP(*y - ((*u + *v) >> 2));
-      rgb [2] = CLAMP(*v + rgb [1]);
-      rgb [0] = CLAMP(*u + rgb [1]);
-#endif
+   for (i=0; i<count; i++, rgb+=rgbstride) {
+      rgb [1] = CLAMP(y [i] - ((u [i] + v [i]) >> 2));
+      rgb [2] = CLAMP(v [i] + rgb [1]);
+      rgb [0] = CLAMP(u [i] + rgb [1]);
    }
+#endif
 }
 

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list