//这个函数只是以源像素的Alpha通道合成
procedure TBitmap32.AlphaBlendPixel(var pDest: TRGBQuad; pSrc: TRGBQuad);
begin
if (pSrc.rgbReserved = $FF) then
begin
PRGBArray(pDest) := PRGBArray(pSrc);
exit;
end;
if (pSrc.rgbReserved = 0) then
exit;
// 以下用不着判断[0,0xFF],我验算过了
if (PRGBArray(pSrc) <> PRGBArray(pDest)) then
begin
pDest.rgbBlue := (PSrc.rgbBlue - pDest.rgbBlue) * pSrc.rgbReserved div $FF + pDest.rgbBlue;
pDest.rgbGreen := (PSrc.rgbGreen - pDest.rgbGreen) * pSrc.rgbReserved div $FF + pDest.rgbGreen;
pDest.rgbRed := (PSrc.rgbRed - pDest.rgbRed) * pSrc.rgbReserved div $FF + pDest.rgbRed;
end;
end;
for y := Tr.Top to Tr.Bottom - 1 do
begin
Target := Tge.ScanLine[y];
Source := ScanLine[y - Dsty];
for x := Tr.Left to Tr.Right - 1 do
begin
//这里替换了
// CombineAlphaPixel(Target^[x], Target^[x], Target^[x].rgbReserved, Source^[x - DstX], Source^[x- DstX].rgbReserved);
AlphaBlendPixel(Target^[x], Source^[x]);
end;
end;
end;
for i := 0 to LayerList.Count -1 do
begin
TBitmap32(LayerList.Items[i ]).DrawTo(0,0, Image1.Picture.Bitmap);
end;
}
//:o:o:o:o:o:o//
[ Last edited by croslq on 2005-10-15 at 14:39 ]Author:
croslq Time: 2005-10-10 10:21 Subject: 请高手把上面哪个函数MMX优化一下
for y := Tr.Top to Tr.Bottom - 1 do
begin
Target := TargetBitmap.ScanLine[y];
Source := Mask8.ScanLine[y - Dsty];
for x := TR.Left to Tr.Right - 1 do
begin
if (Target^[x] + Source^[x - Dstx]) > 255 then
Target^[x] := 255
else
Target^[x] := Target^[x] + Source^[x - Dstx];
end;
end;
end;
//开始增量计算
for i := 0 to nInc -1 do
begin
nJudgeX := nJudgeX + nTwoIx;
nJudgeY := nJudgeY + nTwoIy;
//通过增量法计算的当前点是否属于直线上的点
bPlot := FALSE;
//检测 X 方向
if(nJudgeX >= 0) then
begin
bPlot := TRUE;
nJudgeX := nJudgeX - nTwoIy;
//将任意走向的直线统一起来
if(nDx > 0) then
inc(x)
else if(nDx < 0) then
dec(x)
end;
//检测 Y 方向
if(nJudgeY >= 0) then
begin
bPlot := TRUE;
nJudgeY := nJudgeY - nTwoIx;
//将任意走向的直线统一起来
if(nDy > 0) then
inc(y)
else if(nDy < 0) then
dec(y);
end;
//如果当前点在直线上, 则绘制当前点
if(bPlot) then
// SetPixel(hdc, x, y, clr);
DrawMaskPen(Target, x- MaskPen8.Width div 2, y- MaskPen8.Height div 2, MaskPen8);
end;//end for
end;
function CrossFadeColor(FromColor, ToColor: TColor32; Rate: Single) : TColor32;
var
R,G,B,A: BYTE;
begin
// r := Round(RedComponent(FromColor) * Rate + RedComponent(ToColor) * (1 - Rate));
// g := Round(GreenComponent(FromColor) * Rate + GreenComponent(ToColor) * (1 - Rate));
// b := Round(BlueComponent(FromColor) * Rate + BlueComponent(ToColor) * (1 - Rate));
// a := Round(AlphaComponent(FromColor) * Rate + AlphaComponent(ToColor) * (1 - Rate));
r := RedComponent(FromColor);
g := GreenComponent(FromColor);
b := BlueComponent(FromColor);
a := Round(AlphaComponent(FromColor) * Rate);
Result := RGBA(r,g,b,a); //RGB(b,g,r);
end;
// type
// intarray = array[0..1] of integer;
// pintarray = ^intarray;
procedure hpixel(x : single; y : integer);
var
FadeRate : single;
begin
FadeRate := x - trunc(x);
with bitmap do
begin
if (x>=0) and (y>=0) and (height>y) and (width>x) then
pColor32array(bitmap.ScanLine[y])[trunc(x)] := CrossFadeColor(Color,pColor32array(bitmap.ScanLine[y])[trunc(x)],1-FadeRate);
if (trunc(x)+1>=0) and (y>=0) and (height>y) and (width>trunc(x)+1) then
pColor32array(bitmap.ScanLine[y])[trunc(x)+1]:=CrossFadeColor(Color,pColor32array(bitmap.ScanLine[y])[trunc(x)+1],FadeRate);
end;
end;
procedure vpixel(x : integer; y : single);
var
FadeRate : single;
begin
FadeRate:=y-trunc(y);
with bitmap do
begin
if (x>=0) and (trunc(y)>=0) and (height>trunc(y)) and (width>x) then
pColor32array(bitmap.ScanLine[trunc(y)])[x]:=CrossFadeColor(Color,pColor32array(bitmap.ScanLine[trunc(y)])[x],1-FadeRate);
if (x>=0) and (trunc(y)+1>=0) and (height>trunc(y)+1) and (width>x) then
pColor32array(bitmap.ScanLine[trunc(y)+1])[x]:=CrossFadeColor(Color,pColor32array(bitmap.ScanLine[trunc(y)+1])[x],FadeRate);
end;
end;
var i: integer;
ly, lx, currentx, currenty, deltax, deltay, l, skipl: single;
begin
if (x1 <> x2) or (y1 <> y2) then
begin
// bitmap.PixelFormat := pf32Bit;
// Bitmap.Clear($00000000);
if lx > ly then
begin
l := trunc(lx);
deltay := (y2-y1)/l;
if x1 > x2 then
begin
deltax := -1;
skipl := (currentx - trunc(currentx));
end
else
begin
deltax := 1;
skipl := 1- (currentx - trunc(currentx));
end;
end
else
begin
l := trunc(ly);
deltax := (x2-x1)/l;
if y1 > y2 then
begin
deltay := -1;
skipl := (currenty-trunc(currenty));
end
else
begin
deltay := 1;
skipl := 1-(currenty-trunc(currenty));
end;
end;