SOLVED: Special effects lazarus / 39-Graphics ---------------------------------------------------------------------- AsleyCruz · 2020-04-22 11:41 Good morning coders Does anybody have any functions of how to apply special effects on images? Effects like grayscale, sepia, invert colors, brightness, horizontal/vertical flip Thanks in advance, guys. ---------------------------------------------------------------------- winni · 2020-04-22 12:11 hI1 Everything you asked for is built in the BGRAbitmap: grayscale, grayscaleInPlace, negative, horizontalFlip, verticalFlip. Brightness and Sepia I am not shure and now I have not Lazarus at hand. Winni ---------------------------------------------------------------------- winni · 2020-04-22 12:20 Hi! Here  is the algorithm foe Sepia: https://www.geeksforgeeks.org/image-procesing-java-set-6-colored- image-sepia-image-conversion/ Winni ---------------------------------------------------------------------- circular · 2020-04-22 13:08 About Brightness you can use the Normalize function to use all possible colors from black to white. Otherwise you can simply multiply the values of each RGB channels or add/substract a constant. ---------------------------------------------------------------------- lucamar · 2020-04-22 13:53 A good source for those (and lots more) kind of things was Earl F. Glynn's Reference Library, most of which can be found at the Internet Archive's Wayback Machine. ---------------------------------------------------------------------- winni · 2020-04-22 16:29 Hi! Just implemented the missing Sepia. The function Sepia () create  a copy of the TBGRAbitmap but in Sepia color. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function range2byte (float: single) : byte; inline;beginif float > 255 then float := 255 else   if float < 0 then float := 0;   result := round (float);end; function toSepia (col : TBGRAPixel) : TBGRAPixel; inline;beginresult.red :=   range2Byte (0.393*col.red + 0.769*col.green + 0.189*col.blue);result.green:= range2Byte (0.349*col.red + 0.686*col.green + 0.168*col.blue);result.blue :=  range2Byte (0.272*col.red + 0.534*col.green + 0.131*col.blue);result.alpha := col.alpha;end; function Sepia (Orig: TBGRABitmap) : TBGRABitmap;var dest : TBGRABitmap;    i : Integer;    p,q : PBGRAPixel; begindest := TBGRAbitmap.create (Orig.width, Orig.height);p := Orig.Data;;q := dest.Data;for i := 0 to Orig.NbPixels-1 do   begin   q^ := toSepia (p^);   inc(p);   inc(q);   end; // i dest.InvalidateBitmap; result := dest;end;                     Winni ---------------------------------------------------------------------- winni · 2020-04-22 17:33 Hi! As test: "Marianne" in Sepia. Long llive the french revolution! Winni ---------------------------------------------------------------------- AsleyCruz · 2020-04-22 17:59 Quote from: winni on April 22, 2020, 02:11:19 pmhI1 Everything you asked for is built in the BGRAbitmap: grayscale, grayscaleInPlace, negative, horizontalFlip, verticalFlip. Many thanks Winni, I will check the functions out. I haven't used BGRAbitmap too much. Great sample code with sepia... Thanks for your time. ---------------------------------------------------------------------- circular · 2020-04-22 22:33 yeah revolution! Well these days, not really able to go out though. Channels are in sRGB colorspace, which has a gamma. If you want to do transformations in linear RGB, first transform the value with GammaExpansionTab and in the end back with GammaCompressionTab. Using linear RGB will give you less dark areas. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function CompressF (float: single) : byte; inline;begin  if float > 65535 then float := 65535 else   if float < 0 then float := 0;   result := GammaCompressionTab[round (float)];end; function toSepia (col : TBGRAPixel) : TBGRAPixel; inline;begin  with GammaExpansion(col) do  begin    result.red :=   CompressF (0.393*red + 0.769*green + 0.189*blue);    result.green:= CompressF (0.349*red + 0.686*green + 0.168*blue);    result.blue :=  CompressF (0.272*red + 0.534*green + 0.131*blue);  end;  result.alpha := col.alpha;end; ---------------------------------------------------------------------- winni · 2020-04-22 23:43 Quote from: lucamar on April 22, 2020, 03:53:12 pmA good source for those (and lots more) kind of things was Earl F. Glynn's Reference Library, most of which can be found at the Internet Archive's Wayback Machine. Thanx! I did not know that efg is reorganizing his pages. A good source since decades! Winni