Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

size of bpp for bitmap format is 2 bytes, it ought to be cast into short* rather than int* #59

Open
zyzyz opened this issue Dec 15, 2017 · 0 comments

Comments

@zyzyz
Copy link

zyzyz commented Dec 15, 2017

Although the tutorial 5 doesn't mention about the need of checking the bmp file's bpp when loading, but in common/texture.cpp it does do. However, according to the wiki, it shows that the size of data representing the bpp of bitmap is actually 2 bytes:

Offset (hex) Offset (dec) Size (bytes) Windows BITMAPINFOHEADER[1]
1C 28 2 the number of bits per pixel, which is the color depth of the image. Typical values are 1, 4, 8, 16, 24 and 32.

I'm curious why this statement can work,

// the original one...
if ( *(int*)&(header[0x1C])!=24 ) ...

// ...or the re-write version by me 
unsigned int bpp = *reinterpret_cast<int*>(&header[0x1C]);
if (bpp != 24) ...

but I think casting it into short* should make more sense, since short is 2-byte-size in this case. And changing this doesn't affect the correctness.

unsigned int bpp = *reinterpret_cast<short*>(&header[0x1C]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant