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.25 2004/04/06 17:54:32 weiden Exp $ */
20 #undef WIN32_LEAN_AND_MEAN
23 #include <win32k/bitmaps.h>
24 #include <win32k/brush.h>
25 #include <win32k/debug.h>
27 #include <include/object.h>
28 #include <ddk/winddi.h>
29 #include "../eng/objects.h"
33 DIB_4BPP_PutPixel(PSURFOBJ SurfObj
, LONG x
, LONG y
, ULONG c
)
35 PBYTE addr
= SurfObj
->pvScan0
+ (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
+ (x
>>1) + y
* SurfObj
->lDelta
;
43 return (*addr
>> ((1-(x
&1))<<2)) & 0x0f;
47 DIB_4BPP_HLine(PSURFOBJ SurfObj
, LONG x1
, LONG x2
, LONG y
, ULONG c
)
49 PBYTE addr
= SurfObj
->pvScan0
+ (x1
>>1) + y
* SurfObj
->lDelta
;
53 *addr
= (*addr
& notmask
[x1
&1]) | (c
<< ((1-(x1
&1))<<2));
61 DIB_4BPP_VLine(PSURFOBJ SurfObj
, LONG x
, LONG y1
, LONG y2
, ULONG c
)
63 PBYTE addr
= SurfObj
->pvScan0
;
64 int lDelta
= SurfObj
->lDelta
;
66 addr
+= (x
>>1) + y1
* lDelta
;
68 *addr
= (*addr
& notmask
[x
&1]) | (c
<< ((1-(x
&1))<<2));
74 DIB_4BPP_BitBltSrcCopy(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
75 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
76 PRECTL DestRect
, POINTL
*SourcePoint
,
77 XLATEOBJ
* ColorTranslation
)
79 LONG i
, j
, sx
, sy
, f2
, xColor
;
80 PBYTE SourceBits_24BPP
, SourceLine_24BPP
;
81 PBYTE DestBits
, DestLine
, SourceBits_8BPP
, SourceLine_8BPP
;
82 PBYTE SourceBits
, SourceLine
;
84 DestBits
= DestSurf
->pvScan0
+ (DestRect
->left
>>1) + DestRect
->top
* DestSurf
->lDelta
;
86 switch(SourceGDI
->BitsPerPixel
)
92 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
95 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
97 if(DIB_1BPP_GetPixel(SourceSurf
, sx
, sy
) == 0)
99 DIB_4BPP_PutPixel(DestSurf
, i
, j
, XLATEOBJ_iXlate(ColorTranslation
, 0));
101 DIB_4BPP_PutPixel(DestSurf
, i
, j
, XLATEOBJ_iXlate(ColorTranslation
, 1));
112 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
116 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
118 if (NULL
!= ColorTranslation
)
120 DIB_4BPP_PutPixel(DestSurf
, i
, j
, XLATEOBJ_iXlate(ColorTranslation
, DIB_4BPP_GetPixel(SourceSurf
, sx
, sy
)));
124 DIB_4BPP_PutPixel(DestSurf
, i
, j
, DIB_4BPP_GetPixel(SourceSurf
, sx
, sy
));
133 SourceBits_8BPP
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + SourcePoint
->x
;
135 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
137 SourceLine_8BPP
= SourceBits_8BPP
;
139 f2
= DestRect
->left
& 1;
141 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
143 *DestLine
= (*DestLine
& notmask
[f2
]) |
144 ((XLATEOBJ_iXlate(ColorTranslation
, *SourceLine_8BPP
)) << ((4 * (1 - f2
))));
145 if(f2
== 1) { DestLine
++; f2
= 0; } else { f2
= 1; }
149 SourceBits_8BPP
+= SourceSurf
->lDelta
;
150 DestBits
+= DestSurf
->lDelta
;
155 SourceLine
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 2 * SourcePoint
->x
;
158 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
160 SourceBits
= SourceLine
;
162 f2
= DestRect
->left
& 1;
164 for (i
= DestRect
->left
; i
< DestRect
->right
; i
++)
166 xColor
= *((PWORD
) SourceBits
);
167 *DestBits
= (*DestBits
& notmask
[f2
]) |
168 ((XLATEOBJ_iXlate(ColorTranslation
, xColor
)) << ((4 * (1 - f2
))));
169 if(f2
== 1) { DestBits
++; f2
= 0; } else { f2
= 1; }
173 SourceLine
+= SourceSurf
->lDelta
;
174 DestLine
+= DestSurf
->lDelta
;
179 SourceBits_24BPP
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + SourcePoint
->x
* 3;
181 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
183 SourceLine_24BPP
= SourceBits_24BPP
;
185 f2
= DestRect
->left
& 1;
187 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
189 xColor
= (*(SourceLine_24BPP
+ 2) << 0x10) +
190 (*(SourceLine_24BPP
+ 1) << 0x08) +
191 (*(SourceLine_24BPP
));
192 *DestLine
= (*DestLine
& notmask
[f2
]) |
193 ((XLATEOBJ_iXlate(ColorTranslation
, xColor
)) << ((4 * (1 - f2
))));
194 if(f2
== 1) { DestLine
++; f2
= 0; } else { f2
= 1; }
198 SourceBits_24BPP
+= SourceSurf
->lDelta
;
199 DestBits
+= DestSurf
->lDelta
;
204 SourceLine
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 4 * SourcePoint
->x
;
207 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
209 SourceBits
= SourceLine
;
211 f2
= DestRect
->left
& 1;
213 for (i
= DestRect
->left
; i
< DestRect
->right
; i
++)
215 xColor
= *((PDWORD
) SourceBits
);
216 *DestBits
= (*DestBits
& notmask
[f2
]) |
217 ((XLATEOBJ_iXlate(ColorTranslation
, xColor
)) << ((4 * (1 - f2
))));
218 if(f2
== 1) { DestBits
++; f2
= 0; } else { f2
= 1; }
222 SourceLine
+= SourceSurf
->lDelta
;
223 DestLine
+= DestSurf
->lDelta
;
228 DbgPrint("DIB_4BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI
->BitsPerPixel
);
235 DIB_4BPP_BitBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
236 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
237 PRECTL DestRect
, POINTL
*SourcePoint
,
238 PBRUSHOBJ Brush
, PPOINTL BrushOrigin
,
239 XLATEOBJ
*ColorTranslation
, ULONG Rop4
)
242 ULONG Dest
, Source
, Pattern
;
247 /* Pattern brushes */
248 PGDIBRUSHOBJ GdiBrush
;
249 HBITMAP PatternSurface
= NULL
;
251 ULONG PatternWidth
, PatternHeight
;
252 static const ULONG ExpandSolidColor
[16] =
274 return DIB_4BPP_BitBltSrcCopy(
284 UsesSource
= ((Rop4
& 0xCC0000) >> 2) != (Rop4
& 0x330000);
285 UsesPattern
= ((Rop4
& 0xF00000) >> 4) != (Rop4
& 0x0F0000);
293 if (Brush
->iSolidColor
== 0xFFFFFFFF)
295 PBITMAPOBJ PatternBitmap
;
297 GdiBrush
= CONTAINING_RECORD(
302 PatternBitmap
= BITMAPOBJ_LockBitmap(GdiBrush
->hbmPattern
);
303 PatternSurface
= BitmapToSurf(PatternBitmap
, NULL
);
304 BITMAPOBJ_UnlockBitmap(GdiBrush
->hbmPattern
);
306 PatternObj
= (PSURFOBJ
)AccessUserObject((ULONG
)PatternSurface
);
307 PatternWidth
= PatternObj
->sizlBitmap
.cx
;
308 PatternHeight
= PatternObj
->sizlBitmap
.cy
;
313 RoundedRight
= DestRect
->right
- ((DestRect
->right
- DestRect
->left
) & 0x7);
315 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++, sy
++)
317 DestBits
= (PULONG
)(DestSurf
->pvScan0
+ (DestRect
->left
>> 1) + j
* DestSurf
->lDelta
);
323 Dest
= DIB_4BPP_GetPixel(DestSurf
, i
, j
);
327 Source
= DIB_GetSource(SourceSurf
, SourceGDI
, sx
, sy
, ColorTranslation
);
332 if (Brush
->iSolidColor
== 0xFFFFFFFF)
333 Pattern
= DIB_1BPP_GetPixel(PatternObj
, i
% PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
;
335 Pattern
= Brush
->iSolidColor
& 0xF;
338 DIB_4BPP_PutPixel(DestSurf
, i
, j
, DIB_DoRop(Rop4
, Dest
, Source
, Pattern
) & 0xF);
345 for (; i
< RoundedRight
; i
+= 8, sx
+= 8, DestBits
++)
351 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 1, sy
, ColorTranslation
)) |
352 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 0, sy
, ColorTranslation
) << 4) |
353 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 3, sy
, ColorTranslation
) << 8) |
354 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 2, sy
, ColorTranslation
) << 12) |
355 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 5, sy
, ColorTranslation
) << 16) |
356 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 4, sy
, ColorTranslation
) << 20) |
357 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 7, sy
, ColorTranslation
) << 24) |
358 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 6, sy
, ColorTranslation
) << 28);
362 if (Brush
->iSolidColor
== 0xFFFFFFFF)
364 Pattern
= DIB_1BPP_GetPixel(PatternObj
, i
% PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
;
365 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 1) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 4;
366 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 2) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 8;
367 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 3) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 12;
368 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 4) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 16;
369 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 5) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 20;
370 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 6) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 24;
371 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 7) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 28;
375 Pattern
= ExpandSolidColor
[Brush
->iSolidColor
& 0xF];
378 *DestBits
= DIB_DoRop(Rop4
, Dest
, Source
, Pattern
);
381 /* Process the rest of pixel on the line */
382 for (; i
< DestRect
->right
; i
++, sx
++)
384 Dest
= DIB_4BPP_GetPixel(DestSurf
, i
, j
);
387 Source
= DIB_GetSource(SourceSurf
, SourceGDI
, sx
, sy
, ColorTranslation
);
391 if (Brush
->iSolidColor
== 0xFFFFFFFF)
392 Pattern
= DIB_1BPP_GetPixel(PatternObj
, i
% PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
;
394 Pattern
= Brush
->iSolidColor
& 0xF;
396 DIB_4BPP_PutPixel(DestSurf
, i
, j
, DIB_DoRop(Rop4
, Dest
, Source
, Pattern
) & 0xF);
400 if (PatternSurface
!= NULL
)
401 EngDeleteSurface(PatternSurface
);
406 BOOLEAN
DIB_4BPP_StretchBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
407 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
408 RECTL
* DestRect
, RECTL
*SourceRect
,
409 POINTL
* MaskOrigin
, POINTL
* BrushOrigin
,
410 XLATEOBJ
*ColorTranslation
, ULONG Mode
)
412 DbgPrint("DIB_4BPP_StretchBlt: Source BPP: %u\n", SourceGDI
->BitsPerPixel
);
417 DIB_4BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
418 PSURFGDI DestGDI
, PSURFGDI SourceGDI
,
419 RECTL
* DestRect
, POINTL
*SourcePoint
,
420 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)