ReactOS  0.4.13-dev-482-ge57f103
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 
13 DibLoadImage(LPTSTR lpFilename)
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;
63  lpBitmap->info->bmiHeader.biCompression = BI_RGB;
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 
89 VOID
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 }
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1454
rwlock_t lock
Definition: tcpcore.h:1163
UINT height
Definition: desk.h:48
GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
Definition: image.c:2342
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
#define INT
Definition: polytest.cpp:20
#define ZeroMemory
Definition: winbase.h:1635
CHAR * LPTSTR
Definition: xmlstorage.h:192
BYTE * bits
Definition: desk.h:46
GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
Definition: image.c:2239
GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap *bitmap, GDIPCONST GpRect *rect, UINT flags, PixelFormat format, BitmapData *lockeddata)
Definition: image.c:1030
DWORD biCompression
Definition: amvideo.idl:35
UINT width
Definition: desk.h:47
smooth NULL
Definition: ftsmooth.c:416
Definition: uimain.c:88
GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap *bitmap, BitmapData *lockeddata)
Definition: image.c:1176
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
if(!(yy_init))
Definition: macro.lex.yy.c:714
BITMAPINFO * info
Definition: desk.h:45
VOID DibFreeImage(PDIBITMAP lpBitmap)
Definition: dibitmap.c:90
DWORD biSizeImage
Definition: amvideo.idl:36
GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR *filename, GpBitmap **bitmap)
Definition: image.c:1360
GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
Definition: image.c:2107
Definition: desk.h:43
#define PixelFormat32bppPARGB
static HBITMAP bitmap
Definition: clipboard.c:1344
#define BI_RGB
Definition: precomp.h:35
#define HeapFree(x, y, z)
Definition: compat.h:394
PDIBITMAP DibLoadImage(LPTSTR lpFilename)
Definition: dibitmap.c:13