BOOL init_dib_info(dib_info *dib, const BITMAPINFOHEADER *bi, const DWORD *bit_fields, RGBQUAD *color_table, int color_table_size, void *bits, enum dib_info_flags flags) { dib->bit_count = bi->biBitCount; dib->width = bi->biWidth; dib->height = bi->biHeight; dib->stride = get_dib_stride( dib->width, dib->bit_count ); dib->bits.ptr = bits; dib->bits.is_copy = FALSE; dib->bits.free = NULL; dib->bits.param = NULL; dib->flags = flags; if(dib->height < 0) /* top-down */ { dib->height = -dib->height; } else /* bottom-up */ { /* bits always points to the top-left corner and the stride is -ve */ dib->bits.ptr = (BYTE*)dib->bits.ptr + (dib->height - 1) * dib->stride; dib->stride = -dib->stride; } dib->funcs = &funcs_null; switch(dib->bit_count) { case 32: if(bi->biCompression == BI_RGB) bit_fields = bit_fields_888; init_bit_fields(dib, bit_fields); if(dib->red_mask == 0xff0000 && dib->green_mask == 0x00ff00 && dib->blue_mask == 0x0000ff) dib->funcs = &funcs_8888; else dib->funcs = &funcs_32; break; case 24: dib->funcs = &funcs_24; break; case 16: if(bi->biCompression == BI_RGB) bit_fields = bit_fields_555; init_bit_fields(dib, bit_fields); if(dib->red_mask == 0x7c00 && dib->green_mask == 0x03e0 && dib->blue_mask == 0x001f) dib->funcs = &funcs_555; else dib->funcs = &funcs_16; break; case 8: dib->funcs = &funcs_8; break; case 4: dib->funcs = &funcs_4; break; case 1: dib->funcs = &funcs_1; break; default: TRACE("bpp %d not supported, will forward to graphics driver.\n", dib->bit_count); return FALSE; } if(color_table) { if (flags & private_color_table) { dib->color_table = HeapAlloc(GetProcessHeap(), 0, color_table_size * sizeof(dib->color_table[0])); if(!dib->color_table) return FALSE; memcpy(dib->color_table, color_table, color_table_size * sizeof(color_table[0])); } else dib->color_table = color_table; dib->color_table_size = color_table_size; } else { dib->color_table = NULL; dib->color_table_size = 0; } return TRUE; }
static void init_dib_info(dib_info *dib, const BITMAPINFOHEADER *bi, const DWORD *bit_fields, const RGBQUAD *color_table, void *bits) { dib->bit_count = bi->biBitCount; dib->width = bi->biWidth; dib->height = bi->biHeight; dib->rect.left = 0; dib->rect.top = 0; dib->rect.right = bi->biWidth; dib->rect.bottom = abs( bi->biHeight ); dib->compression = bi->biCompression; dib->stride = get_dib_stride( dib->width, dib->bit_count ); dib->bits.ptr = bits; dib->bits.is_copy = FALSE; dib->bits.free = NULL; dib->bits.param = NULL; if(dib->height < 0) /* top-down */ { dib->height = -dib->height; } else /* bottom-up */ { /* bits always points to the top-left corner and the stride is -ve */ dib->bits.ptr = (BYTE*)dib->bits.ptr + (dib->height - 1) * dib->stride; dib->stride = -dib->stride; } dib->funcs = &funcs_null; switch(dib->bit_count) { case 32: if(bi->biCompression == BI_RGB) bit_fields = bit_fields_888; init_bit_fields(dib, bit_fields); if(dib->red_mask == 0xff0000 && dib->green_mask == 0x00ff00 && dib->blue_mask == 0x0000ff) dib->funcs = &funcs_8888; else dib->funcs = &funcs_32; break; case 24: dib->funcs = &funcs_24; break; case 16: if(bi->biCompression == BI_RGB) bit_fields = bit_fields_555; init_bit_fields(dib, bit_fields); if(dib->red_mask == 0x7c00 && dib->green_mask == 0x03e0 && dib->blue_mask == 0x001f) dib->funcs = &funcs_555; else dib->funcs = &funcs_16; break; case 8: dib->funcs = &funcs_8; break; case 4: dib->funcs = &funcs_4; break; case 1: dib->funcs = &funcs_1; break; } if (color_table && bi->biClrUsed) { dib->color_table = color_table; dib->color_table_size = bi->biClrUsed; } else { dib->color_table = NULL; dib->color_table_size = 0; } }