|
|
Home » Community » Newbie corner » StaticImage cannot show BMP file
|
|
|
|
|
|
|
|
|
Re: StaticImage cannot show BMP file [message #43607 is a reply to message #43605] |
Fri, 12 September 2014 10:36   |
jerson
Messages: 202 Registered: June 2010 Location: Bombay, India
|
Experienced Member |

|
|
Hi Koldo
I undertook re-building the IDE package. After fixing the errors encountered I got it to build successfully
in void TextCompareCtrl::Paint(Draw& draw)
WString ln = (WString)l.text; had to be done in Textctrl.cpp to overcome WString expected error.
Result with Controls4u_Demo:
The newly built IDE now does not open BMP files now. Is it something to do with the MinGW 4.8.1 compiler I use?
PNG, JPG works. TIF does not list/shows blank when loaded. The new build of IDE says "New Bitmap Image.bmp not an image" for BMP files. The pre-compiled binary of IDE works correctly. Can someone hazard a guess as to what I am doing wrong?
Another issue which might be related to this problem is that I am unable to debug programs using gdb internal. The program seemingly executes till the breakpoint and the screen won't refresh. Asking it to single step into or step over a code line shows the status Running.... and then it stops again. Asking the debugger to run makes the code perform as normal. However, when the debugger stops at a breakpoint, there is no screen refresh. I am out of ideas as to where to look for answers; so, I never asked this question. GDB_MI2 mode at least works this far, Legacy mode crashes the IDE.
Regards
Jerson
PS: Interchanged versions of MinGW. Problem still remains. JPG, PNG, TIF works ok, only BMP has a problem.
[Updated on: Fri, 12 September 2014 11:21] Report message to a moderator
|
|
|
|
Re: StaticImage cannot show BMP file [message #43609 is a reply to message #43608] |
Fri, 12 September 2014 15:05   |
jerson
Messages: 202 Registered: June 2010 Location: Bombay, India
|
Experienced Member |

|
|
Hello Jibe
I am using 7635, so, I am not too far out of date. Hopefully nothing has changed in the plugin. I wouldn't know how to confirm that though.
I have been trying to decode what is going wrong. In the file BMP.cpp(LoadBMPHeader()) I found something wrong.
The following directives gave me this
sizeof(BMP_INFOHEADER) = 40
AsString(header.biWidth) = 50266112
AsString(header.biHeight) = 65536
AsString(header.biPlanes) = 24 This should be bits per pixel (bitCount)
AsString(header.biBitCount) = 0 This is the cause of failure. Code exits here Valid values 1,4,8,16,24,32
AsString(header.biCompression) = 3032481792 This too is wrong
AsString(header.biSizeImage) = 33
Can someone more knowledgeable than me please check why this happens.
My suspicion is that something is going wrong with the BMP structures alignments.
Regards
Jerson
[Updated on: Fri, 12 September 2014 15:12] Report message to a moderator
|
|
|
Re: StaticImage cannot show BMP file [message #43610 is a reply to message #43609] |
Fri, 12 September 2014 15:33   |
jerson
Messages: 202 Registered: June 2010 Location: Bombay, India
|
Experienced Member |

|
|
Hello Koldo and Jibe
I have resolved the issue.
This is the original structure in bmphdr.h
struct BMP_FILEHEADER {
word bfType;
dword bfSize;
word bfReserved1;
word bfReserved2;
dword bfOffBits;
sizeof(BMP_FILEHEADER) shows 16!!!
So, I made the following change
Now, I get sizeof(BMP_FILEHEADER) as 14 which is the expected value
With this change, BMP files are being displayed in Controls4U_Demo. Can some of you experts please check what's causing this behaviour??
Regards
Jerson
[Updated on: Fri, 12 September 2014 15:34] Report message to a moderator
|
|
|
Re: StaticImage cannot show BMP file [message #43614 is a reply to message #43610] |
Sat, 13 September 2014 20:18   |
hans
Messages: 44 Registered: March 2006 Location: Germany
|
Member |
|
|
Hi, your struct BMP_FILEHEADER has the wrong memory layout,
it must be "packed" meaning no gaps between the members.
You have:
struct BMP_FILEHEADER {
word bfType; 2 bytes
gap-------------------------->2 bytes
dword bfSize; 4 bytes
word bfReserved1; 2 bytes
word bfReserved2; 2 bytes
dword bfOffBits; 4 bytes
In sum 16 bytes
but the Microsoft spec requires that no gap between members exists (in the time defining the struct it was traded not to "waste" space often).
So it must be
struct BMP_FILEHEADER {
word bfType; 2 bytes
dword bfSize; 4 bytes
word bfReserved1; 2 bytes
word bfReserved2; 2 bytes
dword bfOffBits; 4 bytes
In sum 14 bytes
Your change to get it work (bfOffBits changing type) is not right, because
you have still bfSize member at invalid memory position.
The upp code tries to get the "packed" aligment by using for Microsoft Compiler
#ifdef COMPILER_MSC
#pragma pack(push, 1)
#endif
or for GCC
#ifdef COMPILER_GCC
__attribute__((packed))
#endif
You can check if the right compiler #define is defined.
Or your compiler ignores this directive for whatever reason.
Hope it helps.
[Updated on: Sat, 13 September 2014 23:30] Report message to a moderator
|
|
|
Re: StaticImage cannot show BMP file [message #43617 is a reply to message #43614] |
Sun, 14 September 2014 05:19  |
jerson
Messages: 202 Registered: June 2010 Location: Bombay, India
|
Experienced Member |

|
|
Hello Hans
Thanks for your reply. The structure is defined correctly as I can see with the __attribute__ packed as below
#ifdef COMPILER_MSC
#pragma pack(push, 1)
#endif
struct BMP_FILEHEADER {
word bfType;
dword bfSize;
word bfReserved1;
word bfReserved2;
dword bfOffBits;
void SwapEndian()
{
#ifdef CPU_BIG_ENDIAN
bfType = UPP::SwapEndian(bfType);
bfSize = UPP::SwapEndian(bfSize);
bfOffBits = UPP::SwapEndian(bfOffBits);
#endif
}
}
#ifdef COMPILER_GCC
__attribute__((packed))
#endif
;
As I am a relative newbie to this toolchain, I really don't know where to look to identify if the compiler is messing things for me.
This is how my build methods screen looks.

Regards
[Updated on: Sun, 14 September 2014 05:23] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat Apr 26 18:13:27 CEST 2025
Total time taken to generate the page: 0.02697 seconds
|
|
|