3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS Display Control Panel
5 * FILE: lib/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
));
43 lpBitmap
->header
= HeapAlloc(GetProcessHeap(), 0, dwFileSize
);
44 if (lpBitmap
->header
== NULL
)
50 bSuccess
= ReadFile(hFile
, lpBitmap
->header
, dwFileSize
, &dwBytesRead
, NULL
);
54 (dwBytesRead
!= dwFileSize
) ||
55 (lpBitmap
->header
->bfType
!= * (WORD
*) "BM") ||
56 (lpBitmap
->header
->bfSize
!= dwFileSize
))
58 HeapFree(GetProcessHeap(), 0, lpBitmap
->header
);
62 lpBitmap
->info
= (BITMAPINFO
*)(lpBitmap
->header
+ 1);
63 lpBitmap
->bits
= (BYTE
*)lpBitmap
->header
+ lpBitmap
->header
->bfOffBits
;
65 /* Get the DIB width and height */
66 if (lpBitmap
->info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
68 lpBitmap
->width
= ((BITMAPCOREHEADER
*)lpBitmap
->info
)->bcWidth
;
69 lpBitmap
->height
= ((BITMAPCOREHEADER
*)lpBitmap
->info
)->bcHeight
;
73 lpBitmap
->width
= lpBitmap
->info
->bmiHeader
.biWidth
;
74 lpBitmap
->height
= abs(lpBitmap
->info
->bmiHeader
.biHeight
);
82 DibFreeImage(PDIBITMAP lpBitmap
)
88 if (lpBitmap
->header
!= NULL
)
89 HeapFree(GetProcessHeap(), 0, lpBitmap
->header
);
91 /* Free the bitmap structure */
93 HeapFree(GetProcessHeap(), 0, lpBitmap
);