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
Medium

Registriert seit: 23. Jan 2008
3.679 Beiträge
 
Delphi 2007 Enterprise
 
#1

Re: [GR32] How to add intensity?

  Alt 23. Jan 2010, 18:22
Aha! You basically want a color tint. The 100% formula for this is:

Brightness := (original.R + original.G + original.B)/(3*255) // normalized to 0..1
NewColor := RGB(tint.R*Brightness, tint.G*Brightness, tint.B*Brightness)

That is what jfheins already wrote, I suppose your implementation had rounding issues or did not normalize brightness (I'm too lazy to verfy this now ).

This should do the trick:
Delphi-Quellcode:
var
  Bits: PColor32Entry;
  Color: TColor32Entry;
  I, J: Integer;
  Percent: Single;
  Brightness: Single;
begin
  Color.ARGB := Color32(AColor);
  Percent := APercent / 100;
  Bits := @ASource.Bits[0];

  for I := 0 to ASource.Height - 1 do
  begin
    for J := 0 to ASource.Width - 1 do
    begin
      Brightness := (Bits.R+Bits.G+Bits.B)/765;
      Bits.R := Lerp(Bits.R, Round(Brightness * Color.R), Percent);
      Bits.G := Lerp(Bits.G, Round(Brightness * Color.G), Percent);
      Bits.B := Lerp(Bits.B, Round(Brightness * Color.B), Percent);

      Inc(Bits);
    end;
  end;

  ASource.Changed;
end;
As a refinement, you could calculate the brightness weighted according to the suggestion by the JPEG commité, that accounts for green being percieved brightest, followed by red and blue darkest at equal values.
The line
Brightness := (Bits.R+Bits.G+Bits.B)/765;
would then look like
Brightness := (0.299*Bits.R + 0.587*Bits.G + 0.114*Bits.B)/765;

It's a few operations more, but might improve the result notably.
"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


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 08:41 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