News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Ernest Murphy's image library

Started by Vortex, March 03, 2005, 04:18:10 PM

Previous topic - Next topic

Vortex

Hi friends,

There was a local bug in Ernest Murphy's image displaying function BitmapFromFile.asm

Thanks to El_Choni for discovering and fixing this bug:

http://board.win32asmcommunity.net/viewtopic.php?t=10650

f0dder suggested fixing another bug found in BitmapFromMemory.asm

http://board.win32asmcommunity.net/viewtopic.php?p=145356#145356

Here is a small example displaying a JPG image from file.

[attachment deleted by admin]

pbrennick

Vortex,
Actually, as it turns out, El_Choni was mistaken.  He apologized for the false bug report.

Paul

Vortex

#2
No, It's not a false bug report. To proove this : put the original image handling functions to the sample project and you get only a blank dialog box with no image.

http://board.win32asmcommunity.net/viewtopic.php?p=81754#81754

Posted: February 14th, 2003

Quote
Oh, I see... then I don't understand why I can't make it work (sorry for posting a false bug, anyway).

Posted: February 16th, 2003

Quote
Ok, adding 1 to dwLength solved the whole thing. It must be a problem of terminating zeroes or something like that. Thanks for your help.

http://board.win32asmcommunity.net/viewtopic.php?p=82146#82146

Vortex

This example displays the same image from memory.

[attachment deleted by admin]

Vortex

#4
Finally, here is the image library with the latest bug fix of lamer.

Many thanks to f0dder ,  El_Choni and lamer for the corrections.

Concering the functions BitmapFromFile and BitmapFromMemory, the statements :

invoke CoInitialize, NULL at the beginning of the source code

invoke CoUninitialize at the end of the source code


should be included to initialize and uninitiaize COM

http://board.win32asmcommunity.net/index.php?topic=10650.0
http://board.win32asmcommunity.net/index.php?topic=18776.0
http://www.masmforum.com/simple/index.php?topic=2743.0

EDIT: Below, you will find the attachment.

Vortex

Many thanks to KetilO who found another bug in the BitmapFromPicture function.

The screen DC is not released, this can cause to run out DC's.
This line releases the DC :
invoke ReleaseDC,NULL,compDC

Here is the new attachment.

[attachment deleted by admin]

QvasiModo

BitmapFromPicture still doesn't release the screen DC in the last attachment you posted. Also BitmapFromFile doesn't release the memory allocated by CoTaskMemAlloc.

In any case I'd suggest a restructuring of all the code, since exiting the function in more than one place is rather messy, and it lacks a lot of error checking... :( If you're interested I could do that, got some free time this weekend.

One more thing, in BitmapFromResource, the resource type for images should not be the string "IMAGE" but the numeric constant 2110. However this would break backwards compatibility... not sure what to do about that.

Vortex

Hi QvasiModo,

About the CoTaskMemAlloc problem, you can check this post :
http://board.win32asmcommunity.net/index.php?topic=18776.msg145356#msg145356

Back home, I will restudy the problem about releasing DCs.

Dougiem's OLE image routine is a stable one :

http://www.masmforum.com/simple/index.php?topic=2946.msg22966#msg22966

QvasiModo

You are right about CoTaskMemAlloc :thumbu in that case only a small change has to be done, if CreateStreamOnHGlobal fails then the memory has to be released. Also if OleLoadPicture fails pStream should be released, and if BitmapFromPicture fails pPicture should be released.

The problem I mentioned about releasing the DC also only happens on error, so in normal circumstances it won't be noticed. But for the sake of reliability, specially since it's a static library to be used in many programs, we have to consider every case. :)

Thanks for the link to Dougiem's code, I'll add it to my masm32 folder :U

Vortex

Hi QvasiModo,

Thanks for your support. Here is the revised package according to your suggestions. Would you like to check the fixed source codes of the image library?

[attachment deleted by admin]

QvasiModo

Seems great now :U

One detail: at BitmapFromMemory I think we should be checking for errors at the first call to CoTaskMemAlloc. Here's a revised version of BitmapFromMemory.asm, I also moved the call to release_pPicture higher in the code so the IPicture object is also released if BitmapFromPicture happens to fail.

What do you think of these changes?

[attachment deleted by admin]

Vortex

Nice work :U

I replaced the previous version of BitmapFromMemory with your new one, thanks.

Here is the new package.

EDIT : I modified BitmapFromFile by moving up the call to release_pPicture

[attachment deleted by admin]

hutch--

I need to know when this is dead stable so I can put it into the current project.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

Hi Hutch,

I have to do some additional tests and I will announce the final revised package.

Vortex

Hi Hutch,

Here is the latest release. Could you test the package to put it to the masm32 project?

[attachment deleted by admin]