[FFmpeg-devel] [PATCH] Interleaved memset/memcpy.

Måns Rullgård mans
Mon Aug 24 12:29:10 CEST 2009


Nathan Caldwell <saintdev at gmail.com> writes:

> This patch adds an interleaved memset (useful for setting rows of
> pixels in eg: packed RGB). And an interleaved memcpy (useful for
> planar -> packed RGB).

Interleaved implies to me that two or more sources are interleaved
into the destination.  I'm thinking "sparse" would be a better
description of these.

> -- 
> -Nathan Caldwell
>
> diff --git libavutil/mem.c libavutil/mem.c
> index 741450b..3618112 100644
> --- libavutil/mem.c
> +++ libavutil/mem.c
> @@ -157,3 +157,43 @@ char *av_strdup(const char *s)
>      return ptr;
>  }
>  
> +char *av_interleave_memcpy(char *dest, const char *src, unsigned int n,
> +                           unsigned int step)
> +{
> +    int i, j;
> +    if (step == 1)
> +        return memcpy(dest, src, n);
> +
> +    for (i = j = 0; i < n - 1; i++) {
> +        dest[j] = src[i];
> +        j += step;
> +        i++;
> +        dest[j] = src[i];
> +        j += step;
> +    }

Is this unrolling really necessary?  Doesn't gcc unroll loops like
this anyway?

> +    for(; i < n; i++) {
> +        dest[j] = src[i];
> +        j += step;
> +    }
> +
> +    return dest;
> +}
> +
> +void av_interleave_memset(char *ptr, char c, unsigned int n, unsigned int step)
> +{
> +    int i;
> +    if (step == 1) {
> +        memset(ptr, c, n);
> +        return;
> +    }
> +
> +    for (i = 0; i < (n - 1) * step; i += step) {
> +        ptr[i] = c;
> +        i += step;
> +        ptr[i] = c;
> +    }
> +
> +    for (; i < n * step; i += step)
> +        ptr[i] = c;
> +}

Same as above.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list