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 // The 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
86 BYTE srcmask
, dstmask
, xormask
;
88 // 'd' and 's' are the dest & src buffer pointers that I use on my x-sweep
89 // 'pd' and 'ps' are the dest & src buffer pointers used on the inner y-sweep
90 PBYTE d
, pd
; // dest ptrs
91 PBYTE s
, ps
; // src ptrs
95 xormask
= 0xFF * (BYTE
)XLATEOBJ_iXlate(pxlo
, 0);
97 if ( DestRect
->top
<= SourcePoint
->y
)
99 // Moving up (scan top -> bottom)
101 dy2
= DestRect
->bottom
- 1;
102 sy1
= SourcePoint
->y
;
104 ySrcDelta
= SourceSurf
->lDelta
;
105 yDstDelta
= DestSurf
->lDelta
;
109 // Moving down (scan bottom -> top)
110 dy1
= DestRect
->bottom
- 1;
112 sy1
= SourcePoint
->y
+ dy1
- dy2
;
114 ySrcDelta
= -SourceSurf
->lDelta
;
115 yDstDelta
= -DestSurf
->lDelta
;
117 if ( DestRect
->left
<= SourcePoint
->x
)
119 // Moving left (scan left->right)
121 swx
= (sl
-(dl
&7))&~7;
127 // Moving right (scan right->left)
129 swx
= (sr
- (dr
& 7)) & ~7; // (sr - 7) & ~7; // We need the left edge of this block. Thus the -7
133 d
= &(((PBYTE
)DestSurf
->pvScan0
)[dy1
*DestSurf
->lDelta
+ (dwx
>>3)]);
134 s
= &(((PBYTE
)SourceSurf
->pvScan0
)[sy1
*SourceSurf
->lDelta
+ (swx
>>3)]);
144 srcmask
&= (1<<(8-diff
))-1;
149 srcmask
&= ~((1<<(8-diff
))-1);
153 // We unfortunately *must* have 5 different versions of the inner
154 // loop to be certain we don't try to read from memory that is not
155 // needed and may in fact be invalid.
160 *pd
= (BYTE
)((*pd
& dstmask
) | ((ps
[0]^xormask
) & srcmask
));
162 // This *must* be here, because we could be going up *or* down...
170 else if ( !(0xFF00 & (srcmask
<<shift
) ) ) // Check if ps[0] not needed...
174 *pd
= (BYTE
)((*pd
& dstmask
)
175 | ( ( (ps
[1]^xormask
) >> shift
) & srcmask
));
177 // This *must* be here, because we could be going up *or* down...
185 else if ( !(0xFF & (srcmask
<<shift
) ) ) // Check if ps[1] not needed...
189 *pd
= (*pd
& dstmask
)
190 | ( ( (ps
[0]^xormask
) << ( 8 - shift
) ) & srcmask
);
192 // This *must* be here, because we could be going up *or* down...
200 else // Both ps[0] and ps[1] are needed
204 *pd
= (*pd
& dstmask
)
205 | ( ( ( ((ps
[1]^xormask
))|((ps
[0]^xormask
)<<8) ) >> shift
) & srcmask
);
207 // This *must* be here, because we could be going up *or* down...
216 // This *must* be here, because we could be going right *or* left...
227 DIB_1BPP_BitBltSrcCopy(PBLTINFO BltInfo
)
230 LONG i
, j
, sx
, sy
= BltInfo
->SourcePoint
.y
;
232 switch ( BltInfo
->SourceSurface
->iBitmapFormat
)
235 DIB_1BPP_BitBltSrcCopy_From1BPP ( BltInfo
->DestSurface
, BltInfo
->SourceSurface
, BltInfo
->XlateSourceToDest
, &BltInfo
->DestRect
, &BltInfo
->SourcePoint
);
239 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
241 sx
= BltInfo
->SourcePoint
.x
;
242 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
244 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_4BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
245 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
253 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
255 sx
= BltInfo
->SourcePoint
.x
;
256 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
258 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_8BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
259 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
267 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
269 sx
= BltInfo
->SourcePoint
.x
;
270 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
272 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_16BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
273 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
281 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
283 sx
= BltInfo
->SourcePoint
.x
;
284 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
286 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_24BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
287 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
295 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
297 sx
= BltInfo
->SourcePoint
.x
;
298 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
300 Color
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, DIB_32BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
));
301 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, Color
);
309 DbgPrint("DIB_1BPP_BitBlt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo
->SourceSurface
->iBitmapFormat
));
318 DIB_1BPP_BitBlt(PBLTINFO BltInfo
)
321 LONG SourceX
, SourceY
;
323 ULONG Dest
, Source
= 0, Pattern
= 0;
330 UsesSource
= ROP4_USES_SOURCE(BltInfo
->Rop4
);
331 UsesPattern
= ROP4_USES_PATTERN(BltInfo
->Rop4
);
333 RoundedRight
= BltInfo
->DestRect
.right
-
334 ((BltInfo
->DestRect
.right
- BltInfo
->DestRect
.left
) & 31);
335 SourceY
= BltInfo
->SourcePoint
.y
;
339 if (BltInfo
->PatternSurface
)
341 PatternY
= (BltInfo
->DestRect
.top
+ BltInfo
->BrushOrigin
.y
) %
342 BltInfo
->PatternSurface
->sizlBitmap
.cy
;
346 /* FIXME: Shouldn't it be expanded? */
348 Pattern
= BltInfo
->Brush
->iSolidColor
;
352 for (DestY
= BltInfo
->DestRect
.top
; DestY
< BltInfo
->DestRect
.bottom
; DestY
++)
354 DestX
= BltInfo
->DestRect
.left
;
355 SourceX
= BltInfo
->SourcePoint
.x
;
357 (PBYTE
)BltInfo
->DestSurface
->pvScan0
+
358 (BltInfo
->DestRect
.left
>> 3) +
359 DestY
* BltInfo
->DestSurface
->lDelta
);
364 /* FIXME: This case is completely untested!!! */
366 Dest
= *((PBYTE
)DestBits
);
367 NoBits
= 31 - (DestX
& 31);
372 /* FIXME: This is incorrect! */
373 for (Index
= 31 - NoBits
; Index
>= 0; Index
++)
374 Source
|= (DIB_GetSource(SourceSurf
, SourceX
+ Index
, SourceY
, ColorTranslation
) << (31 - Index
));
377 if (BltInfo
->PatternSurface
)
380 for (k
= 31 - NoBits
; k
>= 0; k
++)
381 Pattern
|= (DIB_GetSourceIndex(PatternObj
, (X
+ BrushOrigin
.x
+ k
) % PatternWidth
, PatternY
) << (31 - k
));
384 Dest
= DIB_DoRop(BltInfo
->Rop4
, Dest
, Source
, Pattern
);
385 Dest
&= ~((1 << (31 - NoBits
)) - 1);
386 Dest
|= *((PBYTE
)DestBits
) & ((1 << (31 - NoBits
)) - 1);
395 for (; DestX
< RoundedRight
; DestX
+= 32, DestBits
++, SourceX
+= 32)
402 for (Index
= 0; Index
< 8; Index
++)
404 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
, SourceY
, BltInfo
->XlateSourceToDest
) << (7 - Index
);
405 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
+ 8, SourceY
, BltInfo
->XlateSourceToDest
) << (8 + (7 - Index
));
406 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
+ 16, SourceY
, BltInfo
->XlateSourceToDest
) << (16 + (7 - Index
));
407 Source
|= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
+ Index
+ 24, SourceY
, BltInfo
->XlateSourceToDest
) << (24 + (7 - Index
));
411 if (BltInfo
->PatternSurface
)
414 for (Index
= 0; Index
< 8; Index
++)
416 Pattern
|= DIB_GetSourceIndex(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
) << (7 - Index
);
417 Pattern
|= DIB_GetSourceIndex(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
+ 8) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
) << (8 + (7 - Index
));
418 Pattern
|= DIB_GetSourceIndex(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
+ 16) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
) << (16 + (7 - Index
));
419 Pattern
|= DIB_GetSourceIndex(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
+ Index
+ 24) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
) << (24 + (7 - Index
));
423 *DestBits
= DIB_DoRop(BltInfo
->Rop4
, Dest
, Source
, Pattern
);
426 if (DestX
< BltInfo
->DestRect
.right
)
428 for (; DestX
< BltInfo
->DestRect
.right
; DestX
++, SourceX
++)
430 Dest
= DIB_1BPP_GetPixel(BltInfo
->DestSurface
, DestX
, DestY
);
434 Source
= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
, SourceY
, BltInfo
->XlateSourceToDest
);
437 if (BltInfo
->PatternSurface
)
439 Pattern
= DIB_GetSourceIndex(BltInfo
->PatternSurface
, (DestX
+ BltInfo
->BrushOrigin
.x
) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
);
442 DIB_1BPP_PutPixel(BltInfo
->DestSurface
, DestX
, DestY
, DIB_DoRop(BltInfo
->Rop4
, Dest
, Source
, Pattern
) & 0xF);
447 if (BltInfo
->PatternSurface
)
450 PatternY
%= BltInfo
->PatternSurface
->sizlBitmap
.cy
;
457 /* BitBlt Optimize */
459 DIB_1BPP_ColorFill(SURFOBJ
* DestSurface
, RECTL
* DestRect
, ULONG color
)
463 for (DestY
= DestRect
->top
; DestY
< DestRect
->bottom
; DestY
++)
465 DIB_1BPP_HLine(DestSurface
, DestRect
->left
, DestRect
->right
, DestY
, color
);
469 #endif // !_USE_DIBLIB_
472 DIB_1BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
473 RECTL
* DestRect
, RECTL
*SourceRect
,
474 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)