# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1304387031 0 # Node ID d90222530bb9bff795388ac8af649cfd36bc2b53 # Parent 2b1b9b9957489df58f0854c0c70dda8f78e1453c Added code to detect the actual color depth of loaded bitmap files on Windows. It seems that any LoadImage() loaded bitmaps are converted to the native screen depth... So using the internal functions to check the depth is useless. diff -r 2b1b9b995748 -r d90222530bb9 win/dw.c --- a/win/dw.c Mon May 02 17:51:35 2011 +0000 +++ b/win/dw.c Tue May 03 01:43:51 2011 +0000 @@ -8806,15 +8806,58 @@ ReleaseDC(handle, hdc); -#if 0 - /* force a CONFIGURE event on the underlying renderbox */ - dw_window_get_pos_size( handle, NULL, NULL, &cx, &cy ); - SendMessage( handle, WM_SIZE, 0, MAKELPARAM(cx, cy) ); -#endif - return pixmap; } +/* Read the file bitmap header ourselves... + * apparently we can't check the depth once loaded... + * since it seems to normalize it to our screen depth. + */ +unsigned long _read_bitmap_header(char *file) +{ + BITMAPFILEHEADER header; + BITMAPINFO *info; + FILE *fp; + int infosize; + int depth = 0; + + /* Try opening the file; use "rb" mode to read this *binary* file. */ + if((fp = fopen(file, "rb")) == NULL) + return 0; + + /* Read the file header and any following bitmap information... */ + if(fread(&header, sizeof(BITMAPFILEHEADER), 1, fp) < 1) + { + /* Couldn't read the file header */ + fclose(fp); + return 0; + } + + if(header.bfType != 'MB') /* Check for BM reversed... */ + { + /* Not a bitmap file */ + fclose(fp); + return 0; + } + + infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER); + if((info = (BITMAPINFO *)calloc(infosize, 1)) == NULL) + { + /* Couldn't allocate memory for bitmap info */ + fclose(fp); + return 0; + } + + if(fread(info, 1, infosize, fp) == infosize) + { + /* Read the bitmap header */ + depth = info->bmiHeader.biBitCount; + } + free(info); + fclose(fp); + return depth; +} + /* * Creates a pixmap from a file. * Parameters: @@ -8832,6 +8875,7 @@ HDC hdc; ULONG cx, cy; char *file = malloc(strlen(filename) + 5); + BITMAPINFO *info; if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) { @@ -8859,6 +8903,7 @@ pixmap->handle = handle; pixmap->hbm = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); + pixmap->depth = _read_bitmap_header(file); if ( !pixmap->hbm ) { @@ -8871,17 +8916,11 @@ pixmap->hdc = CreateCompatibleDC( hdc ); GetObject( pixmap->hbm, sizeof(bm), &bm ); pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; - pixmap->depth = bm.bmBitsPixel; SelectObject( pixmap->hdc, pixmap->hbm ); ReleaseDC( handle, hdc ); free( file ); pixmap->transcolor = DW_RGB_TRANSPARENT; -#if 0 - /* force a CONFIGURE event on the underlying renderbox */ - dw_window_get_pos_size( handle, NULL, NULL, &cx, &cy ); - SendMessage( handle, WM_SIZE, 0, MAKELPARAM(cx, cy) ); -#endif return pixmap; } @@ -8922,6 +8961,7 @@ fwrite( data, 1, len, fp ); fclose( fp ); pixmap->hbm = (HBITMAP)LoadImage( NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + pixmap->depth = _read_bitmap_header(file); } else { @@ -8944,19 +8984,12 @@ GetObject( pixmap->hbm, sizeof(bm), &bm ); pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; - pixmap->depth = bm.bmBitsPixel; SelectObject( pixmap->hdc, pixmap->hbm ); ReleaseDC( handle, hdc ); pixmap->transcolor = DW_RGB_TRANSPARENT; -#if 0 - /* force a CONFIGURE event on the underlying renderbox */ - dw_window_get_pos_size( handle, NULL, NULL, &cx, &cy ); - SendMessage( handle, WM_SIZE, 0, MAKELPARAM(cx, cy) ); -#endif - return pixmap; }