Original Post
I'm trying to work with a 24bpp bitmap that I created using CreateDIBSection. If I understand the MSDN correctly the width of each scanline is aligned to DWORD (NT) or WORD (Win9x) boundries but I must be missing something because when I account for the extra padding the image is still messed up.
This is how I am creating the bitmap:
Colin Jeanne | Invader's Realm
"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud [edited by - Invader X on March 21, 2004 8:25:36 PM]
BITMAPINFOHEADER bmi; bmi.biSize = sizeof(BITMAPINFOHEADER); bmi.biWidth = crp->size; bmi.biHeight = -crp->size; bmi.biPlanes = 1; bmi.biBitCount = 24; bmi.biCompression = BI_RGB; bmi.biClrImportant = 0; bmi.biSizeImage = 0; HDC hdc = GetDC(hwnd); crp->hbm = CreateDIBSection(hdc, reinterpret_cast<BITMAPINFO *>(&bmi), DIB_RGB_COLORS, reinterpret_cast<LPVOID *>(&crp->bits), 0, 0);This is how I am trying to set each pixel:
//size is the width of the image in pixels
void SetPixel(char *bits, unsigned long x, unsigned long y, int size, COLORREF c) {
unsigned long padding = sizeof(DWORD) - (3 * size % sizeof(DWORD));
if (padding == sizeof(DWORD))
padding = 0;
unsigned long linear_pixel = (x + (size + padding) * y) * 3;
bits[linear_pixel] = GetBValue(c);
bits[linear_pixel + 1] = GetGValue(c);
bits[linear_pixel + 2] = GetRValue(c);
}
If the width is DWORD aligned then the image paints perfectly. Is there something I'm not taking into account?
"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud [edited by - Invader X on March 21, 2004 8:25:36 PM]