Restored from previous forum. Originally posted by ebs.
raphael,
yes, the code is correct. i'm not sure if the structures are correct in purebasic though. isn't 'bmiHeader' in BITMAPINFO of type BITMAPINFOHEADER instead of long? BITMAPINFO would be bigger than BITMAPINFOHEADER then. that's what i understand from the wingdi.h at least.
Yes, I looked it up in the APIViewer and I agree with you. In PureBasic, I think this is correct:
Code: Select all
Structure BITMAPINFO
bmiHeader.BITMAPINFOHEADER
bmiColors.b[4]
EndStructure
NOT
Code: Select all
Structure BITMAPINFO
bmiHeader.l
bmiColors.l
EndStructure
Maybe someone thought that the bmiHeader element was supposed to be a pointer (long), but I don't think so. You'll notice that I made bmiColors an array of 4 bytes (like the RGBQUAD structure) instead of a long. This should be the same thing, just a little easier to assign the colors individually.
shouldn't
bitmap_header->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
be like
bitmap_header\bmiHeader\biSize = sizeof(BITMAPINFOHEADER)
in pb?
Yes, but the bitmap_header variable is just a pointer to the bitmapbuffer memory, so I think you can do something like this:
Code: Select all
; note new structure which includes the extra 16 bytes
Structure BITMAPINFOPLUS16
bmiHeader.BITMAPINFOHEADER
bmiColors.b[4]
extrabytes.b[16]
EndStructure
; all fields should be initialized to 0 when created
bitmapbuffer.BITMAPINFOPLUS16
bitmapbuffer\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bitmapbuffer\bmiHeader\biPlanes = 1
bitmapbuffer\bmiHeader\biBitCount = 32
bitmapbuffer\bmiHeader\biCompression = #BI_BITFIELDS
bitmapbuffer\bmiHeader\biWidth = surface_width
bitmapbuffer\bmiHeader\biHeight = -surface_height
bitmapbuffer\bmiColors[0] = $ff
bitmapbuffer\bmiColors[1] = $ff
bitmapbuffer\bmiColors[2] = $ff
I'm not sure why the C code uses longs when setting the bmiColors values. I believe they are bytes, not longs, as the definition of RGBQUAD is an array of four bytes.
Hope this helps,
Eric