Jump to content
  • Advertisement

Archived

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

TempusElf

24bit vs. 32bit in terms of speed

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!