d3c60d43236573f3a5ae9f8abcf0979c52430dde
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.
27 DIB_24BPP_PutPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
, ULONG c
)
29 PBYTE addr
= (PBYTE
)SurfObj
->pvScan0
+ (y
* SurfObj
->lDelta
) + (x
<< 1) + x
;
30 *(PUSHORT
)(addr
) = c
& 0xFFFF;
31 *(addr
+ 2) = (c
>> 16) & 0xFF;
35 DIB_24BPP_GetPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
)
37 PBYTE addr
= (PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ (x
<< 1) + x
;
38 return *(PUSHORT
)(addr
) + (*(addr
+ 2) << 16);
44 DIB_24BPP_VLine(SURFOBJ
*SurfObj
, LONG x
, LONG y1
, LONG y2
, ULONG c
)
46 PBYTE addr
= (PBYTE
)SurfObj
->pvScan0
+ y1
* SurfObj
->lDelta
+ (x
<< 1) + x
;
47 LONG lDelta
= SurfObj
->lDelta
;
51 *(PUSHORT
)(addr
) = c
& 0xFFFF;
52 *(addr
+ 2) = c
>> 16;
59 DIB_24BPP_BitBltSrcCopy(PBLTINFO BltInfo
)
61 LONG i
, j
, sx
, sy
, xColor
, f1
;
62 PBYTE SourceBits
, DestBits
, SourceLine
, DestLine
;
63 PBYTE SourceBits_4BPP
, SourceLine_4BPP
;
64 PWORD SourceBits_16BPP
, SourceLine_16BPP
;
66 DestBits
= (PBYTE
)BltInfo
->DestSurface
->pvScan0
+ (BltInfo
->DestRect
.top
* BltInfo
->DestSurface
->lDelta
) + BltInfo
->DestRect
.left
* 3;
68 switch(BltInfo
->SourceSurface
->iBitmapFormat
)
71 sx
= BltInfo
->SourcePoint
.x
;
72 sy
= BltInfo
->SourcePoint
.y
;
74 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
76 sx
= BltInfo
->SourcePoint
.x
;
77 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
79 if(DIB_1BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
) == 0)
81 DIB_24BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, 0));
83 DIB_24BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, 1));
92 SourceBits_4BPP
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + (BltInfo
->SourcePoint
.x
>> 1);
94 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
96 SourceLine_4BPP
= SourceBits_4BPP
;
98 sx
= BltInfo
->SourcePoint
.x
;
101 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
103 xColor
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
,
104 (*SourceLine_4BPP
& altnotmask
[f1
]) >> (4 * (1 - f1
)));
105 *DestLine
++ = xColor
& 0xff;
106 *(PWORD
)DestLine
= xColor
>> 8;
108 if(f1
== 1) { SourceLine_4BPP
++; f1
= 0; } else { f1
= 1; }
112 SourceBits_4BPP
+= BltInfo
->SourceSurface
->lDelta
;
113 DestBits
+= BltInfo
->DestSurface
->lDelta
;
118 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + BltInfo
->SourcePoint
.x
;
121 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
123 SourceBits
= SourceLine
;
126 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
128 xColor
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, *SourceBits
);
129 *DestBits
= xColor
& 0xff;
130 *(PWORD
)(DestBits
+ 1) = xColor
>> 8;
135 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
136 DestLine
+= BltInfo
->DestSurface
->lDelta
;
141 SourceBits_16BPP
= (PWORD
)((PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + 2 * BltInfo
->SourcePoint
.x
);
143 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
145 SourceLine_16BPP
= SourceBits_16BPP
;
148 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
150 xColor
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, *SourceLine_16BPP
);
151 *DestLine
++ = xColor
& 0xff;
152 *(PWORD
)DestLine
= xColor
>> 8;
157 SourceBits_16BPP
= (PWORD
)((PBYTE
)SourceBits_16BPP
+ BltInfo
->SourceSurface
->lDelta
);
158 DestBits
+= BltInfo
->DestSurface
->lDelta
;
163 if (NULL
== BltInfo
->XlateSourceToDest
|| 0 != (BltInfo
->XlateSourceToDest
->flXlate
& XO_TRIVIAL
))
165 if (BltInfo
->DestRect
.top
< BltInfo
->SourcePoint
.y
)
167 SourceBits
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + 3 * BltInfo
->SourcePoint
.x
;
168 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
170 RtlMoveMemory(DestBits
, SourceBits
, 3 * (BltInfo
->DestRect
.right
- BltInfo
->DestRect
.left
));
171 SourceBits
+= BltInfo
->SourceSurface
->lDelta
;
172 DestBits
+= BltInfo
->DestSurface
->lDelta
;
177 SourceBits
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ ((BltInfo
->SourcePoint
.y
+ BltInfo
->DestRect
.bottom
- BltInfo
->DestRect
.top
- 1) * BltInfo
->SourceSurface
->lDelta
) + 3 * BltInfo
->SourcePoint
.x
;
178 DestBits
= (PBYTE
)BltInfo
->DestSurface
->pvScan0
+ ((BltInfo
->DestRect
.bottom
- 1) * BltInfo
->DestSurface
->lDelta
) + 3 * BltInfo
->DestRect
.left
;
179 for (j
= BltInfo
->DestRect
.bottom
- 1; BltInfo
->DestRect
.top
<= j
; j
--)
181 RtlMoveMemory(DestBits
, SourceBits
, 3 * (BltInfo
->DestRect
.right
- BltInfo
->DestRect
.left
));
182 SourceBits
-= BltInfo
->SourceSurface
->lDelta
;
183 DestBits
-= BltInfo
->DestSurface
->lDelta
;
189 sx
= BltInfo
->SourcePoint
.x
;
190 sy
= BltInfo
->SourcePoint
.y
;
192 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
194 sx
= BltInfo
->SourcePoint
.x
;
195 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
197 DWORD pixel
= DIB_24BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
);
198 DIB_24BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, pixel
));
207 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + 4 * BltInfo
->SourcePoint
.x
;
210 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
212 SourceBits
= SourceLine
;
215 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
217 xColor
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, *((PDWORD
) SourceBits
));
218 *DestBits
= xColor
& 0xff;
219 *(PWORD
)(DestBits
+ 1) = xColor
>> 8;
224 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
225 DestLine
+= BltInfo
->DestSurface
->lDelta
;
230 DbgPrint("DIB_24BPP_Bitblt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo
->SourceSurface
->iBitmapFormat
));
238 DIB_24BPP_BitBlt(PBLTINFO BltInfo
)
241 ULONG SourceX
, SourceY
;
243 ULONG Dest
, Source
= 0, Pattern
= 0;
248 UsesSource
= ROP4_USES_SOURCE(BltInfo
->Rop4
);
249 UsesPattern
= ROP4_USES_PATTERN(BltInfo
->Rop4
);
251 SourceY
= BltInfo
->SourcePoint
.y
;
253 (PBYTE
)BltInfo
->DestSurface
->pvScan0
+
254 (BltInfo
->DestRect
.left
<< 1) + BltInfo
->DestRect
.left
+
255 BltInfo
->DestRect
.top
* BltInfo
->DestSurface
->lDelta
);
259 if (BltInfo
->PatternSurface
)
261 PatternY
= (BltInfo
->DestRect
.top
- BltInfo
->BrushOrigin
.y
) %
262 BltInfo
->PatternSurface
->sizlBitmap
.cy
;
266 Pattern
= BltInfo
->Brush
->iSolidColor
;
270 for (DestY
= BltInfo
->DestRect
.top
; DestY
< BltInfo
->DestRect
.bottom
; DestY
++)
272 SourceX
= BltInfo
->SourcePoint
.x
;
274 for (DestX
= BltInfo
->DestRect
.left
; DestX
< BltInfo
->DestRect
.right
; DestX
++, DestBits
+= 3, SourceX
++)
276 Dest
= *((PUSHORT
)DestBits
) + (*(DestBits
+ 2) << 16);
280 Source
= DIB_GetSource(BltInfo
->SourceSurface
, SourceX
, SourceY
, BltInfo
->XlateSourceToDest
);
283 if (BltInfo
->PatternSurface
)
285 Pattern
= DIB_GetSource(BltInfo
->PatternSurface
, (DestX
- BltInfo
->BrushOrigin
.x
) % BltInfo
->PatternSurface
->sizlBitmap
.cx
, PatternY
, BltInfo
->XlatePatternToDest
);
288 Dest
= DIB_DoRop(BltInfo
->Rop4
, Dest
, Source
, Pattern
) & 0xFFFFFF;
289 *(PUSHORT
)(DestBits
) = Dest
& 0xFFFF;
290 *(DestBits
+ 2) = Dest
>> 16;
294 if (BltInfo
->PatternSurface
)
297 PatternY
%= BltInfo
->PatternSurface
->sizlBitmap
.cy
;
299 DestBits
-= (BltInfo
->DestRect
.right
- BltInfo
->DestRect
.left
) * 3;
300 DestBits
+= BltInfo
->DestSurface
->lDelta
;
306 /* BitBlt Optimize */
308 DIB_24BPP_ColorFill(SURFOBJ
* DestSurface
, RECTL
* DestRect
, ULONG color
)
312 #if defined(_M_IX86) && !defined(_MSC_VER)
313 PBYTE xaddr
= (PBYTE
)DestSurface
->pvScan0
+ DestRect
->top
* DestSurface
->lDelta
+ (DestRect
->left
<< 1) + DestRect
->left
;
316 ULONG xCount
=DestRect
->right
- DestRect
->left
;
318 for (DestY
= DestRect
->top
; DestY
< DestRect
->bottom
; DestY
++)
322 xaddr
= (PBYTE
)((ULONG_PTR
)addr
+ DestSurface
->lDelta
);
326 /* For small fills, don't bother doing anything fancy */
329 *(PUSHORT
)(addr
) = color
;
331 *(addr
) = color
>> 16;
337 /* Align to 4-byte address */
338 while (0 != ((ULONG_PTR
) addr
& 0x3))
340 *(PUSHORT
)(addr
) = color
;
342 *(addr
) = color
>> 16;
346 /* If the color we need to fill with is 0ABC, then the final mem pattern
347 * (note little-endianness) would be:
349 * |C.B.A|C.B.A|C.B.A|C.B.A| <- pixel borders
350 * |C.B.A.C|B.A.C.B|A.C.B.A| <- ULONG borders
352 * So, taking endianness into account again, we need to fill with these
353 * ULONGs: CABC BCAB ABCA */
355 /* This is about 30% faster than the generic C code below */
356 __asm__
__volatile__ (
358 " andl $0xffffff, %%ecx\n" /* 0ABC */
359 " movl %%ecx, %%ebx\n" /* Construct BCAB in ebx */
361 " movl %%ecx, %%eax\n"
363 " orl %%eax, %%ebx\n"
364 " movl %%ecx, %%edx\n" /* Construct ABCA in edx */
366 " movl %%ecx, %%eax\n"
368 " orl %%eax, %%edx\n"
369 " movl %%ecx, %%eax\n" /* Construct CABC in eax */
371 " orl %%ecx, %%eax\n"
372 " movl %2, %%ecx\n" /* Load count */
374 " movl %3, %%edi\n" /* Load dest */
376 " movl %%eax, (%%edi)\n" /* Store 4 pixels, 12 bytes */
377 " movl %%ebx, 4(%%edi)\n"
378 " movl %%edx, 8(%%edi)\n"
384 : "m"(color
), "m"(Count
), "m"(addr
)
385 : "%eax", "%ebx", "%ecx", "%edx", "%edi");
386 Count
= Count
& 0x03;
389 *(PUSHORT
)(addr
) = color
;
391 *(addr
) = color
>> 16;
398 for (DestY
= DestRect
->top
; DestY
< DestRect
->bottom
; DestY
++)
400 DIB_24BPP_HLine(DestSurface
, DestRect
->left
, DestRect
->right
, DestY
, color
);
407 DIB_24BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
408 RECTL
* DestRect
, POINTL
*SourcePoint
,
409 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)
411 ULONG X
, Y
, SourceX
, SourceY
, Source
, wd
, Dest
;
414 SourceY
= SourcePoint
->y
;
415 DestBits
= (BYTE
*)((PBYTE
)DestSurf
->pvScan0
+
416 (DestRect
->left
* 3) +
417 DestRect
->top
* DestSurf
->lDelta
);
418 wd
= DestSurf
->lDelta
- ((DestRect
->right
- DestRect
->left
) * 3);
420 for(Y
= DestRect
->top
; Y
< DestRect
->bottom
; Y
++)
422 SourceX
= SourcePoint
->x
;
423 for(X
= DestRect
->left
; X
< DestRect
->right
; X
++, DestBits
+= 3, SourceX
++)
425 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
, SourceY
);
426 if(Source
!= iTransColor
)
428 Dest
= XLATEOBJ_iXlate(ColorTranslation
, Source
) & 0xFFFFFF;
429 *(PUSHORT
)(DestBits
) = Dest
& 0xFFFF;
430 *(DestBits
+ 2) = Dest
>> 16;
435 DestBits
= (BYTE
*)((ULONG_PTR
)DestBits
+ wd
);
451 static __inline UCHAR
454 return (val
> 255) ? 255 : val
;
458 DIB_24BPP_AlphaBlend(SURFOBJ
* Dest
, SURFOBJ
* Source
, RECTL
* DestRect
,
459 RECTL
* SourceRect
, CLIPOBJ
* ClipRegion
,
460 XLATEOBJ
* ColorTranslation
, BLENDOBJ
* BlendObj
)
462 INT Rows
, Cols
, SrcX
, SrcY
;
465 BLENDFUNCTION BlendFunc
;
466 register NICEPIXEL32 DstPixel
, SrcPixel
;
469 DPRINT("DIB_24BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
470 SourceRect
->left
, SourceRect
->top
, SourceRect
->right
, SourceRect
->bottom
,
471 DestRect
->left
, DestRect
->top
, DestRect
->right
, DestRect
->bottom
);
473 ASSERT(DestRect
->bottom
- DestRect
->top
== SourceRect
->bottom
- SourceRect
->top
&&
474 DestRect
->right
- DestRect
->left
== SourceRect
->right
- SourceRect
->left
);
476 BlendFunc
= BlendObj
->BlendFunction
;
477 if (BlendFunc
.BlendOp
!= AC_SRC_OVER
)
479 DPRINT1("BlendOp != AC_SRC_OVER\n");
482 if (BlendFunc
.BlendFlags
!= 0)
484 DPRINT1("BlendFlags != 0\n");
487 if ((BlendFunc
.AlphaFormat
& ~AC_SRC_ALPHA
) != 0)
489 DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc
.AlphaFormat
);
492 if ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0 &&
493 BitsPerFormat(Source
->iBitmapFormat
) != 32)
495 DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
499 Dst
= (PUCHAR
)((ULONG_PTR
)Dest
->pvScan0
+ (DestRect
->top
* Dest
->lDelta
) +
500 (DestRect
->left
* 3));
501 DstDelta
= Dest
->lDelta
- ((DestRect
->right
- DestRect
->left
) * 3);
502 SrcBpp
= BitsPerFormat(Source
->iBitmapFormat
);
504 Rows
= DestRect
->bottom
- DestRect
->top
;
505 SrcY
= SourceRect
->top
;
508 Cols
= DestRect
->right
- DestRect
->left
;
509 SrcX
= SourceRect
->left
;
512 SrcPixel
.ul
= DIB_GetSource(Source
, SrcX
++, SrcY
, ColorTranslation
);
513 SrcPixel
.col
.red
= SrcPixel
.col
.red
* BlendFunc
.SourceConstantAlpha
/ 255;
514 SrcPixel
.col
.green
= SrcPixel
.col
.green
* BlendFunc
.SourceConstantAlpha
/ 255;
515 SrcPixel
.col
.blue
= SrcPixel
.col
.blue
* BlendFunc
.SourceConstantAlpha
/ 255;
516 SrcPixel
.col
.alpha
= (SrcBpp
== 32) ? (SrcPixel
.col
.alpha
* BlendFunc
.SourceConstantAlpha
/ 255) : BlendFunc
.SourceConstantAlpha
;
518 Alpha
= ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0) ?
519 SrcPixel
.col
.alpha
: BlendFunc
.SourceConstantAlpha
;
521 /* copy only 24bits of dst */
522 DstPixel
.ul
= *(PUSHORT
)(Dst
) + (*(Dst
+2) << 16);
523 DstPixel
.col
.red
= Clamp8(DstPixel
.col
.red
* (255 - Alpha
) / 255 + SrcPixel
.col
.red
);
524 DstPixel
.col
.green
= Clamp8(DstPixel
.col
.green
* (255 - Alpha
) / 255 + SrcPixel
.col
.green
);
525 DstPixel
.col
.blue
= Clamp8(DstPixel
.col
.blue
* (255 - Alpha
) / 255 + SrcPixel
.col
.blue
);
526 /* copy back 24bits of result */
527 *(PUSHORT
)(Dst
) = (USHORT
)(DstPixel
.ul
& 0xFFFF);
528 *(Dst
+ 2) = (UCHAR
)((DstPixel
.ul
>> 16) & 0xFF);
529 Dst
= (PUCHAR
)((ULONG_PTR
)Dst
+ 3);
531 Dst
= (PUCHAR
)((ULONG_PTR
)Dst
+ DstDelta
);