2 * PROJECT: Win32 subsystem
3 * LICENSE: See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/dib/dib1bpp.c
5 * PURPOSE: Device Independant Bitmap functions, 1bpp
6 * PROGRAMMERS: Jason Filby
15 DIB_1BPP_PutPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
, ULONG c
)
17 PBYTE addr
= (PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ (x
>> 3);
20 *addr
&= ~MASK1BPP(x
);
26 DIB_1BPP_GetPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
)
28 PBYTE addr
= (PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ (x
>> 3);
30 return (*addr
& MASK1BPP(x
) ? 1 : 0);
34 DIB_1BPP_HLine(SURFOBJ
*SurfObj
, LONG x1
, LONG x2
, LONG y
, ULONG c
)
38 DIB_1BPP_PutPixel(SurfObj
, x1
, y
, c
);
44 DIB_1BPP_VLine(SURFOBJ
*SurfObj
, LONG x
, LONG y1
, LONG y2
, ULONG c
)
48 DIB_1BPP_PutPixel(SurfObj
, x
, y1
, c
);
55 DIB_1BPP_BitBltSrcCopy_From1BPP (
62 // the 'window' in this sense is the x-position that corresponds
63 // to the left-edge of the 8-pixel byte we are currently working with.
64 // dwx is current x-window, dwx2 is the 'last' window we need to process
65 int dwx
, dwx2
; // destination window x-position
66 int swx
; // source window y-position
68 // left and right edges of source and dest rectangles
69 int dl
= DestRect
->left
; // dest left
70 int dr
= DestRect
->right
-1; // dest right (inclusive)
71 int sl
= SourcePoint
->x
; // source left
72 int sr
= sl
+ dr
- dl
; // source right (inclusive)
74 // which direction are we going?
77 int ySrcDelta
, yDstDelta
;
79 // following 4 variables are used for the y-sweep
81 int dy1
; // dest y start
82 int dy2
; // dest y end
83 int sy1
; // src y start
87 BYTE srcmask
, dstmask
, xormask
;
89 // 'd' and 's' are the dest & src buffer pointers that I use on my x-sweep
90 // 'pd' and 'ps' are the dest & src buffer pointers used on the inner y-sweep
91 PBYTE d
, pd
; // dest ptrs
92 PBYTE s
, ps
; // src ptrs
96 xormask
= 0xFF * XLATEOBJ_iXlate(pxlo
, 0);
98 if ( DestRect
->top
<= SourcePoint
->y
)
100 // moving up ( scan top -> bottom )
102 dy2
= DestRect
->bottom
- 1;
103 sy1
= SourcePoint
->y
;
105 ySrcDelta
= SourceSurf
->lDelta
;
106 yDstDelta
= DestSurf
->lDelta
;
110 // moving down ( scan bottom -> top )
111 dy1
= DestRect
->bottom
- 1;
113 sy1
= SourcePoint
->y
+ dy1
- dy2
;
115 ySrcDelta
= -SourceSurf
->lDelta
;
116 yDstDelta
= -DestSurf
->lDelta
;
118 if ( DestRect
->left
<= SourcePoint
->x
)
120 // moving left ( scan left->right )
122 swx
= (sl
-(dl
&7))&~7;
128 // moving right ( scan right->left )
130 swx
= (sr
-(dr
&7))&~7; //(sr-7)&~7; // we need the left edge of this block... thus the -7
134 d
= &(((PBYTE
)DestSurf
->pvScan0
)[dy1
*DestSurf
->lDelta
+ (dwx
>>3)]);
135 s
= &(((PBYTE
)SourceSurf
->pvScan0
)[sy1
*SourceSurf
->lDelta
+ (swx
>>3)]);
142 dx
= dwx
; /* dest x for this pass */
146 srcmask
&= (1<<(8-diff
))-1;
152 srcmask
&= ~((1<<(8-diff
))-1);
156 // we unfortunately *must* have 5 different versions of the inner
157 // loop to be certain we don't try to read from memory that is not
158 // needed and may in fact be invalid
163 *pd
= (BYTE
)((*pd
& dstmask
) | ((ps
[0]^xormask
) & srcmask
));
165 // this *must* be here, because we could be going up *or* down...
173 else if ( !(0xFF00 & (srcmask
<<shift
) ) ) // check if ps[0] not needed...
177 *pd
= (BYTE
)((*pd
& dstmask
)
178 | ( ( (ps
[1]^xormask
) >> shift
) & srcmask
));
180 // this *must* be here, because we could be going up *or* down...
188 else if ( !(0xFF & (srcmask
<<shift
) ) ) // check if ps[1] not needed...
192 *pd
= (*pd
& dstmask
)
193 | ( ( (ps
[0]^xormask
) << ( 8 - shift
) ) & srcmask
);
195 // this *must* be here, because we could be going up *or* down...
203 else // both ps[0] and ps[1] are needed
207 *pd
= (*pd
& dstmask
)
208 | ( ( ( ((ps
[1]^xormask
))|((ps
[0]^xormask
)<<8) ) >> shift
) & srcmask
);
210 // this *must* be here, because we could be going up *or* down...
219 // this *must* be here, because we could be going right *or* left...
230 DIB_1BPP_BitBltSrcCopy(PBLTINFO BltInfo
)
233 LONG i
, j
, sx
, sy
= BltInfo
->SourcePoint
.y
;
235 switch ( BltInfo
->SourceSurface
->iBitmapFormat
)
238 DIB_1BPP_BitBltSrcCopy_From1BPP ( BltInfo
->DestSurface
, BltInfo
->SourceSurface
, BltInfo
->XlateSourceToDest
, &BltInfo
->DestRect
, &BltInfo
->SourcePoint
);
242 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
244 sx
= BltInfo
->SourcePoint
.x
;
245 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
247 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_4BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
248 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
256 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
258 sx
= BltInfo
->SourcePoint
.x
;
259 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
261 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_8BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
262 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
270 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
272 sx
= BltInfo
->SourcePoint
.x
;
273 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
275 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_16BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
276 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
284 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
286 sx
= BltInfo
->SourcePoint
.x
;
287 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
289 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_24BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
290 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
298 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
300 sx
= BltInfo
->SourcePoint
.x
;
301 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
303 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_32BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
304 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
312 DbgPrint("DIB_1BPP_BitBlt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo
->SourceSurface
->iBitmapFormat
));
320 DIB_1BPP_BitBlt(PBLTINFO BltInfo
)
323 ULONG SourceX
, SourceY
;
325 ULONG Dest
, Source
= 0, Pattern
= 0;
332 UsesSource
= ROP4_USES_SOURCE(BltInfo
->Rop4
);
333 UsesPattern
= ROP4_USES_PATTERN(BltInfo
->Rop4
);
335 RoundedRight
= BltInfo
->DestRect
.right
-
336 ((BltInfo
->DestRect
.right
- BltInfo
->DestRect
.left
) & 31);
337 SourceY
= BltInfo
->SourcePoint
.y
;
341 if (BltInfo
->PatternSurface
)
343 PatternY
= (BltInfo
->DestRect
.top
+ BltInfo
->BrushOrigin
.y
) %
344 BltInfo
->PatternSurface
->sizlBitmap
.cy
;
348 /* FIXME: Shouldn't it be expanded? */
350 Pattern
= BltInfo
->Brush
->iSolidColor
;
354 for (DestY
= BltInfo
->DestRect
.top
; DestY
< BltInfo
->DestRect
.bottom
; DestY
++)
356 DestX
= BltInfo
->DestRect
.left
;
357 SourceX
= BltInfo
->SourcePoint
.x
;
359 (PBYTE
)BltInfo
->DestSurface
->pvScan0
+
360 (BltInfo
->DestRect
.left
>> 3) +
361 DestY
* BltInfo
->DestSurface
->lDelta
);
366 /* FIXME: This case is completely untested!!! */
368 Dest
= *((PBYTE
)DestBits
);
369 NoBits
= 31 - (DestX
& 31);
374 /* FIXME: This is incorrect! */
375 for (Index
= 31 - NoBits
; Index
>= 0; Index
++)
376 Source
|= (DIB_GetSource(SourceSurf
, SourceX
+ Index
, SourceY
, ColorTranslation
) << (31 - Index
));
379 if (BltInfo
->PatternSurface
)
382 for (k
= 31 - NoBits
; k
>= 0; k
++)
383 Pattern
|= (DIB_GetSourceIndex(PatternObj
, (X
+ BrushOrigin
.x
+ k
) % PatternWidth
, PatternY
) << (31 - k
));
386 Dest
= DIB_DoRop(Rop4
, Dest
, Source
, Pattern
);
387 Dest
&= ~((1 << (31 - NoBits
)) - 1);
388 Dest
|= *((PBYTE
)DestBits
) & ((1 << (31 - NoBits
)) - 1);
397 for (; DestX
< RoundedRight
; DestX
+= 32, DestBits
++, SourceX
+= 32)
404 for (Index
= 0; Index
< 8; Index
++)
406 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
, SourceY
, BltInfo
->XlateSourceToDest
) << (7 - Index
);
407 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
+ 8, SourceY
, BltInfo
->XlateSourceToDest
) << (8 + (7 - Index
));
408 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
+ 16, SourceY
, BltInfo
->XlateSourceToDest
) << (16 + (7 - Index
));
409 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
+ 24, SourceY
, BltInfo
->XlateSourceToDest
) << (24 + (7 - Index
));
413 if (BltInfo
->PatternSurface
)
416 for (Index
= 0; Index
< 8; Index
++)
418 Pattern
|= DIB_GetSourceIndex(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
) << (7 - Index
);
419 Pattern
|= DIB_GetSourceIndex(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
+ 8) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
) << (8 + (7 - Index
));
420 Pattern
|= DIB_GetSourceIndex(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
+ 16) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
) << (16 + (7 - Index
));
421 Pattern
|= DIB_GetSourceIndex(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
+ 24) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
) << (24 + (7 - Index
));
425 *DestBits
= DIB_DoRop(BltInfo
->Rop4
, Dest
, Source
, Pattern
);
428 if (DestX
< BltInfo
->DestRect
.right
)
430 for (; DestX
< BltInfo
->DestRect
.right
; DestX
++, SourceX
++)
432 Dest
= DIB_1BPP_GetPixel(BltInfo
->DestSurface
, DestX
, DestY
);
436 Source
= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
, SourceY
, BltInfo
->XlateSourceToDest
);
439 if (BltInfo
->PatternSurface
)
441 Pattern
= DIB_GetSourceIndex(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
);
444 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, DestX
, DestY
, DIB_DoRop(BltInfo
->Rop4
, Dest
, Source
, Pattern
) & 0xF);
449 if (BltInfo
->PatternSurface
)
452 PatternY
%= BltInfo
->PatternSurface
->sizlBitmap
.cy
;
459 /* BitBlt Optimize */
461 DIB_1BPP_ColorFill(SURFOBJ
* DestSurface
, RECTL
* DestRect
, ULONG color
)
465 for (DestY
= DestRect
->top
; DestY
< DestRect
->bottom
; DestY
++)
467 DIB_1BPP_HLine(DestSurface
, DestRect
->left
, DestRect
->right
, DestY
, color
);
473 DIB_1BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
474 RECTL
* DestRect
, RECTL
*SourceRect
,
475 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)
481 DIB_1BPP_AlphaBlend(SURFOBJ
* Dest
, SURFOBJ
* Source
, RECTL
* DestRect
,
482 RECTL
* SourceRect
, CLIPOBJ
* ClipRegion
,
483 XLATEOBJ
* ColorTranslation
, BLENDOBJ
* BlendObj
)