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.
26 DIB_1BPP_PutPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
, ULONG c
)
28 PBYTE addr
= (PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ (x
>> 3);
31 *addr
&= ~MASK1BPP(x
);
37 DIB_1BPP_GetPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
)
39 PBYTE addr
= (PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ (x
>> 3);
41 return (*addr
& MASK1BPP(x
) ? 1 : 0);
45 DIB_1BPP_HLine(SURFOBJ
*SurfObj
, LONG x1
, LONG x2
, LONG y
, ULONG c
)
48 DIB_1BPP_PutPixel(SurfObj
, x1
, y
, c
);
54 DIB_1BPP_VLine(SURFOBJ
*SurfObj
, LONG x
, LONG y1
, LONG y2
, ULONG c
)
57 DIB_1BPP_PutPixel(SurfObj
, x
, y1
, c
);
64 DIB_1BPP_BitBltSrcCopy_From1BPP (
71 // the 'window' in this sense is the x-position that corresponds
72 // to the left-edge of the 8-pixel byte we are currently working with.
73 // dwx is current x-window, dwx2 is the 'last' window we need to process
74 int dwx
, dwx2
; // destination window x-position
75 int swx
; // source window y-position
77 // left and right edges of source and dest rectangles
78 int dl
= DestRect
->left
; // dest left
79 int dr
= DestRect
->right
-1; // dest right (inclusive)
80 int sl
= SourcePoint
->x
; // source left
81 int sr
= sl
+ dr
- dl
; // source right (inclusive)
83 // which direction are we going?
86 int ySrcDelta
, yDstDelta
;
88 // following 4 variables are used for the y-sweep
90 int dy1
; // dest y start
91 int dy2
; // dest y end
92 int sy1
; // src y start
96 BYTE srcmask
, dstmask
, xormask
;
98 // 'd' and 's' are the dest & src buffer pointers that I use on my x-sweep
99 // 'pd' and 'ps' are the dest & src buffer pointers used on the inner y-sweep
100 PBYTE d
, pd
; // dest ptrs
101 PBYTE s
, ps
; // src ptrs
105 xormask
= 0xFF * XLATEOBJ_iXlate(pxlo
, 0);
107 if ( DestRect
->top
<= SourcePoint
->y
)
109 // moving up ( scan top -> bottom )
111 dy2
= DestRect
->bottom
- 1;
112 sy1
= SourcePoint
->y
;
114 ySrcDelta
= SourceSurf
->lDelta
;
115 yDstDelta
= DestSurf
->lDelta
;
119 // moving down ( scan bottom -> top )
120 dy1
= DestRect
->bottom
- 1;
122 sy1
= SourcePoint
->y
+ dy1
- dy2
;
124 ySrcDelta
= -SourceSurf
->lDelta
;
125 yDstDelta
= -DestSurf
->lDelta
;
127 if ( DestRect
->left
<= SourcePoint
->x
)
129 // moving left ( scan left->right )
131 swx
= (sl
-(dl
&7))&~7;
137 // moving right ( scan right->left )
139 swx
= (sr
-(dr
&7))&~7; //(sr-7)&~7; // we need the left edge of this block... thus the -7
143 d
= &(((PBYTE
)DestSurf
->pvScan0
)[dy1
*DestSurf
->lDelta
+ (dwx
>>3)]);
144 s
= &(((PBYTE
)SourceSurf
->pvScan0
)[sy1
*SourceSurf
->lDelta
+ (swx
>>3)]);
151 dx
= dwx
; /* dest x for this pass */
155 srcmask
&= (1<<(8-diff
))-1;
161 srcmask
&= ~((1<<(8-diff
))-1);
165 // we unfortunately *must* have 5 different versions of the inner
166 // loop to be certain we don't try to read from memory that is not
167 // needed and may in fact be invalid
172 *pd
= (BYTE
)((*pd
& dstmask
) | ((ps
[0]^xormask
) & srcmask
));
174 // this *must* be here, because we could be going up *or* down...
182 else if ( !(0xFF00 & (srcmask
<<shift
) ) ) // check if ps[0] not needed...
186 *pd
= (BYTE
)((*pd
& dstmask
)
187 | ( ( (ps
[1]^xormask
) >> shift
) & srcmask
));
189 // this *must* be here, because we could be going up *or* down...
197 else if ( !(0xFF & (srcmask
<<shift
) ) ) // check if ps[1] not needed...
201 *pd
= (*pd
& dstmask
)
202 | ( ( (ps
[0]^xormask
) << ( 8 - shift
) ) & srcmask
);
204 // this *must* be here, because we could be going up *or* down...
212 else // both ps[0] and ps[1] are needed
216 *pd
= (*pd
& dstmask
)
217 | ( ( ( ((ps
[1]^xormask
))|((ps
[0]^xormask
)<<8) ) >> shift
) & srcmask
);
219 // this *must* be here, because we could be going up *or* down...
228 // this *must* be here, because we could be going right *or* left...
239 DIB_1BPP_BitBltSrcCopy(PBLTINFO BltInfo
)
242 LONG i
, j
, sx
, sy
= BltInfo
->SourcePoint
.y
;
244 switch ( BltInfo
->SourceSurface
->iBitmapFormat
)
247 DIB_1BPP_BitBltSrcCopy_From1BPP ( BltInfo
->DestSurface
, BltInfo
->SourceSurface
, BltInfo
->XlateSourceToDest
, &BltInfo
->DestRect
, &BltInfo
->SourcePoint
);
251 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
253 sx
= BltInfo
->SourcePoint
.x
;
254 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
256 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_4BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
257 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
265 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
267 sx
= BltInfo
->SourcePoint
.x
;
268 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
270 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_8BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
271 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
279 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
281 sx
= BltInfo
->SourcePoint
.x
;
282 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
284 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_16BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
285 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
293 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
295 sx
= BltInfo
->SourcePoint
.x
;
296 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
298 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_24BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
299 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
307 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
309 sx
= BltInfo
->SourcePoint
.x
;
310 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
312 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_32BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
313 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
321 DbgPrint("DIB_1BPP_BitBlt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo
->SourceSurface
->iBitmapFormat
));
329 DIB_1BPP_BitBlt(PBLTINFO BltInfo
)
332 ULONG SourceX
, SourceY
;
334 ULONG Dest
, Source
= 0, Pattern
= 0;
341 UsesSource
= ROP4_USES_SOURCE(BltInfo
->Rop4
);
342 UsesPattern
= ROP4_USES_PATTERN(BltInfo
->Rop4
);
344 RoundedRight
= BltInfo
->DestRect
.right
-
345 ((BltInfo
->DestRect
.right
- BltInfo
->DestRect
.left
) & 31);
346 SourceY
= BltInfo
->SourcePoint
.y
;
350 if (BltInfo
->PatternSurface
)
352 PatternY
= (BltInfo
->DestRect
.top
+ BltInfo
->BrushOrigin
.y
) %
353 BltInfo
->PatternSurface
->sizlBitmap
.cy
;
357 /* FIXME: Shouldn't it be expanded? */
359 Pattern
= BltInfo
->Brush
->iSolidColor
;
363 for (DestY
= BltInfo
->DestRect
.top
; DestY
< BltInfo
->DestRect
.bottom
; DestY
++)
365 DestX
= BltInfo
->DestRect
.left
;
366 SourceX
= BltInfo
->SourcePoint
.x
;
368 (PBYTE
)BltInfo
->DestSurface
->pvScan0
+
369 (BltInfo
->DestRect
.left
>> 3) +
370 DestY
* BltInfo
->DestSurface
->lDelta
);
375 /* FIXME: This case is completely untested!!! */
377 Dest
= *((PBYTE
)DestBits
);
378 NoBits
= 31 - (DestX
& 31);
383 /* FIXME: This is incorrect! */
384 for (Index
= 31 - NoBits
; Index
>= 0; Index
++)
385 Source
|= (DIB_GetSource(SourceSurf
, SourceX
+ Index
, SourceY
, ColorTranslation
) << (31 - Index
));
388 if (BltInfo
->PatternSurface
)
391 for (k
= 31 - NoBits
; k
>= 0; k
++)
392 Pattern
|= (DIB_GetSource(PatternObj
, (X
+ BrushOrigin
.x
+ k
) % PatternWidth
, PatternY
, BltInfo
->XlatePatternToDest
) << (31 - k
));
395 Dest
= DIB_DoRop(Rop4
, Dest
, Source
, Pattern
);
396 Dest
&= ~((1 << (31 - NoBits
)) - 1);
397 Dest
|= *((PBYTE
)DestBits
) & ((1 << (31 - NoBits
)) - 1);
406 for (; DestX
< RoundedRight
; DestX
+= 32, DestBits
++, SourceX
+= 32)
413 for (Index
= 0; Index
< 8; Index
++)
415 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
, SourceY
, BltInfo
->XlateSourceToDest
) << (7 - Index
);
416 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
+ 8, SourceY
, BltInfo
->XlateSourceToDest
) << (8 + (7 - Index
));
417 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
+ 16, SourceY
, BltInfo
->XlateSourceToDest
) << (16 + (7 - Index
));
418 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
+ 24, SourceY
, BltInfo
->XlateSourceToDest
) << (24 + (7 - Index
));
422 if (BltInfo
->PatternSurface
)
425 for (Index
= 0; Index
< 8; Index
++)
427 Pattern
|= DIB_GetSource(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
, BltInfo
->XlatePatternToDest
) << (7 - Index
);
428 Pattern
|= DIB_GetSource(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
+ 8) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
, BltInfo
->XlatePatternToDest
) << (8 + (7 - Index
));
429 Pattern
|= DIB_GetSource(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
+ 16) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
, BltInfo
->XlatePatternToDest
) << (16 + (7 - Index
));
430 Pattern
|= DIB_GetSource(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
+ 24) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
, BltInfo
->XlatePatternToDest
) << (24 + (7 - Index
));
434 *DestBits
= DIB_DoRop(BltInfo
->Rop4
, Dest
, Source
, Pattern
);
437 if (DestX
< BltInfo
->DestRect
.right
)
439 for (; DestX
< BltInfo
->DestRect
.right
; DestX
++, SourceX
++)
441 Dest
= DIB_1BPP_GetPixel(BltInfo
->DestSurface
, DestX
, DestY
);
445 Source
= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
, SourceY
, BltInfo
->XlateSourceToDest
);
448 if (BltInfo
->PatternSurface
)
450 Pattern
= DIB_GetSource(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
, BltInfo
->XlatePatternToDest
);
453 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, DestX
, DestY
, DIB_DoRop(BltInfo
->Rop4
, Dest
, Source
, Pattern
) & 0xF);
458 if (BltInfo
->PatternSurface
)
461 PatternY
%= BltInfo
->PatternSurface
->sizlBitmap
.cy
;
468 /* BitBlt Optimize */
470 DIB_1BPP_ColorFill(SURFOBJ
* DestSurface
, RECTL
* DestRect
, ULONG color
)
474 for (DestY
= DestRect
->top
; DestY
< DestRect
->bottom
; DestY
++)
476 DIB_1BPP_HLine(DestSurface
, DestRect
->left
, DestRect
->right
, DestY
, color
);
483 DIB_1BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
484 RECTL
* DestRect
, RECTL
*SourceRect
,
485 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)
491 DIB_1BPP_AlphaBlend(SURFOBJ
* Dest
, SURFOBJ
* Source
, RECTL
* DestRect
,
492 RECTL
* SourceRect
, CLIPOBJ
* ClipRegion
,
493 XLATEOBJ
* ColorTranslation
, BLENDOBJ
* BlendObj
)