[PATCH 1/2] Implement function to generate rgb4/bgrToYUV tables.

Stefano Sabatini stefano.sabatini-lala
Fri May 14 00:39:56 CEST 2010


---
 swscale-test.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/swscale-test.c b/swscale-test.c
index 887973a..2b6d651 100644
--- a/swscale-test.c
+++ b/swscale-test.c
@@ -225,6 +225,62 @@ static void selfTest(uint8_t *ref[4], int refStride[4], int w, int h)
 #define W 96
 #define H 96
 
+#define RGB2YUV_SHIFT 15
+#define BY ( (int)(0.114*219/255*(1<<RGB2YUV_SHIFT)+0.5))
+#define BV (-(int)(0.081*224/255*(1<<RGB2YUV_SHIFT)+0.5))
+#define BU ( (int)(0.500*224/255*(1<<RGB2YUV_SHIFT)+0.5))
+#define GY ( (int)(0.587*219/255*(1<<RGB2YUV_SHIFT)+0.5))
+#define GV (-(int)(0.419*224/255*(1<<RGB2YUV_SHIFT)+0.5))
+#define GU (-(int)(0.331*224/255*(1<<RGB2YUV_SHIFT)+0.5))
+#define RY ( (int)(0.299*219/255*(1<<RGB2YUV_SHIFT)+0.5))
+#define RV ( (int)(0.500*224/255*(1<<RGB2YUV_SHIFT)+0.5))
+#define RU (-(int)(0.169*224/255*(1<<RGB2YUV_SHIFT)+0.5))
+
+int main(void)
+{
+    int i, j, tmp, r, g, b;
+
+    static uint8_t rgb4ToYUV_table[3][16];
+    static uint8_t bgr4ToYUV_table[3][16];
+
+    for (i = 0; i < 16; i++) {
+        r = ( i       & 1) * 255;
+        g = ((i >> 1) & 3) * 85;
+        b = ((i >> 3) & 1) * 255;
+        rgb4ToYUV_table[0][i] = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
+        rgb4ToYUV_table[1][i] = ((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128;
+        rgb4ToYUV_table[2][i] = ((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128;
+
+        tmp = b; b = r; r = tmp;
+        bgr4ToYUV_table[0][i] = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
+        bgr4ToYUV_table[1][i] = ((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128;
+        bgr4ToYUV_table[2][i] = ((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128;
+    }
+
+    printf("static const uint8_t rgb4ToYUV_table[3][16] = {\n");
+    for (i = 0; i < 3; i++) {
+        printf("{ ");
+        for (j = 0; j < 16; j++) {
+            printf("%3d, ", rgb4ToYUV_table[i][j]);
+        }
+        printf("},\n");
+    }
+    printf("};\n");
+
+    printf("static const uint8_t bgr4ToYUV_table[3][16] = {\n");
+    for (i = 0; i < 3; i++) {
+        printf("{ ");
+        for (j = 0; j < 16; j++) {
+            printf("%3d, ", bgr4ToYUV_table[i][j]);
+        }
+        printf("},\n");
+    }
+    printf("};\n");
+
+    return 0;
+}
+
+#if 0
 int main(int argc, char **argv)
 {
     uint8_t *rgb_data = av_malloc (W*H*4);
@@ -258,3 +314,4 @@ int main(int argc, char **argv)
 
     return 0;
 }
+#endif
-- 
1.7.0


--NzB8fVQJ5HfG6fxh
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0002-Implement-bgr4-and-rgb4-bitstream-input-support.patch"




More information about the ffmpeg-devel mailing list