|
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?
|
|
|
|
|
fearless_ wrote: What does the line that has the overload operator do? What line?
|
|
|
|
|
m_nPaletteEntries = 1 << m_pBIH->biBitCount;
|
|
|
|
|
This is a bitwise left-shift operation which is equivalent to
m_nPaletteEntries = pow(2, m_pBIH->biBitCount); 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."
|
|
|
|
|
It's not pow, it's multiply by 2.
|
|
|
|
|
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."
|
|
|
|
|
I found myself thinking about this when I woke up this morning and you are, of course, quite correct.
|
|
|
|
|
Richard I appreciate your willingness to help
|
|
|
|
|
fearless_ wrote: Would you mind helping me further? I loaded the bitmap, however when I check the values from the array into which the bitmap is loaded they show up as 0 (null).
1. How did you load the bitmap?
2. How did you "check the values from the array into which the bitmap is loaded"?
3. Did you try to open this bitmap with some graphic editor/viewer?
|
|
|
|
|
Victor thanks for offering to help, take a look at my reply to Richard
|
|
|
|
|
You are messing around with stuff you do not have to do on Windows and there is no advantage in doing what you are doing other than learning.
You can load a bitmap with one line of code using the API LoadBitmap()
LoadBitmapA function (winuser.h) - Win32 apps | Microsoft Docs[^]
One line of code will load it for you and it doesn't care what the bitmap format is.
HBITMAP MyBmp = LoadBitmap(0, "Yourbitmapname.bmp");
Once you have a HBITMAP (handle to a bitmap) in Windows you can basically do everything with it.
If you want the details from the bitmap once you have it loaded you just ask windows to extract them for you
So with my handle above I can extract the header with 2 lines of code the 3rd line is just to throw the details out (it assumes you are doing a console app).
BITMAP bm;
GetObject(MyBmp, sizeof(bm), &bm);
printf("Bitmap is wth: %u ht: %u bitdepth: %u\r\n", bm.bmWidth, bm.bmHeight, bm.bmBitsPixel);
So I can load the bitmap and extract the header with 3 lines in absolute safety.
If you are messing around with the actual header etc in Windows you are doing it all wrong
The only time you might play with a BMP file header is writing a BMP in a specific format.
That is why there is no need for libraries on Windows to handle bitmaps. Now JPEGS are a little trickier it's about 20 lines of code to get windows to load one of those most of the issue the filename has to be in UNICODE. Let me know if you need to know how to do it.
In vino veritas
modified 12-Mar-20 11:48am.
|
|
|
|
|
leon de boer wrote: One line of code will load it for you and it doesn't care what the bitmap format is.
HBITMAP MyBmp = LoadBitmap(0, "Yourbitmapname.bmp");
You probaly meant the [LoadImageA function (winuser.h) - Win32 apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadimagea) function that can load the bitmap from the file.
LoadBitmap only loads the bitmap from resources.
|
|
|
|
|
Yep sorry needed more coffee last night, clearly
In vino veritas
|
|
|
|
|
I`m learning how to work with bitmaps. Could someone explain what`s a palette when reading from a bitmap
|
|
|
|
|
A palette is a collection of indexed colours. In a bitmap using a palette, instead of refering to a colour by specifying its raw value, it is specified by its index in the palette instead.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
Thanks phil.o, so this palette is used as a compression method/way to save space? Is this feature used at all? How do people usually store data to bmps with or without using a palette?
|
|
|
|
|
Exactly, this allows to save space by 1) only referencing used colours in the palette 2) using colour references instead of raw values.
This feature is used in .gif files, as well as in icons, IIRC. It is not used in .bmp files, which store colour information uncompressed. It may be used in other formats as well.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
Unfortunately (I would call it that, because it's a mess) BMP files are in theory quite general, with tons of annoying features being piled onto it. Using any of those features results in a BMP file that a lot of software can't read (or reads differently than intended) because almost everyone treats BMP as only 24bit-uncompressed with no fancy extras. But anyway, in theory, a BMP file can indicate that it has 8 or fewer bits per pixel and then it must have a color table aka palette. The pixel data can even be compressed then.
|
|
|
|
|
Thanks for the update. I never had to work with bmps other than plain 24 bpp (or 8 bpp for b/w) uncompressed data.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
thanks for your help. So biBitCount less than 9 it`s no longer what you would consider a bitmap
|
|
|
|
|
Yes I would still consider it as a bitmap.
I was specifically talking about .bmp files. The general notion of bitmap is something different.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
my bad, I meant it`s no longer a .bmp
|
|
|
|
|
But apparently I'd be wrong, as harold aptroot told, .bmp format is way more generic than that.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|