AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Vignette effect

Ein Thema von WojTec · begonnen am 15. Sep 2010 · letzter Beitrag vom 20. Sep 2010
Antwort Antwort
WojTec

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

Re: Vignette effect

  Alt 18. Sep 2010, 13:09
This is what I have:

Delphi-Quellcode:
function VignetteBrightness(X, Y: Single): Single;
var
  distance: Single;
  inner_radius, outer_radius: Single;
begin
  inner_radius := 50;
  outer_radius := 150;

  // calculate the distance from the origin (center of the image)
  distance := SQRT(SQR(x) + SQR(Y));

  if distance <= inner_radius then
    result := 1.0 // Brightness 100%
  else if distance <= outer_radius then
    // decreasing Brightness from 100% downto 0%
    result := (distance - inner_radius) / (outer_radius - inner_radius)
  else
    result := 0.0; // it's dark outside the outer_radius
end;

procedure Vignette(ASource: TBitmap32);
var
  Bits: PColor32Entry;
  I, J, XCenter, YCenter: Integer;
  Brightness: Single;
begin
  XCenter := ASource.Width div 2;
  YCenter := ASource.Height div 2;

  Bits := @ASource.Bits[0];

  for J := 0 to ASource.Height - 1 do
  begin
    for I := 0 to ASource.Width - 1 do
    begin
      Brightness := VignetteBrightness(I - XCenter, J - YCenter) * 0.5{=effect depth} + 0.3{basic brightness};

      Bits.R := IntToByte(Round(Bits.R + Brightness));
      Bits.G := IntToByte(Round(Bits.G + Brightness));
      Bits.B := IntToByte(Round(Bits.B + Brightness));

      Inc(Bits);
    end;
  end;

  ASource.Changed;
end;
And no effect - image not changed. Why?
I tried change inner_radius, outer_radius, effect depth and basic brightness, bot no effect too
  Mit Zitat antworten Zitat
Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#2

AW: Re: Vignette effect

  Alt 18. Sep 2010, 13:43
And no effect - image not changed. Why?
You must multiply with the brightness factor.
And you have to care about arithmetic overflow.

Delphi-Quellcode:
function ClampByte(value:Integer):Byte;
begin
  if value > 255 then
    result := 255
  (* not neccesary when a pixel is multiplied with a positive value
  else if value < 0
    result := 0
  *)

  else
    result := Byte(value);
end;
...
Bits.R := ClampByte(Round(Bits.R * Brightness));
  Mit Zitat antworten Zitat
WojTec

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

Re: Vignette effect

  Alt 18. Sep 2010, 14:30
Ah, of course, that's my mistake
Ok, working, but not exactly as should - darker should be near edges, not center as is now
  Mit Zitat antworten Zitat
Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#4

AW: Re: Vignette effect

  Alt 18. Sep 2010, 15:19
Ok, working, but not exactly as should - darker should be near edges, not center as is now
Hmm ,there is a little bug:
Delphi-Quellcode:
  else if distance <= outer_radius then
    // decreasing Brightness from 100% downto 0%
// result := (distance - inner_radius) / (outer_radius - inner_radius) // wrong
    result := (outer_radius - distance) / (outer_radius - inner_radius)
  Mit Zitat antworten Zitat
WojTec

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

Re: Vignette effect

  Alt 18. Sep 2010, 18:36
You are great! This is much faster than my method: I draw white shape on black or grey (or in other grey scale color) background, apply blur and finally blend with image - effect is powerful, but blur part is very slow if greater radius is used.

Can I ask yet one more question? Your nice brightness function generates circle - is possible to use ellipse in image orientation?
  Mit Zitat antworten Zitat
Benutzerbild von xZise
xZise

Registriert seit: 3. Mär 2006
Ort: Waldbronn
4.303 Beiträge
 
Delphi 2009 Professional
 
#6

AW: Vignette effect

  Alt 18. Sep 2010, 20:58
You could also apply this on an ellipse. The main idea is, to reduce the brightness depending on the distance to the edge.
So you have the width/height and the location (x, y). Now you must change the inner/outer radius from a absolute to a relative value.

Argh at the moment I'm too tired to explain this complete.

Fabian
Fabian
Eigentlich hat MS Windows ab Vista den Hang zur Selbstzerstörung abgewöhnt – mkinzler
  Mit Zitat antworten Zitat
Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#7

AW: Vignette effect

  Alt 18. Sep 2010, 23:28
Delphi-Quellcode:
function CalcVignetteBrightness(X, Y: Single): Single;
var
  distance : Single;
  inner_radius, outer_radius, : Single;
begin
  inner_radius := 50;
  outer_radius := 150;
  x := x * 0.75; // <= try this

  // calculate the distance from the origin (center of the image)
  distance := SQRT(SQR(x) + SQR(Y));
  Mit Zitat antworten Zitat
Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#8

AW: Vignette effect

  Alt 19. Sep 2010, 06:43
Mal eine Frage, sollte das Ergebnis nicht so aussehen ? (Image 1)
Bei eurer Methode kommt das dabei heraus. (Image 2)
Angehängte Grafiken
Dateityp: jpg Pictures.jpg (12,0 KB, 23x aufgerufen)
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser

Geändert von turboPASCAL (19. Sep 2010 um 06:48 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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 11:00 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz