[FFmpeg-devel] [PATCH] sws: Rotated Dispersed Dither for unscaled yuv->mono

Michael Niedermayer michaelni at gmx.at
Fri Jan 18 20:55:55 CET 2013


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libswscale/output.c           |   12 ++++++++++++
 libswscale/swscale_internal.h |    1 +
 libswscale/yuv2rgb.c          |   16 +++++++++++-----
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/libswscale/output.c b/libswscale/output.c
index 8c20068..ae8096e 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -134,6 +134,18 @@ DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
 };
 #endif
 
+DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8d_220)[][64]={
+{179,148,  3,168, 58, 17, 72,217,  0,110,192,124, 48,213,103, 31, 86,175, 52,162,189,138,  7,172, 62, 21, 76,206, 10,120,203,134, 45,210,100, 34, 89,165, 41,151,179,148,  3,168, 58, 17, 72,217,  0,110,192,124, 48,213,103, 31, 86,175, 52,162,189,138,  7,172,},
+{120, 38, 93, 45,155,100,182,144,165, 55,151, 14, 69,  3,113, 58,196,127,217,107,110, 28, 82, 48,158,103,186,141,175, 65,162, 24, 79,  7,117, 62,199,131,206, 96,120, 38, 93, 45,155,100,182,144,165, 55,151, 14, 69,  3,113, 58,196,127,217,107,110, 28, 82, 48,},
+{ 65,203, 24,134,210,117, 34,199, 89, 41, 96,179, 38,148,168,155, 17,182, 72,  0, 55,192, 14,124,213,113, 31,196, 86, 52,107,189, 28,138,172,158, 21,186, 76, 10, 65,203, 24,134,210,117, 34,199, 89, 41, 96,179, 38,148,168,155, 17,182, 72,  0, 55,192, 14,124,},
+{175,162,189, 79,138,  7, 62, 21,131, 76,206,120,203, 93,134, 45,100, 34,144, 89,165,151,179, 69,148,  3, 58, 17,127, 72,217,110,192, 82,124, 48,103, 31,141, 86,175,162,189, 79,138,  7, 62, 21,131, 76,206,120,203, 93,134, 45,100, 34,144, 89,165,151,179, 69,},
+{ 52,217,107, 28, 82,172, 48,158,186,141, 10,175, 65, 24, 79,210,  7,117,199,131, 41,206, 96, 38, 93,168, 45,155,182,144,  0,165, 55, 14, 69,213,  3,113,196,127, 52,217,107, 28, 82,172, 48,158,186,141, 10,175, 65, 24, 79,210,  7,117,199,131, 41,206, 96, 38,},
+{ 72,  0,110, 55,192,124,213,103,113, 31, 86, 52,162,107,189,138,172, 62,158, 21, 76, 10,120, 65,203,134,210,100,117, 34, 89, 41,151, 96,179,148,168, 58,155, 17, 72,  0,110, 55,192,124,213,103,113, 31, 86, 52,162,107,189,138,172, 62,158, 21, 76, 10,120, 65,},
+{ 34,144,165,151, 14,179, 69,  3, 58,196, 17,127,217,110, 28,192, 82, 48,103,186, 31,141,175,162, 24,189, 79,  7, 62,199, 21,131,206,120, 38,203, 93, 45,100,182, 34,144,165,151, 14,179, 69,  3, 58,196, 17,127,217,110, 28,192, 82, 48,103,186, 31,141,175,162,},
+{199, 89,131, 41, 96, 38,148, 93,168,155,182, 72,144,  0, 55, 14,124, 69,213,113,196, 86,127, 52,107, 28,138, 82,172,158,186, 76,141, 10, 65, 24,134, 79,210,117,199, 89,131, 41, 96, 38,148, 93,168,155,182, 72,144,  0, 55, 14,124, 69,213,113,196, 86,127, 52,},
+{ 62, 21, 76,206, 10,120,203,134, 45,210,100, 34, 89,165, 41,151,179,148,  3,168, 58, 17, 72,217,  0,110,192,124, 48,213,103, 31, 86,175, 52,162,189,138,  7,172, 62, 21, 76,206, 10,120,203,134, 45,210,100, 34, 89,165, 41,151,179,148,  3,168, 58, 17, 72,217,},
+};
+
 #define output_pixel(pos, val, bias, signedness) \
     if (big_endian) { \
         AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index 6a942d6..dd1eebb 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -742,6 +742,7 @@ extern const uint64_t ff_dither8[2];
 extern const uint8_t dithers[8][8][8];
 extern const uint16_t dither_scale[15][16];
 
+extern const uint8_t ff_dither_8x8d_220[9][64];
 
 extern const AVClass sws_context_class;
 
diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c
index 53b69d0..184618f 100644
--- a/libswscale/yuv2rgb.c
+++ b/libswscale/yuv2rgb.c
@@ -142,6 +142,7 @@ const int *sws_getCoefficients(int colorspace)
             const uint8_t *pv   = src[2] + (y >> 1) * srcStride[2];         \
             const uint8_t av_unused *pa_1, *pa_2;                           \
             unsigned int h_size = c->dstW >> 3;                             \
+            int dither_idx = 24*(y/8)%40;                                   \
             if (alpha) {                                                    \
                 pa_1 = src[3] + y * srcStride[3];                           \
                 pa_2 = pa_1   +     srcStride[3];                           \
@@ -578,8 +579,13 @@ YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
 CLOSEYUV2RGBFUNC(8)
 
 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
-    const uint8_t *d128 = dither_8x8_220[y & 7];
+    const uint8_t *d128 = ff_dither_8x8d_220[y & 7] + dither_idx;
     char out_1 = 0, out_2 = 0;
+
+    dither_idx += 8;
+    if (dither_idx == 40)
+        dither_idx = 0;
+
     g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
 
 #define PUTRGB1(out, src, i, o)                     \
@@ -589,15 +595,15 @@ YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
     out += out + g[Y + d128[1 + o]];
 
     PUTRGB1(out_1, py_1, 0, 0);
-    PUTRGB1(out_2, py_2, 0, 0 + 8);
+    PUTRGB1(out_2, py_2, 0, 0 + 64);
 
-    PUTRGB1(out_2, py_2, 1, 2 + 8);
+    PUTRGB1(out_2, py_2, 1, 2 + 64);
     PUTRGB1(out_1, py_1, 1, 2);
 
     PUTRGB1(out_1, py_1, 2, 4);
-    PUTRGB1(out_2, py_2, 2, 4 + 8);
+    PUTRGB1(out_2, py_2, 2, 4 + 64);
 
-    PUTRGB1(out_2, py_2, 3, 6 + 8);
+    PUTRGB1(out_2, py_2, 3, 6 + 64);
     PUTRGB1(out_1, py_1, 3, 6);
 
     dst_1[0] = out_1;
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list