[FFmpeg-devel] Extend/optimize RGB to RGB conversions funcsintorgb2rgb.c

Don Moir donmoir at comcast.net
Mon Sep 10 21:52:52 CEST 2012


----- Original Message ----- 
From: "Don Moir" <donmoir at comcast.net>
To: "FFmpeg development discussions and patches" <ffmpeg-devel at ffmpeg.org>
Sent: Monday, September 10, 2012 3:48 PM
Subject: Re: [FFmpeg-devel] Extend/optimize RGB to RGB conversions 
funcsintorgb2rgb.c


>> void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size )
>> {
>>    int i;
>>    uint8_t *psrc = src;
>>
>>    for ( i = 0 ; i < src_size ; i += 3, psrc +=3, dst +=4 )
>>    {
>> #if HAVE_BIGENDIAN
>>        /* RGB24 (= R,G,B) -> BGR32 (= 255,R,G,B) */
>>        dst[0] = 255;
>>        dst[1] = psrc[0];
>>        dst[2] = psrc[1];
>>        dst[3] = psrc[2];
>> #else
>>        dst[0] = psrc[2];
>>        dst[1] = psrc[1];
>>        dst[2] = psrc[0];
>>        dst[3] = 255;
>> #endif
>>    }
>> }
>
> You might try something like this that does 4 pixels within the loop. It 
> might be interesting to see if performance is better for this. I do it asm 
> and don't do it line by line for my own purposes.
>
> Note: somewhat pseudo code. I do it differently so modified here.
>
> void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size )
> {
>    int nPixels = src_size / 3;
>    int pixels4 = nPixels >> 2;
>    int extra = nPixels % 4;
>    uint32_t* pDst (uint32_t*)dst;
>    uint32_t* pSrc (uint32_t*)src;
>
>    for (int i = 0; i < pixels4; ++i)
>    {
> #if HAVE_BIGENDIAN
>        pDst[0] = 0xFF000000 | (pSrc[0] >> 8);
>        pDst[1] = 0xFF000000 | (pSrc[0] << 16) | (pSrc[1] >> 16);
>        pDst[2] = 0xFF000000 | (pSrc[1] << 8) | (pSrc[2] >> 24);
>        pDst[3] = 0xFF000000 | pSrc[2];
> #else
>        pDst[0] = 0xFF000000 | pSrc[0];
>        pDst[1] = 0xFF000000 | (pSrc[1] << 8) | (pSrc[0] >> 24);
>        pDst[2] = 0xFF000000 | ((pSrc[2] << 16) | (pSrc[1] >> 16);
>        pDst[3] = 0xFF000000 | (pSrc[2] >> 8);
> #endif
>        pDst +=4;
>        pSrc +=3;
>    }
>

Sorry mistake:

-    uint8_t* pBytes = (uint8_t*)pDst;
+   uint8_t* pBytes = (uint8_t*)pSrc;

>    for (int i = 0; i < extra; i++)
>    {
> #if HAVE_BIGENDIAN
>        *pDst++ = 0xFF000000 | (pBytes[0] << 16) | (pBytes[1] << 8) | 
> (pBytes[2]);
> #else
>        *pDst++ = 0xFF000000 | (pBytes[2] << 16) | (pBytes[1] << 8) | 
> (pBytes[0]);
> #endif
>        pBytes += 3;
>    }
> }
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel 



More information about the ffmpeg-devel mailing list