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

minor28

I have struggled to try to draw an image from memory without success. The image is not a regular image so I have to process the data.

Following bitmapinfo which I have populated BITMAPINFO structure with.

Width=974
height=836

DX=0.85
DY=0.85

RGB/1,0,0,0
RGB/2,255,255,255
RGB/3,255,19,19
RGB/4,0,192,0
RGB/5,192,180,159
RGB/6,254,255,181
RGB/7,221,235,255
RGB/8,124,182,242

Pixel data consits of bytes in allocated memory like {05 05 05 01 01 01 ....} where each byte is the index of the zerobased color table.

I have tryed this code.

invoke CreateDIBSection,hSHP1DC,addr bmi,DIB_RGB_COLORS,offset pPixelData,0,0
mov hBitmap,eax ;=2F051225h
invoke SetDIBits,hSHP1DC,hBitmap,0,bsb._height,pPixelData,addr bmi,DIB_RGB_COLORS ;=344h =836
invoke DeleteDC,hSHP1DC

No image!

I have tryed this code


invoke CreateCompatibleBitmap,hSHP1DC,bsb._width,bsb._height
mov hBitmap,eax ;=0C1051063h
invoke CreateCompatibleDC,hSHP1DC
mov hDC,eax ;=0AF011155h
invoke CreateDIBSection,hSHP1DC,addr bmi,DIB_RGB_COLORS,offset pPixelData,0,0
mov hBitmap,eax
invoke SetDIBits,hSHP1DC,hBitmap,0,bsb._height,pPixelData,addr bmi,DIB_RGB_COLORS ;=0
invoke SelectObject,hDC,hBitmap ;=0185000Fh
push eax
invoke BitBlt,hSHP1DC,0,0,bsb._width,bsb._height,hDC,0,0,SRCCOPY ;1
pop eax
invoke DeleteObject,eax
invoke DeleteDC,hDC
invoke DeleteDC,hSHP1DC

No image!

hSHP1DC is DC of a static window to hold the image. pPixelData is the pointer to allocated memory (LocalAlloc).

Can anyone give me a hint how to proceed? I am not familiar with drawing images.

Twister

What do you mean that the bitmap is not a normal image? Does it not follow the Microsoft Bitmap Image Format? If it doesn't then it is considered as a broken image, or corrupted.

Just convert the image to a regular 24-bit Microsoft Bitmap Image.

minor28

I am trying to convert the image to a  regular bitmap. The image file (*.kap) has a header with strings as I wrote above and pixel data as hex values not as a regular bitmap. I have allocated memory for pixel data converted to byte values and populated a bitmap info structure based on the string header. I want to draw the image with converted data from the file to the static window.

baltoro

You should start off with: Bitmaps. Most of the Windows Bitmap GDI functions are pretty picky about the format that the image is in. There are several header structures (depending on whether you are using a DIBSection or a file in memory.) Here is the MSDN page about BITMAPINFOHEADER. All the data must be contiguous in memory.
Edgar has an assembly language Graphics Library, that is designed to work with DIBSections.
Here is an excellent discussion about: Saving a Memory DC to Bitmap, on this forum.
If you search this forum for: DIBSection, you will find lots of useful information.
Baltoro

Twister


petezl

Cats and women do as they please
Dogs and men should realise it.

minor28

I have been searching without finding anything similar. I have read MSDN. I have not seen the GDAL site but I have got a dll converting the file to a tiff file. I want to read the kap-file and display it diredtly on screen not using a dll.

This is my code in principal.



BitmapProc proc
LOCAL bmi:BITMAPINFOHEADER
LOCAL rgbArray[8]:RGBQUAD


invoke GetDlgItem,hWin,IDC_SHP1
mov hSHP1,eax
invoke GetDC,hSHP1
mov hSHP1DC,eax

mov bmi.biSize,sizeof bmi
mov bmi.biWidth,974
mov bmi.biHeight,836
mov bmi.biPlanes,1
mov bmi.biBitCount,8
mov bmi.biCompression,BI_RGB
mov bmi.biSizeImage,814264
mov bmi.bmiHeader.biXPelsPerMeter,0
mov bmi.bmiHeader.biYPelsPerMeter,0
mov bmi.biClrUsed,8
mov bmi.biClrImportant,8

rgbArray = {00 00 00 00, FF FF FF 00, 13 13 FF 00, 00 C0 00 00, .....}


invoke LocalAlloc,LMEM_FIXED or LMEM_ZEROINIT,bmi.biSizeImage
mov hPixelData,eax
invoke LocalLock,hPixelData
mov pPixelData,eax

pPixelData = {05 05 05 05 05 01 01 08 08 04 .......}


invoke CreateDIBSection,hSHP1DC,addr bmi,DIB_RGB_COLORS,offset pPixelData,0,0
mov hBitmap,eax
invoke SetDIBits,hSHP1DC,hBitmap,0,bmi.biHeight,pPixelData,addr bmi,DIB_RGB_COLORS

invoke DeleteDC,hSHP1DC
invoke LocalFree,hPixelData

BitmapProc endp


Return value from SetDIBits function is the number of rows written as it should but nothing is painted. Is anything wrong with bitmapinfo structure or array of pixeldata? Am I missing som API?

dedndave

i have never heard of this file format, so i googled it out of curiousity
i found this description, if it helps any (i know it does not answer your question - lol)

http://libbsb.sourceforge.net/bsb_file_format.html

petezl

Looks at first glance that your code is reasonable! Problem is probably screwed BitmapInfoHeader data...

try to write the data to file as bitmap then its a simple case of loading and blting it to the dc.
A blank (black) screen suggests that the info sent to the dc was not compatible
Think of CreateCompatibleBitmap api as creating a <standard ms compatible> grid filled with zeros. ie blank!
If your generated bitmap doesn't comply fully then the call will almost certainly fail.

Anyway, an interesting exercise!
Cats and women do as they please
Dogs and men should realise it.

dedndave

yes - it is interesting
i take it you are receiving image data from a sat ?
or are you able to d/l these files from NOAA

petezl

Parsing the .kap file, extracting and inserting the raster data into a bitmap array, then updating the BITMAPINFOHEADER is one way and probably one of the easier approaches! Then save it to file. (I'd steer clear of DC's during this stage!)
Need to find the structure details of the kap file, maybe better than shown here:http://libbsb.sourceforge.net/bsb_file_format.html yet that's a good place to start!

A small kap file to play with would certainly be of help!

Good thing with this approach is that you can easily test results by double clicking on the produced file and it should open in paint.

With a good file its an easy matter to load and display it in a window by using:
invoke LoadImage, NULL, addr imageFilePth,IMAGE_BITMAP,0,0,LR_LOADFROMFILE
mov hbitmap, eax

invoke CreateCompatibleDC, NULL
mov hMemDC, eax

invoke SelectObject, hMemDC, hbitmap
invoke GetClientRect, hWnd, addr rect

invoke BitBlt, hdc,0,0, rect.right, rect.bottom, hMemDC,0,0, SRCCOPY
invoke DeleteDC, hMemDC


in your WM_PAINT call.

Once the two halves are working you should be able to make it all one process!

Going on here a bit (just thinking out loud!) ah.


Cats and women do as they please
Dogs and men should realise it.

petezl

Cats and women do as they please
Dogs and men should realise it.

dedndave

playing around a little, here - lol
i see that NOAA has a freebie program that will not only convert the file format (i used TIFF), but will also "re-project"
i.e., change the chart projection
the program is a little clumsy to use, but the results are very cool

http://www.csc.noaa.gov/crs/chartreproj.html

not only do they have windows and linux, but solaris versions

dedndave

i changed the projection of this one
(these charts are huge - this is scaled way down and converted to GIF - lol)


petezl

Ah yes, you can see the need for the special file format now!
Irregular shape as well...
Cats and women do as they please
Dogs and men should realise it.