Hi,

I'm really fascinated by the image.lib made by ernie. it can load GIFs, JPEGs, BMPs..and other formats!! it's really great! but I've some problems with it. I changed BmpButton from m32lib a bit to load gifs instead of bitmaps. the part i changed is:

original:


invoke LoadBitmap,hModule,rnum1
mov hBmpU, eax
invoke LoadBitmap,hModule,rnum2
mov hBmpD, eax


changed:


invoke BitmapFromResource, hModule, rnum1
mov hBmpU, eax
invoke BitmapFromResource,hModule,rnum2
mov hBmpD, eax


the whole thing works great. i call:


invoke GifButton,hWin,350,479,10001,10002,4000


and have a working gifbutton there. but after this call i try to load a jpeg file from file (not from resource).


invoke BitmapFromFile, ADDR mappath
.if eax==0
invoke GetLastError
invoke FormatMessage,FORMAT_MESSAGE_FROM_SYSTEM,0,eax,0,addr errormessage,50,0
invoke MessageBox,hWin,addr errormessage,addr szDisplayName,0
.endif


i'm 100% sure, that the mappath is correct, because the call works without calling the gifbutton procedure earlier. but BitmapFromFile returns, that the file could not be found! if i call gifbutton AFTER loading this jpeg, everything works fine. but using the gifbutton first and the loading the jpeg returns the error i mentioned some lines above.

this is the complete code that does not work:


invoke GifButton,hWin,350,479,10001,10002,4000
mov hgo,eax
INVOKE GetDC,hWin
mov myDC,eax
INVOKE CreateSolidBrush,000000h
mov blackbrush,eax
INVOKE CreateSolidBrush,00FFFFFFh
mov whitebrush,eax
RGB 50h,50h,50h
INVOKE CreateSolidBrush,eax
mov greybrush,eax
INVOKE CreateCompatibleDC,myDC
mov backbuffer,eax
INVOKE CreateCompatibleBitmap,myDC,screenrect.right,screenrect.bottom
mov backbitmap,eax
INVOKE SelectObject,backbuffer,backbitmap
mov oldbit,eax
INVOKE FillRect, backbuffer, ADDR screenrect, whitebrush ;fill invis screen with black
invoke CreatePen,PS_SOLID,1,00FFFFFFh
mov whitepen,eax
invoke CreatePen,PS_SOLID,1,00FF0000h
mov bluepen,eax
RGB 080h,080h,080h
invoke CreatePen,PS_SOLID,1,eax
mov greypen,eax
RGB 0FFh,0,0
invoke CreatePen,PS_SOLID,1,eax
mov redpen,eax
RGB 0FFh,0FFh,0
invoke CreatePen,PS_SOLID,1,eax
mov yellowpen,eax

invoke BitmapFromFile, ADDR mappath
.if eax==0
invoke GetLastError
invoke FormatMessage,FORMAT_MESSAGE_FROM_SYSTEM,0,eax,0,addr errormessage,50,0
invoke MessageBox,hWin,addr errormessage,addr szDisplayName,0
.endif
mov mapbit,eax
invoke CreateCompatibleDC,myDC
mov mapbitdc,eax
invoke SelectObject,mapbitdc,mapbit
invoke BitBlt,backbuffer,0,0,screenrect.right,screenrect.bottom,mapbitdc,0,0,SRCCOPY


and this is the code that works:


invoke BitmapFromFile, ADDR mappath
.if eax==0
invoke GetLastError
invoke FormatMessage,FORMAT_MESSAGE_FROM_SYSTEM,0,eax,0,addr errormessage,50,0
invoke MessageBox,hWin,addr errormessage,addr szDisplayName,0
.endif
mov mapbit,eax
invoke CreateCompatibleDC,myDC
mov mapbitdc,eax
invoke SelectObject,mapbitdc,mapbit
invoke GifButton,hWin,350,479,10001,10002,4000
mov hgo,eax

invoke BitBlt,backbuffer,0,0,screenrect.right,screenrect.bottom,mapbitdc,0,0,SRCCOPY


the only thing that i see that could be wrong is, that the code between gifbutton and loading the jpeg causes the problems, or loading the gif doesn't clean up something...i just don't know.

can you help me?

thanks..
NOP
Posted on 2002-06-08 08:45:06 by NOP-erator
hi guys,

no reply yet....hmmm...

i tried debugging the whole thing, and acutally found out what the problem is:
this is a part from Ernie's BitmapFromFile code:


invoke MultiByteToWideChar, CP_ACP, 0, pszFileName, -1, pwszFileName, dwLength
; now we can create out picture object
invoke OleLoadPicturePath, pwszFileName, NULL, NULL, NULL, ADDR IID_IPicture, ADDR pPicture
.IF eax > 80000000H ; hresult failed
; we didn't get the file to open, assume bad filename
invoke SetLastError, ERROR_FILE_NOT_FOUND
mov eax, NULL
ret
.ENDIF

while debugging, i saw that in the working version, my filepath is
"C",00,":",00,"\",00,"m",00,"a",00,"p",00,".",00,"j",00,"p",00,"g",00,00,00
in memory, after calling "MultiByteToWideChar".
but in the not working version it is:
"C",00,":",00,"\",00,"m",00,"a",00,"p",00,".",00,"j",00,"p",00,"g",00,"y",00, etc. and some other crap...

in my opinion that means, that the "OleLoadPicturePath" appends this "crap" after the actual filepath and, of course, can't find the file then. and that means, that the string has to be "double-zero-terminated" after MultiByteToWideChar like in the path where the program works.
but how to make the filepath double-zero-terminated? just appending a second ,0 after the filepath in the .data section doesn't help...

thanks in advance...

bye
Posted on 2002-06-08 13:26:53 by NOP-erator
The strting looks strange with all those extra zero pads in there cause its a Unicode string to keep OleLoadPic happy (this is a COM type of functioon, and COM only speaks Unicode).

My guess is it is another bug in the MultiByteToWideCharacter API call.... it has been trouble in the past. All I can suggest right now is to try adding a few extra bytes to the string size you pass it for the translation.

Sorry... I'm getting married next week and we're busy as all hell here.
Posted on 2002-06-08 14:14:11 by Ernie
erm, but doesn't MultiByteToWideChar append a zero after every character? i mean, the original string is "C:\map.jpg", and after calling MultiByteToWideChar it turns to "C",00,":" ...etc..
i've checked that with softice..if i display the memory location of the formated string by multibytetowidechar. and as i said, the difference is, that in the working version, the string is at least double zero terminated after multibytetowidechar. but it is just one zero terminated in the not working version..so how should the function recognize the end of the string when there is one zero after every character? this seems to be the problem...

just using


.data
filepath db "C:\map.jpg",10 dup(0)

doesn't help too...

best wishes for your marriage (i don't know what to wish in english :tongue: )

bye..
Posted on 2002-06-08 14:42:07 by NOP-erator

I'm getting married next week and we're busy as all hell here.
My congratulations and best wishes for that. :)
Posted on 2002-06-08 16:07:25 by Maverick
NOP & Mav: Thanks for your warm wishes.

NOP: I just noticed you have the old, orgional versioon of this routine (the one people already reported is buggy). I re-did the string length for Unicode trranslation, it seemed pretty good after that. Please try downloading my lib again from here.

..so how should the function recognize the end of the string when there is one zero after every character? this seems to be the problem...


Not really... Unicode defines a word (not a byte) for eacxh character, so the function is looking for both zeros.

The problem is MultiByteToWide, which isn't giving us those characters correctly.
Posted on 2002-06-08 20:56:16 by Ernie
hey ernie,

I already had the latest version of the image.lib, but there was something else. nevertheless, i downloaded it again, and replaced the "old" with the new. i tried to run my program, but i had the same error.
so i just built in the two lines


MessageBoxW PROTO :DWORD, :DWORD, :DWORD, :DWORD
invoke MessageBoxW, 0, pwszFileName, 0, 0

in your BitmapFromFile procedure like you told someone in the other thread, recompiled the whole thing...and......it worked!!!!!!!!!! the path was correct!! the image was shown...everything was fine...
it was really strange to me and i removed the two lines again and recompiled...it still worked..so it seems Ernie, that you just forgot to recompile your lib after changing the code????!!!!

anyways...thanks!!!!!! great work!!!

bye,
NOP
Posted on 2002-06-09 03:34:39 by NOP-erator
hehehehe.. of COURSE that's possible. But more likely, I forgot to replace the .lib itself in the package, and just updated the .asm.

Funny you're the first to notice that. I'll fix the download (somday soon, I'm off to Atlantic City for my bachlor party in 2 minuits) and re-post it.


Glad you got it working, sorry for the problem.
Posted on 2002-06-09 07:59:24 by Ernie
k, thx! np!

NOP
Posted on 2002-06-09 13:44:55 by NOP-erator
Hey Ernie, i wanna know if u coded all the algos to unpack jpg's in image.lib, if it's affirmative, can u tell me the book/reference u use to code it?. Im interesed in image processing.

Greets and thanks.
Posted on 2002-06-10 01:52:40 by r00t
I'm not Ernie, but I know the imagelib relies on some COM stuff provided by Windows to load various fileformats... so he hasn't coded the decompression algorithms (it is not a bad thing, as you don't have to worry about patents... especially when dealing with gif images...)

PS : Ernie, Happy Marriage ! :grin:
Posted on 2002-06-10 03:15:48 by JCP