[WIN32K] Add StretchBlt function ability to flip images (#3458)

Modify dib\dibxxbpp.c programs to understand flipped images. See Videos at CORE-16642

1. Mirroring Horizontally works.
2. Mirroring Vertically works.
3. Rotation 180° works.

CORE-16642, CORE-14408, CORE-16634
This commit is contained in:
Doug Lyons 2021-02-20 17:28:36 -06:00 committed by GitHub
parent 89843bec56
commit ce7836c6d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 2307 additions and 168 deletions

View file

@ -6,6 +6,7 @@
* PROGRAMMERS: Jason Filby
* Thomas Bluemel
* Gregor Anich
* Doug Lyons
*/
#include <win32k.h>
@ -13,6 +14,9 @@
#define NDEBUG
#include <debug.h>
#define DEC_OR_INC(var, decTrue, amount) \
((var) = (decTrue) ? ((var) - (amount)) : ((var) + (amount)))
VOID
DIB_32BPP_PutPixel(SURFOBJ *SurfObj, LONG x, LONG y, ULONG c)
{
@ -51,46 +55,137 @@ DIB_32BPP_BitBltSrcCopy(PBLTINFO BltInfo)
{
LONG i, j, sx, sy, xColor, f1;
PBYTE SourceBits, DestBits, SourceLine, DestLine;
PBYTE SourceBitsT, SourceBitsB, DestBitsT, DestBitsB;
PBYTE SourceBits_4BPP, SourceLine_4BPP;
PDWORD Source32, Dest32;
DWORD Index, DestWidth, DestHeight;
BOOLEAN bTopToBottom, bLeftToRight;
BOOLEAN blDeltaSrcNeg, blDeltaDestNeg;
BOOLEAN blDeltaAdjustDone = FALSE;
DPRINT("DIB_32BPP_BitBltSrcCopy: SourcePoint (%d, %d), SourceSurface cx/cy (%d/%d), "
"DestSurface cx/cy (%d/%d) DestRect: (%d,%d)-(%d,%d)\n",
BltInfo->SourcePoint.x, BltInfo->SourcePoint.y,
BltInfo->SourceSurface->sizlBitmap.cx, BltInfo->SourceSurface->sizlBitmap.cy,
BltInfo->DestSurface->sizlBitmap.cx, BltInfo->DestSurface->sizlBitmap.cy,
BltInfo->DestRect.left, BltInfo->DestRect.top, BltInfo->DestRect.right, BltInfo->DestRect.bottom);
DPRINT("BltInfo->DestSurface->lDelta is '%d' and BltInfo->SourceSurface->lDelta is '%d'.\n",
BltInfo->DestSurface->lDelta, BltInfo->SourceSurface->lDelta);
DPRINT("iBitmapFormat is %d and width,height is (%d,%d).\n", BltInfo->SourceSurface->iBitmapFormat,
BltInfo->DestRect.right - BltInfo->DestRect.left, BltInfo->DestRect.bottom - BltInfo->DestRect.top);
DPRINT("BltInfo->SourcePoint.x is '%d' and BltInfo->SourcePoint.y is '%d'.\n",
BltInfo->SourcePoint.x, BltInfo->SourcePoint.y);
/* Do not deal with negative numbers for these values */
if ((BltInfo->DestRect.left < 0) || (BltInfo->DestRect.top < 0) ||
(BltInfo->DestRect.right < 0) || (BltInfo->DestRect.bottom < 0))
return FALSE;
/* Detect negative lDelta's meaning Bottom-Up bitmaps */
blDeltaSrcNeg = BltInfo->SourceSurface->lDelta < 0;
blDeltaDestNeg = BltInfo->DestSurface->lDelta < 0;
/* Get back left to right flip here */
bLeftToRight = BltInfo->DestRect.left > BltInfo->DestRect.right;
/* Check for top to bottom flip needed. */
bTopToBottom = BltInfo->DestRect.top > BltInfo->DestRect.bottom;
DPRINT("bTopToBottom is '%d' and DestSurface->lDelta < 0 is '%d' and SourceSurface->lDelta < 0 is '%d'.\n",
bTopToBottom, BltInfo->DestSurface->lDelta < 0 ? 1 : 0, BltInfo->SourceSurface->lDelta < 0 ? 1 : 0);
/* Make WellOrdered with top < bottom and left < right */
RECTL_vMakeWellOrdered(&BltInfo->DestRect);
DestWidth = BltInfo->DestRect.right - BltInfo->DestRect.left;
DestHeight = BltInfo->DestRect.bottom - BltInfo->DestRect.top;
DestBits = (PBYTE)BltInfo->DestSurface->pvScan0
+ (BltInfo->DestRect.top * BltInfo->DestSurface->lDelta)
+ 4 * BltInfo->DestRect.left;
DPRINT("iBitmapFormat is %d and width,height is (%d,%d).\n", BltInfo->SourceSurface->iBitmapFormat,
DestWidth, DestHeight);
switch (BltInfo->SourceSurface->iBitmapFormat)
{
case BMF_1BPP:
DPRINT("1BPP Case Selected with DestRect Width of '%d'.\n",
DestWidth);
if (bLeftToRight || bTopToBottom)
DPRINT("bLeftToRight is '%d' and bTopToBottom is '%d'.\n", bLeftToRight, bTopToBottom);
sx = BltInfo->SourcePoint.x;
/* This sets sy to the top line */
sy = BltInfo->SourcePoint.y;
if (bTopToBottom)
{
/* This sets sy to the bottom line */
sy += BltInfo->SourceSurface->lDelta * (DestHeight - 1);
}
for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
{
sx = BltInfo->SourcePoint.x;
for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
if (bLeftToRight)
{
/* This sets the sx to the rightmost pixel */
sx += (DestWidth - 1);
}
for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
{
if (DIB_1BPP_GetPixel(BltInfo->SourceSurface, sx, sy) == 0)
{
DIB_32BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 0));
} else {
}
else
{
DIB_32BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 1));
}
sx++;
DEC_OR_INC(sx, bLeftToRight, 1);
}
sy++;
DEC_OR_INC(sy, bTopToBottom, 1);
}
break;
case BMF_4BPP:
DPRINT("4BPP Case Selected with DestRect Width of '%d'.\n",
DestWidth);
if (bLeftToRight || bTopToBottom)
DPRINT("bLeftToRight is '%d' and bTopToBottom is '%d'.\n", bLeftToRight, bTopToBottom);
/* This sets SourceBits_4BPP to the top line */
SourceBits_4BPP = (PBYTE)BltInfo->SourceSurface->pvScan0
+ (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
+ (BltInfo->SourcePoint.x >> 1);
if (bTopToBottom)
{
/* This sets SourceBits_4BPP to the bottom line */
SourceBits_4BPP += BltInfo->SourceSurface->lDelta * (DestHeight - 1);
}
for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
{
SourceLine_4BPP = SourceBits_4BPP;
sx = BltInfo->SourcePoint.x;
if (bLeftToRight)
{
/* This sets sx to the rightmost pixel */
sx += (DestWidth - 1);
}
f1 = sx & 1;
for (i=BltInfo->DestRect.left; i<BltInfo->DestRect.right; i++)
@ -99,66 +194,120 @@ DIB_32BPP_BitBltSrcCopy(PBLTINFO BltInfo)
(*SourceLine_4BPP & altnotmask[f1]) >> (4 * (1 - f1)));
DIB_32BPP_PutPixel(BltInfo->DestSurface, i, j, xColor);
if (f1 == 1) {
SourceLine_4BPP++;
DEC_OR_INC(SourceLine_4BPP, bLeftToRight, 1);
f1 = 0;
} else {
f1 = 1;
}
sx++;
DEC_OR_INC(sx, bLeftToRight, 1);
}
SourceBits_4BPP += BltInfo->SourceSurface->lDelta;
DEC_OR_INC(SourceBits_4BPP, bTopToBottom, BltInfo->SourceSurface->lDelta);
}
break;
case BMF_8BPP:
SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + BltInfo->SourcePoint.x;
DPRINT("8BPP Case Selected with DestRect Width of '%d'.\n",
DestWidth);
if (bLeftToRight || bTopToBottom)
DPRINT("bLeftToRight is '%d' and bTopToBottom is '%d'.\n", bLeftToRight, bTopToBottom);
/* This sets SourceLine to the top line */
SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0
+ (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
+ BltInfo->SourcePoint.x;
DestLine = DestBits;
if (bTopToBottom)
{
/* This sets SourceLine to the bottom line */
SourceLine += BltInfo->SourceSurface->lDelta * (DestHeight - 1);
}
for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
{
SourceBits = SourceLine;
DestBits = DestLine;
if (bLeftToRight)
{
/* This sets the SourceBits to the rightmost pixel */
SourceBits += (DestWidth - 1);
}
for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
{
xColor = *SourceBits;
*((PDWORD) DestBits) = (DWORD)XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor);
SourceBits += 1;
DEC_OR_INC(SourceBits, bLeftToRight, 1);
DestBits += 4;
}
SourceLine += BltInfo->SourceSurface->lDelta;
DEC_OR_INC(SourceLine, bTopToBottom, BltInfo->SourceSurface->lDelta);
DestLine += BltInfo->DestSurface->lDelta;
}
break;
case BMF_16BPP:
SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 2 * BltInfo->SourcePoint.x;
DPRINT("16BPP Case Selected with DestRect Width of '%d'.\n",
DestWidth);
if (bLeftToRight || bTopToBottom)
DPRINT("bLeftToRight is '%d' and bTopToBottom is '%d'.\n", bLeftToRight, bTopToBottom);
/* This sets SourceLine to the top line */
SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0
+ (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
+ 2 * BltInfo->SourcePoint.x;
DestLine = DestBits;
if (bTopToBottom)
{
/* This sets SourceLine to the bottom line */
SourceLine += BltInfo->SourceSurface->lDelta * (DestHeight - 1);
}
for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
{
SourceBits = SourceLine;
DestBits = DestLine;
if (bLeftToRight)
{
/* This sets the SourceBits to the rightmost pixel */
SourceBits += (DestWidth - 1) * 2;
}
for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
{
xColor = *((PWORD) SourceBits);
*((PDWORD) DestBits) = (DWORD)XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor);
SourceBits += 2;
DEC_OR_INC(SourceBits, bLeftToRight, 2);
DestBits += 4;
}
SourceLine += BltInfo->SourceSurface->lDelta;
DEC_OR_INC(SourceLine, bTopToBottom, BltInfo->SourceSurface->lDelta);
DestLine += BltInfo->DestSurface->lDelta;
}
break;
case BMF_24BPP:
DPRINT("24BPP Case Selected with DestRect Width of '%d'.\n",
DestWidth);
if (bLeftToRight || bTopToBottom)
DPRINT("bLeftToRight is '%d' and bTopToBottom is '%d'.\n", bLeftToRight, bTopToBottom);
/* This sets SourceLine to the top line */
SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0
+ (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
+ 3 * BltInfo->SourcePoint.x;
if (bTopToBottom)
{
/* This sets SourceLine to the bottom line */
SourceLine += BltInfo->SourceSurface->lDelta * (DestHeight - 1);
}
DestLine = DestBits;
for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
@ -166,46 +315,109 @@ DIB_32BPP_BitBltSrcCopy(PBLTINFO BltInfo)
SourceBits = SourceLine;
DestBits = DestLine;
if (bLeftToRight)
{
/* This sets the SourceBits to the rightmost pixel */
SourceBits += (DestWidth - 1) * 3;
}
for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
{
xColor = (*(SourceBits + 2) << 0x10) +
(*(SourceBits + 1) << 0x08) +
(*(SourceBits));
*((PDWORD)DestBits) = (DWORD)XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, xColor);
SourceBits += 3;
DEC_OR_INC(SourceBits, bLeftToRight, 3);
DestBits += 4;
}
SourceLine += BltInfo->SourceSurface->lDelta;
DEC_OR_INC(SourceLine, bTopToBottom, BltInfo->SourceSurface->lDelta);
DestLine += BltInfo->DestSurface->lDelta;
}
break;
case BMF_32BPP:
if (NULL == BltInfo->XlateSourceToDest ||
0 != (BltInfo->XlateSourceToDest->flXlate & XO_TRIVIAL))
DPRINT("32BPP Case Selected with SourcePoint (%d,%d) and DestRect Width/height of '%d/%d' DestRect: (%d,%d)-(%d,%d).\n",
BltInfo->SourcePoint.x, BltInfo->SourcePoint.y, DestWidth, DestHeight,
BltInfo->DestRect.left, BltInfo->DestRect.top, BltInfo->DestRect.right, BltInfo->DestRect.bottom);
if (bLeftToRight || bTopToBottom)
DPRINT("bLeftToRight is '%d' and bTopToBottom is '%d'.\n", bLeftToRight, bTopToBottom);
/* This handles the negative lDelta's which represent Top-to-Bottom bitmaps */
if (((blDeltaSrcNeg || blDeltaDestNeg) && !(blDeltaSrcNeg && blDeltaDestNeg)) && bTopToBottom)
{
DPRINT("Adjusting for lDelta's here.\n");
if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
{
SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
/* SourceBits points to top-left pixel for lDelta < 0 and bottom-left for lDelta > 0 */
SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0
+ (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
+ 4 * BltInfo->SourcePoint.x;
for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
{
RtlMoveMemory(DestBits, SourceBits, 4 * (BltInfo->DestRect.right - BltInfo->DestRect.left));
RtlMoveMemory(DestBits, SourceBits, 4 * DestWidth);
SourceBits += BltInfo->SourceSurface->lDelta;
DestBits += BltInfo->DestSurface->lDelta;
}
}
else
{
/* SourceBits points to bottom-left pixel for lDelta < 0 and top-left for lDelta > 0 */
SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0
+ ((BltInfo->SourcePoint.y
+ BltInfo->DestRect.bottom
- BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta)
+ DestHeight - 1) * BltInfo->SourceSurface->lDelta)
+ 4 * BltInfo->SourcePoint.x;
DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 + ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta) + 4 * BltInfo->DestRect.left;
/* SourceBits points to bottom-left pixel for lDelta < 0 and top-left for lDelta > 0 */
DestBits = (PBYTE)BltInfo->DestSurface->pvScan0
+ ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta)
+ 4 * BltInfo->DestRect.left;
for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--)
{
RtlMoveMemory(DestBits, SourceBits, 4 * (BltInfo->DestRect.right - BltInfo->DestRect.left));
RtlMoveMemory(DestBits, SourceBits, 4 * DestWidth);
SourceBits -= BltInfo->SourceSurface->lDelta;
DestBits -= BltInfo->DestSurface->lDelta;
}
}
blDeltaAdjustDone = TRUE;
}
/* This tests for whether we can use simplified/quicker code below.
* It works for increasing source and destination areas only and there is no overlap and no flip.
*/
if ((BltInfo->XlateSourceToDest == NULL ||
(BltInfo->XlateSourceToDest->flXlate & XO_TRIVIAL) != 0) &&
(!bTopToBottom && !bLeftToRight))
{
DPRINT("XO_TRIVIAL is TRUE.\n");
if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
{
/* SourceBits points to top-left pixel for lDelta < 0 and bottom-left for lDelta > 0 */
SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0
+ (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
+ 4 * BltInfo->SourcePoint.x;
for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
{
RtlMoveMemory(DestBits, SourceBits, 4 * DestWidth);
SourceBits += BltInfo->SourceSurface->lDelta;
DestBits += BltInfo->DestSurface->lDelta;
}
}
else
{
/* SourceBits points to bottom-left pixel for lDelta < 0 and top-left for lDelta > 0 */
SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0
+ ((BltInfo->SourcePoint.y
+ DestHeight - 1) * BltInfo->SourceSurface->lDelta)
+ 4 * BltInfo->SourcePoint.x;
/* SourceBits points to bottom-left pixel for lDelta < 0 and top-left for lDelta > 0 */
DestBits = (PBYTE)BltInfo->DestSurface->pvScan0
+ ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta)
+ 4 * BltInfo->DestRect.left;
for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--)
{
RtlMoveMemory(DestBits, SourceBits, 4 * DestWidth);
SourceBits -= BltInfo->SourceSurface->lDelta;
DestBits -= BltInfo->DestSurface->lDelta;
}
@ -213,66 +425,272 @@ DIB_32BPP_BitBltSrcCopy(PBLTINFO BltInfo)
}
else
{
if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
DPRINT("XO_TRIVIAL is NOT TRUE.\n");
if (!bTopToBottom && !bLeftToRight)
{
SourceBits = ((PBYTE)BltInfo->SourceSurface->pvScan0 + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x);
for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
{
if (BltInfo->DestRect.left < BltInfo->SourcePoint.x)
SourceBits = ((PBYTE)BltInfo->SourceSurface->pvScan0
+ (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
+ 4 * BltInfo->SourcePoint.x);
for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
{
Dest32 = (DWORD *) DestBits;
Source32 = (DWORD *) SourceBits;
for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
if (BltInfo->DestRect.left < BltInfo->SourcePoint.x)
{
*Dest32++ = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32++);
Dest32 = (DWORD *) DestBits;
Source32 = (DWORD *) SourceBits;
for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
{
*Dest32++ = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32++);
}
}
else
{
Dest32 = (DWORD *) DestBits + (DestWidth - 1);
Source32 = (DWORD *) SourceBits + (DestWidth - 1);
for (i = BltInfo->DestRect.right - 1; BltInfo->DestRect.left <= i; i--)
{
*Dest32-- = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32--);
}
}
SourceBits += BltInfo->SourceSurface->lDelta;
DestBits += BltInfo->DestSurface->lDelta;
}
else
}
else
{
SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0
+ ((BltInfo->SourcePoint.y
+ DestHeight - 1) * BltInfo->SourceSurface->lDelta)
+ 4 * BltInfo->SourcePoint.x;
DestBits = (PBYTE)BltInfo->DestSurface->pvScan0
+ ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta)
+ 4 * BltInfo->DestRect.left;
for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--)
{
Dest32 = (DWORD *) DestBits + (BltInfo->DestRect.right - BltInfo->DestRect.left - 1);
Source32 = (DWORD *) SourceBits + (BltInfo->DestRect.right - BltInfo->DestRect.left - 1);
for (i = BltInfo->DestRect.right - 1; BltInfo->DestRect.left <= i; i--)
if (BltInfo->DestRect.left < BltInfo->SourcePoint.x)
{
*Dest32-- = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32--);
Dest32 = (DWORD *) DestBits;
Source32 = (DWORD *) SourceBits;
for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
{
*Dest32++ = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32++);
}
}
else
{
Dest32 = (DWORD *) DestBits + (DestWidth - 1);
Source32 = (DWORD *) SourceBits + (DestWidth - 1);
for (i = BltInfo->DestRect.right - 1; BltInfo->DestRect.left <= i; i--)
{
*Dest32-- = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32--);
}
}
SourceBits -= BltInfo->SourceSurface->lDelta;
DestBits -= BltInfo->DestSurface->lDelta;
}
SourceBits += BltInfo->SourceSurface->lDelta;
DestBits += BltInfo->DestSurface->lDelta;
}
}
else
{
SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0 + ((BltInfo->SourcePoint.y + BltInfo->DestRect.bottom - BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 + ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta) + 4 * BltInfo->DestRect.left;
for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--)
/* Buffering for source and destination flip overlaps. Fixes KHMZ MirrorTest CORE-16642 */
BOOL TopToBottomDone = FALSE;
/* No need to flip a LeftToRight bitmap only one pixel wide */
if ((bLeftToRight) && (DestWidth > 1))
{
if (BltInfo->DestRect.left < BltInfo->SourcePoint.x)
DPRINT("Flip is bLeftToRight.\n");
/* Allocate enough pixels for a row in DWORD's */
DWORD *store = ExAllocatePoolWithTag(NonPagedPool,
(DestWidth + 1) * 4, TAG_DIB);
if (store == NULL)
{
Dest32 = (DWORD *) DestBits;
Source32 = (DWORD *) SourceBits;
for (i = BltInfo->DestRect.left; i < BltInfo->DestRect.right; i++)
{
*Dest32++ = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32++);
}
DPRINT1("Storage Allocation Failed.\n");
return FALSE;
}
/* This sets SourceBits to the bottom line */
SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0
+ ((BltInfo->SourcePoint.y + DestHeight - 1)
* BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
/* This sets DestBits to the bottom line */
DestBits = (PBYTE)BltInfo->DestSurface->pvScan0
+ (BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta
+ 4 * BltInfo->DestRect.left;
for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--)
{
/* Set Dest32 to right pixel */
Dest32 = (DWORD *) DestBits + (DestWidth - 1);
Source32 = (DWORD *) SourceBits;
Index = 0;
/* Store pixels from left to right */
for (i = BltInfo->DestRect.right - 1; BltInfo->DestRect.left <= i; i--)
{
store[Index] = *Source32++;
Index++;
}
Index = 0;
/* Copy stored dat to pixels from right to left */
for (i = BltInfo->DestRect.right - 1; BltInfo->DestRect.left <= i; i--)
{
*Dest32-- = store[Index];
Index++;
}
SourceBits -= BltInfo->SourceSurface->lDelta;
DestBits -= BltInfo->DestSurface->lDelta;
}
ExFreePoolWithTag(store, TAG_DIB);
TopToBottomDone = TRUE;
}
/* Top to Botoom Handling if bitmap more than one pixel high */
if ((bTopToBottom) && (DestHeight > 1))
{
/* Note: It is very important that this code remain optimized for time used.
* Otherwise you will have random crashes in ReactOS that are undesirable.
* For an example of this just try executing the code here two times.
*/
DPRINT("Flip is bTopToBottom.\n");
/* Allocate enough pixels for a row in DWORD's */
DWORD *store = ExAllocatePoolWithTag(NonPagedPool,
(DestWidth + 1) * 4, TAG_DIB);
if (store == NULL)
{
DPRINT1("Storage Allocation Failed.\n");
return FALSE;
}
/* This set DestBitsT to the top line */
DestBitsT = (PBYTE)BltInfo->DestSurface->pvScan0
+ ((BltInfo->DestRect.top) * BltInfo->DestSurface->lDelta)
+ 4 * BltInfo->DestRect.left;
/* This sets DestBitsB to the bottom line */
DestBitsB = (PBYTE)BltInfo->DestSurface->pvScan0
+ (BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta
+ 4 * BltInfo->DestRect.left;
/* The TopToBottomDone flag indicates that we are flipping for bTopToBottom and bLeftToRight
* and have already completed the bLeftToRight. So we will lose our first flip output
* unless we work with its output which is at the destination site. So in this case
* our new Source becomes the previous outputs Destination.
* Also in we use the same logic when we have corrected for negative lDelta's above
* and already completed a flip from Source to Destination for the first step
*/
if (TopToBottomDone || blDeltaAdjustDone)
{
/* This sets SourceBitsB to the bottom line */
SourceBitsB = DestBitsB;
/* This sets SourceBitsT to the top line */
SourceBitsT = DestBitsT;
}
else
{
Dest32 = (DWORD *) DestBits + (BltInfo->DestRect.right - BltInfo->DestRect.left - 1);
Source32 = (DWORD *) SourceBits + (BltInfo->DestRect.right - BltInfo->DestRect.left - 1);
for (i = BltInfo->DestRect.right - 1; BltInfo->DestRect.left <= i; i--)
{
*Dest32-- = XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, *Source32--);
}
/* This sets SourceBitsB to the bottom line */
SourceBitsB = (PBYTE)BltInfo->SourceSurface->pvScan0
+ ((BltInfo->SourcePoint.y + DestHeight - 1)
* BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
/* This sets SourceBitsT to the top line */
SourceBitsT = (PBYTE)BltInfo->SourceSurface->pvScan0
+ (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) + 4 * BltInfo->SourcePoint.x;
}
SourceBits -= BltInfo->SourceSurface->lDelta;
DestBits -= BltInfo->DestSurface->lDelta;
/* Overlaps and Vertical flips do not mix well. So we test for this and handle it
* by using two operations. First we just do a copy of the source to the destination.
* Then we do a flip in place at the destination location and we are done.
*/
if ((BltInfo->SourcePoint.y != BltInfo->DestRect.top) && // The values are not equal and
(abs(BltInfo->SourcePoint.y - BltInfo->DestRect.top) < (DestHeight + 2)) && // they are NOT seperated by > DestHeight
(BltInfo->SourceSurface->pvScan0 == BltInfo->DestSurface->pvScan0)) // and same surface (probably screen)
{
DPRINT("Flips Need Adjustments, so do move here.\n");
if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
{
/* SourceBits points to top-left pixel for lDelta < 0 and bottom-left for lDelta > 0 */
SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0
+ (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
+ 4 * BltInfo->SourcePoint.x;
for (j = BltInfo->DestRect.top; j < BltInfo->DestRect.bottom; j++)
{
RtlMoveMemory(DestBits, SourceBits, 4 * DestWidth);
SourceBits += BltInfo->SourceSurface->lDelta;
DestBits += BltInfo->DestSurface->lDelta;
}
}
else
{
/* SourceBits points to bottom-left pixel for lDelta < 0 and top-left for lDelta > 0 */
SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0
+ ((BltInfo->SourcePoint.y
+ DestHeight - 1) * BltInfo->SourceSurface->lDelta)
+ 4 * BltInfo->SourcePoint.x;
/* SourceBits points to bottom-left pixel for lDelta < 0 and top-left for lDelta > 0 */
DestBits = (PBYTE)BltInfo->DestSurface->pvScan0
+ ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta)
+ 4 * BltInfo->DestRect.left;
for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--)
{
RtlMoveMemory(DestBits, SourceBits, 4 * DestWidth);
SourceBits -= BltInfo->SourceSurface->lDelta;
DestBits -= BltInfo->DestSurface->lDelta;
}
}
/* This sets SourceBitsB to the bottom line */
SourceBitsB = DestBitsB;
/* This sets SourceBitsT to the top line */
SourceBitsT = DestBitsT;
}
/* Vertical Flip code starts here */
for (j = 0; j < DestHeight / 2 ; j++)
{
/* Store bottom row of Source pixels */
RtlMoveMemory(store, SourceBitsB, 4 * DestWidth);
/* Copy top Source row to bottom Destination row overwriting it */
RtlMoveMemory(DestBitsB, SourceBitsT, 4 * DestWidth);
/* Copy stored bottom row of Source pixels to Destination top row of pixels */
RtlMoveMemory(DestBitsT, store, 4 * DestWidth);
/* Index top rows down and bottom rows up */
SourceBitsT += BltInfo->SourceSurface->lDelta;
SourceBitsB -= BltInfo->SourceSurface->lDelta;
DestBitsT += BltInfo->DestSurface->lDelta;
DestBitsB -= BltInfo->DestSurface->lDelta;
}
if (DestHeight % 2)
{
/* If we had an odd number of lines we handle the center one here */
DPRINT("Handling Top To Bottom with Odd Number of lines.\n");
RtlMoveMemory(DestBitsB, SourceBitsT, 4 * DestWidth);
}
ExFreePoolWithTag(store, TAG_DIB);
}
}
}
break;
default:
DPRINT1("DIB_32BPP_Bitblt: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo->SourceSurface->iBitmapFormat));
DPRINT1("DIB_32BPP_BitBltSrcCopy: Unhandled Source BPP: %u\n", BitsPerFormat(BltInfo->SourceSurface->iBitmapFormat));
return FALSE;
}
@ -352,7 +770,7 @@ DIB_32BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
register NICEPIXEL32 DstPixel, SrcPixel;
UCHAR Alpha, SrcBpp;
DPRINT("DIB_32BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
DPRINT("DIB_32BPP_AlphaBlend: SourceRect: (%d,%d)-(%d,%d), DestRect: (%d,%d)-(%d,%d)\n",
SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);