Mercurial > dwindows
comparison win/dw.c @ 966:d90222530bb9
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.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 03 May 2011 01:43:51 +0000 |
parents | 25b24bb098fd |
children | c8490b0d8577 |
comparison
equal
deleted
inserted
replaced
965:2b1b9b995748 | 966:d90222530bb9 |
---|---|
8804 | 8804 |
8805 SelectObject(pixmap->hdc, pixmap->hbm); | 8805 SelectObject(pixmap->hdc, pixmap->hbm); |
8806 | 8806 |
8807 ReleaseDC(handle, hdc); | 8807 ReleaseDC(handle, hdc); |
8808 | 8808 |
8809 #if 0 | |
8810 /* force a CONFIGURE event on the underlying renderbox */ | |
8811 dw_window_get_pos_size( handle, NULL, NULL, &cx, &cy ); | |
8812 SendMessage( handle, WM_SIZE, 0, MAKELPARAM(cx, cy) ); | |
8813 #endif | |
8814 | |
8815 return pixmap; | 8809 return pixmap; |
8810 } | |
8811 | |
8812 /* Read the file bitmap header ourselves... | |
8813 * apparently we can't check the depth once loaded... | |
8814 * since it seems to normalize it to our screen depth. | |
8815 */ | |
8816 unsigned long _read_bitmap_header(char *file) | |
8817 { | |
8818 BITMAPFILEHEADER header; | |
8819 BITMAPINFO *info; | |
8820 FILE *fp; | |
8821 int infosize; | |
8822 int depth = 0; | |
8823 | |
8824 /* Try opening the file; use "rb" mode to read this *binary* file. */ | |
8825 if((fp = fopen(file, "rb")) == NULL) | |
8826 return 0; | |
8827 | |
8828 /* Read the file header and any following bitmap information... */ | |
8829 if(fread(&header, sizeof(BITMAPFILEHEADER), 1, fp) < 1) | |
8830 { | |
8831 /* Couldn't read the file header */ | |
8832 fclose(fp); | |
8833 return 0; | |
8834 } | |
8835 | |
8836 if(header.bfType != 'MB') /* Check for BM reversed... */ | |
8837 { | |
8838 /* Not a bitmap file */ | |
8839 fclose(fp); | |
8840 return 0; | |
8841 } | |
8842 | |
8843 infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER); | |
8844 if((info = (BITMAPINFO *)calloc(infosize, 1)) == NULL) | |
8845 { | |
8846 /* Couldn't allocate memory for bitmap info */ | |
8847 fclose(fp); | |
8848 return 0; | |
8849 } | |
8850 | |
8851 if(fread(info, 1, infosize, fp) == infosize) | |
8852 { | |
8853 /* Read the bitmap header */ | |
8854 depth = info->bmiHeader.biBitCount; | |
8855 } | |
8856 free(info); | |
8857 fclose(fp); | |
8858 return depth; | |
8816 } | 8859 } |
8817 | 8860 |
8818 /* | 8861 /* |
8819 * Creates a pixmap from a file. | 8862 * Creates a pixmap from a file. |
8820 * Parameters: | 8863 * Parameters: |
8830 HPIXMAP pixmap; | 8873 HPIXMAP pixmap; |
8831 BITMAP bm; | 8874 BITMAP bm; |
8832 HDC hdc; | 8875 HDC hdc; |
8833 ULONG cx, cy; | 8876 ULONG cx, cy; |
8834 char *file = malloc(strlen(filename) + 5); | 8877 char *file = malloc(strlen(filename) + 5); |
8878 BITMAPINFO *info; | |
8835 | 8879 |
8836 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 8880 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
8837 { | 8881 { |
8838 if(file) | 8882 if(file) |
8839 free(file); | 8883 free(file); |
8857 | 8901 |
8858 hdc = GetDC(handle); | 8902 hdc = GetDC(handle); |
8859 | 8903 |
8860 pixmap->handle = handle; | 8904 pixmap->handle = handle; |
8861 pixmap->hbm = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); | 8905 pixmap->hbm = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); |
8906 pixmap->depth = _read_bitmap_header(file); | |
8862 | 8907 |
8863 if ( !pixmap->hbm ) | 8908 if ( !pixmap->hbm ) |
8864 { | 8909 { |
8865 free(file); | 8910 free(file); |
8866 free(pixmap); | 8911 free(pixmap); |
8869 } | 8914 } |
8870 | 8915 |
8871 pixmap->hdc = CreateCompatibleDC( hdc ); | 8916 pixmap->hdc = CreateCompatibleDC( hdc ); |
8872 GetObject( pixmap->hbm, sizeof(bm), &bm ); | 8917 GetObject( pixmap->hbm, sizeof(bm), &bm ); |
8873 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; | 8918 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; |
8874 pixmap->depth = bm.bmBitsPixel; | |
8875 SelectObject( pixmap->hdc, pixmap->hbm ); | 8919 SelectObject( pixmap->hdc, pixmap->hbm ); |
8876 ReleaseDC( handle, hdc ); | 8920 ReleaseDC( handle, hdc ); |
8877 free( file ); | 8921 free( file ); |
8878 pixmap->transcolor = DW_RGB_TRANSPARENT; | 8922 pixmap->transcolor = DW_RGB_TRANSPARENT; |
8879 | 8923 |
8880 #if 0 | |
8881 /* force a CONFIGURE event on the underlying renderbox */ | |
8882 dw_window_get_pos_size( handle, NULL, NULL, &cx, &cy ); | |
8883 SendMessage( handle, WM_SIZE, 0, MAKELPARAM(cx, cy) ); | |
8884 #endif | |
8885 return pixmap; | 8924 return pixmap; |
8886 } | 8925 } |
8887 | 8926 |
8888 /* | 8927 /* |
8889 * Creates a pixmap from memory. | 8928 * Creates a pixmap from memory. |
8920 if ( fp != NULL ) | 8959 if ( fp != NULL ) |
8921 { | 8960 { |
8922 fwrite( data, 1, len, fp ); | 8961 fwrite( data, 1, len, fp ); |
8923 fclose( fp ); | 8962 fclose( fp ); |
8924 pixmap->hbm = (HBITMAP)LoadImage( NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); | 8963 pixmap->hbm = (HBITMAP)LoadImage( NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); |
8964 pixmap->depth = _read_bitmap_header(file); | |
8925 } | 8965 } |
8926 else | 8966 else |
8927 { | 8967 { |
8928 unlink( file ); | 8968 unlink( file ); |
8929 free( pixmap ); | 8969 free( pixmap ); |
8942 pixmap->hdc = CreateCompatibleDC( hdc ); | 8982 pixmap->hdc = CreateCompatibleDC( hdc ); |
8943 | 8983 |
8944 GetObject( pixmap->hbm, sizeof(bm), &bm ); | 8984 GetObject( pixmap->hbm, sizeof(bm), &bm ); |
8945 | 8985 |
8946 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; | 8986 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; |
8947 pixmap->depth = bm.bmBitsPixel; | |
8948 | 8987 |
8949 SelectObject( pixmap->hdc, pixmap->hbm ); | 8988 SelectObject( pixmap->hdc, pixmap->hbm ); |
8950 | 8989 |
8951 ReleaseDC( handle, hdc ); | 8990 ReleaseDC( handle, hdc ); |
8952 pixmap->transcolor = DW_RGB_TRANSPARENT; | 8991 pixmap->transcolor = DW_RGB_TRANSPARENT; |
8953 | |
8954 #if 0 | |
8955 /* force a CONFIGURE event on the underlying renderbox */ | |
8956 dw_window_get_pos_size( handle, NULL, NULL, &cx, &cy ); | |
8957 SendMessage( handle, WM_SIZE, 0, MAKELPARAM(cx, cy) ); | |
8958 #endif | |
8959 | 8992 |
8960 return pixmap; | 8993 return pixmap; |
8961 } | 8994 } |
8962 | 8995 |
8963 /* | 8996 /* |