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
);
456 =======================================
457 Stretching functions goes below
458 Some parts of code are based on an
459 article "Bresenhame image scaling"
460 Dr. Dobb Journal, May 2002
461 =======================================
464 typedef unsigned short PIXEL
;
466 /* 16-bit HiColor (565 format) */
467 __inline PIXEL
average16(PIXEL a
, PIXEL b
)
469 // This one doesn't work
477 unsigned short mask = ~ (((a | b) & 0x0410) << 1);
478 return ((a & mask) + (b & mask)) >> 1;
481 // This one should be correct, but it's too long
483 unsigned char r1, g1, b1, r2, g2, b2, rr, gr, br;
486 r1 = (a & 0xF800) >> 11;
487 g1 = (a & 0x7E0) >> 5;
490 r2 = (b & 0xF800) >> 11;
491 g2 = (b & 0x7E0) >> 5;
498 res = (rr << 11) + (gr << 5) + br;
502 // This one is the short form of the correct one ;-)
503 return (((a
^ b
) & 0xf7deU
) >> 1) + (a
& b
);
506 //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
507 void ScaleLineAvg16(PIXEL
*Target
, PIXEL
*Source
, int SrcWidth
, int TgtWidth
)
509 int NumPixels
= TgtWidth
;
510 int IntPart
= SrcWidth
/ TgtWidth
;
511 int FractPart
= SrcWidth
% TgtWidth
;
512 int Mid
= TgtWidth
>> 1;
517 skip
= (TgtWidth
< SrcWidth
) ? 0 : (TgtWidth
/ (2*SrcWidth
) + 1);
520 while (NumPixels
-- > 0)
525 p
= average16(p
, *(Source
+1));
543 FinalCopy16(PIXEL
*Target
, PIXEL
*Source
, PSPAN ClipSpans
, UINT ClipSpansCount
, UINT
*SpanIndex
,
544 UINT DestY
, RECTL
*DestRect
)
548 while ( ClipSpans
[*SpanIndex
].Y
< DestY
||
549 (ClipSpans
[*SpanIndex
].Y
== DestY
&&
550 ClipSpans
[*SpanIndex
].X
+ ClipSpans
[*SpanIndex
].Width
< DestRect
->left
))
553 if (ClipSpansCount
<= *SpanIndex
)
555 /* No more spans, everything else is clipped away, we're done */
559 while (ClipSpans
[*SpanIndex
].Y
== DestY
)
561 if (ClipSpans
[*SpanIndex
].X
< DestRect
->right
)
563 Left
= max(ClipSpans
[*SpanIndex
].X
, DestRect
->left
);
565 Right
= min(ClipSpans
[*SpanIndex
].X
+ ClipSpans
[*SpanIndex
].Width
,
568 memcpy(Target
+ Left
- DestRect
->left
, Source
+ Left
- DestRect
->left
,
569 (Right
- Left
) * sizeof(PIXEL
));
574 if (ClipSpansCount
<= *SpanIndex
)
576 /* No more spans, everything else is clipped away, we're done */
584 //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
585 BOOLEAN
ScaleRectAvg16(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
586 RECTL
* DestRect
, RECTL
*SourceRect
,
587 POINTL
* MaskOrigin
, POINTL BrushOrigin
,
588 CLIPOBJ
*ClipRegion
, XLATEOBJ
*ColorTranslation
,
591 int NumPixels
= DestRect
->bottom
- DestRect
->top
;
593 int IntPart
= (((SourceRect
->bottom
- SourceRect
->top
) /
594 (DestRect
->bottom
- DestRect
->top
)) * SourceSurf
->lDelta
) >> 1;
596 int FractPart
= (SourceRect
->bottom
- SourceRect
->top
) %
597 (DestRect
->bottom
- DestRect
->top
);
599 int Mid
= (DestRect
->bottom
- DestRect
->top
) >> 1;
602 PIXEL
*ScanLine
, *ScanLineAhead
;
603 PIXEL
*PrevSource
= NULL
;
604 PIXEL
*PrevSourceAhead
= NULL
;
606 PIXEL
*Target
= (PIXEL
*) ((PBYTE
)DestSurf
->pvScan0
+ (DestRect
->top
*
607 DestSurf
->lDelta
) + 2 * DestRect
->left
);
609 PIXEL
*Source
= (PIXEL
*) ((PBYTE
)SourceSurf
->pvScan0
+ (SourceRect
->top
*
610 SourceSurf
->lDelta
) + 2 * SourceRect
->left
);
617 if (! ClipobjToSpans(&ClipSpans
, &ClipSpansCount
, ClipRegion
, DestRect
))
621 if (0 == ClipSpansCount
)
623 /* No clip spans == empty clipping region, everything clipped away */
624 ASSERT(NULL
== ClipSpans
);
627 skip
= (DestRect
->bottom
- DestRect
->top
< SourceRect
->bottom
- SourceRect
->top
)
628 ? 0 : ((DestRect
->bottom
- DestRect
->top
) /
629 (2 * (SourceRect
->bottom
- SourceRect
->top
)) + 1);
633 ScanLine
= (PIXEL
*)ExAllocatePool(PagedPool
, (DestRect
->right
- DestRect
->left
) *
636 ScanLineAhead
= (PIXEL
*)ExAllocatePool(PagedPool
, (DestRect
->right
-
637 DestRect
->left
) * sizeof(PIXEL
));
639 DestY
= DestRect
->top
;
641 while (NumPixels
-- > 0)
643 if (Source
!= PrevSource
)
645 if (Source
== PrevSourceAhead
)
647 /* the next scan line has already been scaled and stored in
648 * ScanLineAhead; swap the buffers that ScanLine and ScanLineAhead
651 PIXEL
*tmp
= ScanLine
;
652 ScanLine
= ScanLineAhead
;
657 ScaleLineAvg16(ScanLine
, Source
, SourceRect
->right
- SourceRect
->left
,
658 DestRect
->right
- DestRect
->left
);
663 if (E
>= Mid
&& PrevSourceAhead
!= (PIXEL
*)((BYTE
*)Source
+
668 ScaleLineAvg16(ScanLineAhead
, (PIXEL
*)((BYTE
*)Source
+
669 SourceSurf
->lDelta
), SourceRect
->right
-
670 SourceRect
->left
, DestRect
->right
- DestRect
->left
);
672 for (x
= 0; x
< DestRect
->right
- DestRect
->left
; x
++)
674 ScanLine
[x
] = average16(ScanLine
[x
], ScanLineAhead
[x
]);
677 PrevSourceAhead
= (PIXEL
*)((BYTE
*)Source
+ SourceSurf
->lDelta
);
680 if (! FinalCopy16(Target
, ScanLine
, ClipSpans
, ClipSpansCount
, &SpanIndex
, DestY
, DestRect
))
682 /* No more spans, everything else is clipped away, we're done */
683 ExFreePool(ClipSpans
);
684 ExFreePool(ScanLine
);
685 ExFreePool(ScanLineAhead
);
690 Target
= (PIXEL
*)((BYTE
*)Target
+ DestSurf
->lDelta
);
694 if (E
>= DestRect
->bottom
- DestRect
->top
)
696 E
-= DestRect
->bottom
- DestRect
->top
;
697 Source
= (PIXEL
*)((BYTE
*)Source
+ SourceSurf
->lDelta
);
701 if (skip
> 0 && Source
!= PrevSource
)
703 ScaleLineAvg16(ScanLine
, Source
, SourceRect
->right
- SourceRect
->left
,
704 DestRect
->right
- DestRect
->left
);
709 if (! FinalCopy16(Target
, ScanLine
, ClipSpans
, ClipSpansCount
, &SpanIndex
,
712 /* No more spans, everything else is clipped away, we're done */
713 ExFreePool(ClipSpans
);
714 ExFreePool(ScanLine
);
715 ExFreePool(ScanLineAhead
);
719 Target
= (PIXEL
*)((BYTE
*)Target
+ DestSurf
->lDelta
);
722 ExFreePool(ClipSpans
);
723 ExFreePool(ScanLine
);
724 ExFreePool(ScanLineAhead
);
730 //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
731 BOOLEAN
DIB_16BPP_StretchBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
732 RECTL
* DestRect
, RECTL
*SourceRect
,
733 POINTL
* MaskOrigin
, POINTL BrushOrigin
,
734 CLIPOBJ
*ClipRegion
, XLATEOBJ
*ColorTranslation
,
759 DPRINT("DIB_16BPP_StretchBlt: Source BPP: %u, srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
760 BitsPerFormat(SourceSurf
->iBitmapFormat
), SourceRect
->left
, SourceRect
->top
, SourceRect
->right
, SourceRect
->bottom
,
761 DestRect
->left
, DestRect
->top
, DestRect
->right
, DestRect
->bottom
);
763 /* Calc the Zoom height of Source */
764 SrcSizeY
= SourceRect
->bottom
- SourceRect
->top
;
766 /* Calc the Zoom Width of Source */
767 SrcSizeX
= SourceRect
->right
- SourceRect
->left
;
769 /* Calc the Zoom height of Destions */
770 DesSizeY
= DestRect
->bottom
- DestRect
->top
;
772 /* Calc the Zoom width of Destions */
773 DesSizeX
= DestRect
->right
- DestRect
->left
;
775 /* Calc the zoom factor of soruce height */
776 SrcZoomYHight
= SrcSizeY
/ DesSizeY
;
777 SrcZoomYLow
= SrcSizeY
- (SrcZoomYHight
* DesSizeY
);
779 /* Calc the zoom factor of soruce width */
780 SrcZoomXHight
= SrcSizeX
/ DesSizeX
;
781 SrcZoomXLow
= SrcSizeX
- (SrcZoomXHight
* DesSizeX
);
785 sy
= SourceRect
->top
;
787 DestBits
= (PULONG
)((PBYTE
)DestSurf
->pvScan0
+ (DestRect
->left
<< 1) +
788 DestRect
->top
* DestSurf
->lDelta
);
790 DifflDelta
= DestSurf
->lDelta
- (DesSizeX
<< 1);
792 switch(SourceSurf
->iBitmapFormat
)
796 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
797 /* This is a reference implementation, it hasn't been optimized for speed */
799 for (DesY
=0; DesY
<DesSizeY
; DesY
++)
801 sx
= SourceRect
->left
;
804 for (DesX
=0; DesX
<DesSizeX
; DesX
++)
806 *DestBits
= XLATEOBJ_iXlate(ColorTranslation
,
807 DIB_1BPP_GetPixel(SourceSurf
, sx
, sy
));
809 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ 2);
812 sx_dec
+= SrcZoomXLow
;
813 if (sx_dec
>= sx_max
)
820 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ DifflDelta
);
823 sy_dec
+= SrcZoomYLow
;
824 if (sy_dec
>= sy_max
)
833 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
834 /* This is a reference implementation, it hasn't been optimized for speed */
836 for (DesY
=0; DesY
<DesSizeY
; DesY
++)
838 sx
= SourceRect
->left
;
841 for (DesX
=0; DesX
<DesSizeX
; DesX
++)
843 *DestBits
= XLATEOBJ_iXlate(ColorTranslation
,
844 DIB_4BPP_GetPixel(SourceSurf
, sx
, sy
));
846 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ 2);
849 sx_dec
+= SrcZoomXLow
;
850 if (sx_dec
>= sx_max
)
857 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ DifflDelta
);
860 sy_dec
+= SrcZoomYLow
;
861 if (sy_dec
>= sy_max
)
870 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
871 /* This is a reference implementation, it hasn't been optimized for speed */
873 for (DesY
=0; DesY
<DesSizeY
; DesY
++)
875 sx
= SourceRect
->left
;
878 for (DesX
=0; DesX
<DesSizeX
; DesX
++)
880 *DestBits
= XLATEOBJ_iXlate(ColorTranslation
,
881 DIB_8BPP_GetPixel(SourceSurf
, sx
, sy
));
883 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ 2);
886 sx_dec
+= SrcZoomXLow
;
887 if (sx_dec
>= sx_max
)
894 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ DifflDelta
);
897 sy_dec
+= SrcZoomYLow
;
898 if (sy_dec
>= sy_max
)
908 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
909 /* This is a reference implementation, it hasn't been optimized for speed */
911 DestBits
= (PULONG
)((PBYTE
)DestSurf
->pvScan0
+ (DestRect
->left
<< 1) +
912 DestRect
->top
* DestSurf
->lDelta
);
914 DifflDelta
= DestSurf
->lDelta
- (DesSizeX
<< 1);
916 for (DesY
=0; DesY
<DesSizeY
; DesY
++)
918 sx
= SourceRect
->left
;
921 for (DesX
=0; DesX
<DesSizeX
; DesX
++)
923 *DestBits
= XLATEOBJ_iXlate(ColorTranslation
,
924 DIB_24BPP_GetPixel(SourceSurf
, sx
, sy
));
926 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ 2);
929 sx_dec
+= SrcZoomXLow
;
930 if (sx_dec
>= sx_max
)
937 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ DifflDelta
);
940 sy_dec
+= SrcZoomYLow
;
941 if (sy_dec
>= sy_max
)
950 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
951 /* This is a reference implementation, it hasn't been optimized for speed */
953 for (DesY
=0; DesY
<DesSizeY
; DesY
++)
955 sx
= SourceRect
->left
;
958 for (DesX
=0; DesX
<DesSizeX
; DesX
++)
960 *DestBits
= XLATEOBJ_iXlate(ColorTranslation
,
961 DIB_32BPP_GetPixel(SourceSurf
, sx
, sy
));
963 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ 2);
966 sx_dec
+= SrcZoomXLow
;
967 if (sx_dec
>= sx_max
)
973 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ DifflDelta
);
976 sy_dec
+= SrcZoomYLow
;
977 if (sy_dec
>= sy_max
)
986 return ScaleRectAvg16(DestSurf
, SourceSurf
, DestRect
, SourceRect
, MaskOrigin
, BrushOrigin
,
987 ClipRegion
, ColorTranslation
, Mode
);
991 DPRINT1("DIB_16BPP_StretchBlt: Unhandled Source BPP: %u\n", BitsPerFormat(SourceSurf
->iBitmapFormat
));
1001 DIB_16BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
1002 RECTL
* DestRect
, POINTL
*SourcePoint
,
1003 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)
1005 ULONG RoundedRight
, X
, Y
, SourceX
, SourceY
, Source
, wd
, Dest
;
1008 RoundedRight
= DestRect
->right
- ((DestRect
->right
- DestRect
->left
) & 0x1);
1009 SourceY
= SourcePoint
->y
;
1010 DestBits
= (ULONG
*)((PBYTE
)DestSurf
->pvScan0
+
1011 (DestRect
->left
<< 1) +
1012 DestRect
->top
* DestSurf
->lDelta
);
1013 wd
= DestSurf
->lDelta
- ((DestRect
->right
- DestRect
->left
) << 1);
1015 for(Y
= DestRect
->top
; Y
< DestRect
->bottom
; Y
++)
1017 SourceX
= SourcePoint
->x
;
1018 for(X
= DestRect
->left
; X
< RoundedRight
; X
+= 2, DestBits
++, SourceX
+= 2)
1021 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
, SourceY
);
1023 if(Source
!= iTransColor
)
1026 Dest
|= (XLATEOBJ_iXlate(ColorTranslation
, Source
) & 0xFFFF);
1029 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
+ 1, SourceY
);
1030 if(Source
!= iTransColor
)
1033 Dest
|= (XLATEOBJ_iXlate(ColorTranslation
, Source
) << 16);
1039 if(X
< DestRect
->right
)
1041 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
, SourceY
);
1042 if(Source
!= iTransColor
)
1044 *((USHORT
*)DestBits
) = (USHORT
)XLATEOBJ_iXlate(ColorTranslation
,
1048 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ 2);
1052 DestBits
= (ULONG
*)((ULONG_PTR
)DestBits
+ wd
);
1081 static __inline UCHAR
1084 return (val
> 31) ? 31 : val
;
1087 static __inline UCHAR
1090 return (val
> 63) ? 63 : val
;
1094 DIB_16BPP_AlphaBlend(SURFOBJ
* Dest
, SURFOBJ
* Source
, RECTL
* DestRect
,
1095 RECTL
* SourceRect
, CLIPOBJ
* ClipRegion
,
1096 XLATEOBJ
* ColorTranslation
, BLENDOBJ
* BlendObj
)
1098 INT Rows
, Cols
, SrcX
, SrcY
;
1099 register PUSHORT Dst
;
1101 BLENDFUNCTION BlendFunc
;
1102 register NICEPIXEL16 DstPixel
;
1103 register NICEPIXEL32 SrcPixel
;
1104 UCHAR Alpha
, SrcBpp
;
1106 DPRINT("DIB_16BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
1107 SourceRect
->left
, SourceRect
->top
, SourceRect
->right
, SourceRect
->bottom
,
1108 DestRect
->left
, DestRect
->top
, DestRect
->right
, DestRect
->bottom
);
1110 ASSERT(DestRect
->bottom
- DestRect
->top
== SourceRect
->bottom
- SourceRect
->top
&&
1111 DestRect
->right
- DestRect
->left
== SourceRect
->right
- SourceRect
->left
);
1113 BlendFunc
= BlendObj
->BlendFunction
;
1114 if (BlendFunc
.BlendOp
!= AC_SRC_OVER
)
1116 DPRINT1("BlendOp != AC_SRC_OVER\n");
1119 if (BlendFunc
.BlendFlags
!= 0)
1121 DPRINT1("BlendFlags != 0\n");
1124 if ((BlendFunc
.AlphaFormat
& ~AC_SRC_ALPHA
) != 0)
1126 DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc
.AlphaFormat
);
1129 if ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0 &&
1130 BitsPerFormat(Source
->iBitmapFormat
) != 32)
1132 DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
1136 Dst
= (PUSHORT
)((ULONG_PTR
)Dest
->pvScan0
+ (DestRect
->top
* Dest
->lDelta
) +
1137 (DestRect
->left
<< 1));
1138 DstDelta
= Dest
->lDelta
- ((DestRect
->right
- DestRect
->left
) << 1);
1139 SrcBpp
= BitsPerFormat(Source
->iBitmapFormat
);
1141 Rows
= DestRect
->bottom
- DestRect
->top
;
1142 SrcY
= SourceRect
->top
;
1145 Cols
= DestRect
->right
- DestRect
->left
;
1146 SrcX
= SourceRect
->left
;
1151 DstPixel
.us
= DIB_GetSource(Source
, SrcX
++, SrcY
, ColorTranslation
);
1152 SrcPixel
.col
.red
= (DstPixel
.col
.red
<< 3) | (DstPixel
.col
.red
>> 2);
1154 SrcPixel
.col
.green
= (DstPixel
.col
.green
<< 2) |
1155 (DstPixel
.col
.green
>> 4);
1157 SrcPixel
.col
.blue
= (DstPixel
.col
.blue
<< 3) | (DstPixel
.col
.blue
>> 2);
1161 SrcPixel
.ul
= DIB_GetSourceIndex(Source
, SrcX
++, SrcY
);
1163 SrcPixel
.col
.red
= SrcPixel
.col
.red
*
1164 BlendFunc
.SourceConstantAlpha
/ 255;
1166 SrcPixel
.col
.green
= SrcPixel
.col
.green
*
1167 BlendFunc
.SourceConstantAlpha
/ 255;
1169 SrcPixel
.col
.blue
= SrcPixel
.col
.blue
*
1170 BlendFunc
.SourceConstantAlpha
/ 255;
1172 SrcPixel
.col
.alpha
= (SrcBpp
== 32) ?
1173 (SrcPixel
.col
.alpha
*
1174 BlendFunc
.SourceConstantAlpha
/ 255) :
1175 BlendFunc
.SourceConstantAlpha
;
1177 Alpha
= ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0) ?
1178 SrcPixel
.col
.alpha
: BlendFunc
.SourceConstantAlpha
;
1181 DstPixel
.col
.red
= Clamp5(DstPixel
.col
.red
* (255 - Alpha
) / 255 +
1182 (SrcPixel
.col
.red
>> 3));
1184 DstPixel
.col
.green
= Clamp6(DstPixel
.col
.green
* (255 - Alpha
) / 255 +
1185 (SrcPixel
.col
.green
>> 2));
1187 DstPixel
.col
.blue
= Clamp5(DstPixel
.col
.blue
* (255 - Alpha
) / 255 +
1188 (SrcPixel
.col
.blue
>> 3));
1190 *Dst
++ = DstPixel
.us
;
1193 Dst
= (PUSHORT
)((ULONG_PTR
)Dst
+ DstDelta
);