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_8BPP_PutPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
, ULONG c
)
29 PBYTE byteaddr
= (PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ x
;
35 DIB_8BPP_GetPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
)
37 PBYTE byteaddr
= (PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ x
;
39 return (ULONG
)(*byteaddr
);
43 DIB_8BPP_HLine(SURFOBJ
*SurfObj
, LONG x1
, LONG x2
, LONG y
, ULONG c
)
45 memset((PBYTE
)SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ x1
, (BYTE
) c
, x2
- x1
);
49 DIB_8BPP_VLine(SURFOBJ
*SurfObj
, LONG x
, LONG y1
, LONG y2
, ULONG c
)
51 PBYTE byteaddr
= (PBYTE
)SurfObj
->pvScan0
+ y1
* SurfObj
->lDelta
;
52 PBYTE addr
= byteaddr
+ x
;
53 LONG lDelta
= SurfObj
->lDelta
;
64 DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo
)
66 LONG i
, j
, sx
, sy
, xColor
, f1
;
67 PBYTE SourceBits
, DestBits
, SourceLine
, DestLine
;
68 PBYTE SourceBits_4BPP
, SourceLine_4BPP
;
70 DestBits
= (PBYTE
)BltInfo
->DestSurface
->pvScan0
+ (BltInfo
->DestRect
.top
* BltInfo
->DestSurface
->lDelta
) + BltInfo
->DestRect
.left
;
72 switch(BltInfo
->SourceSurface
->iBitmapFormat
)
75 sx
= BltInfo
->SourcePoint
.x
;
76 sy
= BltInfo
->SourcePoint
.y
;
78 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
80 sx
= BltInfo
->SourcePoint
.x
;
81 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
83 if(DIB_1BPP_GetPixel(BltInfo
->SourceSurface
, sx
, sy
) == 0)
85 DIB_8BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, 0));
87 DIB_8BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, 1));
96 SourceBits_4BPP
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + (BltInfo
->SourcePoint
.x
>> 1);
98 for (j
=BltInfo
->DestRect
.top
; j
<BltInfo
->DestRect
.bottom
; j
++)
100 SourceLine_4BPP
= SourceBits_4BPP
;
101 sx
= BltInfo
->SourcePoint
.x
;
104 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
106 xColor
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
,
107 (*SourceLine_4BPP
& altnotmask
[f1
]) >> (4 * (1 - f1
)));
108 DIB_8BPP_PutPixel(BltInfo
->DestSurface
, i
, j
, xColor
);
109 if(f1
== 1) { SourceLine_4BPP
++; f1
= 0; } else { f1
= 1; }
113 SourceBits_4BPP
+= BltInfo
->SourceSurface
->lDelta
;
118 if (NULL
== BltInfo
->XlateSourceToDest
|| 0 != (BltInfo
->XlateSourceToDest
->flXlate
& XO_TRIVIAL
))
120 if (BltInfo
->DestRect
.top
< BltInfo
->SourcePoint
.y
)
122 SourceBits
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + BltInfo
->SourcePoint
.x
;
123 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
125 RtlMoveMemory(DestBits
, SourceBits
, BltInfo
->DestRect
.right
- BltInfo
->DestRect
.left
);
126 SourceBits
+= BltInfo
->SourceSurface
->lDelta
;
127 DestBits
+= BltInfo
->DestSurface
->lDelta
;
132 SourceBits
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ ((BltInfo
->SourcePoint
.y
+ BltInfo
->DestRect
.bottom
- BltInfo
->DestRect
.top
- 1) * BltInfo
->SourceSurface
->lDelta
) + BltInfo
->SourcePoint
.x
;
133 DestBits
= (PBYTE
)BltInfo
->DestSurface
->pvScan0
+ ((BltInfo
->DestRect
.bottom
- 1) * BltInfo
->DestSurface
->lDelta
) + BltInfo
->DestRect
.left
;
134 for (j
= BltInfo
->DestRect
.bottom
- 1; BltInfo
->DestRect
.top
<= j
; j
--)
136 RtlMoveMemory(DestBits
, SourceBits
, BltInfo
->DestRect
.right
- BltInfo
->DestRect
.left
);
137 SourceBits
-= BltInfo
->SourceSurface
->lDelta
;
138 DestBits
-= BltInfo
->DestSurface
->lDelta
;
144 if (BltInfo
->DestRect
.top
< BltInfo
->SourcePoint
.y
)
146 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + BltInfo
->SourcePoint
.x
;
148 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
150 SourceBits
= SourceLine
;
152 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
154 *DestBits
++ = XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, *SourceBits
++);
156 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
157 DestLine
+= BltInfo
->DestSurface
->lDelta
;
162 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ ((BltInfo
->SourcePoint
.y
+ BltInfo
->DestRect
.bottom
- BltInfo
->DestRect
.top
- 1) * BltInfo
->SourceSurface
->lDelta
) + BltInfo
->SourcePoint
.x
;
163 DestLine
= (PBYTE
)BltInfo
->DestSurface
->pvScan0
+ ((BltInfo
->DestRect
.bottom
- 1) * BltInfo
->DestSurface
->lDelta
) + BltInfo
->DestRect
.left
;
164 for (j
= BltInfo
->DestRect
.bottom
- 1; BltInfo
->DestRect
.top
<= j
; j
--)
166 SourceBits
= SourceLine
;
168 for (i
=BltInfo
->DestRect
.left
; i
<BltInfo
->DestRect
.right
; i
++)
170 *DestBits
++ = XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, *SourceBits
++);
172 SourceLine
-= BltInfo
->SourceSurface
->lDelta
;
173 DestLine
-= BltInfo
->DestSurface
->lDelta
;
180 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + 2 * BltInfo
->SourcePoint
.x
;
183 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
185 SourceBits
= SourceLine
;
188 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
190 xColor
= *((PWORD
) SourceBits
);
191 *DestBits
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, xColor
);
196 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
197 DestLine
+= BltInfo
->DestSurface
->lDelta
;
202 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + 3 * BltInfo
->SourcePoint
.x
;
205 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
207 SourceBits
= SourceLine
;
210 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
212 xColor
= (*(SourceBits
+ 2) << 0x10) +
213 (*(SourceBits
+ 1) << 0x08) +
215 *DestBits
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, xColor
);
220 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
221 DestLine
+= BltInfo
->DestSurface
->lDelta
;
226 SourceLine
= (PBYTE
)BltInfo
->SourceSurface
->pvScan0
+ (BltInfo
->SourcePoint
.y
* BltInfo
->SourceSurface
->lDelta
) + 4 * BltInfo
->SourcePoint
.x
;
229 for (j
= BltInfo
->DestRect
.top
; j
< BltInfo
->DestRect
.bottom
; j
++)
231 SourceBits
= SourceLine
;
234 for (i
= BltInfo
->DestRect
.left
; i
< BltInfo
->DestRect
.right
; i
++)
236 xColor
= *((PDWORD
) SourceBits
);
237 *DestBits
= XLATEOBJ_iXlate(BltInfo
->XlateSourceToDest
, xColor
);
242 SourceLine
+= BltInfo
->SourceSurface
->lDelta
;
243 DestLine
+= BltInfo
->DestSurface
->lDelta
;
248 DPRINT1("DIB_8BPP_Bitblt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo
->SourceSurface
->iBitmapFormat
));
255 /* BitBlt Optimize */
257 DIB_8BPP_ColorFill(SURFOBJ
* DestSurface
, RECTL
* DestRect
, ULONG color
)
260 for (DestY
= DestRect
->top
; DestY
< DestRect
->bottom
; DestY
++)
262 DIB_8BPP_HLine(DestSurface
, DestRect
->left
, DestRect
->right
, DestY
, color
);
268 =======================================
269 Stretching functions goes below
270 Some parts of code are based on an
271 article "Bresenhame image scaling"
272 Dr. Dobb Journal, May 2002
273 =======================================
276 typedef unsigned char PIXEL
;
278 /* 16-bit HiColor (565 format) */
279 __inline PIXEL
average8(PIXEL a
, PIXEL b
)
281 return a
; // FIXME: Depend on SetStretchMode
284 //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
285 void ScaleLineAvg8(PIXEL
*Target
, PIXEL
*Source
, int SrcWidth
, int TgtWidth
)
287 int NumPixels
= TgtWidth
;
288 int IntPart
= SrcWidth
/ TgtWidth
;
289 int FractPart
= SrcWidth
% TgtWidth
;
290 int Mid
= TgtWidth
>> 1;
295 skip
= (TgtWidth
< SrcWidth
) ? 0 : (TgtWidth
/ (2*SrcWidth
) + 1);
298 while (NumPixels
-- > 0) {
301 p
= average8(p
, *(Source
+1));
315 FinalCopy8(PIXEL
*Target
, PIXEL
*Source
, PSPAN ClipSpans
, UINT ClipSpansCount
, UINT
*SpanIndex
,
316 UINT DestY
, RECTL
*DestRect
)
320 while (ClipSpans
[*SpanIndex
].Y
< DestY
321 || (ClipSpans
[*SpanIndex
].Y
== DestY
322 && ClipSpans
[*SpanIndex
].X
+ ClipSpans
[*SpanIndex
].Width
< DestRect
->left
))
325 if (ClipSpansCount
<= *SpanIndex
)
327 /* No more spans, everything else is clipped away, we're done */
331 while (ClipSpans
[*SpanIndex
].Y
== DestY
)
333 if (ClipSpans
[*SpanIndex
].X
< DestRect
->right
)
335 Left
= max(ClipSpans
[*SpanIndex
].X
, DestRect
->left
);
336 Right
= min(ClipSpans
[*SpanIndex
].X
+ ClipSpans
[*SpanIndex
].Width
, DestRect
->right
);
337 memcpy(Target
+ Left
- DestRect
->left
, Source
+ Left
- DestRect
->left
,
338 (Right
- Left
) * sizeof(PIXEL
));
341 if (ClipSpansCount
<= *SpanIndex
)
343 /* No more spans, everything else is clipped away, we're done */
351 //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
352 BOOLEAN
ScaleRectAvg8(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
353 RECTL
* DestRect
, RECTL
*SourceRect
,
354 POINTL
* MaskOrigin
, POINTL BrushOrigin
,
355 CLIPOBJ
*ClipRegion
, XLATEOBJ
*ColorTranslation
,
358 int NumPixels
= DestRect
->bottom
- DestRect
->top
;
359 int IntPart
= (((SourceRect
->bottom
- SourceRect
->top
) / (DestRect
->bottom
- DestRect
->top
)) * SourceSurf
->lDelta
); //((SourceRect->bottom - SourceRect->top) / (DestRect->bottom - DestRect->top)) * (SourceRect->right - SourceRect->left);
360 int FractPart
= (SourceRect
->bottom
- SourceRect
->top
) % (DestRect
->bottom
- DestRect
->top
);
361 int Mid
= (DestRect
->bottom
- DestRect
->top
) >> 1;
364 PIXEL
*ScanLine
, *ScanLineAhead
;
365 PIXEL
*PrevSource
= NULL
;
366 PIXEL
*PrevSourceAhead
= NULL
;
367 PIXEL
*Target
= (PIXEL
*) ((PBYTE
)DestSurf
->pvScan0
+ (DestRect
->top
* DestSurf
->lDelta
) + DestRect
->left
);
368 PIXEL
*Source
= (PIXEL
*) ((PBYTE
)SourceSurf
->pvScan0
+ (SourceRect
->top
* SourceSurf
->lDelta
) + SourceRect
->left
);
374 if (! ClipobjToSpans(&ClipSpans
, &ClipSpansCount
, ClipRegion
, DestRect
))
378 if (0 == ClipSpansCount
)
380 /* No clip spans == empty clipping region, everything clipped away */
381 ASSERT(NULL
== ClipSpans
);
384 skip
= (DestRect
->bottom
- DestRect
->top
< SourceRect
->bottom
- SourceRect
->top
) ? 0 : ((DestRect
->bottom
- DestRect
->top
) / (2 * (SourceRect
->bottom
- SourceRect
->top
)) + 1);
387 ScanLine
= (PIXEL
*)ExAllocatePool(PagedPool
, (DestRect
->right
- DestRect
->left
) * sizeof(PIXEL
));
388 ScanLineAhead
= (PIXEL
*)ExAllocatePool(PagedPool
, (DestRect
->right
- DestRect
->left
) * sizeof(PIXEL
));
390 DestY
= DestRect
->top
;
392 while (NumPixels
-- > 0) {
393 if (Source
!= PrevSource
) {
394 if (Source
== PrevSourceAhead
) {
395 /* the next scan line has already been scaled and stored in
396 * ScanLineAhead; swap the buffers that ScanLine and ScanLineAhead
399 PIXEL
*tmp
= ScanLine
;
400 ScanLine
= ScanLineAhead
;
403 ScaleLineAvg8(ScanLine
, Source
, SourceRect
->right
- SourceRect
->left
, DestRect
->right
- DestRect
->left
);
408 if (E
>= Mid
&& PrevSourceAhead
!= (PIXEL
*)((BYTE
*)Source
+ SourceSurf
->lDelta
)) {
410 ScaleLineAvg8(ScanLineAhead
, (PIXEL
*)((BYTE
*)Source
+ SourceSurf
->lDelta
), SourceRect
->right
- SourceRect
->left
, DestRect
->right
- DestRect
->left
);
411 for (x
= 0; x
< DestRect
->right
- DestRect
->left
; x
++)
412 ScanLine
[x
] = average8(ScanLine
[x
], ScanLineAhead
[x
]);
413 PrevSourceAhead
= (PIXEL
*)((BYTE
*)Source
+ SourceSurf
->lDelta
);
416 if (! FinalCopy8(Target
, ScanLine
, ClipSpans
, ClipSpansCount
, &SpanIndex
, DestY
, DestRect
))
418 /* No more spans, everything else is clipped away, we're done */
419 ExFreePool(ClipSpans
);
420 ExFreePool(ScanLine
);
421 ExFreePool(ScanLineAhead
);
425 Target
= (PIXEL
*)((BYTE
*)Target
+ DestSurf
->lDelta
);
428 if (E
>= DestRect
->bottom
- DestRect
->top
) {
429 E
-= DestRect
->bottom
- DestRect
->top
;
430 Source
= (PIXEL
*)((BYTE
*)Source
+ SourceSurf
->lDelta
);
434 if (skip
> 0 && Source
!= PrevSource
)
435 ScaleLineAvg8(ScanLine
, Source
, SourceRect
->right
- SourceRect
->left
, DestRect
->right
- DestRect
->left
);
437 if (! FinalCopy8(Target
, ScanLine
, ClipSpans
, ClipSpansCount
, &SpanIndex
, DestY
, DestRect
))
439 /* No more spans, everything else is clipped away, we're done */
440 ExFreePool(ClipSpans
);
441 ExFreePool(ScanLine
);
442 ExFreePool(ScanLineAhead
);
446 Target
= (PIXEL
*)((BYTE
*)Target
+ DestSurf
->lDelta
);
449 ExFreePool(ClipSpans
);
450 ExFreePool(ScanLine
);
451 ExFreePool(ScanLineAhead
);
456 //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
457 BOOLEAN
DIB_8BPP_StretchBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
458 RECTL
* DestRect
, RECTL
*SourceRect
,
459 POINTL
* MaskOrigin
, POINTL BrushOrigin
,
460 CLIPOBJ
*ClipRegion
, XLATEOBJ
*ColorTranslation
,
473 DPRINT("DIB_8BPP_StretchBlt: Source BPP: %u, srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
474 BitsPerFormat(SourceSurf
->iBitmapFormat
), SourceRect
->left
, SourceRect
->top
, SourceRect
->right
, SourceRect
->bottom
,
475 DestRect
->left
, DestRect
->top
, DestRect
->right
, DestRect
->bottom
);
477 SrcSizeY
= SourceRect
->bottom
- SourceRect
->top
;
478 SrcSizeX
= SourceRect
->right
- SourceRect
->left
;
480 DesSizeY
= DestRect
->bottom
- DestRect
->top
;
481 DesSizeX
= DestRect
->right
- DestRect
->left
;
483 switch(SourceSurf
->iBitmapFormat
)
486 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
487 /* This is a reference implementation, it hasn't been optimized for speed */
489 for (DesY
=DestRect
->top
; DesY
<DestRect
->bottom
; DesY
++)
491 sy
= (((DesY
- DestRect
->top
) * SrcSizeY
) / DesSizeY
) + SourceRect
->top
;
493 for (DesX
=DestRect
->left
; DesX
<DestRect
->right
; DesX
++)
495 sx
= (((DesX
- DestRect
->left
) * SrcSizeX
) / DesSizeX
) + SourceRect
->left
;
497 if(DIB_1BPP_GetPixel(SourceSurf
, sx
, sy
) == 0)
499 DIB_8BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, 0));
503 DIB_8BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, 1));
511 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
512 /* This is a reference implementation, it hasn't been optimized for speed */
514 for (DesY
=DestRect
->top
; DesY
<DestRect
->bottom
; DesY
++)
516 sy
= (((DesY
- DestRect
->top
) * SrcSizeY
) / DesSizeY
) + SourceRect
->top
;
518 for (DesX
=DestRect
->left
; DesX
<DestRect
->right
; DesX
++)
520 sx
= (((DesX
- DestRect
->left
) * SrcSizeX
) / DesSizeX
) + SourceRect
->left
;
521 color
= DIB_4BPP_GetPixel(SourceSurf
, sx
, sy
);
522 DIB_8BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, color
));
528 return ScaleRectAvg8(DestSurf
, SourceSurf
, DestRect
, SourceRect
, MaskOrigin
, BrushOrigin
,
529 ClipRegion
, ColorTranslation
, Mode
);
533 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
534 /* This is a reference implementation, it hasn't been optimized for speed */
536 for (DesY
=DestRect
->top
; DesY
<DestRect
->bottom
; DesY
++)
538 sy
= (((DesY
- DestRect
->top
) * SrcSizeY
) / DesSizeY
) + SourceRect
->top
;
540 for (DesX
=DestRect
->left
; DesX
<DestRect
->right
; DesX
++)
542 sx
= (((DesX
- DestRect
->left
) * SrcSizeX
) / DesSizeX
) + SourceRect
->left
;
543 color
= DIB_16BPP_GetPixel(SourceSurf
, sx
, sy
);
544 DIB_8BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, color
));
550 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
551 /* This is a reference implementation, it hasn't been optimized for speed */
553 for (DesY
=DestRect
->top
; DesY
<DestRect
->bottom
; DesY
++)
555 sy
= (((DesY
- DestRect
->top
) * SrcSizeY
) / DesSizeY
) + SourceRect
->top
;
557 for (DesX
=DestRect
->left
; DesX
<DestRect
->right
; DesX
++)
559 sx
= (((DesX
- DestRect
->left
) * SrcSizeX
) / DesSizeX
) + SourceRect
->left
;
560 color
= DIB_24BPP_GetPixel(SourceSurf
, sx
, sy
);
561 DIB_8BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, color
));
567 /* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
568 /* This is a reference implementation, it hasn't been optimized for speed */
570 for (DesY
=DestRect
->top
; DesY
<DestRect
->bottom
; DesY
++)
572 sy
= (((DesY
- DestRect
->top
) * SrcSizeY
) / DesSizeY
) + SourceRect
->top
;
574 for (DesX
=DestRect
->left
; DesX
<DestRect
->right
; DesX
++)
576 sx
= (((DesX
- DestRect
->left
) * SrcSizeX
) / DesSizeX
) + SourceRect
->left
;
577 color
= DIB_32BPP_GetPixel(SourceSurf
, sx
, sy
);
578 DIB_8BPP_PutPixel(DestSurf
, DesX
, DesY
, XLATEOBJ_iXlate(ColorTranslation
, color
));
586 DPRINT1("DIB_8BPP_StretchBlt: Unhandled Source BPP: %u\n", BitsPerFormat(SourceSurf
->iBitmapFormat
));
594 DIB_8BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
595 RECTL
* DestRect
, POINTL
*SourcePoint
,
596 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)
598 ULONG RoundedRight
, X
, Y
, SourceX
, SourceY
, Source
, wd
, Dest
;
601 RoundedRight
= DestRect
->right
- ((DestRect
->right
- DestRect
->left
) & 0x3);
602 SourceY
= SourcePoint
->y
;
603 DestBits
= (ULONG
*)((PBYTE
)DestSurf
->pvScan0
+ DestRect
->left
+
604 (DestRect
->top
* DestSurf
->lDelta
));
605 wd
= DestSurf
->lDelta
- (DestRect
->right
- DestRect
->left
);
607 for(Y
= DestRect
->top
; Y
< DestRect
->bottom
; Y
++)
609 DestBits
= (ULONG
*)((PBYTE
)DestSurf
->pvScan0
+ DestRect
->left
+
610 (Y
* DestSurf
->lDelta
));
611 SourceX
= SourcePoint
->x
;
612 for (X
= DestRect
->left
; X
< RoundedRight
; X
+= 4, DestBits
++)
616 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
++, SourceY
);
617 if(Source
!= iTransColor
)
620 Dest
|= (XLATEOBJ_iXlate(ColorTranslation
, Source
) & 0xFF);
623 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
++, SourceY
);
624 if(Source
!= iTransColor
)
627 Dest
|= ((XLATEOBJ_iXlate(ColorTranslation
, Source
) << 8) & 0xFF00);
630 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
++, SourceY
);
631 if(Source
!= iTransColor
)
634 Dest
|= ((XLATEOBJ_iXlate(ColorTranslation
, Source
) << 16) & 0xFF0000);
637 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
++, SourceY
);
638 if(Source
!= iTransColor
)
641 Dest
|= ((XLATEOBJ_iXlate(ColorTranslation
, Source
) << 24) & 0xFF000000);
647 if(X
< DestRect
->right
)
649 for (; X
< DestRect
->right
; X
++)
651 Source
= DIB_GetSourceIndex(SourceSurf
, SourceX
++, SourceY
);
652 if(Source
!= iTransColor
)
654 *((BYTE
*)DestBits
) = (BYTE
)(XLATEOBJ_iXlate(ColorTranslation
, Source
) & 0xFF);
656 DestBits
= (PULONG
)((ULONG_PTR
)DestBits
+ 1);
687 return (val
> 255) ? 255 : val
;
691 DIB_8BPP_AlphaBlend(SURFOBJ
* Dest
, SURFOBJ
* Source
, RECTL
* DestRect
,
692 RECTL
* SourceRect
, CLIPOBJ
* ClipRegion
,
693 XLATEOBJ
* ColorTranslation
, BLENDOBJ
* BlendObj
)
695 INT Rows
, Cols
, SrcX
, SrcY
;
698 BLENDFUNCTION BlendFunc
;
699 register NICEPIXEL32 DstPixel
;
700 register NICEPIXEL32 SrcPixel
;
701 register NICEPIXEL16 SrcPixel16
;
703 HPALETTE SrcPalette
, DstPalette
;
704 XLATEOBJ
*SrcTo32Xlate
, *DstTo32Xlate
, *DstFrom32Xlate
;
706 DPRINT("DIB_8BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
707 SourceRect
->left
, SourceRect
->top
, SourceRect
->right
, SourceRect
->bottom
,
708 DestRect
->left
, DestRect
->top
, DestRect
->right
, DestRect
->bottom
);
710 ASSERT(DestRect
->bottom
- DestRect
->top
== SourceRect
->bottom
- SourceRect
->top
&&
711 DestRect
->right
- DestRect
->left
== SourceRect
->right
- SourceRect
->left
);
713 BlendFunc
= BlendObj
->BlendFunction
;
714 if (BlendFunc
.BlendOp
!= AC_SRC_OVER
)
716 DPRINT1("BlendOp != AC_SRC_OVER\n");
719 if (BlendFunc
.BlendFlags
!= 0)
721 DPRINT1("BlendFlags != 0\n");
724 if ((BlendFunc
.AlphaFormat
& ~AC_SRC_ALPHA
) != 0)
726 DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc
.AlphaFormat
);
729 if ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0 &&
730 BitsPerFormat(Source
->iBitmapFormat
) != 32)
732 DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
736 SrcBpp
= BitsPerFormat(Source
->iBitmapFormat
);
737 SrcPalette
= IntEngGetXlatePalette(ColorTranslation
, XO_SRCPALETTE
);
740 SrcTo32Xlate
= IntEngCreateXlate(PAL_RGB
, 0, NULL
, SrcPalette
);
741 if (SrcTo32Xlate
== NULL
)
743 DPRINT1("IntEngCreateXlate failed\n");
750 ASSERT(SrcBpp
>= 16);
753 DstPalette
= IntEngGetXlatePalette(ColorTranslation
, XO_DESTPALETTE
);
754 DstTo32Xlate
= IntEngCreateXlate(PAL_RGB
, 0, NULL
, DstPalette
);
755 DstFrom32Xlate
= IntEngCreateXlate(0, PAL_RGB
, DstPalette
, NULL
);
756 if (DstTo32Xlate
== NULL
|| DstFrom32Xlate
== NULL
)
758 if (SrcTo32Xlate
!= NULL
)
759 EngDeleteXlate(SrcTo32Xlate
);
760 if (DstTo32Xlate
!= NULL
)
761 EngDeleteXlate(DstTo32Xlate
);
762 if (DstFrom32Xlate
!= NULL
)
763 EngDeleteXlate(DstFrom32Xlate
);
764 DPRINT1("IntEngCreateXlate failed\n");
768 Dst
= (PUCHAR
)((ULONG_PTR
)Dest
->pvScan0
+ (DestRect
->top
* Dest
->lDelta
) +
770 DstDelta
= Dest
->lDelta
- (DestRect
->right
- DestRect
->left
);
772 Rows
= DestRect
->bottom
- DestRect
->top
;
773 SrcY
= SourceRect
->top
;
776 Cols
= DestRect
->right
- DestRect
->left
;
777 SrcX
= SourceRect
->left
;
780 if (SrcTo32Xlate
!= NULL
)
782 SrcPixel
.ul
= DIB_GetSource(Source
, SrcX
++, SrcY
, SrcTo32Xlate
);
784 else if (SrcBpp
<= 16)
786 SrcPixel16
.us
= DIB_GetSource(Source
, SrcX
++, SrcY
, ColorTranslation
);
787 SrcPixel
.col
.red
= (SrcPixel16
.col
.red
<< 3) | (SrcPixel16
.col
.red
>> 2);
788 SrcPixel
.col
.green
= (SrcPixel16
.col
.green
<< 2) | (SrcPixel16
.col
.green
>> 4);
789 SrcPixel
.col
.blue
= (SrcPixel16
.col
.blue
<< 3) | (SrcPixel16
.col
.blue
>> 2);
793 SrcPixel
.ul
= DIB_GetSourceIndex(Source
, SrcX
++, SrcY
);
795 SrcPixel
.col
.red
= SrcPixel
.col
.red
* BlendFunc
.SourceConstantAlpha
/ 255;
796 SrcPixel
.col
.green
= SrcPixel
.col
.green
* BlendFunc
.SourceConstantAlpha
/ 255;
797 SrcPixel
.col
.blue
= SrcPixel
.col
.blue
* BlendFunc
.SourceConstantAlpha
/ 255;
798 SrcPixel
.col
.alpha
= (SrcBpp
== 32) ? (SrcPixel
.col
.alpha
* BlendFunc
.SourceConstantAlpha
/ 255) : BlendFunc
.SourceConstantAlpha
;
800 Alpha
= ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0) ?
801 SrcPixel
.col
.alpha
: BlendFunc
.SourceConstantAlpha
;
803 DstPixel
.ul
= XLATEOBJ_iXlate(DstTo32Xlate
, *Dst
);
804 DstPixel
.col
.red
= Clamp8(DstPixel
.col
.red
* (255 - Alpha
) / 255 + SrcPixel
.col
.red
);
805 DstPixel
.col
.green
= Clamp8(DstPixel
.col
.green
* (255 - Alpha
) / 255 + SrcPixel
.col
.green
);
806 DstPixel
.col
.blue
= Clamp8(DstPixel
.col
.blue
* (255 - Alpha
) / 255 + SrcPixel
.col
.blue
);
807 *Dst
++ = XLATEOBJ_iXlate(DstFrom32Xlate
, DstPixel
.ul
);
809 Dst
= (PUCHAR
)((ULONG_PTR
)Dst
+ DstDelta
);
813 if (SrcTo32Xlate
!= NULL
)
814 EngDeleteXlate(SrcTo32Xlate
);
815 if (DstTo32Xlate
!= NULL
)
816 EngDeleteXlate(DstTo32Xlate
);
817 if (DstFrom32Xlate
!= NULL
)
818 EngDeleteXlate(DstFrom32Xlate
);