diff mbox

[FFmpeg-devel,v3,3/5] libavcodec/v210enc: move the duplicate code to template file

Message ID 20190901132023.28531-3-lance.lmwang@gmail.com
State New
Headers show

Commit Message

Lance Wang Sept. 1, 2019, 1:20 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/v210_template.c | 48 +++++++++++++++++++++++++++++++++++++++++
 libavcodec/v210enc.c       | 54 +++++++++++++---------------------------------
 2 files changed, 63 insertions(+), 39 deletions(-)
 create mode 100644 libavcodec/v210_template.c

Comments

Lance Wang Sept. 1, 2019, 2:50 p.m. UTC | #1
Please use this version, change libavcodec to avcodec in the subject for consistent.

On Sun, Sep 01, 2019 at 10:48:22PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavcodec/v210_template.c | 48 +++++++++++++++++++++++++++++++++++++++++
>  libavcodec/v210enc.c       | 54 +++++++++++++---------------------------------
>  2 files changed, 63 insertions(+), 39 deletions(-)
>  create mode 100644 libavcodec/v210_template.c
> 
> diff --git a/libavcodec/v210_template.c b/libavcodec/v210_template.c
> new file mode 100644
> index 0000000..00036ae
> --- /dev/null
> +++ b/libavcodec/v210_template.c
> @@ -0,0 +1,48 @@
> +/*
> + * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
> + * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg 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.
> + *
> + * FFmpeg 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 FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "bytestream.h"
> +#include "internal.h"
> +
> +#define CLIP(v, depth) av_clip(v, 1<<(depth-8), ((1<<depth)-(1<<(depth-8))-1))
> +#define WRITE_PIXELS(a, b, c, depth)                      \
> +    do {                                                  \
> +        val  =  CLIP(*a++, depth)  << (10-depth);         \
> +        val |=  (CLIP(*b++, depth) << (20-depth)) |       \
> +                (CLIP(*c++, depth) << (30-depth));        \
> +        AV_WL32(dst, val);                                \
> +        dst += 4;                                         \
> +    } while (0)
> +
> +static void RENAME(v210_planar_pack)(const TYPE *y,
> +        const TYPE *u, const TYPE *v,
> +        uint8_t *dst, ptrdiff_t width)
> +{
> +    uint32_t val;
> +    int i;
> +
> +    for (i = 0; i < width - 5; i += 6) {
> +        WRITE_PIXELS(u, y, v, DEPTH);
> +        WRITE_PIXELS(y, u, y, DEPTH);
> +        WRITE_PIXELS(v, y, u, DEPTH);
> +        WRITE_PIXELS(y, v, y, DEPTH);
> +    }
> +}
> diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c
> index 69a2efe..3e6abbe 100644
> --- a/libavcodec/v210enc.c
> +++ b/libavcodec/v210enc.c
> @@ -26,45 +26,21 @@
>  #include "internal.h"
>  #include "v210enc.h"
>  
> -#define CLIP(v, depth) av_clip(v, 1 << (depth-8), ((1 << depth)-(1 << (depth-8))-1))
> -#define WRITE_PIXELS(a, b, c, depth)                      \
> -    do {                                                  \
> -        val  =  CLIP(*a++, depth)  << (10-depth);         \
> -        val |=  (CLIP(*b++, depth) << (20-depth)) |       \
> -                (CLIP(*c++, depth) << (30-depth));        \
> -        AV_WL32(dst, val);                                \
> -        dst += 4;                                         \
> -    } while (0)
> -
> -static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u,
> -                                 const uint8_t *v, uint8_t *dst,
> -                                 ptrdiff_t width)
> -{
> -    uint32_t val;
> -    int i;
> -
> -    for (i = 0; i < width - 5; i += 6) {
> -        WRITE_PIXELS(u, y, v, 8);
> -        WRITE_PIXELS(y, u, y, 8);
> -        WRITE_PIXELS(v, y, u, 8);
> -        WRITE_PIXELS(y, v, y, 8);
> -    }
> -}
> -
> -static void v210_planar_pack_10_c(const uint16_t *y, const uint16_t *u,
> -                                  const uint16_t *v, uint8_t *dst,
> -                                  ptrdiff_t width)
> -{
> -    uint32_t val;
> -    int i;
> -
> -    for (i = 0; i < width - 5; i += 6) {
> -        WRITE_PIXELS(u, y, v, 10);
> -        WRITE_PIXELS(y, u, y, 10);
> -        WRITE_PIXELS(v, y, u, 10);
> -        WRITE_PIXELS(y, v, y, 10);
> -    }
> -}
> +#define TYPE uint8_t
> +#define DEPTH 8
> +#define RENAME(a) a ## _ ## 8 ##  _c
> +#include "v210_template.c"
> +#undef TYPE
> +#undef RENAME
> +#undef DEPTH
> +
> +#define TYPE uint16_t
> +#define DEPTH 10
> +#define RENAME(a) a ## _ ## 10 ##  _c
> +#include "v210_template.c"
> +#undef TYPE
> +#undef RENAME
> +#undef DEPTH
>  
>  av_cold void ff_v210enc_init(V210EncContext *s)
>  {
> -- 
> 2.6.4
>
diff mbox

Patch

diff --git a/libavcodec/v210_template.c b/libavcodec/v210_template.c
new file mode 100644
index 0000000..00036ae
--- /dev/null
+++ b/libavcodec/v210_template.c
@@ -0,0 +1,48 @@ 
+/*
+ * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "bytestream.h"
+#include "internal.h"
+
+#define CLIP(v, depth) av_clip(v, 1<<(depth-8), ((1<<depth)-(1<<(depth-8))-1))
+#define WRITE_PIXELS(a, b, c, depth)                      \
+    do {                                                  \
+        val  =  CLIP(*a++, depth)  << (10-depth);         \
+        val |=  (CLIP(*b++, depth) << (20-depth)) |       \
+                (CLIP(*c++, depth) << (30-depth));        \
+        AV_WL32(dst, val);                                \
+        dst += 4;                                         \
+    } while (0)
+
+static void RENAME(v210_planar_pack)(const TYPE *y,
+        const TYPE *u, const TYPE *v,
+        uint8_t *dst, ptrdiff_t width)
+{
+    uint32_t val;
+    int i;
+
+    for (i = 0; i < width - 5; i += 6) {
+        WRITE_PIXELS(u, y, v, DEPTH);
+        WRITE_PIXELS(y, u, y, DEPTH);
+        WRITE_PIXELS(v, y, u, DEPTH);
+        WRITE_PIXELS(y, v, y, DEPTH);
+    }
+}
diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c
index 69a2efe..3e6abbe 100644
--- a/libavcodec/v210enc.c
+++ b/libavcodec/v210enc.c
@@ -26,45 +26,21 @@ 
 #include "internal.h"
 #include "v210enc.h"
 
-#define CLIP(v, depth) av_clip(v, 1 << (depth-8), ((1 << depth)-(1 << (depth-8))-1))
-#define WRITE_PIXELS(a, b, c, depth)                      \
-    do {                                                  \
-        val  =  CLIP(*a++, depth)  << (10-depth);         \
-        val |=  (CLIP(*b++, depth) << (20-depth)) |       \
-                (CLIP(*c++, depth) << (30-depth));        \
-        AV_WL32(dst, val);                                \
-        dst += 4;                                         \
-    } while (0)
-
-static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u,
-                                 const uint8_t *v, uint8_t *dst,
-                                 ptrdiff_t width)
-{
-    uint32_t val;
-    int i;
-
-    for (i = 0; i < width - 5; i += 6) {
-        WRITE_PIXELS(u, y, v, 8);
-        WRITE_PIXELS(y, u, y, 8);
-        WRITE_PIXELS(v, y, u, 8);
-        WRITE_PIXELS(y, v, y, 8);
-    }
-}
-
-static void v210_planar_pack_10_c(const uint16_t *y, const uint16_t *u,
-                                  const uint16_t *v, uint8_t *dst,
-                                  ptrdiff_t width)
-{
-    uint32_t val;
-    int i;
-
-    for (i = 0; i < width - 5; i += 6) {
-        WRITE_PIXELS(u, y, v, 10);
-        WRITE_PIXELS(y, u, y, 10);
-        WRITE_PIXELS(v, y, u, 10);
-        WRITE_PIXELS(y, v, y, 10);
-    }
-}
+#define TYPE uint8_t
+#define DEPTH 8
+#define RENAME(a) a ## _ ## 8 ##  _c
+#include "v210_template.c"
+#undef TYPE
+#undef RENAME
+#undef DEPTH
+
+#define TYPE uint16_t
+#define DEPTH 10
+#define RENAME(a) a ## _ ## 10 ##  _c
+#include "v210_template.c"
+#undef TYPE
+#undef RENAME
+#undef DEPTH
 
 av_cold void ff_v210enc_init(V210EncContext *s)
 {