Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » StaticImage cannot show BMP file
StaticImage cannot show BMP file [message #43589] Wed, 10 September 2014 13:24 Go to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

I am using a StaticImage control in my project and can display JPG images using

stImg.Set("JPGFILE.JPG");

where stImg is a StaticImage control on layout

How can I display a .BMP file? I have found no example to load a BMP file from disk to staticImage. Would it be possible to use plugin/bmp for this purpose or am I shooting in the dark? Can someone please show me a simple example to load a file.bmp from disk and .Set to a StaticImage?

Jerson
Re: StaticImage cannot show BMP file [message #43592 is a reply to message #43589] Thu, 11 September 2014 08:53 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Jerson

StaticImage has to open .bmp files as easily as .jpg or other image formats supported by U++.

Please if you cannot open a .bmp in your program, try to do it using Controls4U_demo and tell me what happen.


Best regards
Iñaki
Re: StaticImage cannot show BMP file [message #43593 is a reply to message #43592] Thu, 11 September 2014 10:55 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Hi Koldo

I have tried your controls4u_demo too. Sorry, it comes back like this when I load the windows BMP file.

I am using v7635 with Mingw

index.php?t=getfile&id=4602&private=0

[Updated on: Thu, 11 September 2014 10:57]

Report message to a moderator

Re: StaticImage cannot show BMP file [message #43594 is a reply to message #43593] Thu, 11 September 2014 11:10 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Jerson

In my case it works well:

index.php?t=getfile&id=4603&private=0

In your case either file does not exist or file format is not supported.

To know if there is a problem with the image format, you could try to open the file with TheIDE in an .iml file, by right clicking the mouse over the icon list, and choosing "Insert from file(s)".


Best regards
Iñaki
Re: StaticImage cannot show BMP file [message #43595 is a reply to message #43594] Thu, 11 September 2014 11:16 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Hi Koldo

Interesting. Insert from files into iml works fine.

Re: StaticImage cannot show BMP file [message #43596 is a reply to message #43595] Thu, 11 September 2014 11:51 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Could you send me a copy of the .bmp, if you want by a PM or by email?

Best regards
Iñaki
Re: StaticImage cannot show BMP file [message #43597 is a reply to message #43596] Thu, 11 September 2014 12:52 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Sent PM
Re: StaticImage cannot show BMP file [message #43602 is a reply to message #43597] Fri, 12 September 2014 08:41 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Jerson

Your images open well:

index.php?t=getfile&id=4609&private=0

Anyway, please try to choose Controls4U from your project package list, right button, select "Package Organizer", and add "plugin/bmp" package. Recompile all the package, and try to open de umages again.
  • Attachment: Image.png
    (Size: 172.92KB, Downloaded 473 times)


Best regards
Iñaki
Re: StaticImage cannot show BMP file [message #43605 is a reply to message #43602] Fri, 12 September 2014 09:18 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Hi Koldo

thanks for you taking time to look into this. plugin/bmp is already listed in the package tree along with plugin/jpg, tif, png etc. I even tried adding it to the USES list. Still BMP does not work for me. I think I will try with PNG and TIF too later today. As a last option, I will try rebuilding the ide from sources to see if it inherits the problem I face. Currently, I use a pre-compiled binary for IDE.

I shall update this thread after experimenting.

Regards
Jerson
Re: StaticImage cannot show BMP file [message #43607 is a reply to message #43605] Fri, 12 September 2014 10:36 Go to previous messageGo to next message
jerson is currently offline  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 #43608 is a reply to message #43607] Fri, 12 September 2014 14:19 Go to previous messageGo to next message
jibe is currently offline  jibe
Messages: 294
Registered: February 2007
Location: France
Experienced Member
Hi Jerson,

Looks like there is something wrong at least in your bmp plugin... Did you try with a fresh and clean install of the latest night build ? Today's version is 7654.
Re: StaticImage cannot show BMP file [message #43609 is a reply to message #43608] Fri, 12 September 2014 15:05 Go to previous messageGo to next message
jerson is currently offline  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 Go to previous messageGo to next message
jerson is currently offline  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
	word   bfOffBits;

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 Go to previous messageGo to next message
hans is currently offline  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 Go to previous message
jerson is currently offline  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.
index.php?t=getfile&id=4610&private=0

Regards

[Updated on: Sun, 14 September 2014 05:23]

Report message to a moderator

Previous Topic: From XSD to XML
Next Topic: HowTo bind StaticImage to SQL
Goto Forum:
  


Current Time: Fri Mar 29 11:01:25 CET 2024

Total time taken to generate the page: 0.01533 seconds