ReactOS 0.4.16-dev-117-g38f21f9
dibitmap.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: dll/cpl/desk/dibitmap.c
5 * PURPOSE: DIB loading
6 *
7 * PROGRAMMERS: Trevor McCort (lycan359@gmail.com)
8 */
9
10#include "desk.h"
11
14{
15 PDIBITMAP lpBitmap;
18
19 if (GdipCreateBitmapFromFile(lpFilename, &bitmap) != Ok)
20 {
21 return NULL;
22 }
23
24 lpBitmap = HeapAlloc(GetProcessHeap(), 0, sizeof(DIBITMAP));
25 if (lpBitmap == NULL)
26 {
28 return NULL;
29 }
30
31 lpBitmap->info = HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO));
32 if (lpBitmap->info == NULL)
33 {
34 HeapFree(GetProcessHeap(), 0, lpBitmap);
36 return NULL;
37 }
38
39 if (GdipGetImageWidth((GpImage*)bitmap, &lpBitmap->width) != Ok ||
40 GdipGetImageHeight((GpImage*)bitmap, &lpBitmap->height) != Ok)
41 {
42 HeapFree(GetProcessHeap(), 0, lpBitmap->info);
43 HeapFree(GetProcessHeap(), 0, lpBitmap);
45 return NULL;
46 }
47
48 lpBitmap->bits = HeapAlloc(GetProcessHeap(), 0, lpBitmap->width * lpBitmap->height * 4);
49 if (!lpBitmap->bits)
50 {
51 HeapFree(GetProcessHeap(), 0, lpBitmap->info);
52 HeapFree(GetProcessHeap(), 0, lpBitmap);
54 return NULL;
55 }
56
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;
64 lpBitmap->info->bmiHeader.biSizeImage = lpBitmap->width * lpBitmap->height * 4;
65
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;
71 lock.Reserved = 0;
72
74 {
75 HeapFree(GetProcessHeap(), 0, lpBitmap->bits);
76 HeapFree(GetProcessHeap(), 0, lpBitmap->info);
77 HeapFree(GetProcessHeap(), 0, lpBitmap);
79 return NULL;
80 }
81
84
85 return lpBitmap;
86}
87
88
89VOID
91{
92 if (lpBitmap == NULL)
93 return;
94
95 /* Free the image data */
96 if (lpBitmap->bits != NULL)
97 HeapFree(GetProcessHeap(), 0, lpBitmap->bits);
98
99 /* Free the bitmap info */
100 if (lpBitmap->info != NULL)
101 HeapFree(GetProcessHeap(), 0, lpBitmap->info);
102
103 /* Free the bitmap structure */
104 if (lpBitmap != NULL)
105 HeapFree(GetProcessHeap(), 0, lpBitmap);
106}
VOID DibFreeImage(PDIBITMAP lpBitmap)
Definition: dibitmap.c:90
PDIBITMAP DibLoadImage(LPTSTR lpFilename)
Definition: dibitmap.c:13
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR *filename, GpBitmap **bitmap)
Definition: image.c:1360
GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
Definition: image.c:2390
GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
Definition: image.c:2287
GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap *bitmap, GDIPCONST GpRect *rect, UINT flags, PixelFormat format, BitmapData *lockeddata)
Definition: image.c:1030
GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
Definition: image.c:2155
GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap *bitmap, BitmapData *lockeddata)
Definition: image.c:1176
#define BI_RGB
Definition: precomp.h:56
@ ImageLockModeUserInputBuf
@ ImageLockModeRead
#define PixelFormat32bppPARGB
@ Ok
Definition: gdiplustypes.h:26
if(dx< 0)
Definition: linetemp.h:194
#define INT
Definition: polytest.cpp:20
Definition: desk.h:44
BYTE * bits
Definition: desk.h:46
UINT height
Definition: desk.h:48
UINT width
Definition: desk.h:47
BITMAPINFO * info
Definition: desk.h:45
Definition: uimain.c:89
USHORT biBitCount
Definition: precomp.h:46
ULONG biCompression
Definition: precomp.h:47
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
rwlock_t lock
Definition: tcpcore.h:0
#define ZeroMemory
Definition: winbase.h:1712
CHAR * LPTSTR
Definition: xmlstorage.h:192