Initial support for 1BPP
[reactos.git] / reactos / subsys / win32k / dib / dib1bpp.c
1 #undef WIN32_LEAN_AND_MEAN
2 #include <windows.h>
3 #include <stdlib.h>
4 #include <win32k/bitmaps.h>
5 #include <win32k/debug.h>
6 #include <debug.h>
7 #include <ddk/winddi.h>
8 #include "../eng/objects.h"
9 #include "dib.h"
10
11 PFN_DIB_PutPixel DIB_1BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c)
12 {
13 unsigned char *vp;
14 unsigned char mask;
15 PBYTE addr = SurfObj->pvBits;
16
17 addr += y * SurfObj->lDelta + (x >> 3);
18
19 if(c == 1)
20 {
21 *addr = (*addr | mask1Bpp[mod(x, 8)]);
22 }
23 else
24 {
25 *addr = (*addr ^ mask1Bpp[mod(x, 8)]);
26 }
27 }
28
29 PFN_DIB_GetPixel DIB_1BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y)
30 {
31 PBYTE addr = SurfObj->pvBits + y * SurfObj->lDelta + (x >> 3);
32
33 if(*addr & mask1Bpp[mod(x, 8)]) return (PFN_DIB_GetPixel)(1);
34 return (PFN_DIB_GetPixel)(0);
35 }
36
37 PFN_DIB_HLine DIB_1BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
38 {
39 LONG cx = x1;
40
41 while(cx <= x2) {
42 DIB_1BPP_PutPixel(SurfObj, cx, y, c);
43 }
44 }
45
46 PFN_DIB_VLine DIB_1BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
47 {
48 while(y1++ <= y2) {
49 DIB_1BPP_PutPixel(SurfObj, x, y1, c);
50 }
51 }
52
53 BOOLEAN DIB_To_1BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
54 SURFGDI *DestGDI, SURFGDI *SourceGDI,
55 PRECTL DestRect, POINTL *SourcePoint,
56 ULONG Delta, XLATEOBJ *ColorTranslation)
57 {
58 ULONG i, j, sx, sy = SourcePoint->y;
59
60 switch(SourceGDI->BitsPerPixel)
61 {
62 case 1:
63 for (j=DestRect->top; j<DestRect->bottom; j++)
64 {
65 sx = SourcePoint->x;
66 for (i=DestRect->left; i<DestRect->right; i++)
67 {
68 if(DIB_1BPP_GetPixel(SourceSurf, sx, sy) == 0)
69 {
70 DIB_1BPP_PutPixel(DestSurf, i, j, 0);
71 } else {
72 DIB_1BPP_PutPixel(DestSurf, i, j, 1);
73 }
74 sx++;
75 }
76 sy++;
77 }
78 break;
79
80 case 4:
81 for (j=DestRect->top; j<DestRect->bottom; j++)
82 {
83 sx = SourcePoint->x;
84 for (i=DestRect->left; i<DestRect->right; i++)
85 {
86 if(XLATEOBJ_iXlate(ColorTranslation, DIB_4BPP_GetPixel(SourceSurf, sx, sy)) == 0)
87 {
88 DIB_1BPP_PutPixel(DestSurf, i, j, 0);
89 } else {
90 DIB_1BPP_PutPixel(DestSurf, i, j, 1);
91 }
92 sx++;
93 }
94 sy++;
95 }
96 break;
97
98 case 24:
99 for (j=DestRect->top; j<DestRect->bottom; j++)
100 {
101 sx = SourcePoint->x;
102 for (i=DestRect->left; i<DestRect->right; i++)
103 {
104 if(XLATEOBJ_iXlate(ColorTranslation, DIB_24BPP_GetPixel(SourceSurf, sx, sy)) == 0)
105 {
106 DIB_1BPP_PutPixel(DestSurf, i, j, 0);
107 } else {
108 DIB_1BPP_PutPixel(DestSurf, i, j, 1);
109 }
110 sx++;
111 }
112 sy++;
113 }
114 break;
115
116 default:
117 DbgPrint("DIB_1BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
118 return FALSE;
119 }
120
121 return TRUE;
122 }