Recent

Author Topic: Gradient difference between LazPaint and Photoshop  (Read 5345 times)

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Gradient difference between LazPaint and Photoshop
« on: December 24, 2015, 09:27:43 am »
Hi,

As you can see these days I am working with LazPaint and Photoshop and find out difference and lacks.
Yes I know Photoshop is not goal of LazPaint but its is kind of a standard and every image that I want to make in LazPaint or BGRABitmap are made in Photoshop and these difference are annoying.
For example today I find out a difference between these two gradients :
I made two gradient with (25,25,25) to transparent and as you can see result is different, it seems LazPaint move color from Color 1 to Color 2 statically but Photoshop has a different formula so result will be more smooth.
So I want to know how can I make a gradient like Photoshop?
@Circular, difference is low but in a real work it has difference that came to eye and you can see the difference here with some try but in real works it will be more annoying, I know that because I am working with BGRA,LazPaint ,PS  and talk to designers full time these days.
Photoshop (made in PS and load in LazPaint) is left and LazPaint is right.

Septe

  • Jr. Member
  • **
  • Posts: 68
Re: Gradient difference between LazPaint and Photoshop
« Reply #1 on: December 24, 2015, 11:57:04 am »
I'm not an expert in this but I've found a few interesting urls, one of which I'll give you:  http://www.stuartdenman.com/improved-color-blending/  I have no clue if this could help.  What I did was I googled using this as search criteria:  a good color gradient algorithm.  I also thought of another idea:  gimp is open source.  You can look at that code and see what they did.  Obviously, you'll have to translate c or c++ (not sure which) but it's not that hard.  Just throwing some ideas out.  I hope this helps.

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: Gradient difference between LazPaint and Photoshop
« Reply #2 on: December 24, 2015, 12:49:02 pm »
Thanks Septe, I think Circular implement such thing in BGRA but I think we should wait for his answer.

circular

  • Hero Member
  • *****
  • Posts: 4224
    • Personal webpage
Re: Gradient difference between LazPaint and Photoshop
« Reply #3 on: January 04, 2016, 04:42:51 pm »
Hello!

Regarding the Photoshop gradient, we already discussed this a little bit in another thread. The thing is that Photoshop add random noise to emulate intermediate colors. This could be done to some extent in LazPaint, however it is not very straightforward. It needs some thinking. I think that the best quality would be achieved by doing some dithering. First the gradient would be rendered with high precision (to that extent, maybe TExpandedPixel would be sufficient) and then colors reduced to TBGRAPixel using Floyd-Steinberg dithering. I guess that would be even better than Photoshop gradient, that uses a random-based dithering.

Regarding Septe suggestion, this is indeed interesting. It is not the same subject in fact, but this could be handy to generate gradients in other color spaces than RGB. It is not very obvious because there are different ways colors can be related within a color space with a hue parameter. Basically, we can go round the circle in a clockwise or anticlockwise way.

We could do that we could simply use the smallest arc. However, that is not necessarily what we might want to do. This would be no problem however if we could define multiple colors in the gradient, not just two colors. Then we could choose intermediate colors to go round the way we would like.
Conscience is the debugger of the mind

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: Gradient difference between LazPaint and Photoshop
« Reply #4 on: January 04, 2016, 06:00:13 pm »
Can you make a sample about what you said?

circular

  • Hero Member
  • *****
  • Posts: 4224
    • Personal webpage
Re: Gradient difference between LazPaint and Photoshop
« Reply #5 on: February 06, 2016, 09:31:30 pm »
I have added a TDitheringAlgorithm parameter to GradientFill.

To do that, I added TDitheringAlgorithm to FillRect with a scanner parameter, and added TExpandedPixel color values for gradients and scanners.

So more generally, if you make a IBGRAScanner that returns TExpandedPixel values, you can draw it with dithering using FillRect.

Conscience is the debugger of the mind

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: Gradient difference between LazPaint and Photoshop
« Reply #6 on: February 06, 2016, 10:14:00 pm »
I like you man, You are fast  :D
Can you prepare a demo for test and for future documentation?
Even now I use your sample codes from 2-3 years ago in forum ;)

circular

  • Hero Member
  • *****
  • Posts: 4224
    • Personal webpage
Re: Gradient difference between LazPaint and Photoshop
« Reply #7 on: February 06, 2016, 11:26:06 pm »
Thanks.  :D

I noticed a bug with the gradient without gamma correction. I just fixed it on SVN.

Here is an example that shows two horizontal gradients. The top one has the dithering and the bottom one does not have it. You can see that the bottom ones looks like vertical bars.

Code: Pascal  [Select][+][-]
  1. uses BGRABitmap, BGRABitmapTypes;
  2.  
  3. { TForm1 }
  4.  
  5. procedure TForm1.FormPaint(Sender: TObject);
  6. begin
  7.   with TBGRABitmap.Create(ClientWidth,ClientHeight) do
  8.   begin
  9.     GradientFill(0,0,Width,Height div 2, BGRA(80,80,80),BGRA(140,140,140),gtLinear,
  10.                                    PointF(0,0),PointF(Width,0),
  11.                                    dmSet,true,False,daFloydSteinberg);
  12.     GradientFill(0,Height div 2,Width,Height, BGRA(80,80,80),BGRA(140,140,140),gtLinear,
  13.                                    PointF(0,0),PointF(Width,0),
  14.                                    dmSet,true,False,daNearestNeighbor);
  15.     Draw(self.Canvas, 0,0);
  16.     Free;
  17.   end;
  18. end;  
Conscience is the debugger of the mind

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: Gradient difference between LazPaint and Photoshop
« Reply #8 on: February 07, 2016, 10:04:33 am »
Im updating BGRABitmapp.
Thanks you very much and results look very good ;)

circular

  • Hero Member
  • *****
  • Posts: 4224
    • Personal webpage
Re: Gradient difference between LazPaint and Photoshop
« Reply #9 on: February 08, 2016, 01:14:57 am »
Yes! thanks for talking about this 8-)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018