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
)
19 if (GdipCreateBitmapFromFile(lpFilename
, &bitmap
) != Ok
)
24 lpBitmap
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIBITMAP
));
27 GdipDisposeImage((GpImage
*)bitmap
);
31 lpBitmap
->info
= HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO
));
32 if (lpBitmap
->info
== NULL
)
34 HeapFree(GetProcessHeap(), 0, lpBitmap
);
35 GdipDisposeImage((GpImage
*)bitmap
);
39 if (GdipGetImageWidth((GpImage
*)bitmap
, &lpBitmap
->width
) != Ok
||
40 GdipGetImageHeight((GpImage
*)bitmap
, &lpBitmap
->height
) != Ok
)
42 HeapFree(GetProcessHeap(), 0, lpBitmap
->info
);
43 HeapFree(GetProcessHeap(), 0, lpBitmap
);
44 GdipDisposeImage((GpImage
*)bitmap
);
48 lpBitmap
->bits
= HeapAlloc(GetProcessHeap(), 0, lpBitmap
->width
* lpBitmap
->height
* 4);
51 HeapFree(GetProcessHeap(), 0, lpBitmap
->info
);
52 HeapFree(GetProcessHeap(), 0, lpBitmap
);
53 GdipDisposeImage((GpImage
*)bitmap
);
57 ZeroMemory(lpBitmap
->info
, sizeof(BITMAPINFO
));
58 lpBitmap
->info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
59 lpBitmap
->info
->bmiHeader
.biWidth
= lpBitmap
->width
;
60 lpBitmap
->info
->bmiHeader
.biHeight
= -(INT
)lpBitmap
->height
;
61 lpBitmap
->info
->bmiHeader
.biPlanes
= 1;
62 lpBitmap
->info
->bmiHeader
.biBitCount
= 32;
63 lpBitmap
->info
->bmiHeader
.biCompression
= BI_RGB
;
64 lpBitmap
->info
->bmiHeader
.biSizeImage
= lpBitmap
->width
* lpBitmap
->height
* 4;
66 lock
.Width
= lpBitmap
->width
;
67 lock
.Height
= lpBitmap
->height
;
68 lock
.Stride
= lpBitmap
->width
* 4;
69 lock
.PixelFormat
= PixelFormat32bppPARGB
;
70 lock
.Scan0
= lpBitmap
->bits
;
73 if (GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
| ImageLockModeUserInputBuf
, PixelFormat32bppPARGB
, &lock
) != Ok
)
75 HeapFree(GetProcessHeap(), 0, lpBitmap
->bits
);
76 HeapFree(GetProcessHeap(), 0, lpBitmap
->info
);
77 HeapFree(GetProcessHeap(), 0, lpBitmap
);
78 GdipDisposeImage((GpImage
*)bitmap
);
82 GdipBitmapUnlockBits(bitmap
, &lock
);
83 GdipDisposeImage((GpImage
*)bitmap
);
90 DibFreeImage(PDIBITMAP lpBitmap
)
95 /* Free the image data */
96 if (lpBitmap
->bits
!= NULL
)
97 HeapFree(GetProcessHeap(), 0, lpBitmap
->bits
);
99 /* Free the bitmap info */
100 if (lpBitmap
->info
!= NULL
)
101 HeapFree(GetProcessHeap(), 0, lpBitmap
->info
);
103 /* Free the bitmap structure */
104 if (lpBitmap
!= NULL
)
105 HeapFree(GetProcessHeap(), 0, lpBitmap
);