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.20 2003/10/06 21:04:24 gvg 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_BitBltSrcCopy(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
76 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
77 PRECTL DestRect
, POINTL
*SourcePoint
,
78 XLATEOBJ
* ColorTranslation
)
80 LONG i
, j
, sx
, sy
, 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 if (NULL
!= ColorTranslation
)
121 DIB_4BPP_PutPixel(DestSurf
, i
, j
, XLATEOBJ_iXlate(ColorTranslation
, DIB_4BPP_GetPixel(SourceSurf
, sx
, sy
)));
125 DIB_4BPP_PutPixel(DestSurf
, i
, j
, DIB_4BPP_GetPixel(SourceSurf
, sx
, sy
));
134 SourceBits_8BPP
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + SourcePoint
->x
;
136 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
138 SourceLine_8BPP
= SourceBits_8BPP
;
140 f2
= DestRect
->left
& 1;
142 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
144 *DestLine
= (*DestLine
& notmask
[i
&1]) |
145 ((XLATEOBJ_iXlate(ColorTranslation
, *SourceLine_8BPP
)) << ((4 * (1-(i
& 1)))));
146 if(f2
== 1) { DestLine
++; f2
= 0; } else { f2
= 1; }
150 SourceBits_8BPP
+= SourceSurf
->lDelta
;
151 DestBits
+= DestSurf
->lDelta
;
156 SourceLine
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 2 * SourcePoint
->x
;
159 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
161 SourceBits
= SourceLine
;
163 f2
= DestRect
->left
& 1;
165 for (i
= DestRect
->left
; i
< DestRect
->right
; i
++)
167 xColor
= *((PWORD
) SourceBits
);
168 *DestBits
= (*DestBits
& notmask
[i
&1]) |
169 ((XLATEOBJ_iXlate(ColorTranslation
, xColor
)) << ((4 * (1-(i
& 1)))));
170 if(f2
== 1) { DestBits
++; f2
= 0; } else { f2
= 1; }
174 SourceLine
+= SourceSurf
->lDelta
;
175 DestLine
+= DestSurf
->lDelta
;
180 SourceBits_24BPP
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + SourcePoint
->x
* 3;
182 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
184 SourceLine_24BPP
= SourceBits_24BPP
;
186 f2
= DestRect
->left
& 1;
188 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
190 xColor
= (*(SourceLine_24BPP
+ 2) << 0x10) +
191 (*(SourceLine_24BPP
+ 1) << 0x08) +
192 (*(SourceLine_24BPP
));
193 *DestLine
= (*DestLine
& notmask
[i
&1]) |
194 ((XLATEOBJ_iXlate(ColorTranslation
, xColor
)) << ((4 * (1-(i
& 1)))));
195 if(f2
== 1) { DestLine
++; f2
= 0; } else { f2
= 1; }
199 SourceBits_24BPP
+= SourceSurf
->lDelta
;
200 DestBits
+= DestSurf
->lDelta
;
205 SourceLine
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 4 * SourcePoint
->x
;
208 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
210 SourceBits
= SourceLine
;
212 f2
= DestRect
->left
& 1;
214 for (i
= DestRect
->left
; i
< DestRect
->right
; i
++)
216 xColor
= *((PDWORD
) SourceBits
);
217 *DestBits
= (*DestBits
& notmask
[i
&1]) |
218 ((XLATEOBJ_iXlate(ColorTranslation
, xColor
)) << ((4 * (1-(i
& 1)))));
219 if(f2
== 1) { DestBits
++; f2
= 0; } else { f2
= 1; }
223 SourceLine
+= SourceSurf
->lDelta
;
224 DestLine
+= DestSurf
->lDelta
;
229 DbgPrint("DIB_4BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI
->BitsPerPixel
);
236 DIB_4BPP_BitBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
237 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
238 PRECTL DestRect
, POINTL
*SourcePoint
,
239 PBRUSHOBJ Brush
, PPOINTL BrushOrigin
,
240 XLATEOBJ
*ColorTranslation
, ULONG Rop4
)
242 LONG i
, j
, k
, sx
, sy
;
243 ULONG Dest
, Source
, Pattern
;
245 BOOL UsesSource
= ((Rop4
& 0xCC0000) >> 2) != (Rop4
& 0x330000);
246 BOOL UsesPattern
= ((Rop4
& 0xF00000) >> 4) != (Rop4
& 0x0F0000);
247 LONG RoundedRight
= DestRect
->right
- (DestRect
->right
& 0x7);
248 static const ULONG ExpandSolidColor
[16] =
270 return(DIB_4BPP_BitBltSrcCopy(DestSurf
, SourceSurf
, DestGDI
, SourceGDI
, DestRect
, SourcePoint
, ColorTranslation
));
276 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
279 DestBits
= (PULONG
)(DestSurf
->pvScan0
+ (DestRect
->left
>>1) + j
* DestSurf
->lDelta
);
280 for (i
=DestRect
->left
; i
<RoundedRight
; i
+=8, DestBits
++)
286 for (k
= 0; k
< 8; k
+= 2)
288 Source
|= (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ (i
- DestRect
->left
) + k
, sy
, ColorTranslation
) << ((k
+ 1) * 4))
289 | (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ (i
- DestRect
->left
) + k
+ 1, sy
, ColorTranslation
) << (k
* 4));
294 /* FIXME: No support for pattern brushes. */
295 Pattern
= ExpandSolidColor
[Brush
->iSolidColor
& 0xF];
297 *DestBits
= DIB_DoRop(Rop4
, Dest
, Source
, Pattern
);
299 if (i
< DestRect
->right
)
302 for (; i
< DestRect
->right
; i
++)
306 Source
= DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ (i
- DestRect
->left
), sy
, ColorTranslation
);
310 /* FIXME: No support for pattern brushes. */
311 Pattern
= ExpandSolidColor
[Brush
->iSolidColor
& 0xF];
313 DIB_4BPP_PutPixel(DestSurf
, i
, j
, DIB_DoRop(Rop4
, Dest
, Source
, Pattern
) & 0xF);