[cpp] SBMPHeader header;
file->read(&header, sizeof(SBMPHeader));
file->seek(header.bitmapDataOffset, SEEK_SET);
if(header.id != 0x4d42) // It isn't a bitmap.
return true;
if(header.width < 1 || header.height < 1) // Bitmaps with width or height under one pixel is a bad sign.
return true;
int newWidth = header.width;
int newHeight = header.height;
width = newWidth;
height = newHeight;[/cpp]
[cpp]struct SBMPHeader
{
unsigned int id; ///< The BMP type.
unsigned int fileSize; ///< The filesize.
unsigned int reserved; ///< Reserved; Should be 0.
unsigned int bitmapDataOffset; ///< The data offset.
unsigned int bitmapHeaderSize; ///< The header size.
unsigned int width; ///< The width.
unsigned int height; ///< The height.
unsigned short planes; ///< The planes.
unsigned short BPP; ///< The bits.
unsigned int compression; ///< The compression type.
unsigned int bitmapDataSize; ///< The size of the bitmap in bytes.
unsigned int pixelPerMeterX; ///< the pixels per meter on the X axis.
unsigned int pixelPerMeterY; ///< the pixels per meter on the Y axis.
unsigned int colours; ///< The colours.
unsigned int importantColours; ///< The important colours.
};[/cpp]
The header isn't the right value and neither are half the other shit. What's odd is that planes is 24.
Well, for example the id in the bit-map header is 2 byte, whereas in your struct it's sizeof(unsigned int) bytes, at least 4 bytes.
How do I fix this?
[QUOTE=Eleventeen;19841432]How do I fix this?[/QUOTE]
Use a type T so that sizeof(T) == 2 ?
Really? What's so difficult about this?
You should be using unt32_t, uint16_t, the types with guaranteed width. Not uint and ushort.
I don't get anything.
[url]http://en.wikipedia.org/wiki/Integer_%28computer_science%29[/url]
Try this:
[cpp]
#include <cstdint>
struct SBMPHeader
{
uint16_t id; ///< The BMP type.
uint32_t fileSize; ///< The filesize.
uint32_t reserved; ///< Reserved; Should be 0.
uint32_t bitmapDataOffset; ///< The data offset.
uint32_t bitmapHeaderSize; ///< The header size.
uint32_t width; ///< The width.
uint32_t height; ///< The height.
uint16_t planes; ///< The planes.
uint16_t BPP; ///< The bits.
uint32_t compression; ///< The compression type.
uint32_t bitmapDataSize; ///< The size of the bitmap in bytes.
uint32_t pixelPerMeterX; ///< the pixels per meter on the X axis.
uint32_t pixelPerMeterY; ///< the pixels per meter on the Y axis.
uint32_t colours; ///< The colours.
uint32_t importantColours; ///< The important colours.
};[/cpp]
[img]http://i47.tinypic.com/2m7eptt.png[/img]
The width, height and the resolution-stuff (pixelPerMeter) are signed.
Make sure your compiler doesn't do fancy alignment stuff with your struct. Try reading each value individually.
compiler is latest GCC
[QUOTE=Eleventeen;19842119]compiler is latest GCC[/QUOTE]
Are you using my code? (It may not work but I need to know what to base myself on to fix it)
Also what bitmap so I can test
I'm using your struct. Sorry or not responding fast, I was banned for expressing an opinion.
[img]http://i47.tinypic.com/2ia8vlu.jpg[/img]
That's a jpeg not a bmp :O
I guess he asked for the original bmp file to test it..
I can't really upload a BMP file..
[QUOTE=Eleventeen;19876504]I can't really upload a BMP file..[/QUOTE]
Mediafire.
Why don't you just check the proper header over here? [url]http://en.wikipedia.org/wiki/BMP_file_format[/url]
Looks like mine is right unless I missed something. I fixed yours using the EasyBMP definitions. I'll look into it during lunch.
EDIT: It's an alignment issue.
I wrote the struct, read the file to memory.
The resulting memdump is fine (matches the file):
[img]http://img442.imageshack.us/img442/7/headerms.png[/img]
However, fileSize starts 4 bytes into the struct instead of 2:
[img]http://img341.imageshack.us/img341/6278/headerfilesize.png[/img]
How do I fix allignment?
[QUOTE=Eleventeen;19914017]How do I fix allignment?[/QUOTE]
Well if you had perhaps followed the link I posted :downs:
[quote=ThatLinkIPosted]
[cpp]
/* Note: the magic number has been removed from the bmp_header structure
since it causes alignment problems
struct bmpfile_magic should be written/read first
followed by the
struct bmpfile_header
[this avoids compiler-specific alignment pragmas etc.]
*/
[/cpp]
[/quote]
Sorry, you need to Log In to post a reply to this thread.