I've got a function which loads a bit map of either 8/16/24 bit color depth.

the 8 bit section works with all image sizes but for some reason the 24 bit section (which dependig on the bitdepth of the screen will convert the bitmap to either 16 or 32 bits, gives an error unless the bitmaps are a certain size.
Funnily enough the error does not occur in the code which I wrote but during a call to GlobalAlloc.

for example: the call to GlobalAlloc fails if the bitmap is say 320x240. but it succeeds if the bitmap size is 640x240.

Does anyone have any idea why this might be happening ?

cheers:confused:
Posted on 2002-09-13 18:19:33 by MArtial_Code
I've never had such problems with GlobalAlloc, perhaps if you post some code.
Posted on 2002-09-13 18:31:02 by Eóin


PT "Converting 24bit RGb to 32bit RGB"
invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,(pBITMAPFILE [ebx]).BIH.biSizeImage
test eax,eax
jz error_close
mov _lpTempBuf,eax
;allocate final 32 bit storage buffer
mov eax,(pBITMAPFILE [ebx]).BIH.biWidth
mov ecx,(pBITMAPFILE [ebx]).BIH.biHeight
mul ecx
shl eax,2;multiply by four since 32 bit values
invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,eax
test eax,eax
jz error_close2
mov (pBITMAPFILE [ebx]).lpImage,eax
;now read it in
invoke ReadFile,_hFile,_lpTempBuf,(pBITMAPFILE [ebx]).BIH.biSizeImage,addr _dwBytesRead,NULL

;now convert each 24 bit RGB value into a 32 bit value
mov eax,(pBITMAPFILE [ebx]).BIH.biWidth
mul (pBITMAPFILE [ebx]).BIH.biHeight
mov edi,(pBITMAPFILE [ebx]).lpImage ;destination buffer
mov esi,_lpTempBuf;source buffer
mov ecx,eax ;ecx=width*height

mov edx,ecx
shl edx,1
add edx,ecx ;multiply edx by 3
[B] do_RGB32:;extract RGB components <problem may have something to do with this loop
mov eax,dword ptr[esi+edx];load in rgb data
and eax,00FFFFFFH
mov dword ptr[edi+ecx*4],eax;build up 32 bit color word write to output buffer
sub edx,3
dec ecx
jg do_RGB32
RGB32_done:[/B]
PT "image Converted"
mov (pBITMAPFILE [ebx]).BIH.biBitCount,32;update the bitmap info
invoke GlobalFree,_lpTempBuf ;free temporary buffer


The above is the section which converts the 24bit rgb to 32bit.
The next call to GlobalAlloc fails. If i substitute mov dword ptr,eax with mov dword ptr, then the next globalalloc succeeds but the image won't be converted properly...

cheers
Posted on 2002-09-13 18:56:19 by MArtial_Code
well I solved the GlobalAlloc problem by passing the flag GMEM_MOVEABLE and using GlobalLock
but now if the mouse moves over the window I get a GPF...
cheers.
Posted on 2002-09-14 05:28:03 by MArtial_Code
weird, I've never used the GlobalAlloc, If this sounds unreasonable please give me a virtual slap ;) . Anyway why not use the HeapCreate and HeapAlloc functions? You can easily create a growable heap and u can allocate memory until pigs start to fly.
Posted on 2002-09-14 12:07:05 by x86asm
WHew...problem solved...
there was a jge which should have been a jg which was causing the problem...its funny how that caused windows to go crazy!!

cheers:alright:
Posted on 2002-09-14 17:22:29 by MArtial_Code