PDA

View Full Version : Pixel format conversions



04-15-2004, 07:18 AM
Is there a good way to convert pixel data between formats?

I have an byte array of pixel data in RGB format - if I want to add an alpha channel, or convert it into BGR format etc, is there a better way of doing it than manually processing the array pixel by pixel, pixel component by pixel component?

Honk
04-15-2004, 11:13 AM
Its depends. If you want to change the pixelformat before you upload it as a texture to the GPU, I would let the GPU/driver do the work since todays GPU's are good in data swizzling.

If you mean pixel format conversions for normal CPU use, you need an appropriate algorithm (or library) that does the conversion. Some conversions can be speeded up by using extended instructions like "MMX-SSE3" or "3dNow!" others cant.

04-15-2004, 11:37 AM
Yeah, this is separate from the GPU, unfortunately. Also, I don't have access to MMX et al, which leaves me with hideous code similar to:

</font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">if((in == RGB && out == BGR)

04-15-2004, 11:42 AM
Well, that ate half my reply...

Let's try again:

</font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">if((in == RGB && out == BGR)

04-15-2004, 11:44 AM
Heh, how embarrasing... I really wish they'd allow "preview" for anon posters... Looks like it doesn't like pipes.

Yeah, this is separate from the GPU, unfortunately. Also, I don't have access to MMX et al, which leaves me with hideous code similar to:


if((in == RGB &amp;&amp; out == BGR) OR (in == BGR &amp;&amp; out == RGB))
for(int i = 0 ; i < pixelCount * 3 ; i++)
{
out[i+2] = in[ i ] ;
out[i+1] = in[i+1] ;
out[ i ] = in[i+2] ;
}
else if((in == RGBA &amp;&amp; out == ...No sequential indices, no bulk array access... a complete performance nightmare. And you don't even gain any readibility through verboseness! :(

Well, thanks anyway - I guess I'm not missing anything. There really isn't a clever way to do this!

04-15-2004, 11:48 AM
Hurrah! :rolleyes:

(Note to self: don't use pipe characters on this forum...)