Archived

This topic is now archived and is closed to further replies.

24bit vs. 32bit in terms of speed

This topic is 5597 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Lets say that I have a pointer: void ** Pixels; it points to an array of 24bit color data for a bitmap that is 100x100. I want to make the entire bitmap green so I say:

BYTE * bPixels = (BYTE*)*Pixels;
for (int c = 0; c<=100*100*3; c+=3)
{
bPixels[c] = 0;
bPixels[c+1] = 255;
bPixels[c+2] = 0;
}

lets say that now I make it a 32bit bitmap and do this instead:

DWORD * bPixels = (DWORD*)*Pixels;
for (int c = 0; c<=100*100; c++)
{
bPixels[c] = 0x0000ff00;
}

Would the second method be executed faster? If so, would the increase in speed justify the increase in memory usage?

Share on other sites
1) Yes, using 32 bit values is faster
2) It is also less cumbersome.
3) Yes, it''s worth the extra memory.

Share on other sites
There''s no reason why you couldn''t roll your 24bit assign into one instruction as you did with the 32bit value.

But even if you do this, dealing with 24bit color values WILL be slower because of memory alignment issues.

So go with 32bit color unless you have a great reason not to, even if the 4th color component is wasted.

Share on other sites
Definitely use 32 bit.
Some cards (like mine) don''t support 24 bit colour at all.

Share on other sites
since you didn''t post this in the DX or OGL forums, i''ll assume Windows GDI is the target? if so, i''m pretty sure Windows uses 32bits per pixel for both 24bpp and 32bpp display modes. it just ignores what goes into the A byte for 24bpp.

Share on other sites
If you are using Windows GDI, 32 bit bitmaps can be slower than 24 bit. As far as I remember I once tested it and 32bit was slower. At least on my computer. I guess it was because the real bottleneck in manipulating bitmaps can be the memory transfers and not individual pixel manipulations that are performed on data in processor cache or registers.

But actually the only way to find it out is to test on your computer and measure the performance.

• 10
• 16
• 14
• 18
• 15