ReactOS 0.4.15-dev-8222-g9164419
dibitmap.c File Reference
#include "desk.h"
Include dependency graph for dibitmap.c:

Go to the source code of this file.

Functions

PDIBITMAP DibLoadImage (LPTSTR lpFilename)
 
VOID DibFreeImage (PDIBITMAP lpBitmap)
 

Function Documentation

◆ DibFreeImage()

VOID DibFreeImage ( PDIBITMAP  lpBitmap)

Definition at line 90 of file dibitmap.c.

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}
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
BYTE * bits
Definition: desk.h:46
BITMAPINFO * info
Definition: desk.h:45

Referenced by BackgroundPageProc(), and ListViewItemChanged().

◆ DibLoadImage()

PDIBITMAP DibLoadImage ( LPTSTR  lpFilename)

Definition at line 13 of file dibitmap.c.

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}
#define HeapAlloc
Definition: compat.h:733
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
UINT height
Definition: desk.h:48
UINT width
Definition: desk.h:47
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

Referenced by ListViewItemChanged().