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_16BPP_PutPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
, ULONG c
)
28 PBYTE byteaddr
= (PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
;
29 PWORD addr
= (PWORD
)byteaddr
+ x
;
35 DIB_16BPP_GetPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
)
37 PBYTE byteaddr
= (PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
;
38 PWORD addr
= (PWORD
)byteaddr
+ x
;
39 return (ULONG
)(*addr
);
43 DIB_16BPP_HLine(SURFOBJ
*SurfObj
, LONG x1
, LONG x2
, LONG y
, ULONG c
)
45 PDWORD addr
= (PDWORD
)((PWORD
)((PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
) + x1
);
47 #if defined(_M_IX86) && !defined(_MSC_VER)
48 /* This is about 10% faster than the generic C code below */
51 __asm__
__volatile__ (
55 " andl $0xffff, %0\n" /* If the pixel value is "abcd", put "abcdabcd" in %eax */
58 " test $0x03, %%edi\n" /* Align to fullword boundary */
64 " mov %1,%%ecx\n" /* Setup count of fullwords to fill */
66 " rep stosl\n" /* The actual fill */
67 " test $0x01, %1\n" /* One left to do at the right side? */
72 : "r"(c
), "r"(Count
), "m"(addr
)
73 : "%eax", "%ecx", "%edi");
82 addr
= (PDWORD
)((PWORD
)(addr
) + 1);
84 cc
= ((c
& 0xffff) << 16) | (c
& 0xffff);
99 DIB_16BPP_VLine(SURFOBJ
*SurfObj
, LONG x
, LONG y1
, LONG y2
, ULONG c
)
101 #if defined(_M_IX86) && !defined(_MSC_VER)
103 " testl %2, %2" "\n\t"
105 " movl %2, %%ecx" "\n\t"
106 " shrl $2, %2" "\n\t"
107 " andl $3, %%ecx" "\n\t"
110 " movw %%ax, (%0)" "\n\t"
111 " addl %1, %0" "\n\t"
114 " testl %2, %2" "\n\t"
117 " movw %%ax, (%0)" "\n\t"
118 " addl %1, %0" "\n\t"
119 " movw %%ax, (%0)" "\n\t"
120 " addl %1, %0" "\n\t"
121 " movw %%ax, (%0)" "\n\t"
122 " addl %1, %0" "\n\t"
123 " movw %%ax, (%0)" "\n\t"
124 " addl %1, %0" "\n\t"
129 : "r"((PBYTE
)SurfObj
->pvScan0
+ (y1
* SurfObj
->lDelta
) + (x
* sizeof (WORD
))),
130 "r"(SurfObj
->lDelta
), "r"(y2
- y1
), "a"(c
)
131 : "cc", "memory", "%ecx");
133 PBYTE byteaddr
= (PBYTE
)(ULONG_PTR
)SurfObj
->pvScan0
+ y1
* SurfObj
->lDelta
;
134 PWORD addr
= (PWORD
)byteaddr
+ x
;
135 LONG lDelta
= SurfObj
->lDelta
;
137 byteaddr
= (PBYTE
)addr
;
143 addr
= (PWORD
)byteaddr
;
149 DIB_16BPP_BitBltSrcCopy(PBLTINFO BltInfo
)
151 LONG i
, j
, sx
, sy
, xColor
, f1
;
152 PBYTE SourceBits
, DestBits
, SourceLine
, DestLine
;
153 PBYTE SourceBits_4BPP
, SourceLine_4BPP
;
154 DestBits
= (PBYTE
)BltInfo
->DestSurface
->pvScan0
+ (BltInfo
->DestRect
.top
* BltInfo
->DestSurface
->lDelta
) + 2 * BltInfo
->DestRect
.left
;
156 switch(BltInfo
->SourceSurface
->iBitmapFormat
)
159 sx
= BltInfo
->SourcePoint
.x
;
160 sy
= BltInfo
->SourcePoint
.y
;
161 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
163 sx
= BltInfo
->SourcePoint
.x
;
164 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
166 if(DIB_1BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
) == 0)
168 DIB_16BPP_PutPixel(BltInfo
->DestSurface
, i
, j
,
169 XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, 0));
173 DIB_16BPP_PutPixel(BltInfo
->DestSurface
, i
, j
,
174 XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, 1));
183 SourceBits_4BPP
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+
184 (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) +
185 (BltInfo
->SourcePoint
.x
>> 1);
187 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
189 SourceLine_4BPP
= SourceBits_4BPP
;
190 sx
= BltInfo
->SourcePoint
.x
;
193 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
195 xColor
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
,
196 (*SourceLine_4BPP
& altnotmask
[f1
]) >> (4 * (1 - f1
)));
197 DIB_16BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, xColor
);
209 SourceBits_4BPP
+= BltInfo
->SourceSurface
->lDelta
;
214 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+
215 (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) +
216 BltInfo
->SourcePoint
.x
;
219 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
221 SourceBits
= SourceLine
;
224 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
226 *((WORD
*)DestBits
) = (WORD
)XLATEOBJ_iXlate(
227 BltInfo
->XlateSourceToDest
, *SourceBits
);
232 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
233 DestLine
+= BltInfo
->DestSurface
->lDelta
;
238 if (NULL
== BltInfo
->XlateSourceToDest
|| 0 !=
239 (BltInfo
->XlateSourceToDest
->flXlate
& XO_TRIVIAL
))
241 if (BltInfo
->DestRect
.top
< BltInfo
->SourcePoint
.y
)
243 SourceBits
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+
244 (BltInfo
->SourcePoint
.y
*
245 BltInfo
->SourceSurface
->lDelta
) + 2 *
246 BltInfo
->SourcePoint
.x
;
248 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
250 RtlMoveMemory(DestBits
, SourceBits
,
251 2 * (BltInfo
->DestRect
.right
-
252 BltInfo
->DestRect
.left
));
254 SourceBits
+= BltInfo
->SourceSurface
->lDelta
;
255 DestBits
+= BltInfo
->DestSurface
->lDelta
;
260 SourceBits
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+
261 ((BltInfo
->SourcePoint
.y
+ BltInfo
->DestRect
.bottom
-
262 BltInfo
->DestRect
.top
- 1) *
263 BltInfo
->SourceSurface
->lDelta
) + 2 *
264 BltInfo
->SourcePoint
.x
;
266 DestBits
= (PBYTE
)BltInfo
->DestSurface
->pvScan0
+
267 ((BltInfo
->DestRect
.bottom
- 1) *
268 BltInfo
->DestSurface
->lDelta
) + 2 *
269 BltInfo
->DestRect
.left
;
271 for (j
= BltInfo
->DestRect
.bottom
- 1;
272 BltInfo
->DestRect
.top
<= j
; j
--)
274 RtlMoveMemory(DestBits
, SourceBits
, 2 *
275 (BltInfo
->DestRect
.right
-
276 BltInfo
->DestRect
.left
));
278 SourceBits
-= BltInfo
->SourceSurface
->lDelta
;
279 DestBits
-= BltInfo
->DestSurface
->lDelta
;
285 if (BltInfo
->DestRect
.top
< BltInfo
->SourcePoint
.y
)
287 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+
288 (BltInfo
->SourcePoint
.y
*
289 BltInfo
->SourceSurface
->lDelta
) + 2 *
290 BltInfo
->SourcePoint
.x
;
293 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
295 SourceBits
= SourceLine
;
297 for (i
= BltInfo
->DestRect
.left
; i
<
298 BltInfo
->DestRect
.right
; i
++)
300 *((WORD
*)DestBits
) = (WORD
)XLATEOBJ_iXlate(
301 BltInfo
->XlateSourceToDest
,
302 *((WORD
*)SourceBits
));
306 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
307 DestLine
+= BltInfo
->DestSurface
->lDelta
;
312 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+
313 ((BltInfo
->SourcePoint
.y
+
314 BltInfo
->DestRect
.bottom
-
315 BltInfo
->DestRect
.top
- 1) *
316 BltInfo
->SourceSurface
->lDelta
) + 2 *
317 BltInfo
->SourcePoint
.x
;
319 DestLine
= (PBYTE
)BltInfo
->DestSurface
->pvScan0
+
320 ((BltInfo
->DestRect
.bottom
- 1) *
321 BltInfo
->DestSurface
->lDelta
) + 2 *
322 BltInfo
->DestRect
.left
;
324 for (j
= BltInfo
->DestRect
.bottom
- 1;
325 BltInfo
->DestRect
.top
<= j
; j
--)
327 SourceBits
= SourceLine
;
329 for (i
= BltInfo
->DestRect
.left
; i
<
330 BltInfo
->DestRect
.right
; i
++)
332 *((WORD
*)DestBits
) = (WORD
)XLATEOBJ_iXlate(
333 BltInfo
->XlateSourceToDest
,
334 *((WORD
*)SourceBits
));
338 SourceLine
-= BltInfo
->SourceSurface
->lDelta
;
339 DestLine
-= BltInfo
->DestSurface
->lDelta
;
346 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+
347 (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) +
348 3 * BltInfo
->SourcePoint
.x
;
352 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
354 SourceBits
= SourceLine
;
357 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
359 xColor
= (*(SourceBits
+ 2) << 0x10) +
360 (*(SourceBits
+ 1) << 0x08) + (*(SourceBits
));
362 *((WORD
*)DestBits
) = (WORD
)XLATEOBJ_iXlate(
363 BltInfo
->XlateSourceToDest
, xColor
);
368 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
369 DestLine
+= BltInfo
->DestSurface
->lDelta
;
374 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+
375 (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) +
376 4 * BltInfo
->SourcePoint
.x
;
380 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
382 SourceBits
= SourceLine
;
385 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
387 *((WORD
*)DestBits
) = (WORD
)XLATEOBJ_iXlate(
388 BltInfo
->XlateSourceToDest
,
389 *((PDWORD
) SourceBits
));
394 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
395 DestLine
+= BltInfo
->DestSurface
->lDelta
;
400 DPRINT1("DIB_16BPP_Bitblt: Unhandled Source BPP: %u\n",
401 BitsPerFormat(BltInfo
->SourceSurface
->iBitmapFormat
));
408 /* Optimize for bitBlt */
410 DIB_16BPP_ColorFill(SURFOBJ
* DestSurface
, RECTL
* DestRect
, ULONG color
)
414 #if defined(_M_IX86) && !defined(_MSC_VER)
415 /* This is about 10% faster than the generic C code below */
416 ULONG delta
= DestSurface
->lDelta
;
417 ULONG width
= (DestRect
->right
- DestRect
->left
) ;
418 PULONG pos
= (PULONG
) ((PBYTE
)DestSurface
->pvScan0
+ DestRect
->top
* delta
+ (DestRect
->left
<<1));
419 color
= (color
&0xffff); /* If the color value is "abcd", put "abcdabcd" into color */
420 color
+= (color
<<16);
422 for (DestY
= DestRect
->top
; DestY
< DestRect
->bottom
; DestY
++)
424 __asm__
__volatile__ (
428 " test $0x03, %%edi\n" /* Align to fullword boundary */
434 " mov %%ebx,%%ecx\n" /* Setup count of fullwords to fill */
436 " rep stosl\n" /* The actual fill */
437 " test $0x01, %%ebx\n" /* One left to do at the right side? */
442 : "a" (color
), "r" (width
), "m" (pos
)
443 : "%ecx", "%ebx", "%edi");
444 pos
=(PULONG
)((ULONG_PTR
)pos
+ delta
);
448 for (DestY
= DestRect
->top
; DestY
< DestRect
->bottom
; DestY
++)
450 DIB_16BPP_HLine (DestSurface
, DestRect
->left
, DestRect
->right
, DestY
, color
);
457 DIB_16BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
458 RECTL
* DestRect
, POINTL
*SourcePoint
,
459 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)
461 ULONG RoundedRight
, X
, Y
, SourceX
, SourceY
, Source
, wd
, Dest
;
464 RoundedRight
= DestRect
->right
- ((DestRect
->right
- DestRect
->left
) & 0x1);
465 SourceY
= SourcePoint
->y
;
466 DestBits
= (ULONG
*)((PBYTE
)DestSurf
->pvScan0
+
467 (DestRect
->left
<< 1) +
468 DestRect
->top
* DestSurf
->lDelta
);
469 wd
= DestSurf
->lDelta
- ((DestRect
->right
- DestRect
->left
) << 1);
471 for(Y
= DestRect
->top
; Y
< DestRect
->bottom
; Y
++)
473 SourceX
= SourcePoint
->x
;
474 for(X
= DestRect
->left
; X
< RoundedRight
; X
+= 2, DestBits
++, SourceX
+= 2)
477 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
, SourceY
);
479 if(Source
!= iTransColor
)
482 Dest
|= (XLATEOBJ_iXlate(ColorTranslation
, Source
) & 0xFFFF);
485 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
+ 1, SourceY
);
486 if(Source
!= iTransColor
)
489 Dest
|= (XLATEOBJ_iXlate(ColorTranslation
, Source
) << 16);
495 if(X
< DestRect
->right
)
497 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
, SourceY
);
498 if(Source
!= iTransColor
)
500 *((USHORT
*)DestBits
) = (USHORT
)XLATEOBJ_iXlate(ColorTranslation
,
504 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ 2);
508 DestBits
= (ULONG
*)((ULONG_PTR
)DestBits
+ wd
);
537 static __inline UCHAR
540 return (val
> 31) ? 31 : val
;
543 static __inline UCHAR
546 return (val
> 63) ? 63 : val
;
550 DIB_16BPP_AlphaBlend(SURFOBJ
* Dest
, SURFOBJ
* Source
, RECTL
* DestRect
,
551 RECTL
* SourceRect
, CLIPOBJ
* ClipRegion
,
552 XLATEOBJ
* ColorTranslation
, BLENDOBJ
* BlendObj
)
554 INT Rows
, Cols
, SrcX
, SrcY
;
555 register PUSHORT Dst
;
557 BLENDFUNCTION BlendFunc
;
558 register NICEPIXEL16 DstPixel
;
559 register NICEPIXEL32 SrcPixel
;
562 DPRINT("DIB_16BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
563 SourceRect
->left
, SourceRect
->top
, SourceRect
->right
, SourceRect
->bottom
,
564 DestRect
->left
, DestRect
->top
, DestRect
->right
, DestRect
->bottom
);
566 ASSERT(DestRect
->bottom
- DestRect
->top
== SourceRect
->bottom
- SourceRect
->top
&&
567 DestRect
->right
- DestRect
->left
== SourceRect
->right
- SourceRect
->left
);
569 BlendFunc
= BlendObj
->BlendFunction
;
570 if (BlendFunc
.BlendOp
!= AC_SRC_OVER
)
572 DPRINT1("BlendOp != AC_SRC_OVER\n");
575 if (BlendFunc
.BlendFlags
!= 0)
577 DPRINT1("BlendFlags != 0\n");
580 if ((BlendFunc
.AlphaFormat
& ~AC_SRC_ALPHA
) != 0)
582 DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc
.AlphaFormat
);
585 if ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0 &&
586 BitsPerFormat(Source
->iBitmapFormat
) != 32)
588 DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
592 Dst
= (PUSHORT
)((ULONG_PTR
)Dest
->pvScan0
+ (DestRect
->top
* Dest
->lDelta
) +
593 (DestRect
->left
<< 1));
594 DstDelta
= Dest
->lDelta
- ((DestRect
->right
- DestRect
->left
) << 1);
595 SrcBpp
= BitsPerFormat(Source
->iBitmapFormat
);
597 Rows
= DestRect
->bottom
- DestRect
->top
;
598 SrcY
= SourceRect
->top
;
601 Cols
= DestRect
->right
- DestRect
->left
;
602 SrcX
= SourceRect
->left
;
607 DstPixel
.us
= DIB_GetSource(Source
, SrcX
++, SrcY
, ColorTranslation
);
608 SrcPixel
.col
.red
= (DstPixel
.col
.red
<< 3) | (DstPixel
.col
.red
>> 2);
610 SrcPixel
.col
.green
= (DstPixel
.col
.green
<< 2) |
611 (DstPixel
.col
.green
>> 4);
613 SrcPixel
.col
.blue
= (DstPixel
.col
.blue
<< 3) | (DstPixel
.col
.blue
>> 2);
617 SrcPixel
.ul
= DIB_GetSourceIndex(Source
, SrcX
++, SrcY
);
619 SrcPixel
.col
.red
= SrcPixel
.col
.red
*
620 BlendFunc
.SourceConstantAlpha
/ 255;
622 SrcPixel
.col
.green
= SrcPixel
.col
.green
*
623 BlendFunc
.SourceConstantAlpha
/ 255;
625 SrcPixel
.col
.blue
= SrcPixel
.col
.blue
*
626 BlendFunc
.SourceConstantAlpha
/ 255;
628 SrcPixel
.col
.alpha
= (SrcBpp
== 32) ?
629 (SrcPixel
.col
.alpha
*
630 BlendFunc
.SourceConstantAlpha
/ 255) :
631 BlendFunc
.SourceConstantAlpha
;
633 Alpha
= ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0) ?
634 SrcPixel
.col
.alpha
: BlendFunc
.SourceConstantAlpha
;
637 DstPixel
.col
.red
= Clamp5(DstPixel
.col
.red
* (255 - Alpha
) / 255 +
638 (SrcPixel
.col
.red
>> 3));
640 DstPixel
.col
.green
= Clamp6(DstPixel
.col
.green
* (255 - Alpha
) / 255 +
641 (SrcPixel
.col
.green
>> 2));
643 DstPixel
.col
.blue
= Clamp5(DstPixel
.col
.blue
* (255 - Alpha
) / 255 +
644 (SrcPixel
.col
.blue
>> 3));
646 *Dst
++ = DstPixel
.us
;
649 Dst
= (PUSHORT
)((ULONG_PTR
)Dst
+ DstDelta
);