1 /* $Id: dibitmap.c 54535 2011-11-29 14:55:58Z dgorbachev $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS Display Control Panel
5 * FILE: dll/cpl/desk/dibitmap.c
8 * PROGRAMMERS: Trevor McCort (lycan359@gmail.com)
14 DibLoadImage(LPTSTR lpFilename
)
17 DWORD dwFileSize
, dwHighSize
, dwBytesRead
;
21 hFile
= CreateFile(lpFilename
,
26 FILE_FLAG_SEQUENTIAL_SCAN
,
28 if (hFile
== INVALID_HANDLE_VALUE
)
31 dwFileSize
= GetFileSize(hFile
, &dwHighSize
);
39 lpBitmap
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIBITMAP
));
46 lpBitmap
->header
= HeapAlloc(GetProcessHeap(), 0, dwFileSize
);
47 if (lpBitmap
->header
== NULL
)
49 HeapFree(GetProcessHeap(), 0, lpBitmap
);
54 bSuccess
= ReadFile(hFile
, lpBitmap
->header
, dwFileSize
, &dwBytesRead
, NULL
);
58 (dwBytesRead
!= dwFileSize
) ||
59 (lpBitmap
->header
->bfType
!= * (WORD
*) "BM") ||
60 (lpBitmap
->header
->bfSize
!= dwFileSize
))
62 HeapFree(GetProcessHeap(), 0, lpBitmap
->header
);
63 HeapFree(GetProcessHeap(), 0, lpBitmap
);
67 lpBitmap
->info
= (BITMAPINFO
*)(lpBitmap
->header
+ 1);
68 lpBitmap
->bits
= (BYTE
*)lpBitmap
->header
+ lpBitmap
->header
->bfOffBits
;
70 /* Get the DIB width and height */
71 if (lpBitmap
->info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
73 lpBitmap
->width
= ((BITMAPCOREHEADER
*)lpBitmap
->info
)->bcWidth
;
74 lpBitmap
->height
= ((BITMAPCOREHEADER
*)lpBitmap
->info
)->bcHeight
;
78 lpBitmap
->width
= lpBitmap
->info
->bmiHeader
.biWidth
;
79 lpBitmap
->height
= abs(lpBitmap
->info
->bmiHeader
.biHeight
);
87 DibFreeImage(PDIBITMAP lpBitmap
)
93 if (lpBitmap
->header
!= NULL
)
94 HeapFree(GetProcessHeap(), 0, lpBitmap
->header
);
96 /* Free the bitmap structure */
98 HeapFree(GetProcessHeap(), 0, lpBitmap
);