Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Important Update: Community Platform Migration​. Learn more​>

Trouble with LOADIMAGE

dboggs
New Contributor I
4,945 Views

We have frequently used the function LOADIMAGE to display an existing .bmp file on the screen. Sometime since installing XE13.1 (package 2013.2.149) on a new computer, this function does not work. Its return value is -1. Is this a known problem, or can somebody confirm that it still works on their setup? We can confirm that it still works on XE12.1.

0 Kudos
18 Replies
Steven_L_Intel1
Employee
4,945 Views

I can't find any problem reports about LOADIMAGE. Can you provide a short example and a sample BMP? ZIP them, please.

0 Kudos
dboggs
New Contributor I
4,945 Views

I really don't need to zip much of an example. The program would be:

PROGRAM LOADIMAGE_TEST
USE IFQWIN
INTEGER(4) :: IRET
IRET = LOADIMAGE ('AnyExistingFilespec.bmp', 0, 0)
END PROGRAM

This simple test program used to work, with all bmp files. We are using Quickwin programs, of course, because that's where LOADIMAGE is supplied.(You don't even have to explicitly open a  child window to see the result). It no longer works, with any bmp file. Incidentally, the corresponding function SAVEIMAGE still works fine.

0 Kudos
Paul_Curtis
Valued Contributor I
4,945 Views

Your LoadImage() invocation seems to be missing a few arguments:

[fortran]

INTERFACE
    INTEGER*4 FUNCTION LoadImage(hinst, lpszName, uType, cxDesired, &
         cyDesired, fuLoad)
        !DEC$ ATTRIBUTES DEFAULT :: LoadImage
        !DEC$ ATTRIBUTES STDCALL, ALIAS : '_LoadImageA@24' :: LoadImage
        !DEC$ ATTRIBUTES REFERENCE :: lpszName
        INTEGER hinst
        CHARACTER*(*) lpszName
        INTEGER uType
        INTEGER cxDesired
        INTEGER cyDesired
        INTEGER fuLoad
    END FUNCTION LoadImage
END INTERFACE

[\fortran]

0 Kudos
Steven_L_Intel1
Employee
4,945 Views

No, this is the LOADIMAGE from IFQWIN - the call is correct,  Let me try some examples.

0 Kudos
Steven_L_Intel1
Employee
4,945 Views

I don't see a problem when I try it with the latest version. I get the BMP displayed and the routine returns 0. You may want to try calling GETLASTERRORQQ after the failed LOADIMAGE to see if there is a useful error code.

0 Kudos
dboggs
New Contributor I
4,945 Views

Thanks for checking, Steve. I had tried calling GERROR--because it (allegedly!) returns the error in a descriptive text form--but it only returned blank. I'm not sure how to use GETLASTERRORQQ, since it only appears a numerical code, and the documentation is not very clear to me. Can you give me an example? I always have trouble looking up error codes.

At any rate, we will continue investigating other possibilities. btw, what is involved in installing an older compiler version along with the current one? Can we just run the package exe file, and then select which compiler to use through Visual Studio?

0 Kudos
Steven_L_Intel1
Employee
4,945 Views

See How can I use older versions of the compiler with different versions of Microsoft Visual Studio*?

The documentation of GETLASTERRORQQ is fairly clear. It returns an integer code you can look up in ifport.f90 (in the compiler Include folder) - the codes start at about line 1226 in the version I'm looking at. You might also try the Windows API GetLastError which might also be instructive. It's possible that your BMP is too big for the window, for example.

0 Kudos
dboggs
New Contributor I
4,945 Views

An update. We have continued testing (a lot) in an effort to better characterize the problem. There definitely is a problem, but it has nothing to do with the compiler version, or the hardware. Rather, it exists only with bmp files created from SAVEIMAGE, and only from a child window that was custom-sized using SETWINDOWCONFIG. The bmp file appears to be ok, meaning that other commercial programs can load and display it, but it cannot be read into an IVF child window using LOADIMAGE--at least if that child window was also sized using SETWINDOWCONFIG.

In short, the problem occurs with certain combinations of SAVEIMAGE, LOADIMAGE, AND SETWINDOWCONFIG. I'll try to upload a simple demo program later.

0 Kudos
andrew_4619
Honored Contributor III
4,945 Views

Last time a played with these PUT GET SAVE image routines they used device independant bitmap (DIB) format. The documentation can be found at http://en.wikipedia.org/wiki/BMP_file_format#Device-independent_bitmaps_and_the_BMP_file_format

You can interogate BMP the header data so see if there is anyone strange about the BMP files produced.

0 Kudos
dboggs
New Contributor I
4,944 Views

Thanks app4619, this is useful and I will investigate.

In the meantime, for Intel review, here is a simple program that documents the failure we see:

[fortran]

PROGRAM

SAVELOADIMAGETEST

USE

IFQWIN

USE

IFCORE

IMPLICIT NONE

INTEGER(4)

:: I4

LOGICAL(4)

:: L4, CUSTOMSIZE

TYPE

(WINDOWCONFIG) WC

! Open child window 1 using either default size or custom size.

OPEN(1, FILE ='USER', TITLE ='Window 1 at default size'

)

CUSTOMSIZE = .true.

IF(CUSTOMSIZE)

THEN

WC.NUMXPIXELS = -1

WC.NUMYPIXELS = -1

WC.NUMTEXTROWS = 20

WC.NUMTEXTCOLS = 60

WC.TITLE =

'Window 1 at custom size'

L4 = SETWINDOWCONFIG (WC)

IF

(.NOT.L4) L4 = SETWINDOWCONFIG (WC)

END IF

WRITE(1, *)

'Message to unit 1'

! Save the screen image.

I4 = SAVEIMAGE (

'ScreenCap.bmp'

, 0, 0, 600, 300)

! Replace the screen image, at an offset to identify success (the above

! write message should appear in the middle of the screen).

I4 = LOADIMAGE (

'ScreenCap.bmp'

, 300, 150)

! Try loading the image in another window

OPEN(2, FILE ='USER', TITLE ='Window 2 at default size'

)

CUSTOMSIZE = .false.

IF(CUSTOMSIZE)

THEN

WC.NUMXPIXELS = -1

WC.NUMYPIXELS = -1

WC.NUMTEXTROWS = 20

WC.NUMTEXTCOLS = 60

WC.TITLE =

'Window 2 at custom size'

L4 = SETWINDOWCONFIG (WC)

IF

(.NOT.L4) L4 = SETWINDOWCONFIG (WC)

i4 = setactiveqq (2)

i4 = focusqq (2)

END IF

I4 = LOADIMAGE (

'ScreenCap.bmp'

, 300, 180)

! Try loading a 3rd-party image in window 2. (leave commented until ready)

!i4 = loadimage (

'butfly.bmp'

, 0, 0)

END PROGRAM

! Results: when does bmp file load OK in window 2?

! Window 1 default Window 2 default Loads OK

! " default " custom fail

! " custom " default OK

! " custom " custom fail

! Load a 3rd-party image: Always OK
[/fortran]

To summarize: LOADIMAGE will fail to load a bmp file into a target window IF the file was created by SAVEIMAGE, AND the target window was sized using SETWINDOWCONFIG. However, the image looks OK when used with a 3rd-party graphics display program, and a 3rd-party bmp file loads OK into the Fortran window even with SETWINDOWCONFIG.

Implication: there is an incompatibility with bmp files created with SAVEIMAGE with subsequent LOADIMAGE in a window processed with SETWINDOWCONFIG.

We have demonstrated this with three different computers, three different operating systems, and three different IVF compiler versions.

0 Kudos
onkelhotte
New Contributor II
4,944 Views

I haven´t tried your code... Maybe this hint helps you: I had the problem that loading a BMP which is bigger than the window it should be displayed in wasn´t drawn. But when you save it and then display it, it should be ok.

0 Kudos
andrew_4619
Honored Contributor III
4,944 Views

If I run that example above  the default window I get is 480 x 320, I4 = SAVEIMAGE ('ScreenCap.bmp', 0, 0, 600, 300) returns l4=0 (ok) but I think the bmp is dubious as the capture (600x300) is bigger than the window. I think the bmp header and data are probably not consistent.

if I capture I4 = SAVEIMAGE ('ScreenCap.bmp', 0, 0, wc.NUMXPIXELS/2, wc.NUMXPIXELS/2) and then I4 = LOADIMAGE ('ScreenCap.bmp', 5, 5) it works as a) theSAVE is within the window and b) the LOAD also fits in the window.

0 Kudos
dboggs
New Contributor I
4,944 Views

I will investigate this. Perhaps there is some undocumented limitation. This would be unfortunate and suspicious, because in general a (3rd-party) bmp does not have to fit within the window in order to load. And, a full screencapture using SAVEIMAGE cannot be loaded back into the very same window using LOADIMAGE, if the window was sized using SETWINDOWCONFIG. Unfortunately this is exactly what we need to do most of the time.

0 Kudos
andrew_4619
Honored Contributor III
4,944 Views

if after the failed loadimage if you call GRSTATUS( ) you get -13 which is 

PARAMETER($GRBITMAPTOOLARGE = -13) ! BITMAP SIZE > WINDOW CONFIG

IMO load and save image topics in the help should really reffer to GRSTATUS as a related topic as a clue. I think there is a potential problem with saveimage as if you ask for more than the winow size it should give an error and perhaps save a bmp that is cropped ie smaller than requested but maximum.

0 Kudos
Neels
New Contributor II
4,944 Views

See also:

<ul>http://software.intel.com/en-us/forums/topic/364209</ul>

0 Kudos
dboggs
New Contributor I
4,944 Views

Neels, the link you gave doesn't work for me ("Page not found") but, with help from others I have found the problem, and it is me (with caveat). Indeed, the pixel limits I was attempting to save exceeded the size of the window (as it was customized using SETWINDOWCONFIG). So the problem has nothing to do with GetWindowConfig. The mystery is why SAVEIMAGE returns 0 (successful) instead of -1 (unsuccessful). Would be nice if the documentation said something (accurate) about that instead of blessing it (which is worse than not returning an error message at all!).

Another funny thing is that the saved image is not defective according to other programs; all the ones I have tried can load the file OK. It is only LOADIMAGE that fails to load it (but at least it returns the error -1). Also, LOADIMAGE does not fail because the file size is bigger than the window--that routinely works with ANY file no matter how big, no matter how it was made.

It is very easy to overlook, or miscalculate, the pixel limits needed for use with SAVEIMAGE. Often the window size is known in terms of character cells, so you have to multiply out by the current font cell size (default 8x16), or call GETWINDOWCONFIG, to get the pixel size of the full window, and don't forget to subtract 1 (because pixel numbering begins at 0).

It would be VERY nice if SAVEIMAGE could accept some kind of flag, such as -1 and -1 for the lower-right x and y pixel coordinates, which would then be converted internally to the size of the window. Then, for example, you could call saveimage with arguments

     (fname, 0, 0, 400, -1) to save the left 400 pixels of the window,
     (fname, 0, 0, -1, 200) to save the top 200 pixels of the window,
     (fname, 0, 0, -1, -1) to save the entire window (the most common case)

and the return error should actually represent an error, not the red herring "false success" that sometimes happens now.

How about it, Intel Quickwin developers?

0 Kudos
Neels
New Contributor II
4,944 Views

Sorry, I added the link wrong, thought it worked differently. Lets see if this works:

http://software.intel.com/en-us/forums/topic/364209

0 Kudos
dboggs
New Contributor I
4,944 Views

Thanks Neels. Interesting exchange.

I have never had trouble with LOADIMAGE on a file that was "too big to fit in the window"--they always load fine, even though they may be clipped at the right and bottom window edges.

0 Kudos
Reply