Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Better sepia wanted (https://www.delphipraxis.net/146744-better-sepia-wanted.html)

WojTec 26. Jan 2010 14:56


Better sepia wanted
 
Hi. I'm looking for better method for sepialize image. Currently I'm using "open source" (similar implementation available everywhere in many languages) method:

Delphi-Quellcode:
Bits.R := (Bits.R + Bits.G + Bits.B) div 3;
Bits.G := Bits.R;
Bits.B := Bits.R;

Inc(Bits.R, AFactor * 2);
Inc(Bits.G, AFactor);

if Bits.R < (AFactor * 2) then Bits.R := 255;
if Bits.G < (AFactor) then Bits.G := 255;
I thought, that result is good till I saw sepialized image from PSP.

Do you know better algorithm?

Blup 28. Jan 2010 10:46

Re: Better sepia wanted
 
try it out
Delphi-Quellcode:
type
  TBGR = packed record
    B, G, R: Byte;
  end;

procedure RenderColor(ABitmap: TBitmap; NewHue, NewSaturation: Word);
var
  Hue, Luminance, Saturation: Word;
  p: ^TBGR;
  c: TColor;
  x, y: Integer;
begin
  // NewHue       := 36;
  // NewSaturation := 64;

  with ABitmap do
  begin
    PixelFormat := pf24Bit;
    for y := 0 to Height - 1 do
    begin
      p := ScanLine[y];
      for x := 0 to Width - 1 do
      begin
        c := RGB(p^.R, p^.G, p^.B);
        ColorRGBToHLS(c, Hue, Luminance, Saturation);
        c := ColorHLSToRGB(NewHue, Luminance, NewSaturation);
        p^.B := GetBValue(c);
        p^.G := GetGValue(c);
        p^.R := GetRValue(c);
        Inc(p);
      end;
    end;
  end;
end;

WojTec 29. Jan 2010 17:40

Re: Better sepia wanted
 
Working quite good, thanks :)
Could you tell what to do to get more grey, like in version in post #1?

PS: I early did't known about ColorRGBToHLS() and ColorHLSToRGB(). What are maximum values for HLS? The same as in Windows color dialog, mean 239, 240, 240? And yet another stupid question: Delphi HLS is the same like HSL (hue, saturation, lightness)?


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:12 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