c libraries needed to deal with bitmaps
-
The
sizeof
operator gives the number of bytes in the object referred to. So in your case it will be the size of aBITMAPFILEHEADER
, and the read operation will read the correct number of bytes into the structure. When complete each field of the structure should be correctly aligned*. *There are conditions where this may not be true, so beware if you have a structure containing single byte elements. You may ignore that for the moment.thanks that makes sense. In the code above do I need m_nPaletteEntries at all? Is used to calculate the offset at which individual pixels are stored?
-
thanks that makes sense. In the code above do I need m_nPaletteEntries at all? Is used to calculate the offset at which individual pixels are stored?
-
You need to examine the different items in the info table as described at BITMAPINFOHEADER structure (Windows) | Microsoft Docs[^]. The values of the items related to colours will tell you whether a colour table is included or not.
I have to take a short break. Your insight (last post included) is priceless Richard, thanks
`DreamLand Page` is my projects facebook page.
-
I have to take a short break. Your insight (last post included) is priceless Richard, thanks
`DreamLand Page` is my projects facebook page.
-
Sorry to disappoint you, but my 'insight' is actually just a matter of reading the documentation.
the code you quoted is the bit that throws me into fog. What does the line that has the overload operator do?
-
the code you quoted is the bit that throws me into fog. What does the line that has the overload operator do?
-
m_nPaletteEntries = 1 << m_pBIH->biBitCount;
-
m_nPaletteEntries = 1 << m_pBIH->biBitCount;
This is a bitwise left-shift operation which is equivalent to
m_nPaletteEntries = pow(2, m_pBIH->biBitCount); // 2 to the power of bpp
What are shift operators in C++?[^] This trick is used quite often, since a bitwise shift operation is way quicker than the
pow()
method, which is rather intense on processing time. Edit: here's an interesting list of useful bitwise tricks: Bit Twiddling Hacks[^]"Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."
-
This is a bitwise left-shift operation which is equivalent to
m_nPaletteEntries = pow(2, m_pBIH->biBitCount); // 2 to the power of bpp
What are shift operators in C++?[^] This trick is used quite often, since a bitwise shift operation is way quicker than the
pow()
method, which is rather intense on processing time. Edit: here's an interesting list of useful bitwise tricks: Bit Twiddling Hacks[^]"Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."
-
For a left-shift by a single bit, yes, a multiplication by 2. But a left-shift by n bits, in the end, is the same as a multiplication by 2 to the power of n; since original value is 1, this leads to 2 to the power of n. Or am I missing something?
"Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."
-
For a left-shift by a single bit, yes, a multiplication by 2. But a left-shift by n bits, in the end, is the same as a multiplication by 2 to the power of n; since original value is 1, this leads to 2 to the power of n. Or am I missing something?
"Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."