[FFmpeg-cvslog] avcodec/dsputil/huffyuv: move diff int16 and add int16 to dsputil

Michael Niedermayer git at videolan.org
Mon Jan 20 04:10:08 CET 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Mon Jan 20 03:50:43 2014 +0100| [da0684820a58ce42a5a2953cbce417e06a54be8f] | committer: Michael Niedermayer

avcodec/dsputil/huffyuv: move diff int16 and add int16 to dsputil

This also fixes masking the bits

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=da0684820a58ce42a5a2953cbce417e06a54be8f
---

 libavcodec/dsputil.c    |   41 +++++++++++++++++++++++++++++++++++++++++
 libavcodec/dsputil.h    |    2 ++
 libavcodec/huffyuvdec.c |   15 +--------------
 libavcodec/huffyuvenc.c |   11 +----------
 4 files changed, 45 insertions(+), 24 deletions(-)

diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c
index 0e9e347..8533e53 100644
--- a/libavcodec/dsputil.c
+++ b/libavcodec/dsputil.c
@@ -1888,6 +1888,45 @@ static void diff_bytes_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
         dst[i+0] = src1[i+0]-src2[i+0];
 }
 
+static void add_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, int w){
+    long i;
+    unsigned long pw_lsb = (mask >> 1) * 0x0001000100010001ULL;
+    unsigned long pw_msb = pw_lsb +  0x0001000100010001ULL;
+    for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) {
+        long a = *(long*)(src+i);
+        long b = *(long*)(dst+i);
+        *(long*)(dst+i) = ((a&pw_lsb) + (b&pw_lsb)) ^ ((a^b)&pw_msb);
+    }
+    for(; i<w; i++)
+        dst[i] = (dst[i] + src[i]) & mask;
+}
+
+static void diff_int16_c(uint16_t *dst, const uint16_t *src1, const uint16_t *src2, unsigned mask, int w){
+    long i;
+#if !HAVE_FAST_UNALIGNED
+    if((long)src2 & (sizeof(long)-1)){
+        for(i=0; i+7<w; i+=8){
+            dst[i+0] = (src1[i+0]-src2[i+0]) & mask;
+            dst[i+1] = (src1[i+1]-src2[i+1]) & mask;
+            dst[i+2] = (src1[i+2]-src2[i+2]) & mask;
+            dst[i+3] = (src1[i+3]-src2[i+3]) & mask;
+        }
+    }else
+#endif
+    {
+        unsigned long pw_lsb = (mask >> 1) * 0x0001000100010001ULL;
+        unsigned long pw_msb = pw_lsb +  0x0001000100010001ULL;
+
+        for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) {
+            long a = *(long*)(src1+i);
+            long b = *(long*)(src2+i);
+            *(long*)(dst+i) = ((a|pw_msb) - (b&pw_lsb)) ^ ((a^b^pw_msb)&pw_msb);
+        }
+    }
+    for (; i<w; i++)
+        dst[i] = (src1[i] - src2[i]) & mask;
+}
+
 static void add_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *diff, int w, int *left, int *left_top){
     int i;
     uint8_t l, lt;
@@ -2773,6 +2812,8 @@ av_cold void ff_dsputil_init(DSPContext* c, AVCodecContext *avctx)
 
     c->add_bytes= add_bytes_c;
     c->diff_bytes= diff_bytes_c;
+    c->add_int16 = add_int16_c;
+    c->diff_int16= diff_int16_c;
     c->add_hfyu_median_prediction= add_hfyu_median_prediction_c;
     c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
     c->add_hfyu_left_prediction  = add_hfyu_left_prediction_c;
diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h
index 0897c56..7ad96f6 100644
--- a/libavcodec/dsputil.h
+++ b/libavcodec/dsputil.h
@@ -193,6 +193,8 @@ typedef struct DSPContext {
     /* huffyuv specific */
     void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
     void (*diff_bytes)(uint8_t *dst/*align 16*/, const uint8_t *src1/*align 16*/, const uint8_t *src2/*align 1*/,int w);
+    void (*add_int16)(uint16_t *dst/*align 16*/, const uint16_t *src/*align 16*/, unsigned mask, int w);
+    void (*diff_int16)(uint16_t *dst/*align 16*/, const uint16_t *src1/*align 16*/, const uint16_t *src2/*align 1*/, unsigned mask, int w);
     /**
      * subtract huffyuv's variant of median prediction
      * note, this might read from src1[-1], src2[-1]
diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
index ced22f6..aafa9e4 100644
--- a/libavcodec/huffyuvdec.c
+++ b/libavcodec/huffyuvdec.c
@@ -708,20 +708,7 @@ static void add_bytes(HYuvContext *s, uint8_t *dst, uint8_t *src, int w)
     if (s->bps <= 8) {
         s->dsp.add_bytes(dst, src, w);
     } else {
-        //FIXME optimize
-        const uint16_t *src16 = (const uint16_t *)src;
-        uint16_t       *dst16 = (      uint16_t *)dst;
-        long i;
-        unsigned long msb = 0x1000100010001ULL << (s->bps-1);
-        unsigned long lsb = msb - 0x1000100010001ULL;
-        unsigned long mask = lsb + msb;
-        for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) {
-            long a = *(long*)(src16+i);
-            long b = *(long*)(dst16+i);
-            *(long*)(dst16+i) = ((a&lsb) + (b&lsb)) ^ ((a^b)&msb);
-        }
-        for(; i<w; i++)
-            dst16[i] = (dst16[i] + src16[i]) & mask;
+        s->dsp.add_int16((uint16_t*)dst, (const uint16_t*)src, s->n - 1, w);
     }
 }
 
diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c
index 5fb7d0c..2bc95b5 100644
--- a/libavcodec/huffyuvenc.c
+++ b/libavcodec/huffyuvenc.c
@@ -38,19 +38,10 @@
 static inline void diff_bytes(HYuvContext *s, uint8_t *dst,
                               const uint8_t *src0, const uint8_t *src1, int w)
 {
-    int i;
     if (s->bps <= 8) {
         s->dsp.diff_bytes(dst, src0, src1, w);
     } else {
-        const uint16_t *src016 = (const uint16_t *)src0;
-        const uint16_t *src116 = (const uint16_t *)src1;
-        uint16_t       *dst16  = (      uint16_t *)dst;
-
-        for (i = 0; i < w; i++) {
-            dst16[i] = src016[i] - src116[i];
-        }
-
-        //FIXME optimize
+        s->dsp.diff_int16((uint16_t *)dst, (const uint16_t *)src0, (const uint16_t *)src1, s->n - 1, w);
     }
 }
 



More information about the ffmpeg-cvslog mailing list