[FFmpeg-cvslog] dsputil: Split off HuffYUV encoding bits into their own context

Diego Biurrun git at videolan.org
Wed May 28 00:26:46 CEST 2014


ffmpeg | branch: master | Diego Biurrun <diego at biurrun.de> | Mon Dec 23 18:42:11 2013 +0100| [512f3ffe9b4bb86767c2b1176554407c75fe1a5c] | committer: Diego Biurrun

dsputil: Split off HuffYUV encoding bits into their own context

Also shorten HuffYUV context member names to avoid clutter.

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

 configure                          |    7 ++-
 libavcodec/Makefile                |    1 +
 libavcodec/dsputil.c               |   56 ------------------
 libavcodec/dsputil.h               |   13 -----
 libavcodec/huffyuv.h               |    2 +
 libavcodec/huffyuvenc.c            |   36 ++++++------
 libavcodec/huffyuvencdsp.c         |   84 +++++++++++++++++++++++++++
 libavcodec/huffyuvencdsp.h         |   41 +++++++++++++
 libavcodec/pngenc.c                |   16 ++---
 libavcodec/utvideo.h               |    2 +
 libavcodec/utvideoenc.c            |    4 +-
 libavcodec/x86/Makefile            |    1 +
 libavcodec/x86/dsputilenc_mmx.c    |   68 ----------------------
 libavcodec/x86/huffyuvencdsp_mmx.c |  113 ++++++++++++++++++++++++++++++++++++
 14 files changed, 278 insertions(+), 166 deletions(-)

diff --git a/configure b/configure
index 2349863..a7a3ac2 100755
--- a/configure
+++ b/configure
@@ -1542,6 +1542,7 @@ CONFIG_EXTRA="
     hpeldsp
     huffman
     huffyuvdsp
+    huffyuvencdsp
     intrax8
     lgplv3
     lpc
@@ -1773,7 +1774,7 @@ h264_decoder_select="cabac golomb h264chroma h264dsp h264pred h264qpel videodsp"
 h264_decoder_suggest="error_resilience"
 hevc_decoder_select="cabac dsputil golomb videodsp"
 huffyuv_decoder_select="dsputil huffyuvdsp"
-huffyuv_encoder_select="dsputil huffman"
+huffyuv_encoder_select="dsputil huffman huffyuvencdsp"
 iac_decoder_select="imc_decoder"
 imc_decoder_select="dsputil fft mdct sinewin"
 indeo3_decoder_select="hpeldsp"
@@ -1826,7 +1827,7 @@ on2avc_decoder_select="mdct"
 opus_decoder_deps="avresample"
 png_decoder_deps="zlib"
 png_encoder_deps="zlib"
-png_encoder_select="dsputil"
+png_encoder_select="huffyuvencdsp"
 prores_decoder_select="dsputil"
 prores_encoder_select="dsputil"
 qcelp_decoder_select="lsp"
@@ -1857,7 +1858,7 @@ truespeech_decoder_select="dsputil"
 tscc_decoder_deps="zlib"
 twinvq_decoder_select="mdct lsp sinewin"
 utvideo_decoder_select="dsputil"
-utvideo_encoder_select="dsputil huffman"
+utvideo_encoder_select="dsputil huffman huffyuvencdsp"
 vble_decoder_select="huffyuvdsp"
 vc1_decoder_select="error_resilience h263_decoder h264chroma h264qpel intrax8"
 vc1image_decoder_select="vc1_decoder"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ffe93f9..7060979 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -47,6 +47,7 @@ OBJS-$(CONFIG_H264QPEL)                += h264qpel.o
 OBJS-$(CONFIG_HPELDSP)                 += hpeldsp.o
 OBJS-$(CONFIG_HUFFMAN)                 += huffman.o
 OBJS-$(CONFIG_HUFFYUVDSP)              += huffyuvdsp.o
+OBJS-$(CONFIG_HUFFYUVENCDSP)           += huffyuvencdsp.o
 OBJS-$(CONFIG_INTRAX8)                 += intrax8.o intrax8dsp.o
 OBJS-$(CONFIG_LIBXVID)                 += libxvid_rc.o
 OBJS-$(CONFIG_LPC)                     += lpc.o
diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c
index 2e23ef3..ab0206b 100644
--- a/libavcodec/dsputil.c
+++ b/libavcodec/dsputil.c
@@ -53,10 +53,6 @@ uint32_t ff_square_tab[512] = { 0, };
 #include "dsputil_template.c"
 #include "dsputilenc_template.c"
 
-// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
-#define pb_7f (~0UL / 255 * 0x7f)
-#define pb_80 (~0UL / 255 * 0x80)
-
 const uint8_t ff_alternate_horizontal_scan[64] = {
      0,  1,  2,  3,  8,  9, 16, 17,
     10, 11,  4,  5,  6,  7, 15, 14,
@@ -1663,55 +1659,6 @@ void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type)
     }
 }
 
-static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, 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];
-            dst[i + 1] = src1[i + 1] - src2[i + 1];
-            dst[i + 2] = src1[i + 2] - src2[i + 2];
-            dst[i + 3] = src1[i + 3] - src2[i + 3];
-            dst[i + 4] = src1[i + 4] - src2[i + 4];
-            dst[i + 5] = src1[i + 5] - src2[i + 5];
-            dst[i + 6] = src1[i + 6] - src2[i + 6];
-            dst[i + 7] = src1[i + 7] - src2[i + 7];
-        }
-    } else
-#endif
-    for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
-        long a = *(long *) (src1 + i);
-        long b = *(long *) (src2 + i);
-        *(long *) (dst + i) = ((a | pb_80) - (b & pb_7f)) ^
-                              ((a ^ b ^ pb_80) & pb_80);
-    }
-    for (; i < w; i++)
-        dst[i + 0] = src1[i + 0] - src2[i + 0];
-}
-
-static void sub_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1,
-                                         const uint8_t *src2, int w,
-                                         int *left, int *left_top)
-{
-    int i;
-    uint8_t l, lt;
-
-    l  = *left;
-    lt = *left_top;
-
-    for (i = 0; i < w; i++) {
-        const int pred = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF);
-        lt     = src1[i];
-        l      = src2[i];
-        dst[i] = l - pred;
-    }
-
-    *left     = l;
-    *left_top = lt;
-}
-
 #define BUTTERFLY2(o1, o2, i1, i2)              \
     o1 = (i1) + (i2);                           \
     o2 = (i1) - (i2);
@@ -2485,9 +2432,6 @@ av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
 
     c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
 
-    c->diff_bytes                 = diff_bytes_c;
-    c->sub_hfyu_median_prediction = sub_hfyu_median_prediction_c;
-
     c->bswap_buf   = bswap_buf;
     c->bswap16_buf = bswap16_buf;
 
diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h
index 8c95e78..2cfbd55 100644
--- a/libavcodec/dsputil.h
+++ b/libavcodec/dsputil.h
@@ -185,19 +185,6 @@ typedef struct DSPContext {
 
     me_cmp_func pix_abs[2][4];
 
-    /* HuffYUV specific */
-    void (*diff_bytes)(uint8_t *dst /* align 16 */,
-                       uint8_t *src1 /* align 16 */,
-                       uint8_t *src2 /* align 1 */,
-                       int w);
-    /**
-     * Subtract HuffYUV's variant of median prediction.
-     * Note, this might read from src1[-1], src2[-1].
-     */
-    void (*sub_hfyu_median_prediction)(uint8_t *dst, const uint8_t *src1,
-                                       const uint8_t *src2, int w,
-                                       int *left, int *left_top);
-
     void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
     void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
 
diff --git a/libavcodec/huffyuv.h b/libavcodec/huffyuv.h
index 14b4abc..f76d62a 100644
--- a/libavcodec/huffyuv.h
+++ b/libavcodec/huffyuv.h
@@ -35,6 +35,7 @@
 #include "dsputil.h"
 #include "get_bits.h"
 #include "huffyuvdsp.h"
+#include "huffyuvencdsp.h"
 #include "put_bits.h"
 
 #define VLC_BITS 11
@@ -83,6 +84,7 @@ typedef struct HYuvContext {
     unsigned int bitstream_buffer_size;
     DSPContext dsp;
     HuffYUVDSPContext hdsp;
+    HuffYUVEncDSPContext hencdsp;
 } HYuvContext;
 
 void ff_huffyuv_common_init(AVCodecContext *s);
diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c
index 1442b75..b401a95 100644
--- a/libavcodec/huffyuvenc.c
+++ b/libavcodec/huffyuvenc.c
@@ -29,6 +29,7 @@
 #include "avcodec.h"
 #include "huffyuv.h"
 #include "huffman.h"
+#include "huffyuvencdsp.h"
 #include "put_bits.h"
 
 static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst,
@@ -48,7 +49,7 @@ static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst,
             dst[i] = temp - left;
             left   = temp;
         }
-        s->dsp.diff_bytes(dst + 16, src + 16, src + 15, w - 16);
+        s->hencdsp.diff_bytes(dst + 16, src + 16, src + 15, w - 16);
         return src[w-1];
     }
 }
@@ -80,7 +81,7 @@ static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst,
         a = at;
     }
 
-    s->dsp.diff_bytes(dst + 16, src + 16, src + 12, w * 4 - 16);
+    s->hencdsp.diff_bytes(dst + 16, src + 16, src + 12, w * 4 - 16);
 
     *red   = src[(w - 1) * 4 + R];
     *green = src[(w - 1) * 4 + G];
@@ -109,7 +110,7 @@ static inline void sub_left_prediction_rgb24(HYuvContext *s, uint8_t *dst,
         b = bt;
     }
 
-    s->dsp.diff_bytes(dst + 48, src + 48, src + 48 - 3, w * 3 - 48);
+    s->hencdsp.diff_bytes(dst + 48, src + 48, src + 48 - 3, w * 3 - 48);
 
     *red   = src[(w - 1) * 3 + 0];
     *green = src[(w - 1) * 3 + 1];
@@ -146,6 +147,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
     int i, j;
 
     ff_huffyuv_common_init(avctx);
+    ff_huffyuvencdsp_init(&s->hencdsp);
 
     avctx->extradata = av_mallocz(1024*30); // 256*3+4 == 772
     avctx->stats_out = av_mallocz(1024*30); // 21*256*3(%llu ) + 3(\n) + 1(0) = 16132
@@ -503,9 +505,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
             lefttopy = p->data[0][3];
             lefttopu = p->data[1][1];
             lefttopv = p->data[2][1];
-            s->dsp.sub_hfyu_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride + 4, width - 4 , &lefty, &lefttopy);
-            s->dsp.sub_hfyu_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride + 2, width2 - 2, &leftu, &lefttopu);
-            s->dsp.sub_hfyu_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride + 2, width2 - 2, &leftv, &lefttopv);
+            s->hencdsp.sub_hfyu_median_pred(s->temp[0], p->data[0] + 4, p->data[0] + fake_ystride + 4, width  - 4, &lefty, &lefttopy);
+            s->hencdsp.sub_hfyu_median_pred(s->temp[1], p->data[1] + 2, p->data[1] + fake_ustride + 2, width2 - 2, &leftu, &lefttopu);
+            s->hencdsp.sub_hfyu_median_pred(s->temp[2], p->data[2] + 2, p->data[2] + fake_vstride + 2, width2 - 2, &leftv, &lefttopv);
             encode_422_bitstream(s, 0, width - 4);
             y++; cy++;
 
@@ -515,7 +517,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                 if (s->bitstream_bpp == 12) {
                     while (2 * cy > y) {
                         ydst = p->data[0] + p->linesize[0] * y;
-                        s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
+                        s->hencdsp.sub_hfyu_median_pred(s->temp[0], ydst - fake_ystride, ydst, width, &lefty, &lefttopy);
                         encode_gray_bitstream(s, width);
                         y++;
                     }
@@ -525,9 +527,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                 udst = p->data[1] + p->linesize[1] * cy;
                 vdst = p->data[2] + p->linesize[2] * cy;
 
-                s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
-                s->dsp.sub_hfyu_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
-                s->dsp.sub_hfyu_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
+                s->hencdsp.sub_hfyu_median_pred(s->temp[0], ydst - fake_ystride, ydst, width,  &lefty, &lefttopy);
+                s->hencdsp.sub_hfyu_median_pred(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
+                s->hencdsp.sub_hfyu_median_pred(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
 
                 encode_422_bitstream(s, 0, width);
             }
@@ -540,7 +542,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                     ydst = p->data[0] + p->linesize[0] * y;
 
                     if (s->predictor == PLANE && s->interlaced < y) {
-                        s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
+                        s->hencdsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
 
                         lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
                     } else {
@@ -556,9 +558,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                 vdst = p->data[2] + p->linesize[2] * cy;
 
                 if (s->predictor == PLANE && s->interlaced < cy) {
-                    s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
-                    s->dsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2);
-                    s->dsp.diff_bytes(s->temp[2] + width2, vdst, vdst - fake_vstride, width2);
+                    s->hencdsp.diff_bytes(s->temp[1],          ydst, ydst - fake_ystride, width);
+                    s->hencdsp.diff_bytes(s->temp[2],          udst, udst - fake_ustride, width2);
+                    s->hencdsp.diff_bytes(s->temp[2] + width2, vdst, vdst - fake_vstride, width2);
 
                     lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
                     leftu = sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu);
@@ -591,7 +593,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         for (y = 1; y < s->height; y++) {
             uint8_t *dst = data + y*stride;
             if (s->predictor == PLANE && s->interlaced < y) {
-                s->dsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width * 4);
+                s->hencdsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width * 4);
                 sub_left_prediction_bgr32(s, s->temp[0], s->temp[1], width,
                                           &leftr, &leftg, &leftb, &lefta);
             } else {
@@ -619,8 +621,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         for (y = 1; y < s->height; y++) {
             uint8_t *dst = data + y * stride;
             if (s->predictor == PLANE && s->interlaced < y) {
-                s->dsp.diff_bytes(s->temp[1], dst, dst - fake_stride,
-                                  width * 3);
+                s->hencdsp.diff_bytes(s->temp[1], dst, dst - fake_stride,
+                                      width * 3);
                 sub_left_prediction_rgb24(s, s->temp[0], s->temp[1], width,
                                           &leftr, &leftg, &leftb);
             } else {
diff --git a/libavcodec/huffyuvencdsp.c b/libavcodec/huffyuvencdsp.c
new file mode 100644
index 0000000..6c30877
--- /dev/null
+++ b/libavcodec/huffyuvencdsp.c
@@ -0,0 +1,84 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "libavutil/attributes.h"
+#include "huffyuvencdsp.h"
+#include "mathops.h"
+
+// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
+#define pb_7f (~0UL / 255 * 0x7f)
+#define pb_80 (~0UL / 255 * 0x80)
+
+static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, 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];
+            dst[i + 1] = src1[i + 1] - src2[i + 1];
+            dst[i + 2] = src1[i + 2] - src2[i + 2];
+            dst[i + 3] = src1[i + 3] - src2[i + 3];
+            dst[i + 4] = src1[i + 4] - src2[i + 4];
+            dst[i + 5] = src1[i + 5] - src2[i + 5];
+            dst[i + 6] = src1[i + 6] - src2[i + 6];
+            dst[i + 7] = src1[i + 7] - src2[i + 7];
+        }
+    } else
+#endif
+    for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
+        long a = *(long *) (src1 + i);
+        long b = *(long *) (src2 + i);
+        *(long *) (dst + i) = ((a | pb_80) - (b & pb_7f)) ^
+                              ((a ^ b ^ pb_80) & pb_80);
+    }
+    for (; i < w; i++)
+        dst[i + 0] = src1[i + 0] - src2[i + 0];
+}
+
+static void sub_hfyu_median_pred_c(uint8_t *dst, const uint8_t *src1,
+                                   const uint8_t *src2, int w,
+                                   int *left, int *left_top)
+{
+    int i;
+    uint8_t l, lt;
+
+    l  = *left;
+    lt = *left_top;
+
+    for (i = 0; i < w; i++) {
+        const int pred = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF);
+        lt     = src1[i];
+        l      = src2[i];
+        dst[i] = l - pred;
+    }
+
+    *left     = l;
+    *left_top = lt;
+}
+
+av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c)
+{
+    c->diff_bytes           = diff_bytes_c;
+    c->sub_hfyu_median_pred = sub_hfyu_median_pred_c;
+
+    if (ARCH_X86)
+        ff_huffyuvencdsp_init_x86(c);
+}
diff --git a/libavcodec/huffyuvencdsp.h b/libavcodec/huffyuvencdsp.h
new file mode 100644
index 0000000..603c36f
--- /dev/null
+++ b/libavcodec/huffyuvencdsp.h
@@ -0,0 +1,41 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_HUFFYUVENCDSP_H
+#define AVCODEC_HUFFYUVENCDSP_H
+
+#include <stdint.h>
+
+typedef struct HuffYUVEncDSPContext {
+    void (*diff_bytes)(uint8_t *dst /* align 16 */,
+                       uint8_t *src1 /* align 16 */,
+                       uint8_t *src2 /* align 1 */,
+                       int w);
+    /**
+     * Subtract HuffYUV's variant of median prediction.
+     * Note, this might read from src1[-1], src2[-1].
+     */
+    void (*sub_hfyu_median_pred)(uint8_t *dst, const uint8_t *src1,
+                                 const uint8_t *src2, int w,
+                                 int *left, int *left_top);
+} HuffYUVEncDSPContext;
+
+void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c);
+void ff_huffyuvencdsp_init_x86(HuffYUVEncDSPContext *c);
+
+#endif /* AVCODEC_HUFFYUVENCDSP_H */
diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index a6015ff..a349ee8 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -21,7 +21,7 @@
 
 #include "avcodec.h"
 #include "bytestream.h"
-#include "dsputil.h"
+#include "huffyuvencdsp.h"
 #include "png.h"
 
 /* TODO:
@@ -33,7 +33,7 @@
 #define IOBUF_SIZE 4096
 
 typedef struct PNGEncContext {
-    DSPContext dsp;
+    HuffYUVEncDSPContext hdsp;
 
     uint8_t *bytestream;
     uint8_t *bytestream_start;
@@ -111,7 +111,7 @@ static void sub_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top,
     }
 }
 
-static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type,
+static void png_filter_row(PNGEncContext *c, uint8_t *dst, int filter_type,
                            uint8_t *src, uint8_t *top, int size, int bpp)
 {
     int i;
@@ -121,11 +121,11 @@ static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type,
         memcpy(dst, src, size);
         break;
     case PNG_FILTER_VALUE_SUB:
-        dsp->diff_bytes(dst, src, src - bpp, size);
+        c->hdsp.diff_bytes(dst, src, src - bpp, size);
         memcpy(dst, src, bpp);
         break;
     case PNG_FILTER_VALUE_UP:
-        dsp->diff_bytes(dst, src, top, size);
+        c->hdsp.diff_bytes(dst, src, top, size);
         break;
     case PNG_FILTER_VALUE_AVG:
         for (i = 0; i < bpp; i++)
@@ -153,7 +153,7 @@ static uint8_t *png_choose_filter(PNGEncContext *s, uint8_t *dst,
         int cost, bcost = INT_MAX;
         uint8_t *buf1 = dst, *buf2 = dst + size + 16;
         for (pred = 0; pred < 5; pred++) {
-            png_filter_row(&s->dsp, buf1 + 1, pred, src, top, size, bpp);
+            png_filter_row(s, buf1 + 1, pred, src, top, size, bpp);
             buf1[0] = pred;
             cost = 0;
             for (i = 0; i <= size; i++)
@@ -165,7 +165,7 @@ static uint8_t *png_choose_filter(PNGEncContext *s, uint8_t *dst,
         }
         return buf2;
     } else {
-        png_filter_row(&s->dsp, dst + 1, pred, src, top, size, bpp);
+        png_filter_row(s, dst + 1, pred, src, top, size, bpp);
         dst[0] = pred;
         return dst;
     }
@@ -462,7 +462,7 @@ static av_cold int png_enc_init(AVCodecContext *avctx)
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
-    ff_dsputil_init(&s->dsp, avctx);
+    ff_huffyuvencdsp_init(&s->hdsp);
 
     s->filter_type = av_clip(avctx->prediction_method,
                              PNG_FILTER_VALUE_NONE,
diff --git a/libavcodec/utvideo.h b/libavcodec/utvideo.h
index 0a1317e..a430274 100644
--- a/libavcodec/utvideo.h
+++ b/libavcodec/utvideo.h
@@ -30,6 +30,7 @@
 #include "libavutil/common.h"
 #include "avcodec.h"
 #include "dsputil.h"
+#include "huffyuvencdsp.h"
 
 enum {
     PRED_NONE = 0,
@@ -66,6 +67,7 @@ extern const int ff_ut_rgb_order[4];
 typedef struct UtvideoContext {
     AVCodecContext *avctx;
     DSPContext     dsp;
+    HuffYUVEncDSPContext hdsp;
 
     uint32_t frame_info_size, flags, frame_info;
     int      planes;
diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c
index b63858d..7fa4389 100644
--- a/libavcodec/utvideoenc.c
+++ b/libavcodec/utvideoenc.c
@@ -31,6 +31,7 @@
 #include "bytestream.h"
 #include "put_bits.h"
 #include "dsputil.h"
+#include "huffyuvencdsp.h"
 #include "mathops.h"
 #include "utvideo.h"
 #include "huffman.h"
@@ -109,6 +110,7 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
     }
 
     ff_dsputil_init(&c->dsp, avctx);
+    ff_huffyuvencdsp_init(&c->hdsp);
 
     /* Check the prediction method, and error out if unsupported */
     if (avctx->prediction_method < 0 || avctx->prediction_method > 4) {
@@ -312,7 +314,7 @@ static void median_predict(UtvideoContext *c, uint8_t *src, uint8_t *dst, int st
 
     /* Rest of the coded part uses median prediction */
     for (j = 1; j < height; j++) {
-        c->dsp.sub_hfyu_median_prediction(dst, src - stride, src, width, &A, &B);
+        c->hdsp.sub_hfyu_median_pred(dst, src - stride, src, width, &A, &B);
         dst += width;
         src += stride;
     }
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index a354dd8..fef98a5 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -15,6 +15,7 @@ OBJS-$(CONFIG_H264PRED)                += x86/h264_intrapred_init.o
 OBJS-$(CONFIG_H264QPEL)                += x86/h264_qpel.o
 OBJS-$(CONFIG_HPELDSP)                 += x86/hpeldsp_init.o
 OBJS-$(CONFIG_HUFFYUVDSP)              += x86/huffyuvdsp_init.o
+OBJS-$(CONFIG_HUFFYUVENCDSP)           += x86/huffyuvencdsp_mmx.o
 OBJS-$(CONFIG_LPC)                     += x86/lpc.o
 OBJS-$(CONFIG_MPEGAUDIODSP)            += x86/mpegaudiodsp.o
 OBJS-$(CONFIG_MPEGVIDEO)               += x86/mpegvideo.o
diff --git a/libavcodec/x86/dsputilenc_mmx.c b/libavcodec/x86/dsputilenc_mmx.c
index dc57c69..79066a7 100644
--- a/libavcodec/x86/dsputilenc_mmx.c
+++ b/libavcodec/x86/dsputilenc_mmx.c
@@ -29,7 +29,6 @@
 #include "libavcodec/dct.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/mpegvideo.h"
-#include "libavcodec/mathops.h"
 #include "dsputil_x86.h"
 
 void ff_get_pixels_mmx(int16_t *block, const uint8_t *pixels, int line_size);
@@ -694,70 +693,6 @@ static int vsad16_mmxext(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
 }
 #undef SUM
 
-static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
-{
-    x86_reg i = 0;
-
-    __asm__ volatile (
-        "1:                             \n\t"
-        "movq  (%2, %0), %%mm0          \n\t"
-        "movq  (%1, %0), %%mm1          \n\t"
-        "psubb %%mm0, %%mm1             \n\t"
-        "movq %%mm1, (%3, %0)           \n\t"
-        "movq 8(%2, %0), %%mm0          \n\t"
-        "movq 8(%1, %0), %%mm1          \n\t"
-        "psubb %%mm0, %%mm1             \n\t"
-        "movq %%mm1, 8(%3, %0)          \n\t"
-        "add $16, %0                    \n\t"
-        "cmp %4, %0                     \n\t"
-        " jb 1b                         \n\t"
-        : "+r" (i)
-        : "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w - 15));
-
-    for (; i < w; i++)
-        dst[i + 0] = src1[i + 0] - src2[i + 0];
-}
-
-static void sub_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *src1,
-                                              const uint8_t *src2, int w,
-                                              int *left, int *left_top)
-{
-    x86_reg i = 0;
-    uint8_t l, lt;
-
-    __asm__ volatile (
-        "movq  (%1, %0), %%mm0          \n\t" // LT
-        "psllq $8, %%mm0                \n\t"
-        "1:                             \n\t"
-        "movq  (%1, %0), %%mm1          \n\t" // T
-        "movq  -1(%2, %0), %%mm2        \n\t" // L
-        "movq  (%2, %0), %%mm3          \n\t" // X
-        "movq %%mm2, %%mm4              \n\t" // L
-        "psubb %%mm0, %%mm2             \n\t"
-        "paddb %%mm1, %%mm2             \n\t" // L + T - LT
-        "movq %%mm4, %%mm5              \n\t" // L
-        "pmaxub %%mm1, %%mm4            \n\t" // max(T, L)
-        "pminub %%mm5, %%mm1            \n\t" // min(T, L)
-        "pminub %%mm2, %%mm4            \n\t"
-        "pmaxub %%mm1, %%mm4            \n\t"
-        "psubb %%mm4, %%mm3             \n\t" // dst - pred
-        "movq %%mm3, (%3, %0)           \n\t"
-        "add $8, %0                     \n\t"
-        "movq -1(%1, %0), %%mm0         \n\t" // LT
-        "cmp %4, %0                     \n\t"
-        " jb 1b                         \n\t"
-        : "+r" (i)
-        : "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w));
-
-    l  = *left;
-    lt = *left_top;
-
-    dst[0] = src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt) & 0xFF);
-
-    *left_top = src1[w - 1];
-    *left     = src2[w - 1];
-}
-
 #define MMABS_MMX(a,z)                          \
     "pxor "    #z ", " #z "             \n\t"   \
     "pcmpgtw " #a ", " #z "             \n\t"   \
@@ -1010,7 +945,6 @@ av_cold void ff_dsputilenc_init_mmx(DSPContext *c, AVCodecContext *avctx,
             (dct_algo == FF_DCT_AUTO || dct_algo == FF_DCT_MMX))
             c->fdct = ff_fdct_mmx;
 
-        c->diff_bytes      = diff_bytes_mmx;
         c->sum_abs_dctelem = sum_abs_dctelem_mmx;
 
         c->sse[0]  = sse16_mmx;
@@ -1046,8 +980,6 @@ av_cold void ff_dsputilenc_init_mmx(DSPContext *c, AVCodecContext *avctx,
         if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
             c->vsad[0] = vsad16_mmxext;
         }
-
-        c->sub_hfyu_median_prediction = sub_hfyu_median_prediction_mmxext;
     }
 
     if (INLINE_SSE2(cpu_flags)) {
diff --git a/libavcodec/x86/huffyuvencdsp_mmx.c b/libavcodec/x86/huffyuvencdsp_mmx.c
new file mode 100644
index 0000000..8ffaced
--- /dev/null
+++ b/libavcodec/x86/huffyuvencdsp_mmx.c
@@ -0,0 +1,113 @@
+/*
+ * SIMD-optimized HuffYUV encoding functions
+ * Copyright (c) 2000, 2001 Fabrice Bellard
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni at gmx.at>
+ *
+ * MMX optimization by Nick Kurshev <nickols_k at mail.ru>
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
+#include "libavcodec/huffyuvencdsp.h"
+#include "libavcodec/mathops.h"
+
+#if HAVE_INLINE_ASM
+
+static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
+{
+    x86_reg i = 0;
+
+    __asm__ volatile (
+        "1:                             \n\t"
+        "movq  (%2, %0), %%mm0          \n\t"
+        "movq  (%1, %0), %%mm1          \n\t"
+        "psubb %%mm0, %%mm1             \n\t"
+        "movq %%mm1, (%3, %0)           \n\t"
+        "movq 8(%2, %0), %%mm0          \n\t"
+        "movq 8(%1, %0), %%mm1          \n\t"
+        "psubb %%mm0, %%mm1             \n\t"
+        "movq %%mm1, 8(%3, %0)          \n\t"
+        "add $16, %0                    \n\t"
+        "cmp %4, %0                     \n\t"
+        " jb 1b                         \n\t"
+        : "+r" (i)
+        : "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w - 15));
+
+    for (; i < w; i++)
+        dst[i + 0] = src1[i + 0] - src2[i + 0];
+}
+
+static void sub_hfyu_median_pred_mmxext(uint8_t *dst, const uint8_t *src1,
+                                        const uint8_t *src2, int w,
+                                        int *left, int *left_top)
+{
+    x86_reg i = 0;
+    uint8_t l, lt;
+
+    __asm__ volatile (
+        "movq  (%1, %0), %%mm0          \n\t" // LT
+        "psllq $8, %%mm0                \n\t"
+        "1:                             \n\t"
+        "movq  (%1, %0), %%mm1          \n\t" // T
+        "movq  -1(%2, %0), %%mm2        \n\t" // L
+        "movq  (%2, %0), %%mm3          \n\t" // X
+        "movq %%mm2, %%mm4              \n\t" // L
+        "psubb %%mm0, %%mm2             \n\t"
+        "paddb %%mm1, %%mm2             \n\t" // L + T - LT
+        "movq %%mm4, %%mm5              \n\t" // L
+        "pmaxub %%mm1, %%mm4            \n\t" // max(T, L)
+        "pminub %%mm5, %%mm1            \n\t" // min(T, L)
+        "pminub %%mm2, %%mm4            \n\t"
+        "pmaxub %%mm1, %%mm4            \n\t"
+        "psubb %%mm4, %%mm3             \n\t" // dst - pred
+        "movq %%mm3, (%3, %0)           \n\t"
+        "add $8, %0                     \n\t"
+        "movq -1(%1, %0), %%mm0         \n\t" // LT
+        "cmp %4, %0                     \n\t"
+        " jb 1b                         \n\t"
+        : "+r" (i)
+        : "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w));
+
+    l  = *left;
+    lt = *left_top;
+
+    dst[0] = src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt) & 0xFF);
+
+    *left_top = src1[w - 1];
+    *left     = src2[w - 1];
+}
+
+#endif /* HAVE_INLINE_ASM */
+
+av_cold void ff_huffyuvencdsp_init_x86(HuffYUVEncDSPContext *c)
+{
+#if HAVE_INLINE_ASM
+    int cpu_flags = av_get_cpu_flags();
+
+    if (INLINE_MMX(cpu_flags)) {
+        c->diff_bytes = diff_bytes_mmx;
+    }
+
+    if (INLINE_MMXEXT(cpu_flags)) {
+        c->sub_hfyu_median_pred = sub_hfyu_median_pred_mmxext;
+    }
+#endif /* HAVE_INLINE_ASM */
+}



More information about the ffmpeg-cvslog mailing list