Jump to content

are bitmap files platform dependant?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
15 replies to this topic

#1
PAUL1966

PAUL1966

    Newbie

  • Members
  • Pip
  • 3 posts
Hi!

Here is a question i started to think about when i recently started my latest project. I have not got any answer to my question yet,
so i hope that someone here might help me.

Declarations such as WORD, DWORD, UINT and LONG are as far as i know platform dependant. That is, the number of memory bytes they allocate can differ from computer to computer platform.

Now, according to the specification of a bitmap file the BITMAPFILEHEADER consist of :
UINT bfTYPE;
DWORD bfSize
and some other variables.

As the bitmap file consist of variables that are platform dependant this should then mean that the size of the bitmap file can vary between different platforms.

But as far as i know bitmap files are platform independant!!!

How is this?

//Paul

#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Datatypes does not depend on the platform/operating system, but on the architecture of the processor. The names for the datatypes you see in the BITMAPFILEHEADER is just some names Windows have given them. Actually "UINT" is the same as "unsigned int," and "DWORD" is the same as "signed int," or just "int."

#3
PAUL1966

PAUL1966

    Newbie

  • Members
  • Pip
  • 3 posts
Hi!

As you say, "UINT" is the same as "unsigned int" and according to the C standard a "int" or "unsigned int" is defined as "at least 16 bits". This means that an int can actually be more than 16 bits on some architectures.

So if you have two computers with different architecture (one that defines a UINT as 16 bits, and the other that defines a UINT as 32 bits) and creates a bitmap file on one computer. Then it will be corrupt if you try to read it on the other computer, would it not?

#4
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts

PAUL1966 said:

This means that an int can actually be more than 16 bits on some architectures.
On modern computers it almost always is. On 32-bit processors the size is 32-bit, and on 64-bit processors the size is 64-bit. It's possible to use real mode on most processors though, so you make the size go 16-bit instead.

About your next question; I'm not sure. I would (after I thought about it) say it would be corrupted, but I can't say for sure, I've never tried to open a 32-bit bitmap file on a 16-bit processor. There's probably some other people around here who can help you further, with a more detailed explanation.

#5
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
What type of specifications are you looking at that lists the header with those terms? I'd have to believe it is a Windows specification list?

#6
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
I think he has used a specification page like those you can find on MSDN, such as this one.

#7
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
Ahh, makes sense then. I did a quick google search and found several but all used Windows terms.

#8
PAUL1966

PAUL1966

    Newbie

  • Members
  • Pip
  • 3 posts
Yes, the info is taken from a Microsoft Windows spec of Bitmap file format. But is is also the only spec i found when googlling on bitmap.

The question is the same between 32- and 64-bit computers
as between 16- and 32-bit machines.

Does anyone know?

#9
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Another question: would the endian-ness of the OS affect reading the file?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#10
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
I've never heard that term before.

#11
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Endianness is about how the data is stored in the memory. When you're talking about endianness, you're usually talking about big endian, little endian, and some times mixed endian. There's much more information on Wikipedia.

#12
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,720 posts
UPDATE: FREAD AND FWRITE DO NOT COMPENSATE FOR BIG/LITTLE ENDIAN MODE.

And yes, it would affect the data. 0xABCD is not the same as 0xDCBA. I think (but I'm not sure) that fread() and fwrite() take care of that. If you need to use specific data sizes that are cross-platform, instead of using BYTE,WORD,DWORD, and QWORD, use __int8, __int16, __int32, and __int64 (use unsigned prefix if necessary). These are guaranteed to be the same size on any system, indicated by the number after int which is the number of bits.