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.31 2004/04/07 20:23:38 navaraf 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
= 0, PatternY
;
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)) && Brush
;
289 if (Brush
->iSolidColor
== 0xFFFFFFFF)
291 PBITMAPOBJ PatternBitmap
;
293 GdiBrush
= CONTAINING_RECORD(
298 PatternBitmap
= BITMAPOBJ_LockBitmap(GdiBrush
->hbmPattern
);
299 PatternSurface
= BitmapToSurf(PatternBitmap
, NULL
);
300 BITMAPOBJ_UnlockBitmap(GdiBrush
->hbmPattern
);
302 PatternObj
= (PSURFOBJ
)AccessUserObject((ULONG
)PatternSurface
);
303 PatternWidth
= PatternObj
->sizlBitmap
.cx
;
304 PatternHeight
= PatternObj
->sizlBitmap
.cy
;
311 Pattern
= ExpandSolidColor
[Brush
->iSolidColor
& 0xF];
316 RoundedRight
= DestRect
->right
- ((DestRect
->right
- DestRect
->left
) & 0x7);
318 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++, sy
++)
320 DestBits
= (PULONG
)(DestSurf
->pvScan0
+ (DestRect
->left
>> 1) + j
* DestSurf
->lDelta
);
325 PatternY
= j
% PatternHeight
;
329 Dest
= DIB_4BPP_GetPixel(DestSurf
, i
, j
);
333 Source
= DIB_GetSource(SourceSurf
, SourceGDI
, sx
, sy
, ColorTranslation
);
338 Pattern
= DIB_1BPP_GetPixel(PatternObj
, i
% PatternWidth
, PatternY
) ? GdiBrush
->crFore
: GdiBrush
->crBack
;
341 DIB_4BPP_PutPixel(DestSurf
, i
, j
, DIB_DoRop(Rop4
, Dest
, Source
, Pattern
) & 0xF);
345 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ 1);
348 for (; i
< RoundedRight
; i
+= 8, sx
+= 8, DestBits
++)
354 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 1, sy
, ColorTranslation
)) |
355 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 0, sy
, ColorTranslation
) << 4) |
356 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 3, sy
, ColorTranslation
) << 8) |
357 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 2, sy
, ColorTranslation
) << 12) |
358 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 5, sy
, ColorTranslation
) << 16) |
359 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 4, sy
, ColorTranslation
) << 20) |
360 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 7, sy
, ColorTranslation
) << 24) |
361 (DIB_GetSource(SourceSurf
, SourceGDI
, sx
+ 6, sy
, ColorTranslation
) << 28);
365 Pattern
= DIB_1BPP_GetPixel(PatternObj
, (i
+ 1) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
;
366 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 0) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 4;
367 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 3) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 8;
368 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 2) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 12;
369 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 5) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 16;
370 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 4) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 20;
371 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 7) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 24;
372 Pattern
|= (DIB_1BPP_GetPixel(PatternObj
, (i
+ 6) % PatternWidth
, j
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
) << 28;
374 *DestBits
= DIB_DoRop(Rop4
, Dest
, Source
, Pattern
);
377 /* Process the rest of pixel on the line */
378 for (; i
< DestRect
->right
; i
++, sx
++)
380 Dest
= DIB_4BPP_GetPixel(DestSurf
, i
, j
);
383 Source
= DIB_GetSource(SourceSurf
, SourceGDI
, sx
, sy
, ColorTranslation
);
387 Pattern
= DIB_1BPP_GetPixel(PatternObj
, i
% PatternWidth
, PatternY
) ? GdiBrush
->crFore
: GdiBrush
->crBack
;
389 DIB_4BPP_PutPixel(DestSurf
, i
, j
, DIB_DoRop(Rop4
, Dest
, Source
, Pattern
) & 0xF);
393 if (PatternSurface
!= NULL
)
394 EngDeleteSurface(PatternSurface
);
399 BOOLEAN
DIB_4BPP_StretchBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
400 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
401 RECTL
* DestRect
, RECTL
*SourceRect
,
402 POINTL
* MaskOrigin
, POINTL
* BrushOrigin
,
403 XLATEOBJ
*ColorTranslation
, ULONG Mode
)
405 DbgPrint("DIB_4BPP_StretchBlt: Source BPP: %u\n", SourceGDI
->BitsPerPixel
);
410 DIB_4BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
411 PSURFGDI DestGDI
, PSURFGDI SourceGDI
,
412 RECTL
* DestRect
, POINTL
*SourcePoint
,
413 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)