2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: dll/cpl/desk/dibitmap.c
7 * PROGRAMMERS: Trevor McCort (lycan359@gmail.com)
13 DibLoadImage(LPTSTR lpFilename
)
16 DWORD dwFileSize
, dwHighSize
, dwBytesRead
;
20 hFile
= CreateFile(lpFilename
,
25 FILE_FLAG_SEQUENTIAL_SCAN
,
27 if (hFile
== INVALID_HANDLE_VALUE
)
30 dwFileSize
= GetFileSize(hFile
, &dwHighSize
);
38 lpBitmap
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIBITMAP
));
45 lpBitmap
->header
= HeapAlloc(GetProcessHeap(), 0, dwFileSize
);
46 if (lpBitmap
->header
== NULL
)
48 HeapFree(GetProcessHeap(), 0, lpBitmap
);
53 bSuccess
= ReadFile(hFile
, lpBitmap
->header
, dwFileSize
, &dwBytesRead
, NULL
);
57 (dwBytesRead
!= dwFileSize
) ||
58 (lpBitmap
->header
->bfType
!= * (WORD
*) "BM") ||
59 (lpBitmap
->header
->bfSize
!= dwFileSize
))
61 HeapFree(GetProcessHeap(), 0, lpBitmap
->header
);
62 HeapFree(GetProcessHeap(), 0, lpBitmap
);
66 lpBitmap
->info
= (BITMAPINFO
*)(lpBitmap
->header
+ 1);
67 lpBitmap
->bits
= (BYTE
*)lpBitmap
->header
+ lpBitmap
->header
->bfOffBits
;
69 /* Get the DIB width and height */
70 if (lpBitmap
->info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
72 lpBitmap
->width
= ((BITMAPCOREHEADER
*)lpBitmap
->info
)->bcWidth
;
73 lpBitmap
->height
= ((BITMAPCOREHEADER
*)lpBitmap
->info
)->bcHeight
;
77 lpBitmap
->width
= lpBitmap
->info
->bmiHeader
.biWidth
;
78 lpBitmap
->height
= abs(lpBitmap
->info
->bmiHeader
.biHeight
);
86 DibFreeImage(PDIBITMAP lpBitmap
)
92 if (lpBitmap
->header
!= NULL
)
93 HeapFree(GetProcessHeap(), 0, lpBitmap
->header
);
95 /* Free the bitmap structure */
97 HeapFree(GetProcessHeap(), 0, lpBitmap
);