Delphi World - это проект, являющийся сборником статей и малодокументированных возможностей  по программированию в среде Delphi. Здесь вы найдёте работы по следующим категориям: delphi, delfi, borland, bds, дельфи, делфи, дэльфи, дэлфи, programming, example, программирование, исходные коды, code, исходники, source, sources, сорцы, сорсы, soft, programs, программы, and, how, delphiworld, базы данных, графика, игры, интернет, сети, компоненты, классы, мультимедиа, ос, железо, программа, интерфейс, рабочий стол, синтаксис, технологии, файловая система...
Смешать два цвета с использованием коэффициента прозрачности

Оформил: DeeCo
Автор: http://www.swissdelphicenter.ch

// This function mixes two bytes According to value of TRANS 
// The value of TRANS is between 0 (result then will be equal to FG) 
// and 255 (result then will be equal to BG) 
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       // AL=AL*BL 
  mov BX,AX    // BX=AX 
  xor AH,AH
   mov AL,DH
   xor AL,$FF   // AX=(255-TRANS) 
  mul CL       // AL=AL*CL 
  add AX,BX    // AX=AX+BX 
  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;

 // Here we mix R,G and B channels of our colors separately. 
// The value of T is between 0 and 255 as described above. 

// As you know, TColor value is 4 bytes length integer value where 
// low byte is red channel, 2nd byte is green and 3rd byte is blue 

function MixColors(FG, BG: TColor; T: byte): TColor;
 var r,g,b:byte;
 begin
   R := MixBytes(FG and 255,BG and 255,T); // extracting and mixing Red 
  G := MixBytes((FG shr 8) and 255,(BG shr 8) and 255,T); // the same with green 
  B := MixBytes((FG shr 16) and 255,(BG shr 16) and 255,T); // and blue, of course 
  Result := r+g*256+b*65536; // finishing with combining all channels together 
end;
Проект Delphi World © Выпуск 2002 - 2024
Автор проекта: USU Software
Вы можете выкупить этот проект.