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
;
40 return (ULONG
)(*addr
);
44 DIB_16BPP_HLine(SURFOBJ
*SurfObj
, LONG x1
, LONG x2
, LONG y
, ULONG c
)
46 PDWORD addr
= (PDWORD
)((PWORD
)((PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
) + x1
);
50 /* This is about 10% faster than the generic C code below */
53 __asm__
__volatile__ (
57 " andl $0xffff, %0\n" /* If the pixel value is "abcd", put "abcdabcd" in %eax */
60 " test $0x03, %%edi\n" /* Align to fullword boundary */
66 " mov %1,%%ecx\n" /* Setup count of fullwords to fill */
68 " rep stosl\n" /* The actual fill */
69 " test $0x01, %1\n" /* One left to do at the right side? */
74 : "r"(c
), "r"(Count
), "m"(addr
)
75 : "%eax", "%ecx", "%edi");
80 if (0 != (cx
& 0x01)) {
83 addr
= (PDWORD
)((PWORD
)(addr
) + 1);
85 cc
= ((c
& 0xffff) << 16) | (c
& 0xffff);
98 DIB_16BPP_VLine(SURFOBJ
*SurfObj
, LONG x
, LONG y1
, LONG y2
, ULONG c
)
102 " testl %2, %2" "\n\t"
104 " movl %2, %%ecx" "\n\t"
105 " shrl $2, %2" "\n\t"
106 " andl $3, %%ecx" "\n\t"
109 " movw %%ax, (%0)" "\n\t"
110 " addl %1, %0" "\n\t"
113 " testl %2, %2" "\n\t"
116 " movw %%ax, (%0)" "\n\t"
117 " addl %1, %0" "\n\t"
118 " movw %%ax, (%0)" "\n\t"
119 " addl %1, %0" "\n\t"
120 " movw %%ax, (%0)" "\n\t"
121 " addl %1, %0" "\n\t"
122 " movw %%ax, (%0)" "\n\t"
123 " addl %1, %0" "\n\t"
128 : "r"((PBYTE
)SurfObj
->pvScan0
+ (y1
* SurfObj
->lDelta
) + (x
* sizeof (WORD
))),
129 "r"(SurfObj
->lDelta
), "r"(y2
- y1
), "a"(c
)
130 : "cc", "memory", "%ecx");
132 PBYTE byteaddr
= SurfObj
->pvScan0
+ y1
* SurfObj
->lDelta
;
133 PWORD addr
= (PWORD
)byteaddr
+ x
;
134 LONG lDelta
= SurfObj
->lDelta
;
136 byteaddr
= (PBYTE
)addr
;
141 addr
= (PWORD
)byteaddr
;
147 DIB_16BPP_BitBltSrcCopy(PBLTINFO BltInfo
)
149 LONG i
, j
, sx
, sy
, xColor
, f1
;
150 PBYTE SourceBits
, DestBits
, SourceLine
, DestLine
;
151 PBYTE SourceBits_4BPP
, SourceLine_4BPP
;
152 DestBits
= (PBYTE
)BltInfo
->DestSurface
->pvScan0
+ (BltInfo
->DestRect
.top
* BltInfo
->DestSurface
->lDelta
) + 2 * BltInfo
->DestRect
.left
;
154 switch(BltInfo
->SourceSurface
->iBitmapFormat
)
157 sx
= BltInfo
->SourcePoint
.x
;
158 sy
= BltInfo
->SourcePoint
.y
;
160 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
162 sx
= BltInfo
->SourcePoint
.x
;
163 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
165 if(DIB_1BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
) == 0)
167 DIB_16BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, 0));
169 DIB_16BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, 1));
178 SourceBits_4BPP
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + (BltInfo
->SourcePoint
.x
>> 1);
180 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
182 SourceLine_4BPP
= SourceBits_4BPP
;
183 sx
= BltInfo
->SourcePoint
.x
;
186 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
188 xColor
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
,
189 (*SourceLine_4BPP
& altnotmask
[f1
]) >> (4 * (1 - f1
)));
190 DIB_16BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, xColor
);
191 if(f1
== 1) { SourceLine_4BPP
++; f1
= 0; } else { f1
= 1; }
195 SourceBits_4BPP
+= BltInfo
->SourceSurface
->lDelta
;
200 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + BltInfo
->SourcePoint
.x
;
203 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
205 SourceBits
= SourceLine
;
208 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
210 *((WORD
*)DestBits
) = (WORD
)XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, *SourceBits
);
215 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
216 DestLine
+= BltInfo
->DestSurface
->lDelta
;
221 if (NULL
== BltInfo
->XlateSourceToDest
|| 0 != (BltInfo
->XlateSourceToDest
->flXlate
& XO_TRIVIAL
))
223 if (BltInfo
->DestRect
.top
< BltInfo
->SourcePoint
.y
)
225 SourceBits
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + 2 * BltInfo
->SourcePoint
.x
;
226 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
228 RtlMoveMemory(DestBits
, SourceBits
, 2 * (BltInfo
->DestRect
.right
- BltInfo
->DestRect
.left
));
229 SourceBits
+= BltInfo
->SourceSurface
->lDelta
;
230 DestBits
+= BltInfo
->DestSurface
->lDelta
;
235 SourceBits
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ ((BltInfo
->SourcePoint
.y
+ BltInfo
->DestRect
.bottom
- BltInfo
->DestRect
.top
- 1) * BltInfo
->SourceSurface
->lDelta
) + 2 * BltInfo
->SourcePoint
.x
;
236 DestBits
= (PBYTE
)BltInfo
->DestSurface
->pvScan0
+ ((BltInfo
->DestRect
.bottom
- 1) * BltInfo
->DestSurface
->lDelta
) + 2 * BltInfo
->DestRect
.left
;
237 for (j
= BltInfo
->DestRect
.bottom
- 1; BltInfo
->DestRect
.top
<= j
; j
--)
239 RtlMoveMemory(DestBits
, SourceBits
, 2 * (BltInfo
->DestRect
.right
- BltInfo
->DestRect
.left
));
240 SourceBits
-= BltInfo
->SourceSurface
->lDelta
;
241 DestBits
-= BltInfo
->DestSurface
->lDelta
;
247 if (BltInfo
->DestRect
.top
< BltInfo
->SourcePoint
.y
)
249 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + 2 * BltInfo
->SourcePoint
.x
;
251 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
253 SourceBits
= SourceLine
;
255 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
257 *((WORD
*)DestBits
) = (WORD
)XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, *((WORD
*)SourceBits
));
261 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
262 DestLine
+= BltInfo
->DestSurface
->lDelta
;
267 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ ((BltInfo
->SourcePoint
.y
+ BltInfo
->DestRect
.bottom
- BltInfo
->DestRect
.top
- 1) * BltInfo
->SourceSurface
->lDelta
) + 2 * BltInfo
->SourcePoint
.x
;
268 DestLine
= (PBYTE
)BltInfo
->DestSurface
->pvScan0
+ ((BltInfo
->DestRect
.bottom
- 1) * BltInfo
->DestSurface
->lDelta
) + 2 * BltInfo
->DestRect
.left
;
269 for (j
= BltInfo
->DestRect
.bottom
- 1; BltInfo
->DestRect
.top
<= j
; j
--)
271 SourceBits
= SourceLine
;
273 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
275 *((WORD
*)DestBits
) = (WORD
)XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, *((WORD
*)SourceBits
));
279 SourceLine
-= BltInfo
->SourceSurface
->lDelta
;
280 DestLine
-= BltInfo
->DestSurface
->lDelta
;
287 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + 3 * BltInfo
->SourcePoint
.x
;
290 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
292 SourceBits
= SourceLine
;
295 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
297 xColor
= (*(SourceBits
+ 2) << 0x10) +
298 (*(SourceBits
+ 1) << 0x08) +
300 *((WORD
*)DestBits
) = (WORD
)XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, xColor
);
305 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
306 DestLine
+= BltInfo
->DestSurface
->lDelta
;
311 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + 4 * BltInfo
->SourcePoint
.x
;
314 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
316 SourceBits
= SourceLine
;
319 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
321 *((WORD
*)DestBits
) = (WORD
)XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, *((PDWORD
) SourceBits
));
326 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
327 DestLine
+= BltInfo
->DestSurface
->lDelta
;
332 DPRINT1("DIB_16BPP_Bitblt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo
->SourceSurface
->iBitmapFormat
));
339 /* Optimize for bitBlt */
341 DIB_16BPP_ColorFill(SURFOBJ
* DestSurface
, RECTL
* DestRect
, ULONG color
)
346 /* This is about 10% faster than the generic C code below */
347 ULONG delta
= DestSurface
->lDelta
;
348 ULONG width
= (DestRect
->right
- DestRect
->left
) ;
349 PULONG pos
= (PULONG
) ((PBYTE
)DestSurface
->pvScan0
+ DestRect
->top
* delta
+ (DestRect
->left
<<1));
350 color
= (color
&0xffff); /* If the color value is "abcd", put "abcdabcd" into color */
351 color
+= (color
<<16);
353 for (DestY
= DestRect
->top
; DestY
< DestRect
->bottom
; DestY
++)
355 __asm__
__volatile__ (
359 " test $0x03, %%edi\n" /* Align to fullword boundary */
365 " mov %%ebx,%%ecx\n" /* Setup count of fullwords to fill */
367 " rep stosl\n" /* The actual fill */
368 " test $0x01, %%ebx\n" /* One left to do at the right side? */
373 : "a" (color
), "r" (width
), "m" (pos
)
374 : "%ecx", "%ebx", "%edi");
375 pos
=(PULONG
)((ULONG_PTR
)pos
+ delta
);
380 for (DestY
= DestRect
->top
; DestY
< DestRect
->bottom
; DestY
++)
382 DIB_16BPP_HLine (DestSurface
, DestRect
->left
, DestRect
->right
, DestY
, color
);
388 =======================================
389 Stretching functions goes below
390 Some parts of code are based on an
391 article "Bresenhame image scaling"
392 Dr. Dobb Journal, May 2002
393 =======================================
396 typedef unsigned short PIXEL
;
398 /* 16-bit HiColor (565 format) */
399 __inline PIXEL
average16(PIXEL a
, PIXEL b
)
401 // This one doesn't work
406 unsigned short mask = ~ (((a | b) & 0x0410) << 1);
407 return ((a & mask) + (b & mask)) >> 1;
410 // This one should be correct, but it's too long
412 unsigned char r1, g1, b1, r2, g2, b2, rr, gr, br;
415 r1 = (a & 0xF800) >> 11;
416 g1 = (a & 0x7E0) >> 5;
419 r2 = (b & 0xF800) >> 11;
420 g2 = (b & 0x7E0) >> 5;
427 res = (rr << 11) + (gr << 5) + br;
431 return a
; // FIXME: Depend on SetStretchMode
434 //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
435 void ScaleLineAvg16(PIXEL
*Target
, PIXEL
*Source
, int SrcWidth
, int TgtWidth
)
437 int NumPixels
= TgtWidth
;
438 int IntPart
= SrcWidth
/ TgtWidth
;
439 int FractPart
= SrcWidth
% TgtWidth
;
440 int Mid
= TgtWidth
>> 1;
445 skip
= (TgtWidth
< SrcWidth
) ? 0 : (TgtWidth
/ (2*SrcWidth
) + 1);
448 while (NumPixels
-- > 0) {
451 p
= average16(p
, *(Source
+1));
465 FinalCopy16(PIXEL
*Target
, PIXEL
*Source
, PSPAN ClipSpans
, UINT ClipSpansCount
, UINT
*SpanIndex
,
466 UINT DestY
, RECTL
*DestRect
)
470 while (ClipSpans
[*SpanIndex
].Y
< DestY
471 || (ClipSpans
[*SpanIndex
].Y
== DestY
472 && ClipSpans
[*SpanIndex
].X
+ ClipSpans
[*SpanIndex
].Width
< DestRect
->left
))
475 if (ClipSpansCount
<= *SpanIndex
)
477 /* No more spans, everything else is clipped away, we're done */
481 while (ClipSpans
[*SpanIndex
].Y
== DestY
)
483 if (ClipSpans
[*SpanIndex
].X
< DestRect
->right
)
485 Left
= max(ClipSpans
[*SpanIndex
].X
, DestRect
->left
);
486 Right
= min(ClipSpans
[*SpanIndex
].X
+ ClipSpans
[*SpanIndex
].Width
, DestRect
->right
);
487 memcpy(Target
+ Left
- DestRect
->left
, Source
+ Left
- DestRect
->left
,
488 (Right
- Left
) * sizeof(PIXEL
));
491 if (ClipSpansCount
<= *SpanIndex
)
493 /* No more spans, everything else is clipped away, we're done */
501 //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
502 BOOLEAN
ScaleRectAvg16(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
503 RECTL
* DestRect
, RECTL
*SourceRect
,
504 POINTL
* MaskOrigin
, POINTL BrushOrigin
,
505 CLIPOBJ
*ClipRegion
, XLATEOBJ
*ColorTranslation
,
508 int NumPixels
= DestRect
->bottom
- DestRect
->top
;
509 int IntPart
= (((SourceRect
->bottom
- SourceRect
->top
) / (DestRect
->bottom
- DestRect
->top
)) * SourceSurf
->lDelta
) >> 1;
510 int FractPart
= (SourceRect
->bottom
- SourceRect
->top
) % (DestRect
->bottom
- DestRect
->top
);
511 int Mid
= (DestRect
->bottom
- DestRect
->top
) >> 1;
514 PIXEL
*ScanLine
, *ScanLineAhead
;
515 PIXEL
*PrevSource
= NULL
;
516 PIXEL
*PrevSourceAhead
= NULL
;
517 PIXEL
*Target
= (PIXEL
*) ((PBYTE
)DestSurf
->pvScan0
+ (DestRect
->top
* DestSurf
->lDelta
) + 2 * DestRect
->left
);
518 PIXEL
*Source
= (PIXEL
*) ((PBYTE
)SourceSurf
->pvScan0
+ (SourceRect
->top
* SourceSurf
->lDelta
) + 2 * SourceRect
->left
);
524 if (! ClipobjToSpans(&ClipSpans
, &ClipSpansCount
, ClipRegion
, DestRect
))
528 if (0 == ClipSpansCount
)
530 /* No clip spans == empty clipping region, everything clipped away */
531 ASSERT(NULL
== ClipSpans
);
534 skip
= (DestRect
->bottom
- DestRect
->top
< SourceRect
->bottom
- SourceRect
->top
) ? 0 : ((DestRect
->bottom
- DestRect
->top
) / (2 * (SourceRect
->bottom
- SourceRect
->top
)) + 1);
537 ScanLine
= (PIXEL
*)ExAllocatePool(PagedPool
, (DestRect
->right
- DestRect
->left
) * sizeof(PIXEL
));
538 ScanLineAhead
= (PIXEL
*)ExAllocatePool(PagedPool
, (DestRect
->right
- DestRect
->left
) * sizeof(PIXEL
));
540 DestY
= DestRect
->top
;
542 while (NumPixels
-- > 0) {
543 if (Source
!= PrevSource
) {
544 if (Source
== PrevSourceAhead
) {
545 /* the next scan line has already been scaled and stored in
546 * ScanLineAhead; swap the buffers that ScanLine and ScanLineAhead
549 PIXEL
*tmp
= ScanLine
;
550 ScanLine
= ScanLineAhead
;
553 ScaleLineAvg16(ScanLine
, Source
, SourceRect
->right
- SourceRect
->left
, DestRect
->right
- DestRect
->left
);
558 if (E
>= Mid
&& PrevSourceAhead
!= (PIXEL
*)((BYTE
*)Source
+ SourceSurf
->lDelta
)) {
560 ScaleLineAvg16(ScanLineAhead
, (PIXEL
*)((BYTE
*)Source
+ SourceSurf
->lDelta
), SourceRect
->right
- SourceRect
->left
, DestRect
->right
- DestRect
->left
);
561 for (x
= 0; x
< DestRect
->right
- DestRect
->left
; x
++)
562 ScanLine
[x
] = average16(ScanLine
[x
], ScanLineAhead
[x
]);
563 PrevSourceAhead
= (PIXEL
*)((BYTE
*)Source
+ SourceSurf
->lDelta
);
566 if (! FinalCopy16(Target
, ScanLine
, ClipSpans
, ClipSpansCount
, &SpanIndex
, DestY
, DestRect
))
568 /* No more spans, everything else is clipped away, we're done */
569 ExFreePool(ClipSpans
);
570 ExFreePool(ScanLine
);
571 ExFreePool(ScanLineAhead
);
575 Target
= (PIXEL
*)((BYTE
*)Target
+ DestSurf
->lDelta
);
578 if (E
>= DestRect
->bottom
- DestRect
->top
) {
579 E
-= DestRect
->bottom
- DestRect
->top
;
580 Source
= (PIXEL
*)((BYTE
*)Source
+ SourceSurf
->lDelta
);
584 if (skip
> 0 && Source
!= PrevSource
)
585 ScaleLineAvg16(ScanLine
, Source
, SourceRect
->right
- SourceRect
->left
, DestRect
->right
- DestRect
->left
);
587 if (! FinalCopy16(Target
, ScanLine
, ClipSpans
, ClipSpansCount
, &SpanIndex
, DestY
, DestRect
))
589 /* No more spans, everything else is clipped away, we're done */
590 ExFreePool(ClipSpans
);
591 ExFreePool(ScanLine
);
592 ExFreePool(ScanLineAhead
);
596 Target
= (PIXEL
*)((BYTE
*)Target
+ DestSurf
->lDelta
);
599 ExFreePool(ClipSpans
);
600 ExFreePool(ScanLine
);
601 ExFreePool(ScanLineAhead
);
606 //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
607 BOOLEAN
DIB_16BPP_StretchBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
608 RECTL
* DestRect
, RECTL
*SourceRect
,
609 POINTL
* MaskOrigin
, POINTL BrushOrigin
,
610 CLIPOBJ
*ClipRegion
, XLATEOBJ
*ColorTranslation
,
623 DPRINT("DIB_16BPP_StretchBlt: Source BPP: %u, srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
624 BitsPerFormat(SourceSurf
->iBitmapFormat
), SourceRect
->left
, SourceRect
->top
, SourceRect
->right
, SourceRect
->bottom
,
625 DestRect
->left
, DestRect
->top
, DestRect
->right
, DestRect
->bottom
);
627 SrcSizeY
= SourceRect
->bottom
- SourceRect
->top
;
628 SrcSizeX
= SourceRect
->right
- SourceRect
->left
;
630 DesSizeY
= DestRect
->bottom
- DestRect
->top
;
631 DesSizeX
= DestRect
->right
- DestRect
->left
;
633 switch(SourceSurf
->iBitmapFormat
)
637 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
638 /* This is a reference implementation, it hasn't been optimized for speed */
640 for (DesY
=DestRect
->top
; DesY
<DestRect
->bottom
; DesY
++)
642 sy
= (((DesY
- DestRect
->top
) * SrcSizeY
) / DesSizeY
) + SourceRect
->top
;
644 for (DesX
=DestRect
->left
; DesX
<DestRect
->right
; DesX
++)
646 sx
= (((DesX
- DestRect
->left
) * SrcSizeX
) / DesSizeX
) + SourceRect
->left
;
648 if(DIB_1BPP_GetPixel(SourceSurf
, sx
, sy
) == 0)
650 DIB_16BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, 0));
654 DIB_16BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, 1));
661 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
662 /* This is a reference implementation, it hasn't been optimized for speed */
664 for (DesY
=DestRect
->top
; DesY
<DestRect
->bottom
; DesY
++)
666 sy
= (((DesY
- DestRect
->top
) * SrcSizeY
) / DesSizeY
) + SourceRect
->top
;
668 for (DesX
=DestRect
->left
; DesX
<DestRect
->right
; DesX
++)
670 sx
= (((DesX
- DestRect
->left
) * SrcSizeX
) / DesSizeX
) + SourceRect
->left
;
671 color
= DIB_4BPP_GetPixel(SourceSurf
, sx
, sy
);
672 DIB_16BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, color
));
678 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
679 /* This is a reference implementation, it hasn't been optimized for speed */
681 for (DesY
=DestRect
->top
; DesY
<DestRect
->bottom
; DesY
++)
683 sy
= (((DesY
- DestRect
->top
) * SrcSizeY
) / DesSizeY
) + SourceRect
->top
;
685 for (DesX
=DestRect
->left
; DesX
<DestRect
->right
; DesX
++)
687 sx
= (((DesX
- DestRect
->left
) * SrcSizeX
) / DesSizeX
) + SourceRect
->left
;
688 color
= DIB_8BPP_GetPixel(SourceSurf
, sx
, sy
);
689 DIB_16BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, color
));
695 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
696 /* This is a reference implementation, it hasn't been optimized for speed */
698 for (DesY
=DestRect
->top
; DesY
<DestRect
->bottom
; DesY
++)
700 sy
= (((DesY
- DestRect
->top
) * SrcSizeY
) / DesSizeY
) + SourceRect
->top
;
702 for (DesX
=DestRect
->left
; DesX
<DestRect
->right
; DesX
++)
704 sx
= (((DesX
- DestRect
->left
) * SrcSizeX
) / DesSizeX
) + SourceRect
->left
;
705 color
= DIB_24BPP_GetPixel(SourceSurf
, sx
, sy
);
706 DIB_16BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, color
));
712 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
713 /* This is a reference implementation, it hasn't been optimized for speed */
715 for (DesY
=DestRect
->top
; DesY
<DestRect
->bottom
; DesY
++)
717 sy
= (((DesY
- DestRect
->top
) * SrcSizeY
) / DesSizeY
) + SourceRect
->top
;
719 for (DesX
=DestRect
->left
; DesX
<DestRect
->right
; DesX
++)
721 sx
= (((DesX
- DestRect
->left
) * SrcSizeX
) / DesSizeX
) + SourceRect
->left
;
722 color
= DIB_32BPP_GetPixel(SourceSurf
, sx
, sy
);
723 DIB_16BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, color
));
729 return ScaleRectAvg16(DestSurf
, SourceSurf
, DestRect
, SourceRect
, MaskOrigin
, BrushOrigin
,
730 ClipRegion
, ColorTranslation
, Mode
);
734 DPRINT1("DIB_16BPP_StretchBlt: Unhandled Source BPP: %u\n", BitsPerFormat(SourceSurf
->iBitmapFormat
));
744 DIB_16BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
745 RECTL
* DestRect
, POINTL
*SourcePoint
,
746 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)
748 ULONG RoundedRight
, X
, Y
, SourceX
, SourceY
, Source
, wd
, Dest
;
751 RoundedRight
= DestRect
->right
- ((DestRect
->right
- DestRect
->left
) & 0x1);
752 SourceY
= SourcePoint
->y
;
753 DestBits
= (ULONG
*)((PBYTE
)DestSurf
->pvScan0
+
754 (DestRect
->left
<< 1) +
755 DestRect
->top
* DestSurf
->lDelta
);
756 wd
= DestSurf
->lDelta
- ((DestRect
->right
- DestRect
->left
) << 1);
758 for(Y
= DestRect
->top
; Y
< DestRect
->bottom
; Y
++)
760 SourceX
= SourcePoint
->x
;
761 for(X
= DestRect
->left
; X
< RoundedRight
; X
+= 2, DestBits
++, SourceX
+= 2)
765 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
, SourceY
);
766 if(Source
!= iTransColor
)
769 Dest
|= (XLATEOBJ_iXlate(ColorTranslation
, Source
) & 0xFFFF);
772 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
+ 1, SourceY
);
773 if(Source
!= iTransColor
)
776 Dest
|= (XLATEOBJ_iXlate(ColorTranslation
, Source
) << 16);
782 if(X
< DestRect
->right
)
784 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
, SourceY
);
785 if(Source
!= iTransColor
)
787 *((USHORT
*)DestBits
) = (USHORT
)XLATEOBJ_iXlate(ColorTranslation
, Source
);
790 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ 2);
793 DestBits
= (ULONG
*)((ULONG_PTR
)DestBits
+ wd
);
821 return (val
> 31) ? 31 : val
;
827 return (val
> 63) ? 63 : val
;
831 DIB_16BPP_AlphaBlend(SURFOBJ
* Dest
, SURFOBJ
* Source
, RECTL
* DestRect
,
832 RECTL
* SourceRect
, CLIPOBJ
* ClipRegion
,
833 XLATEOBJ
* ColorTranslation
, BLENDOBJ
* BlendObj
)
835 INT Rows
, Cols
, SrcX
, SrcY
;
836 register PUSHORT Dst
;
838 BLENDFUNCTION BlendFunc
;
839 register NICEPIXEL16 DstPixel
;
840 register NICEPIXEL32 SrcPixel
;
843 DPRINT("DIB_16BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
844 SourceRect
->left
, SourceRect
->top
, SourceRect
->right
, SourceRect
->bottom
,
845 DestRect
->left
, DestRect
->top
, DestRect
->right
, DestRect
->bottom
);
847 ASSERT(DestRect
->bottom
- DestRect
->top
== SourceRect
->bottom
- SourceRect
->top
&&
848 DestRect
->right
- DestRect
->left
== SourceRect
->right
- SourceRect
->left
);
850 BlendFunc
= BlendObj
->BlendFunction
;
851 if (BlendFunc
.BlendOp
!= AC_SRC_OVER
)
853 DPRINT1("BlendOp != AC_SRC_OVER\n");
856 if (BlendFunc
.BlendFlags
!= 0)
858 DPRINT1("BlendFlags != 0\n");
861 if ((BlendFunc
.AlphaFormat
& ~AC_SRC_ALPHA
) != 0)
863 DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc
.AlphaFormat
);
866 if ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0 &&
867 BitsPerFormat(Source
->iBitmapFormat
) != 32)
869 DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
873 Dst
= (PUSHORT
)((ULONG_PTR
)Dest
->pvScan0
+ (DestRect
->top
* Dest
->lDelta
) +
874 (DestRect
->left
<< 1));
875 DstDelta
= Dest
->lDelta
- ((DestRect
->right
- DestRect
->left
) << 1);
876 SrcBpp
= BitsPerFormat(Source
->iBitmapFormat
);
878 Rows
= DestRect
->bottom
- DestRect
->top
;
879 SrcY
= SourceRect
->top
;
882 Cols
= DestRect
->right
- DestRect
->left
;
883 SrcX
= SourceRect
->left
;
888 DstPixel
.us
= DIB_GetSource(Source
, SrcX
++, SrcY
, ColorTranslation
);
889 SrcPixel
.col
.red
= (DstPixel
.col
.red
<< 3) | (DstPixel
.col
.red
>> 2);
890 SrcPixel
.col
.green
= (DstPixel
.col
.green
<< 2) | (DstPixel
.col
.green
>> 4);
891 SrcPixel
.col
.blue
= (DstPixel
.col
.blue
<< 3) | (DstPixel
.col
.blue
>> 2);
895 SrcPixel
.ul
= DIB_GetSourceIndex(Source
, SrcX
++, SrcY
);
897 SrcPixel
.col
.red
= SrcPixel
.col
.red
* BlendFunc
.SourceConstantAlpha
/ 255;
898 SrcPixel
.col
.green
= SrcPixel
.col
.green
* BlendFunc
.SourceConstantAlpha
/ 255;
899 SrcPixel
.col
.blue
= SrcPixel
.col
.blue
* BlendFunc
.SourceConstantAlpha
/ 255;
900 SrcPixel
.col
.alpha
= (SrcBpp
== 32) ? (SrcPixel
.col
.alpha
* BlendFunc
.SourceConstantAlpha
/ 255) : BlendFunc
.SourceConstantAlpha
;
902 Alpha
= ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0) ?
903 SrcPixel
.col
.alpha
: BlendFunc
.SourceConstantAlpha
;
906 DstPixel
.col
.red
= Clamp5(DstPixel
.col
.red
* (255 - Alpha
) / 255 + (SrcPixel
.col
.red
>> 3));
907 DstPixel
.col
.green
= Clamp6(DstPixel
.col
.green
* (255 - Alpha
) / 255 + (SrcPixel
.col
.green
>> 2));
908 DstPixel
.col
.blue
= Clamp5(DstPixel
.col
.blue
* (255 - Alpha
) / 255 + (SrcPixel
.col
.blue
>> 3));
909 *Dst
++ = DstPixel
.us
;
911 Dst
= (PUSHORT
)((ULONG_PTR
)Dst
+ DstDelta
);