dsputil: add bswap16_buf()

Message ID 1300286405-19314-1-git-send-email-mans@mansr.com
State Committed
Commit 381d37fda91494e312ab2938080a379c5e11998b
Headers show

Commit Message

Mans Rullgard March 16, 2011, 2:40 p.m.
There several places where a buffer is byte-swapped in 16-bit units.
This allows them to share code which can be optimised for various
architectures.

Signed-off-by: Mans Rullgard <mans@mansr.com>
---
 libavcodec/dsputil.c |    7 +++++++
 libavcodec/dsputil.h |    1 +
 2 files changed, 8 insertions(+), 0 deletions(-)

Comments

Kostya Shishkov March 16, 2011, 2:51 p.m. | #1
On Wed, Mar 16, 2011 at 02:40:05PM +0000, Mans Rullgard wrote:
> There several places where a buffer is byte-swapped in 16-bit units.
> This allows them to share code which can be optimised for various
> architectures.
> 
> Signed-off-by: Mans Rullgard <mans@mansr.com>
> ---
>  libavcodec/dsputil.c |    7 +++++++
>  libavcodec/dsputil.h |    1 +
>  2 files changed, 8 insertions(+), 0 deletions(-)
> 
> diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c
> index 1f7bd4c..b293642 100644
> --- a/libavcodec/dsputil.c
> +++ b/libavcodec/dsputil.c
> @@ -222,6 +222,12 @@ static void bswap_buf(uint32_t *dst, const uint32_t *src, int w){
>      }
>  }
>  
> +static void bswap16_buf(uint16_t *dst, const uint16_t *src, int len)
> +{
> +    while (len--)
> +        *dst++ = av_bswap16(*src++);
> +}
> +
>  static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
>  {
>      int s, i;
> @@ -4324,6 +4330,7 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
>      c->add_hfyu_left_prediction  = add_hfyu_left_prediction_c;
>      c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c;
>      c->bswap_buf= bswap_buf;
> +    c->bswap16_buf = bswap16_buf;
>  #if CONFIG_PNG_DECODER
>      c->add_png_paeth_prediction= ff_add_png_paeth_prediction;
>  #endif
> diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h
> index b4798b3..a37475f 100644
> --- a/libavcodec/dsputil.h
> +++ b/libavcodec/dsputil.h
> @@ -369,6 +369,7 @@ typedef struct DSPContext {
>      /* this might write to dst[w] */
>      void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
>      void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
> +    void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
>  
>      void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
>      void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
> -- 
> 1.7.4.1

looks ok
Luca Barbato March 16, 2011, 2:52 p.m. | #2
On 03/16/2011 03:40 PM, Mans Rullgard wrote:
> There several places where a buffer is byte-swapped in 16-bit units.
> This allows them to share code which can be optimised for various
> architectures.

Ok, let see with the usage which is the best alignment constraint if any.

lu

Patch

diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c
index 1f7bd4c..b293642 100644
--- a/libavcodec/dsputil.c
+++ b/libavcodec/dsputil.c
@@ -222,6 +222,12 @@  static void bswap_buf(uint32_t *dst, const uint32_t *src, int w){
     }
 }
 
+static void bswap16_buf(uint16_t *dst, const uint16_t *src, int len)
+{
+    while (len--)
+        *dst++ = av_bswap16(*src++);
+}
+
 static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
 {
     int s, i;
@@ -4324,6 +4330,7 @@  av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
     c->add_hfyu_left_prediction  = add_hfyu_left_prediction_c;
     c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c;
     c->bswap_buf= bswap_buf;
+    c->bswap16_buf = bswap16_buf;
 #if CONFIG_PNG_DECODER
     c->add_png_paeth_prediction= ff_add_png_paeth_prediction;
 #endif
diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h
index b4798b3..a37475f 100644
--- a/libavcodec/dsputil.h
+++ b/libavcodec/dsputil.h
@@ -369,6 +369,7 @@  typedef struct DSPContext {
     /* this might write to dst[w] */
     void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
     void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
+    void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
 
     void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
     void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);