I thought about using GifLib as a 3.5 MB resource section is kinda
<cough> big... But before I start hacking my code into bits and
pieces I need to be certain on one point.

The Bitmaps I'm using - I can save them under Gif easily... np
They will have the same proportions and everything...

But will it have the same proportions after decoding again? So that I can
keep all my hardcoded values?

Thomas uses this for final display:

invoke BitBlt, eax, 0,0,TestGif.dwImageWidth,TestGif.dwImageHeight,hDCBitmap, 0,0,SRCCOPY

which makes me hesitate...

Thanks in advance,
Posted on 2002-03-07 23:19:48 by JimmyClif
They have exactly the same width and height as your bitmap, I just used the variables to be able to change the GIF proportions without having to modify the program.
Hardcoded values are fine.

Posted on 2002-03-08 01:51:23 by Thomas
Alright.. Thanks Thomas :D
Posted on 2002-03-08 10:37:53 by JimmyClif
If the GIFs don't move, you can use the Windows OleLoadPicturePath API to load them. It also does wmf, bmp, jpg, and probably some other things too.

Its a bit of a hassle, as its a COM interface, and you get back a picture object, which means you have to use its "blit to dc" method (named Render) to draw it on your DC during a Paint message, but thats a heck of a lot less code then using a lib.
Posted on 2002-03-08 13:35:00 by Ernie
Your example shows displaying images by loading from from file.Could you explain how to load image from resource without extracting to temp directory and load ? Thanks
Posted on 2002-03-08 15:02:53 by LaptoniC
Do you mean Ernie's or mine?
OleLoadPicture can load a picture from a 'data stream' so you should be able to load it using LoadResource.
My giflib has an example included for loading from resources.

Posted on 2002-03-08 15:14:20 by Thomas
I mean Ernie's.

Your library works perfecly for me.I guess most of the user have problems with your lib because in the demos you define

ColorTable db 32*4 dup (?)

This buffer -as you said to me- must like this

ColorTable db howmanycolorsinthegif*4 dup (?)

Mostly, we have gif files with 256 colors, so I guess, that is why it crashes.I have a suggestion, your GIF_INFO structure has a
ColorCount member.If you allocate that much of memory dynamically it will be more effective.
Keep up the good work
Posted on 2002-03-09 04:50:10 by LaptoniC
Thanks for the idea, I'll think about it. The thing you meantioned can cause problems, but some GIFs crash the giflib because they are created with a program that adds a lot of extra stuff in the GIF which the giflib can't handle.
There's also a problem with GIFs with less than 32 colors iirc.

Posted on 2002-03-09 06:12:44 by Thomas
I have tried to load gif file by loadresource but it didnt worked here is my code

in my rc
800 RCDATA "logo.gif"

in my asm file
gpPicture1 DWORD 0

invoke GetModuleHandle, NULL ;take handle of our app
mov hInstance,eax
In my wndproc

LOCAL rect:RECT, hmWidth:DWORD, hmHeight:DWORD
LOCAL nWidth:DWORD, nHeight:DWORD, neghmHeight:DWORD
.IF uMsg==WM_INITDIALOG ;dialog intialized
invoke LoadResourceImg,hInstance,800,ADDR gpPicture1
it returns 6
invoke BeginPaint, hWin, ADDR ps
mov hdc, eax
.IF gpPicture1
; get width and height of picture
coinvoke gpPicture1, IPicture, get_Width, ADDR hmWidth
coinvoke gpPicture1, IPicture, get_Height, ADDR hmHeight

; convert himetric to pixels
invoke GetDeviceCaps,hdc, LOGPIXELSX
invoke MulDiv, hmWidth, eax, HIMETRIC_INCH
mov nWidth, eax

invoke GetDeviceCaps,hdc, LOGPIXELSY
invoke MulDiv, hmHeight, eax, HIMETRIC_INCH
mov nHeight, eax

xor eax, eax
sub eax, hmHeight
mov neghmHeight, eax

invoke GetClientRect, hWin, ADDR rect
; display picture using IPicture::Render
coinvoke gpPicture1, IPicture, Render, hdc, 0, 0, nWidth, nHeight, 0, hmHeight, hmWidth, neghmHeight, ADDR rect

invoke EndPaint, hWin, ADDR ps

LoadResourceImg PROC hInst:DWORD,lpName:DWORD,ppPicture:DWORD

invoke FindResource, hInst, lpName, RT_RCDATA
.IF eax==0
mov eax,1
mov hRes,eax
invoke LoadResource,hInst,hRes
.IF eax==0
mov eax,2
mov hGlobal,eax

invoke SizeofResource, hInst, hRes
.IF eax==0
mov eax,3
mov Rsize,eax
mov pstm, NULL
; create IStream* from global memory
invoke CreateStreamOnHGlobal, hGlobal, TRUE, ADDR pstm
mov eax,4
.IF !pstm
mov eax,5
.IF ppPicture
mov ecx, ppPicture
mov ecx,
.IF ecx;gpPicture1
coinvoke ecx, IUnknown, Release
invoke OleLoadPicture, pstm, dwFileSize, FALSE, ADDR IID_IPicture, ppPicture
coinvoke pstm, IUnknown, Release
mov eax,6

coinvoke pstm, IUnknown, Release
xor eax,eax
LoadResourceImg endp
Posted on 2002-03-09 12:33:13 by LaptoniC
I follow this thread with great interest...I'll try to use the com method too... Unfortuantely it's weekend and I need to go out and party :( I'll try as soon as I'm sobered up again.

Posted on 2002-03-09 13:49:42 by JimmyClif

Thats a good suggestion, I'll have to work it out.

Would be a good additon to that tut (as would a version that's straight MASM32, without CoLib (which doesn't add code, just a steeper learning curve).
Posted on 2002-03-09 17:43:09 by Ernie
Until the tut comes along (now don't rush me...) here's the source code. Hopefully it will make sense when combined with my existing tut:

// rsrc.rc
2001 JPEG DISCARDABLE "homer-st.jpg"

szResType BYTE "JPEG", 0

; Main Window Proc
.if uMsg==WM_CREATE
invoke LoadPictureRes, 2001, ADDR szResType, ADDR gpPicture1

LoadPictureRes PROC ResID:DWORD, pszResType:DWORD, ppPicture:DWORD
LOCAL hImage:DWORD, hResource:DWORD, pBuf:DWORD
LOCAL pstm:DWORD, dwFileSize:DWORD

; get a resource handle (address) and resource length from the executable
; note: there is no error checking (but will tollerate an error anyway)
invoke FindResource, NULL, ResID, pszResType
mov hResource, eax
invoke LoadResource, NULL, eax
invoke LockResource, eax
mov hImage, eax
invoke SizeofResource, NULL, hResource
mov dwFileSize, eax
mov pstm, NULL
invoke CoTaskMemAlloc, dwFileSize ; copy picture into task memory
mov pBuf, eax
invoke MemCopy, hImage, pBuf, dwFileSize
; create a stream for the picture object's creator
invoke CreateStreamOnHGlobal, pBuf, TRUE, ADDR pstm
.IF ppPicture
mov ecx, ppPicture
mov ecx, [ecx]
.IF ecx ; check if we've been passed an existing object,
coinvoke ecx, IUnknown, Release ; and release it if we have
; create a picrture object
invoke OleLoadPicture, pstm, dwFileSize, TRUE, ADDR IID_IPicture, ppPicture
coinvoke pstm, IUnknown, Release ; release the stream
invoke CoTaskMemFree, pBuf ; free task memory
LoadPictureRes ENDP

For some reason I don't understand, I had to copy the jpg file to task memory to get this routine to fly. When creating IStream direct from the resource handle, OleLoadPicture would fail with an hresult of "unexpected error."
Posted on 2002-03-10 05:53:38 by Ernie
Heya Ernie... thanks for postng this code.. I'll try it out soon...
Yesterday too while surfing I came across a text written by Barry Kauler talking about you and Thomas' GifLib... I just flew over and read a couple of keywords atm but anyway.. here's the link...


hehehe.. after reading it.. he talks about your LoadPic.asm
which I could have gotten on your side long time ago *lol*
but then again... I like to surf a lot :)
Posted on 2002-03-10 23:27:19 by JimmyClif