News:

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

How do I process data to draw a bitmap?

Started by minor28, August 11, 2010, 01:05:48 PM

Previous topic - Next topic

dedndave

well - the file format allows the location (longitude/lattitude) to be specified
as well as a few other things   :P

the irregular shape was my doing - lol

petezl

I was thinking that if the image background is part of a sphere then converting to bitmap on a flat plane will produce distortion!
Yea, lat & long, getting complicated...
Cats and women do as they please
Dogs and men should realise it.

dedndave

well - that reproject program from NOAA allows you to change projections as desired
i could have "flattened" it out, if i wanted to - i was just playing with all the buttons   :P

petezl

Dave, looks like a conversion can be made ok, main problem as I see it now is that placing such an immense bitmap into a window is rather useless!
Ok for manipulation in pShop or other program, but for direct viewing in a window the BM would need some serious size reduction which I have never had the need to persue!
Ie. Back to the original question: using conversion in a dll would only be of benefit if you had a fairly advanced picture handling procedure (with scroll and sizing facility)
My code is a bit too dirty to upload but is directly along the lines I suggested...
Cats and women do as they please
Dogs and men should realise it.

minor28

Thanks both of you,

I have already visit the bsb site as you mentioned and studied the file format.

My intention is not to view the whole image but only a part of it depending of the scrollbars position. Now I am looking at the headerinfo. As I can see the color table is correct. I think I have to calculate the constant for pixel per meter. I still work on it.

dedndave

this is part of the chart at 1X, as viewed with Paint
i have left the scroll bars intact so you can see what portion of the image is displayed



petezl

Got a dim recollection that there is a max_filesize for bitmaps, might present a problem...
Cats and women do as they please
Dogs and men should realise it.

dedndave

yah - i think you'll have to convert the entire image to a bitmap file (RAW or BMP),
then pick a window area out with your own code, making a smaller bitmap
that is, if you want to display it at 1X

minor28

Each scanline of the pixel data must be a multiple of a dword which was one fault.


;number of pixels
mov eax,bsb._width
mov ecx,bsb._height
mul ecx
push eax

;number of line paddings with zeroes
mov eax,bsb._width
mov ecx,4
div ecx
mov eax,bsb._height
mul edx
pop ecx
add eax,ecx
push eax
invoke LocalAlloc,LMEM_FIXED or LMEM_ZEROINIT,eax
mov hPixelData,eax
invoke LocalLock,hPixelData
mov pPixelData,eax
....


Next was allocating stack memory for BITMAPINFO

LOCAL bmi:BITMAPINFOHEADER
LOCAL rgbArray[8]:RGBQUAD

A pointer to bmi is not the same as a pointer to a BITMAPINFO structure.

How do I populate a BITMAPINFO structure with 8 entries of the color table? I tryed this

_BITMAPINFO struct
bmiHeader BITMAPINFOHEADER <?>
bmiColors dd 8 DUP (?)
_BITMAPINFO ends

.data?
bmi _BITMAPINFO <>




invoke CreateDIBSection,hDC,offset bmi,DIB_RGB_COLORS,offset pvBits,0,0
mov hBitmap,eax
invoke SetDIBits,hDC,hBitmap,0,bmi.bmiHeader.biHeight,pPixelData,offset bmi,DIB_RGB_COLORS

Return value of SetDIBits is 344h (number of rows) and the memory at pvBits is filld with data from pPixelData. No image.

Any suggestion how to proceed?

Edit:

invoke GetDIBits,hDC,hBitmap,0,bmi.bmiHeader.biHeight,pvBits,offset bmi,DIB_RGB_COLORS

Returns correct image size but biClrUsed and biClrImportant are set to zeroes.

dedndave

i'm not sure where you're at - lol

yes - each scanline must begin on an offset that is mod 4, relative to the end of the header (+1)
i take it you are creating a 256-color BMP
if that's the case, the palette has a wierd structure
each entry is 4 bytes:
B,G,R,0
half the stuff in a BMP is backwards - the other half is not - lol
also, the first scanline in the file is normally the last line of the image
you can reverse this by negating the height value in the header
i.e., if the height is negative, the scanlines are "right-side-up"

drizz

>> How do I populate a BITMAPINFO structure with 8 entries of the color table? I tryed this...
have you tried SetDIBColorTable?
The truth cannot be learned ... it can only be recognized.

minor28

OK, I changed to a negative height.

SetDIBColorTable return error.

I created an empty bmp-file. Filled it with data from headers and pixel-data from allocated memory. I could open the image with MSPaint but not with LoadImage etc.

dedndave

there were some related threads a while back
let me see what i can find - maybe i will play with it a little.....
......after my nap   :P

minor28

Now both MSPaint and LoadImage API etc opens the image from the newly created file. Still not CreateDIBSection from memory.


invoke CreateDIBSection,hDC,offset bmi,DIB_RGB_COLORS,offset pvBits,0,0
.if eax==0 && pvBits==0
jmp @F
.endif
mov hBitmap,eax

invoke SetDIBits,hDC,hBitmap,0,bmi.biHeight,pPixelData,offset bmi,DIB_RGB_COLORS
.if eax==0
jmp @F
.endif

hDC is handle to Shape device context.

minor28

At last. Problem is solved.


invoke CreateDIBSection,hDC,offset bmi,DIB_RGB_COLORS,offset pvBits,0,0
.if eax==0 && pvBits==0
jmp @F
.endif
mov hBitmap,eax

invoke GetClientRect,hWin,addr rect
invoke StretchDIBits,hDC,0,0,rect.right,rect.bottom,0,0,bmi.biWidth,bmi.biHeight,pPixelData,offset bmi,DIB_RGB_COLORS,SRCCOPY
.if eax==0
jmp @F
.endif


Also I had to write pixeldata to memory from down to up and keep a positive height.

Thanks for your help