AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi [GR32] How to add intensity?
Thema durchsuchen
Ansicht
Themen-Optionen

[GR32] How to add intensity?

Ein Thema von WojTec · begonnen am 22. Jan 2010 · letzter Beitrag vom 12. Jun 2010
Antwort Antwort
Seite 1 von 3  1 23      
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#1

[GR32] How to add intensity?

  Alt 22. Jan 2010, 12:27
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?
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#2

Re: [GR32] How to add intensity?

  Alt 22. Jan 2010, 14:25
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;
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#3

Re: [GR32] How to add intensity?

  Alt 22. Jan 2010, 16:04
Something similar (Lerp() coloring too much - up to solid color). I mean like this:

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

Miniaturansicht angehängter Grafiken
34093_1264244553.png_457.png  
  Mit Zitat antworten Zitat
Benutzerbild von jfheins
jfheins

Registriert seit: 10. Jun 2004
Ort: Garching (TUM)
4.579 Beiträge
 
#4

Re: [GR32] How to add intensity?

  Alt 22. Jan 2010, 16:43
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.

(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.
  Mit Zitat antworten Zitat
Benutzerbild von fkerber
fkerber
(CodeLib-Manager)

Registriert seit: 9. Jul 2003
Ort: Ensdorf
6.723 Beiträge
 
Delphi XE Professional
 
#5

Re: [GR32] How to add intensity?

  Alt 22. Jan 2010, 17:02
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
Frederic Kerber
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#6

Re: [GR32] How to add intensity?

  Alt 22. Jan 2010, 17:40
Zitat von WojTec:
Something similar (Lerp() coloring too much - up to solid color).
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.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#7

Re: [GR32] How to add intensity?

  Alt 22. Jan 2010, 17:59
@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.
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#8

Re: [GR32] How to add intensity?

  Alt 22. Jan 2010, 18:07
@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.
  Mit Zitat antworten Zitat
Benutzerbild von fkerber
fkerber
(CodeLib-Manager)

Registriert seit: 9. Jul 2003
Ort: Ensdorf
6.723 Beiträge
 
Delphi XE Professional
 
#9

Re: [GR32] How to add intensity?

  Alt 22. Jan 2010, 18:49
Hi!

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
Frederic Kerber
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#10

Re: [GR32] How to add intensity?

  Alt 22. Jan 2010, 20:03
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.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 3  1 23      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:31 Uhr.
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