📄 dib16bpp.c
字号:
sx_dec = 0;
for (DesX=0; DesX<DesSizeX; DesX++)
{
*DestBits = XLATEOBJ_iXlate(ColorTranslation,
DIB_1BPP_GetPixel(SourceSurf, sx, sy));
DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
sx += SrcZoomXHight;
sx_dec += SrcZoomXLow;
if (sx_dec >= sx_max)
{
sx++;
sx_dec -= sx_max;
}
}
DestBits = (PULONG)((ULONG_PTR)DestBits + DifflDelta);
sy += SrcZoomYHight;
sy_dec += SrcZoomYLow;
if (sy_dec >= sy_max)
{
sy++;
sy_dec -= sy_max;
}
}
break;
case BMF_4BPP:
/* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
/* This is a reference implementation, it hasn't been optimized for speed */
for (DesY=0; DesY<DesSizeY; DesY++)
{
sx = SourceRect->left;
sx_dec = 0;
for (DesX=0; DesX<DesSizeX; DesX++)
{
*DestBits = XLATEOBJ_iXlate(ColorTranslation,
DIB_4BPP_GetPixel(SourceSurf, sx, sy));
DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
sx += SrcZoomXHight;
sx_dec += SrcZoomXLow;
if (sx_dec >= sx_max)
{
sx++;
sx_dec -= sx_max;
}
}
DestBits = (PULONG)((ULONG_PTR)DestBits + DifflDelta);
sy += SrcZoomYHight;
sy_dec += SrcZoomYLow;
if (sy_dec >= sy_max)
{
sy++;
sy_dec -= sy_max;
}
}
break;
case BMF_8BPP:
/* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
/* This is a reference implementation, it hasn't been optimized for speed */
for (DesY=0; DesY<DesSizeY; DesY++)
{
sx = SourceRect->left;
sx_dec = 0;
for (DesX=0; DesX<DesSizeX; DesX++)
{
*DestBits = XLATEOBJ_iXlate(ColorTranslation,
DIB_8BPP_GetPixel(SourceSurf, sx, sy));
DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
sx += SrcZoomXHight;
sx_dec += SrcZoomXLow;
if (sx_dec >= sx_max)
{
sx++;
sx_dec -= sx_max;
}
}
DestBits = (PULONG)((ULONG_PTR)DestBits + DifflDelta);
sy += SrcZoomYHight;
sy_dec += SrcZoomYLow;
if (sy_dec >= sy_max)
{
sy++;
sy_dec -= sy_max;
}
}
break;
case BMF_24BPP:
/* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
/* This is a reference implementation, it hasn't been optimized for speed */
DestBits = (PULONG)((PBYTE)DestSurf->pvScan0 + (DestRect->left << 1) +
DestRect->top * DestSurf->lDelta);
DifflDelta = DestSurf->lDelta - (DesSizeX << 1);
for (DesY=0; DesY<DesSizeY; DesY++)
{
sx = SourceRect->left;
sx_dec = 0;
for (DesX=0; DesX<DesSizeX; DesX++)
{
*DestBits = XLATEOBJ_iXlate(ColorTranslation,
DIB_24BPP_GetPixel(SourceSurf, sx, sy));
DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
sx += SrcZoomXHight;
sx_dec += SrcZoomXLow;
if (sx_dec >= sx_max)
{
sx++;
sx_dec -= sx_max;
}
}
DestBits = (PULONG)((ULONG_PTR)DestBits + DifflDelta);
sy += SrcZoomYHight;
sy_dec += SrcZoomYLow;
if (sy_dec >= sy_max)
{
sy++;
sy_dec -= sy_max;
}
}
break;
case BMF_32BPP:
/* FIXME : MaskOrigin, BrushOrigin, ClipRegion, Mode ? */
/* This is a reference implementation, it hasn't been optimized for speed */
for (DesY=0; DesY<DesSizeY; DesY++)
{
sx = SourceRect->left;
sx_dec = 0;
for (DesX=0; DesX<DesSizeX; DesX++)
{
*DestBits = XLATEOBJ_iXlate(ColorTranslation,
DIB_32BPP_GetPixel(SourceSurf, sx, sy));
DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
sx += SrcZoomXHight;
sx_dec += SrcZoomXLow;
if (sx_dec >= sx_max)
{
sx++;
sx_dec -= sx_max;
}
}
DestBits = (PULONG)((ULONG_PTR)DestBits + DifflDelta);
sy += SrcZoomYHight;
sy_dec += SrcZoomYLow;
if (sy_dec >= sy_max)
{
sy++;
sy_dec -= sy_max;
}
}
break;
case BMF_16BPP:
return ScaleRectAvg16(DestSurf, SourceSurf, DestRect, SourceRect, MaskOrigin, BrushOrigin,
ClipRegion, ColorTranslation, Mode);
break;
default:
DPRINT1("DIB_16BPP_StretchBlt: Unhandled Source BPP: %u\n", BitsPerFormat(SourceSurf->iBitmapFormat));
return FALSE;
}
return TRUE;
}
BOOLEAN
DIB_16BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
RECTL* DestRect, POINTL *SourcePoint,
XLATEOBJ *ColorTranslation, ULONG iTransColor)
{
ULONG RoundedRight, X, Y, SourceX, SourceY, Source, wd, Dest;
ULONG *DestBits;
RoundedRight = DestRect->right - ((DestRect->right - DestRect->left) & 0x1);
SourceY = SourcePoint->y;
DestBits = (ULONG*)((PBYTE)DestSurf->pvScan0 +
(DestRect->left << 1) +
DestRect->top * DestSurf->lDelta);
wd = DestSurf->lDelta - ((DestRect->right - DestRect->left) << 1);
for(Y = DestRect->top; Y < DestRect->bottom; Y++)
{
SourceX = SourcePoint->x;
for(X = DestRect->left; X < RoundedRight; X += 2, DestBits++, SourceX += 2)
{
Dest = *DestBits;
Source = DIB_GetSourceIndex(SourceSurf, SourceX, SourceY);
if(Source != iTransColor)
{
Dest &= 0xFFFF0000;
Dest |= (XLATEOBJ_iXlate(ColorTranslation, Source) & 0xFFFF);
}
Source = DIB_GetSourceIndex(SourceSurf, SourceX + 1, SourceY);
if(Source != iTransColor)
{
Dest &= 0xFFFF;
Dest |= (XLATEOBJ_iXlate(ColorTranslation, Source) << 16);
}
*DestBits = Dest;
}
if(X < DestRect->right)
{
Source = DIB_GetSourceIndex(SourceSurf, SourceX, SourceY);
if(Source != iTransColor)
{
*((USHORT*)DestBits) = (USHORT)XLATEOBJ_iXlate(ColorTranslation,
Source);
}
DestBits = (PULONG)((ULONG_PTR)DestBits + 2);
}
SourceY++;
DestBits = (ULONG*)((ULONG_PTR)DestBits + wd);
}
return TRUE;
}
typedef union
{
ULONG ul;
struct
{
UCHAR red;
UCHAR green;
UCHAR blue;
UCHAR alpha;
} col;
} NICEPIXEL32;
typedef union
{
USHORT us;
struct
{
USHORT red:5,
green:6,
blue:5;
} col;
} NICEPIXEL16;
static __inline UCHAR
Clamp5(ULONG val)
{
return (val > 31) ? 31 : val;
}
static __inline UCHAR
Clamp6(ULONG val)
{
return (val > 63) ? 63 : val;
}
BOOLEAN
DIB_16BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
RECTL* SourceRect, CLIPOBJ* ClipRegion,
XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
{
INT Rows, Cols, SrcX, SrcY;
register PUSHORT Dst;
ULONG DstDelta;
BLENDFUNCTION BlendFunc;
register NICEPIXEL16 DstPixel;
register NICEPIXEL32 SrcPixel;
UCHAR Alpha, SrcBpp;
DPRINT("DIB_16BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
ASSERT(DestRect->bottom - DestRect->top == SourceRect->bottom - SourceRect->top &&
DestRect->right - DestRect->left == SourceRect->right - SourceRect->left);
BlendFunc = BlendObj->BlendFunction;
if (BlendFunc.BlendOp != AC_SRC_OVER)
{
DPRINT1("BlendOp != AC_SRC_OVER\n");
return FALSE;
}
if (BlendFunc.BlendFlags != 0)
{
DPRINT1("BlendFlags != 0\n");
return FALSE;
}
if ((BlendFunc.AlphaFormat & ~AC_SRC_ALPHA) != 0)
{
DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc.AlphaFormat);
return FALSE;
}
if ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0 &&
BitsPerFormat(Source->iBitmapFormat) != 32)
{
DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
return FALSE;
}
Dst = (PUSHORT)((ULONG_PTR)Dest->pvScan0 + (DestRect->top * Dest->lDelta) +
(DestRect->left << 1));
DstDelta = Dest->lDelta - ((DestRect->right - DestRect->left) << 1);
SrcBpp = BitsPerFormat(Source->iBitmapFormat);
Rows = DestRect->bottom - DestRect->top;
SrcY = SourceRect->top;
while (--Rows >= 0)
{
Cols = DestRect->right - DestRect->left;
SrcX = SourceRect->left;
while (--Cols >= 0)
{
if (SrcBpp <= 16)
{
DstPixel.us = DIB_GetSource(Source, SrcX++, SrcY, ColorTranslation);
SrcPixel.col.red = (DstPixel.col.red << 3) | (DstPixel.col.red >> 2);
SrcPixel.col.green = (DstPixel.col.green << 2) |
(DstPixel.col.green >> 4);
SrcPixel.col.blue = (DstPixel.col.blue << 3) | (DstPixel.col.blue >> 2);
}
else
{
SrcPixel.ul = DIB_GetSourceIndex(Source, SrcX++, SrcY);
}
SrcPixel.col.red = SrcPixel.col.red *
BlendFunc.SourceConstantAlpha / 255;
SrcPixel.col.green = SrcPixel.col.green *
BlendFunc.SourceConstantAlpha / 255;
SrcPixel.col.blue = SrcPixel.col.blue *
BlendFunc.SourceConstantAlpha / 255;
SrcPixel.col.alpha = (SrcBpp == 32) ?
(SrcPixel.col.alpha *
BlendFunc.SourceConstantAlpha / 255) :
BlendFunc.SourceConstantAlpha;
Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
SrcPixel.col.alpha : BlendFunc.SourceConstantAlpha;
DstPixel.us = *Dst;
DstPixel.col.red = Clamp5(DstPixel.col.red * (255 - Alpha) / 255 +
(SrcPixel.col.red >> 3));
DstPixel.col.green = Clamp6(DstPixel.col.green * (255 - Alpha) / 255 +
(SrcPixel.col.green >> 2));
DstPixel.col.blue = Clamp5(DstPixel.col.blue * (255 - Alpha) / 255 +
(SrcPixel.col.blue >> 3));
*Dst++ = DstPixel.us;
}
Dst = (PUSHORT)((ULONG_PTR)Dst + DstDelta);
SrcY++;
}
return TRUE;
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -