Recent

Author Topic: BGRAbitmap Gradient  (Read 23736 times)

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: BGRAbitmap Gradient
« Reply #15 on: April 28, 2016, 08:43:53 am »
Thank you for your remarks
Yes you were right about first and second remark, but when i set GammaCorrection to false the borders become dark, as you can see in screenshots(first one is with changing gtreflected to gtlinear and second one is with setting gamma correction to false).
thanks again


Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   BGRABitmap, BGRABitmapTypes, BGRAGradients, BGRAGradientScanner;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     procedure FormCreate(Sender: TObject);
  17.   private
  18.     { private declarations }
  19.   public
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32. var
  33.   g: TBGRAMultiGradient;
  34.   gs: TBGRAGradientScanner;
  35.   ArrBgraColor: array [0..2] of TBGRAPixel;
  36.   bmpTemp: TBGRABitmap;
  37.   pStart, pEnd: TPointF;
  38.   w, h: integer;
  39. begin
  40.   w := 600;
  41.   h := 360;
  42.   //BGRASetGamma(2.3);
  43.   //Invalidate;
  44.   bmpTemp := TBGRABitmap.Create(w, h, clWhite);
  45.   ArrBgraColor[0] := BGRA(255, 0, 0);//Red
  46.   ArrBgraColor[1] := BGRA(0, 255, 0);//Green
  47.   ArrBgraColor[2] := BGRA(0, 0, 255);//Blue
  48.   g := TBGRAMultiGradient.Create(ArrBgraColor, [0, 0.49, 1], False, False);
  49.   g.InterpolationFunction := @g.CosineInterpolation;
  50.   pStart.x := 0;
  51.   pStart.y := h div 2;
  52.   pEnd.x := w;
  53.   pEnd.y := h div 2;
  54.   gs := TBGRAGradientScanner.Create(g, gtLinear, pStart, pEnd);
  55.   bmpTemp.FillRect(0, 0, w, h, gs, dmSet, daFloydSteinberg);
  56.   bmpTemp.BlendImage(0, 0, bmpTemp, boMultiply);
  57.   bmpTemp.SaveToFile(
  58.     'F:\simin\work\Lazarus\myProjects\(95-02-05)\TestGradient\Pics\pt5.png');
  59.   //Invalidate;
  60.   bmpTemp.Free;
  61.   g.Free;
  62.   gs.Free;
  63. end;
  64.  
  65. end.
  66.  

circular

  • Hero Member
  • *****
  • Posts: 4217
    • Personal webpage
Re: BGRAbitmap Gradient
« Reply #16 on: April 28, 2016, 09:16:34 am »
Hmm... that's surprising. Here is what I get with different gamma corrections 0.4, 1.0 et 1.7:
Conscience is the debugger of the mind

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: BGRAbitmap Gradient
« Reply #17 on: May 02, 2016, 12:29:11 pm »
Hi,
My question is about point in photoshop gradient and bgrabitmap gradient, as you can see in screenshots, there is a concept in photoshop gradient between each position in gradient, which actually means that this position gain its color from color in 2 sides as 50 50, i wanted to ask is there a similar concept in bgra gradient?? it is not positions and colors directly! but i think i can make it with gradient point and and gaining average color of two sides, but i wanted first to know is there something similar in bgrabitmap or not.
thanks prior   

circular

  • Hero Member
  • *****
  • Posts: 4217
    • Personal webpage
Re: BGRAbitmap Gradient
« Reply #18 on: May 02, 2016, 01:03:46 pm »
There isn't this concept of where the 50/50 is in bgra gradient. I suppose indeed that adding an intermediate color would give you a similar result.
 8-)
Conscience is the debugger of the mind

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: BGRAbitmap Gradient
« Reply #19 on: May 02, 2016, 01:19:50 pm »
When reading this discussion, I was wondering: why is the way Photoshop does something the only right way to do it?

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: BGRAbitmap Gradient
« Reply #20 on: May 03, 2016, 02:06:07 pm »
thank you circular, i will test it.

@SymbolicFrank, im developing something that designer designed in PS so i wanted to do exactly look like what PS do.

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: BGRAbitmap Gradient
« Reply #21 on: May 04, 2016, 02:46:41 pm »
Hi
for that "points in photoshop gradient" question I asked previously, i wanted to implement this concept in bgrabitmap and i have a new question about it, i read average methods in bgra doc but i couldnt find a similar method to gain that average color that i want, I thought maybe something like method below maybe give the answer, but in comparing with photoshop 50/50 color, as you can see in screen shots, it seems that there is an other way to gain 50/50 of 2 colors.
my method gain 0,127,127 for 50/50 of BGRA(0,255,0) and BGRA(0,0,255), the right 50/50 color of point in photoshop for same colors is (0,145,125) !
as you can see in screenshots

any help appreciate prior

Code: Pascal  [Select][+][-]
  1. function TSixAm_form.GetAverageColor(C1, C2: TBGRAPixel): TBGRAPixel;
  2. begin
  3.   Result.red := round((c1.red + c2.red) div 2);
  4.   Result.green := round((c1.green + c2.green) div 2);
  5.   Result.blue := round((c1.blue + c2.blue) div 2);
  6. end;
  7.  

circular

  • Hero Member
  • *****
  • Posts: 4217
    • Personal webpage
Re: BGRAbitmap Gradient
« Reply #22 on: May 04, 2016, 07:20:54 pm »
Hmmm... Is it the same thing in Photoshop if the gradient start with yellow instead of red?
Conscience is the debugger of the mind

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: BGRAbitmap Gradient
« Reply #23 on: May 05, 2016, 12:09:42 pm »
I tested hsla to write that average function that i want, but the result I got is not what i want, i added my avg point as a new point in gradient and i did add its position as percent of colors, what i wnat is the exact color of this position(50% in my test) in the gradient, but i cant gain it with this formula!
as you can see in screen shots, i first got the result of gradient with 2 points(0 and 100) and second one is the result of same gradient with my point added exactly the point i mean (in my test 50%) with my avgcolor which i gained from hsla of each color.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   BGRABitmap, BGRABitmapTypes, BGRAGradients, BGRAGradientScanner;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     procedure FormPaint(Sender: TObject);
  17.   private
  18.   public
  19.     function AVGColor(c1, c2: TBGRAPixel; Percent: single): TBGRAPixel;
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.FormPaint(Sender: TObject);
  32. var
  33.   bmp: TBGRABitmap;
  34.   p1, p2: TPointF;
  35.   g: TBGRAMultiGradient;
  36.   gs: TBGRAGradientScanner;
  37.   ArrBgraColor: array [0..2] of TBGRAPixel;
  38.   //ArrBgraColor: array [0..1] of TBGRAPixel;
  39. begin
  40.   bmp := TBGRABitmap.Create(Width, Height);
  41.   p1 := PointF(0, Height / 2);
  42.   p2 := PointF(Width, Height / 2);
  43.  
  44.   //Way1
  45.   //ArrBgraColor[0] := BGRABlack;
  46.   //ArrBgraColor[1] := BGRAWhite;
  47.   //g := TBGRAMultiGradient.Create(ArrBgraColor, [0, 1], True, False);
  48.  
  49.   //Way2
  50.   ArrBgraColor[0] := BGRABlack;
  51.   ArrBgraColor[1] := AVGColor(BGRABlack, BGRAWhite, 50);
  52.   ArrBgraColor[2] := BGRAWhite;
  53.   g := TBGRAMultiGradient.Create(ArrBgraColor, [0, 0.5, 1], True, False);
  54.  
  55.   g.InterpolationFunction := @g.CosineInterpolation;
  56.   gs := TBGRAGradientScanner.Create(g, gtLinear, p1, p2);
  57.   bmp.FillRect(0, 0, Width, Height, gs, dmDrawWithTransparency, daFloydSteinberg);
  58.   bmp.SaveToFile('Pics\w2.png');
  59.   bmp.Draw(Canvas, 0, 0);
  60.   bmp.Free;
  61. end;
  62.  
  63. function TForm1.AVGColor(c1, c2: TBGRAPixel; Percent: single): TBGRAPixel;
  64. var
  65.   h1, h2, Res: THSLAPixel;
  66. begin
  67.   h1 := BGRAToHSLA(c1);
  68.   h2 := BGRAToHSLA(c2);
  69.   with Res do
  70.   begin
  71.     hue := round((h1.hue + h2.hue) * Percent / 100);
  72.     saturation := round((h1.saturation + h2.saturation) * Percent / 100);
  73.     lightness := round((h1.lightness + h2.lightness) * Percent / 100);
  74.     alpha := round((h1.alpha + h2.alpha) * Percent / 100);
  75.   end;
  76.   Result := HSLAToBGRA(Res);
  77. end;
  78.  
  79. end.
  80.  

circular

  • Hero Member
  • *****
  • Posts: 4217
    • Personal webpage
Re: BGRAbitmap Gradient
« Reply #24 on: May 05, 2016, 02:50:53 pm »
I am not sure you got my question so let me rephrase: what happens if you do a gradient with three colors (yellow, green, blue) with Photoshop? What intermediate colors do you have between green and blue?
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: BGRAbitmap Gradient
« Reply #25 on: May 05, 2016, 06:04:54 pm »
Attached yellow, green and blue PS gradient.

circular

  • Hero Member
  • *****
  • Posts: 4217
    • Personal webpage
Re: BGRAbitmap Gradient
« Reply #26 on: May 05, 2016, 07:33:11 pm »
Thanks however I was thinking about yellow(ffff00)/green(00ff00)/blue(0000ff)
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: BGRAbitmap Gradient
« Reply #27 on: May 05, 2016, 08:43:01 pm »
ok here it is

circular

  • Hero Member
  • *****
  • Posts: 4217
    • Personal webpage
Re: BGRAbitmap Gradient
« Reply #28 on: May 05, 2016, 09:31:03 pm »
Thanks!

Ok now the intermediate color is 008080.

So I deduce that Photoshop does a spline interpolation for each color channel separately.
Conscience is the debugger of the mind

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: BGRAbitmap Gradient
« Reply #29 on: May 05, 2016, 10:04:02 pm »
yes i think that in photoshop there is a difference between that exact point when the gradient start with red or yellow!

 

TinyPortal © 2005-2018