Einzelnen Beitrag anzeigen

WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#13

Re: [GR32] How to add intensity?

  Alt 23. Jan 2010, 12:01
Ok, let's start from begining. What I need: I want to add color filter to image with intensity parameter. Output should be like on image from post #3. My current code:

Delphi-Quellcode:
Row.R := (Color.R * Row.R) div 255;
Row.G := (Color.G * Row.G) div 255;
Row.B := (Color.B * Row.B) div 255;
Example output from my code:

(see 1.png, left part - 0%)

Now output with @Medium proposition:

Delphi-Quellcode:
function Lerp(a, b: Byte; t: Double): Byte;
var
  tmp: Double;
begin
  tmp := t*a + (1-t)*b;
  if tmp<0 then result := 0 else
  if tmp>255 then result := 255 else
  result := Round(tmp);
end;

Row.R := Lerp(Color.R, (Color.R * Row.R) div 255, APercent / 100);
Row.G := Lerp(Color.G, (Color.G * Row.G) div 255, APercent / 100);
Row.B := Lerp(Color.B, (Color.B * Row.B) div 255, APercent / 100);
(see 1.png)

And @jfheins (or maybe I don't understand your formula and coded wrong?):

Delphi-Quellcode:
B := (Row.R + Row.G + Row.B) div 3;
Row.R := IntToByte(Round((1 - (APercent / 100)) * Row.R + (APercent / 100) * (Color.R * B)));
Row.G := IntToByte(Round((1 - (APercent / 100)) * Row.G + (APercent / 100) * (Color.G * B)));
Row.B := IntToByte(Round((1 - (APercent / 100)) * Row.B + (APercent / 100) * (Color.B * B)));
(see 2.png)
Miniaturansicht angehängter Grafiken
2_133.png   1_102.png  
  Mit Zitat antworten Zitat