FONDU ENTRE 2 BITMAP(TUTO SCANLINE)

balgrim Messages postés 52 Date d'inscription vendredi 26 avril 2002 Statut Membre Dernière intervention 28 octobre 2003 - 15 déc. 2002 à 00:18
balgrim Messages postés 52 Date d'inscription vendredi 26 avril 2002 Statut Membre Dernière intervention 28 octobre 2003 - 15 déc. 2002 à 00:18
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/12237-fondu-entre-2-bitmap-tuto-scanline

balgrim Messages postés 52 Date d'inscription vendredi 26 avril 2002 Statut Membre Dernière intervention 28 octobre 2003
15 déc. 2002 à 00:18
version optimizé (sans virgule flottante...):

function semitrans(Bmp1,Bmp2:TBitmap;nivo:byte):TBitmap;
var
ATB,ATB2,ATB3:pRGBTripleArray;I,J:integer;
Lvl,invLvl:integer;
begin
//on creer les classes...
result:=TBitmap.Create;
bmp1.PixelFormat:=pf24bit; //format 3byte (rgb). cela permet de synchroniser avec le pTATripleByte;
bmp2.PixelFormat:=pf24bit;
result.PixelFormat:=pf24bit;

result.Height:=bmp1.Height;
result.width:=bmp1.width;

//le niveau sur une echelle de 0 a 1:
lvl := nivo ;
invLvl:= 255-lvl;//sont inverse sur la meme echelle tels que lvl+invlvl=1;


for I:=0 to bmp1.Height-1 do begin
//on fait pointer les tableau de TripleBytes sur la ligne I
ATB:=bmp1.ScanLine[I];
ATB2:=bmp2.ScanLine[I];
ATB3:=result.ScanLine[I];
for J:=0 to bmp1.Width-1 do begin
(*
Pour faire la semitransparenc il suffit d'appliquer les regle de
proportionnalité tels que c = ka + (1-k)b dans un intervalle pour k[0;1].

ainsi 0<=k<=1 et donc si k = 0 alors c=b et si k = 1 alors c=a.
On fait sa pour les 3 couleurs:
*)
ATB3[J].rgbtRed:=byte((invlvl*(ATB[J].rgbtRed-ATB2[J].rgbtRed))shr 8 +ATB2[J].rgbtRed);
ATB3[J].rgbtGreen:=byte((invlvl*(ATB[J].rgbtGreen-ATB2[J].rgbtGreen))shr 8 +ATB2[J].rgbtGreen);
ATB3[J].rgbtBlue:=byte((invlvl*(ATB[J].rgbtBlue-ATB2[J].rgbtBlue))shr 8 +ATB2[J].rgbtBlue);
end;
end;
Rejoignez-nous