- ###############################################################
- Source File : SharpDeskApi.pas
- Authors :
- Malx <Malx@Lowdimension.net>
- BilliBerserker <BilliBerserker@Lowdimension.net>
- ###############################################################
- procedure BlendImageA(bmp : TBitmap32; color : TColor; alpha:integer);
- var
- P : PColor32;
- I : integer;
- sum1,sum2 : real;
- CB,CR,CG : Integer;
- oCB,oCR,oCG : Integer;
- nCB,nCR,nCG : Integer;
- tempAlpha : integer;
- change : Integer;
- begin
- alpha := min(alpha,255);
- alpha := max(alpha,0);
- CR := GetRValue(colortorgb(color));
- CG := GetGValue(colortorgb(color));
- CB := GetBValue(colortorgb(color));
- sum1 := (CB+CR+CG)/3;
- with bmp do begin
- try
- P := PixelPtr[0, 0];
- for I := 0 to Width * Height - 1 do
- begin
- tempAlpha := (P^ shr 24);
- if tempAlpha <> 0 then begin
- oCR := (P^ and $00FF0000)shr 16;
- oCG := (P^ and $0000FF00)shr 8;
- oCB := P^ and $0000FF;
- sum2 := (oCB+oCR+oCG)/3;
- change := round(sum2-sum1);
- nCR := CR + change;
- nCG := CG + change;
- nCB := CB + change;
- nCR := round((alpha/255)*nCR+((255-alpha)/255)*oCR);
- nCG := round((alpha/255)*nCG+((255-alpha)/255)*oCG);
- nCB := round((alpha/255)*nCB+((255-alpha)/255)*oCB);
- if nCB > 255 then nCB := 255
- else if nCB < 0 then nCB := 0;
- if nCR > 255 then nCR := 255
- else if nCR < 0 then nCR := 0;
- if nCG > 255 then nCG := 255
- else if nCG < 0 then nCG := 0;
- P^ := color32(nCR,nCG,nCB,tempAlpha);
- end;
- Inc(P); // proceed to the next pixel
- end;
- finally
- end;
- end;
- end;