Ver Mensaje Individual
  #3  
Antiguo 17-06-2010
FENIXadr FENIXadr is offline
Miembro
 
Registrado: may 2010
Ubicación: Córdoba - Cba. - Argentina
Posts: 104
Reputación: 17
FENIXadr Va por buen camino
Mezclar imagenes

Hola JXJ.... existe una rutina muy interesante de un tal Yurii Zhukow que te permite mezclar 2 puntos en RGB mediante un valor de Alpha a una velocidad más que aceptable...
Acá te dejo la rutina con una pequeña modificación porque restaba 1 a cada color cada vez que hacías una mezcla.. mi aporte es nada comparado con lo brillante de la rutina del señor Zhukow

function MixBytes(FG, BG, TRANS: byte): byte;
asm
push bx // push some regs
push cx
push dx
mov DH,TRANS // remembering Transparency value (or Opacity - as you like)
mov BL,FG // filling registers with our values
mov AL,DH // BL = ForeGround (FG)
mov CL,BG // CL = BackGround (BG)
xor AH,AH // Clear High-order parts of regs
xor BH,BH
xor CH,CH
mul BL // AX=AL*BL
mov BX,AX // BX=AX
xor AH,AH
mov AL,DH
xor AL,$FF // AX=(255-TRANS)
mul CL // AX=AL*CL
add AX,BX // AX=AX+BX
and AL, 1 // ----> Agregado por FENIXadr
add AH, AL // ----> Agregado por FENIXadr
shr AX,8 // Fine! Here we have mixed value in AL
pop dx // Hm... No rubbish after us, ok?
pop cx
pop bx // Bye, dear Assembler - we go home to Delphi!
end;


una vez que tengas esta rutina, podrás usarla de la siguiente manera:



type

TRGBTripleArray = array[word] of TRGBTriple; // "TRGBTriple" está en la Unit "Windows"
PRGBTripleArray = ^TRGBTripleArray;
........
.........
.......
Procedure TForm1.Button1Click(Sender: TObject);
var x, y : Integer;
ScanFrom, ScanTo : PRGBTripleArray;
Alpha : Byte;
begin
Img1.PixelFormat := pf24Bit; // MUY IMPORTANTE
Img2.PixelFormat := pf24Bit; // MUY IMPORTANTE
// Img1 e Img2 son de tipo TBitMap

Alpha := 128;

for y := 0 to Img1.Height - 1 do
begin
ScanFrom := Img1.ScanLine[y];
ScanTo := Img2.ScanLine[y];
for x := 0 to Img1.Width - 1 do
begin
ScanTo[x].rgbtBlue := MixBytes (ScanTo[x].rgbtBlue, ScanFrom[x].rgbtBlue, Alpha);
ScanTo[x].rgbtGreen := MixBytes (ScanTo[x].rgbtGreen, ScanFrom[x].rgbtGreen, Alpha);
ScanTo[x].rgbtRed := MixBytes (ScanTo[x].rgbtRed, ScanFrom[x].rgbtRed, Alpha);
end;
end;
end;


De esta manera ya puedes mezclar dos imágenes con solo modificar Alpha de 0 a 255, que las imágenes suban, bajen, se dezplacen hacia un lado u otro dependerá de tu código.
Solo dos cosas hay que tenes en cuenta :
Primero:
Como puse arriba muy importante la propiedad PixelFormat debe ser pf24Bit sino funcionan muy mal los ScanLine`s

Y Segundo :
Que los ScanLine's no salgan fuera de la imagen porque se genera un error..

Espero que esto te ayude, cualquier cosa por aca andamos..
Responder Con Cita