Delphi-PRAXiS
Seite 1 von 3  1 23      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi [GR32] How to add intensity? (https://www.delphipraxis.net/146557-%5Bgr32%5D-how-add-intensity.html)

WojTec 22. Jan 2010 11:27


[GR32] How to add intensity?
 
I have simple procedure to add color filter to bitmap:

Delphi-Quellcode:
Row.R := (Color.R * Row.R) div 255;
// Repeat for G and B
How to add Intensity parameter (0=original color, 100=as above)?
Or maybe is better method to colorize filter?

Medium 22. Jan 2010 13:25

Re: [GR32] How to add intensity?
 
I haven't really understood what you do with this particular filter, but it looks like you're looking for simple linear interpolation, where you can shift beween two values freely.

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;

procedure YourFilter(Percent: Integer);
begin
  Row.R := Lerp(Color.R, (Color.R*Row.R) div 255, Percent/100);
  //...
end;

WojTec 22. Jan 2010 15:04

Re: [GR32] How to add intensity?
 
Liste der Anhänge anzeigen (Anzahl: 1)
Something similar (Lerp() coloring too much - up to solid color). I mean like this:

http://i46.tinypic.com/2077v9w.png

:)

jfheins 22. Jan 2010 15:43

Re: [GR32] How to add intensity?
 
I would do something like this:

1. You have the "target color" (full brightness and saturation) and the amount you want to blend (between 0 and 1)

2. For each Pixel do:
2.1: multiply the target color with the brightness of the image pixel
2.2: mix the image pixel and the result from 2.1 together, according to the amount.

:arrow: (1-x) * image_pixel + x * (color * image_pixel_brightness)

The Brigness of a pixel is calculated by adding up all the components and dividung the result by 3. However, there is an advanced formula that weights the colors differently.

fkerber 22. Jan 2010 16:02

Re: [GR32] How to add intensity?
 
Hi!

@WojTec:
Could you please attach the image instead of including it in the posting?
This would decrease loading times and the thread is still useful, even if the image has gone on the other server.

Thanks in advance.

Bye,
Frederic

Medium 22. Jan 2010 16:40

Re: [GR32] How to add intensity?
 
Zitat:

Zitat von WojTec
Something similar (Lerp() coloring too much - up to solid color).

:gruebel: Lerp() can be used for just this. Use the original color of a pixel as first parameter, and the color of that pixel as if the effect was applied fully as second. Pass any value between 0 and 1 as third parameter, and get a linear interpolation between the original and the fully affected color. What exactly is your problem? You might also want to provide some more of your actual code alongside, and possibly some sample output too, helping to describe what the difference between the desired and the achieved effect is.

WojTec 22. Jan 2010 16:59

Re: [GR32] How to add intensity?
 
@jfheins, I'm doing something wrong :(:

Delphi-Quellcode:
var
  Row: PBGRAQuad;
  Color: TBGRAQuad;
  I, J: Integer;
  B: Byte;
  C: TColor;
begin
  Color := ColorToTriple24(AColor);
  Row := PBGRAQuad(@ASource.Bits[0]);

  for I := 0 to ASource.Height - 1 do
  begin
    for J := 0 to ASource.Width - 1 do
    begin
      B := (Row.R + Row.G + Row.B) div 3;
      C := TColor(Round((1 - (APercent / 100)) * RGB(Row.R, Row.G, Row.B) + (APercent / 100) * (RGB(Color.R, Color.G, Color.B) * B)));

      Row.R := GetRValue(C);
      Row.G := GetGValue(C);
      Row.B := GetBValue(C);

      Inc(Row);
    end;
  end;
end;
@fkerber, Ok, I'll remmeber.

WojTec 22. Jan 2010 17:07

Re: [GR32] How to add intensity?
 
@Medium, when Color is for example clYellow and 3rd parameter is 1, any pixel of output is = Color. This is wrong - should be as is on example image above.

fkerber 22. Jan 2010 17:49

Re: [GR32] How to add intensity?
 
Hi!

Zitat:

Zitat von WojTec
@fkerber, Ok, I'll remmeber.

Thanks!
You could also do so in the above posting. It's possible by editing the posting (To do this, click on the button "edit" in the upper right corner).


Bye, Frederic

Medium 22. Jan 2010 19:03

Re: [GR32] How to add intensity?
 
Zitat:

Zitat von WojTec
@Medium, when Color is for example clYellow and 3rd parameter is 1, any pixel of output is = Color. This is wrong - should be as is on example image above.

Oops, I switched the "t" and "(1-t)". Just exchange these, and you're good to go.

Regarding the code you posted: You cannot simply multiply with whole combined RGB-values. You must handle each color channel separately.


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:10 Uhr.
Seite 1 von 3  1 23      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz