*** empty log message ***
[reactos.git] / reactos / subsys / win32k / eng / bitmap.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: GDI Driver Bitmap Functions
5 * FILE: subsys/win32k/eng/bitmap.c
6 * PROGRAMER: Jason Filby
7 * REVISION HISTORY:
8 * 3/7/1999: Created
9 */
10
11 #include <ddk/winddi.h>
12
13 HBITMAP EngCreateDeviceBitmap(DHSURF dhsurf, SIZEL Size, ULONG Format)
14 {
15 BITMAP *btc;
16 ULONG bpp, cplanes;
17
18 if(Format==BMF_1BPP)
19 {
20 bpp=1;
21 cplanes=1;
22 } else
23 if((Format==BMF_4BPP) || (Format==BMF_4RLE))
24 {
25 bpp=4;
26 cplanes=1;
27 } else
28 if((Format==BMF_8BPP) || (Format==BMF_8RLE))
29 {
30 bpp=8;
31 cplanes=1;
32 } else
33 if(Format==BMF_16BPP)
34 {
35 bpp=16;
36 cplanes=2;
37 } else
38 if(Format==BMF_24BPP)
39 {
40 bpp=24;
41 cplanes=3;
42 } else
43 if(Format==BMF_32BPP)
44 {
45 bpp=32;
46 cplanes=4;
47 }
48
49 // Allocate memory for the bitmap structure
50 btc=EngAllocMem(FL_ZERO_MEMORY, sizeof(BITMAP), 0);
51
52 // Assign properties of newly created bitmap
53 btc->bmType = Format;
54 btc->bmWidth = Size.cx;
55 btc->bmHeight = Size.cy;
56 btc->bmWidthBytes = Size.cx * cplanes;
57 btc->bmPlanes = cplanes;
58 btc->bmBitsPixel = bpp;
59
60 // Assume that the value returned from ExAllocatePool is the handle value
61 return btc;
62 }
63
64
65 HBITMAP EngCreateBitmap(IN SIZEL Size,
66 IN LONG Width,
67 IN ULONG Format,
68 IN ULONG Flags,
69 IN PVOID Bits)
70 {
71 BITMAP *btc;
72 ULONG tsize;
73
74 // Create the handle for the bitmap
75 btc = EngCreateDeviceBitmap(NULL, Size, Format);
76
77 // Size of bitmap = total pixels * color planes
78 tsize=Size.cx*Size.cy*btc->bmPlanes;
79
80 // Allocate memory for the bitmap
81 if(Bits!=NULL)
82 {
83 if((Flags & BMF_USERMEM)==0)
84 {
85 if((Flags & BMF_NOZEROINIT)==0)
86 {
87 Bits=EngAllocMem(FL_ZERO_MEMORY, tsize, 0);
88 } else {
89 Bits=EngAllocMem(0, tsize, 0);
90 }
91 } else
92 {
93 Bits=EngAllocUserMem(tsize, 0);
94 }
95 }
96
97 btc->bmBits = Bits;
98
99 // Assume that the value returned from ExAllocatePool is the handle value
100 return btc;
101 }