2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: dib4bpp.c,v 1.13 2003/05/18 17:16:17 ea Exp $ */
20 #undef WIN32_LEAN_AND_MEAN
23 #include <win32k/bitmaps.h>
24 #include <win32k/debug.h>
26 #include <ddk/winddi.h>
27 #include "../eng/objects.h"
31 DIB_4BPP_PutPixel(PSURFOBJ SurfObj
, LONG x
, LONG y
, ULONG c
)
33 PBYTE addr
= SurfObj
->pvScan0
;
35 addr
+= (x
>>1) + y
* SurfObj
->lDelta
;
36 *addr
= (*addr
& notmask
[x
&1]) | (c
<< ((1-(x
&1))<<2));
40 DIB_4BPP_GetPixel(PSURFOBJ SurfObj
, LONG x
, LONG y
)
42 PBYTE addr
= SurfObj
->pvScan0
;
44 return (addr
[(x
>>1) + y
* SurfObj
->lDelta
] >> ((1-(x
&1))<<2) ) & 0x0f;
48 DIB_4BPP_HLine(PSURFOBJ SurfObj
, LONG x1
, LONG x2
, LONG y
, ULONG c
)
50 PBYTE addr
= SurfObj
->pvScan0
+ (x1
>>1) + y
* SurfObj
->lDelta
;
54 *addr
= (*addr
& notmask
[x1
&1]) | (c
<< ((1-(x1
&1))<<2));
62 DIB_4BPP_VLine(PSURFOBJ SurfObj
, LONG x
, LONG y1
, LONG y2
, ULONG c
)
64 PBYTE addr
= SurfObj
->pvScan0
;
65 int lDelta
= SurfObj
->lDelta
;
67 addr
+= (x
>>1) + y1
* lDelta
;
69 *addr
= (*addr
& notmask
[x
&1]) | (c
<< ((1-(x
&1))<<2));
75 DIB_4BPP_BitBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
76 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
77 PRECTL DestRect
, POINTL
*SourcePoint
,
78 XLATEOBJ
*ColorTranslation
)
80 LONG i
, j
, sx
, sy
, f1
, f2
, xColor
;
81 PBYTE SourceBits_24BPP
, SourceLine_24BPP
;
82 PBYTE DestBits
, DestLine
, SourceBits_8BPP
, SourceLine_8BPP
;
83 PBYTE SourceBits
, SourceLine
;
85 DestBits
= DestSurf
->pvScan0
+ (DestRect
->left
>>1) + DestRect
->top
* DestSurf
->lDelta
;
87 switch(SourceGDI
->BitsPerPixel
)
93 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
96 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
98 if(DIB_1BPP_GetPixel(SourceSurf
, sx
, sy
) == 0)
100 DIB_4BPP_PutPixel(DestSurf
, i
, j
, XLATEOBJ_iXlate(ColorTranslation
, 0));
102 DIB_4BPP_PutPixel(DestSurf
, i
, j
, XLATEOBJ_iXlate(ColorTranslation
, 1));
113 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
117 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
119 DIB_4BPP_PutPixel(DestSurf
, i
, j
, XLATEOBJ_iXlate(ColorTranslation
, DIB_4BPP_GetPixel(SourceSurf
, sx
, sy
)));
127 SourceBits_8BPP
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + SourcePoint
->x
;
129 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
131 SourceLine_8BPP
= SourceBits_8BPP
;
133 f2
= DestRect
->left
& 1;
135 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
137 *DestLine
= (*DestLine
& notmask
[i
&1]) |
138 ((XLATEOBJ_iXlate(ColorTranslation
, *SourceLine_8BPP
)) << ((4 * (1-(i
& 1)))));
139 if(f2
== 1) { DestLine
++; f2
= 0; } else { f2
= 1; }
143 SourceBits_8BPP
+= SourceSurf
->lDelta
;
144 DestBits
+= DestSurf
->lDelta
;
149 SourceLine
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 2 * SourcePoint
->x
;
152 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
154 SourceBits
= SourceLine
;
156 f2
= DestRect
->left
& 1;
158 for (i
= DestRect
->left
; i
< DestRect
->right
; i
++)
160 xColor
= *((PWORD
) SourceBits
);
161 *DestBits
= (*DestBits
& notmask
[i
&1]) |
162 ((XLATEOBJ_iXlate(ColorTranslation
, xColor
)) << ((4 * (1-(i
& 1)))));
163 if(f2
== 1) { DestBits
++; f2
= 0; } else { f2
= 1; }
167 SourceLine
+= SourceSurf
->lDelta
;
168 DestLine
+= DestSurf
->lDelta
;
173 SourceBits_24BPP
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + SourcePoint
->x
* 3;
175 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
177 SourceLine_24BPP
= SourceBits_24BPP
;
179 f2
= DestRect
->left
& 1;
181 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
183 xColor
= (*(SourceLine_24BPP
+ 2) << 0x10) +
184 (*(SourceLine_24BPP
+ 1) << 0x08) +
185 (*(SourceLine_24BPP
));
186 *DestLine
= (*DestLine
& notmask
[i
&1]) |
187 ((XLATEOBJ_iXlate(ColorTranslation
, xColor
)) << ((4 * (1-(i
& 1)))));
188 if(f2
== 1) { DestLine
++; f2
= 0; } else { f2
= 1; }
192 SourceBits_24BPP
+= SourceSurf
->lDelta
;
193 DestBits
+= DestSurf
->lDelta
;
198 SourceLine
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 4 * SourcePoint
->x
;
201 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
203 SourceBits
= SourceLine
;
205 f2
= DestRect
->left
& 1;
207 for (i
= DestRect
->left
; i
< DestRect
->right
; i
++)
209 xColor
= *((PDWORD
) SourceBits
);
210 *DestBits
= (*DestBits
& notmask
[i
&1]) |
211 ((XLATEOBJ_iXlate(ColorTranslation
, xColor
)) << ((4 * (1-(i
& 1)))));
212 if(f2
== 1) { DestBits
++; f2
= 0; } else { f2
= 1; }
216 SourceLine
+= SourceSurf
->lDelta
;
217 DestLine
+= DestSurf
->lDelta
;
222 DbgPrint("DIB_4BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI
->BitsPerPixel
);