[FFmpeg-devel] Extend/optimize RGB to RGB conversions funcs into rgb2rgb.c

Michael Niedermayer michaelni at gmx.at
Tue Sep 11 03:45:13 CEST 2012


On Sun, Sep 09, 2012 at 11:00:51PM +0200, yann.lepetitcorps at free.fr wrote:
> Here is the .diff file about rgb32torgb24() and rgb24torgb32() funcs
> modifications as generated by the command "git diff"
> 
> => is it on the good format ?
[...]
>  void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size)
>  {
>      int i;
> +    uint8_t *psrc;
> +
> +    psrc = (uint8_t *)src;

you dont need the temporary variable
the pointer isnt constant (wouldnt make sense anyway) its the data
to which it points that may not be changed through the src pointer.


>  
> -    for (i = 0; 3 * i < src_size; i++) {
> +    for (i = 0 ; i < src_size; i += 3 ) {
>  #if HAVE_BIGENDIAN
>          /* RGB24 (= R, G, B) -> BGR32 (= A, R, G, B) */
> -        dst[4 * i + 0] = 255;
> -        dst[4 * i + 1] = src[3 * i + 0];
> -        dst[4 * i + 2] = src[3 * i + 1];
> -        dst[4 * i + 3] = src[3 * i + 2];
> +        dst[0] = 255;
> +        dst[1] = psrc[0];
> +        dst[2] = psrc[1];
> +        dst[3] = psrc[2];
>  #else
> -        dst[4 * i + 0] = src[3 * i + 2];
> -        dst[4 * i + 1] = src[3 * i + 1];
> -        dst[4 * i + 2] = src[3 * i + 0];
> -        dst[4 * i + 3] = 255;
> +        dst[0] = psrc[2];
> +        dst[1] = psrc[1];
> +        dst[2] = psrc[0];
> +        dst[3] = 255;
>  #endif
> +        psrc += 3;
> +	dst += 4;
>      }

instead of using "i" in the loop you could try to use

while(dst < dst_end) {
    ...
}


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is what and why we do it that matters, not just one of them.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120911/042ca5fb/attachment.asc>


More information about the ffmpeg-devel mailing list