I have a question on CreateDibSection. Im creating a section of 32 bpp and im using a function we can say "PutPixel" that simple makes:
The thing is that CreateDIBSection is inverting the colours bytes, i mean if a do a "PutPixel(50, 50, RGB(30,0, 61));", the RED value is considered the BLUE and viceversa. Why this? :roll:
Onother thing is if i pass a positive value to the Height parameter of BITMAPINFO structure when i create the section, then when i BLT the DIB it is horizontal inverted, so i have to pass a negative one. Again, why this? :roll:
void PutPixel(DWORD x, DWORD y, COLORREF Colour)
{
g_lpBMPMem[y * BmpWidth + x] = Colour;
}
The thing is that CreateDIBSection is inverting the colours bytes, i mean if a do a "PutPixel(50, 50, RGB(30,0, 61));", the RED value is considered the BLUE and viceversa. Why this? :roll:
Onother thing is if i pass a positive value to the Height parameter of BITMAPINFO structure when i create the section, then when i BLT the DIB it is horizontal inverted, so i have to pass a negative one. Again, why this? :roll:
Aside the fact that writing a PutPixel procedure defeats the whole point of using CreateDIBSection (it was just an example, I know :) ), what you're describing are not really problems, but the documented functionality of this API call...
1. DIB bitmaps created with the BI_RGB flag use the RGBQUAD format instead of COLORREF. It works just like you described. I undestand you can change this behavior by specifying your own color format (BI_BITFIELDS), but I found it not to work at all unless you happen to describe an exact equivalent to BI_RGB, at least under Win9X. Maybe in up-to-date Windows versions it works like it should. :roll: :-D
2. It's a convention. A positive value means you want to create a bottom-up bitmap, a negative value for a top-down. See this quote from MSDN:
biHeight:
Specifies the height of the bitmap, in pixels. If biHeight is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, the bitmap is a top-down DIB and its origin is the upper-left corner.
If biHeight is negative, indicating a top-down DIB, biCompression must be either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.
Some links:
http://msdn.microsoft.com/library/en-us/gdi/bitmaps_233i.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_0zn6.asp
http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_5f8y.asp
http://msdn.microsoft.com/library/en-us/gdi/colors_9xiq.asp
Hope that helps. :)
1. DIB bitmaps created with the BI_RGB flag use the RGBQUAD format instead of COLORREF. It works just like you described. I undestand you can change this behavior by specifying your own color format (BI_BITFIELDS), but I found it not to work at all unless you happen to describe an exact equivalent to BI_RGB, at least under Win9X. Maybe in up-to-date Windows versions it works like it should. :roll: :-D
2. It's a convention. A positive value means you want to create a bottom-up bitmap, a negative value for a top-down. See this quote from MSDN:
biHeight:
Specifies the height of the bitmap, in pixels. If biHeight is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, the bitmap is a top-down DIB and its origin is the upper-left corner.
If biHeight is negative, indicating a top-down DIB, biCompression must be either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.
Some links:
http://msdn.microsoft.com/library/en-us/gdi/bitmaps_233i.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_0zn6.asp
http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_5f8y.asp
http://msdn.microsoft.com/library/en-us/gdi/colors_9xiq.asp
Hope that helps. :)
yes now i got it. Thanks