Recent

Author Topic: Blend image problem in BGRA bitmap with opacity  (Read 12466 times)

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Blend image problem in BGRA bitmap with opacity
« Reply #15 on: August 17, 2016, 05:06:03 pm »
It may be that the algorithm for SoftLight is different.

To display the difference, I would suggest to generate two layers: one with an horizontal grayscale gradient, and one with a vertical grayscale gradient. With a linear gradient, from black to white, you need only a picture of 256x256 pixels to display all possible combinations.
Conscience is the debugger of the mind

Sanem

  • Full Member
  • ***
  • Posts: 179
Re: Blend image problem in BGRA bitmap with opacity
« Reply #16 on: August 18, 2016, 10:06:25 am »
It may be that the algorithm for SoftLight is different.

To display the difference, I would suggest to generate two layers: one with an horizontal grayscale gradient, and one with a vertical grayscale gradient. With a linear gradient, from black to white, you need only a picture of 256x256 pixels to display all possible combinations.

Thank you for your replay Circular
I tested the case you said, and I got a better difference between BGRA SoftLightBlend and Photoshop SoftLightBlend, as you can see in Screenshots attached (if you see the BGRA blend result and Photoshop blend result right after each other in a photo viewer you can see the difference better) , layer 1 and 2 are the layers that I used for blend in both BGRA and Photoshop, and you can see the result of each blend in third and forth Screenshots attached, any Idea??  Do you think I can discover the difference between BGRA SoftLightBlend algorithm and Photoshop SoftLightBlend algorithm with analyzing each pixel color values and compare them?? or what?? Because I do not think that there must be any difference actually, when I tested Screen Blend and I got same exactly results! 

Here is my code:
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;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     procedure FormCreate(Sender: TObject);
  17.   private
  18.     { private declarations }
  19.   public
  20.     procedure BlendSoftLight;
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.BlendSoftLight;
  33. var
  34.   Layer1, Layer2, Layer3: TBGRABitmap;
  35.   AOperation: TBlendOperation;
  36. begin
  37.   Layer1 := TBGRABitmap.Create('Pics' + PathDelim + 'Layer1_PS.png');
  38.   Layer2 := TBGRABitmap.Create('Pics' + PathDelim + 'Layer2_PS.png');
  39.   Layer3 := TBGRABitmap.Create(Layer2.Width, Layer2.Height);
  40.   AOperation := boSoftLight;
  41.   Layer3.PutImage(0, 0, Layer1, dmSet);
  42.   Layer1.BlendImage(0, 0, Layer2, AOperation);
  43.   Layer3.PutImage(0, 0, Layer1, dmLinearBlend);
  44.   Layer3.SaveToFile('Pics' + PathDelim + 'BlendSoftLight_BGRA.png');
  45.   Layer1.Free;
  46.   Layer2.Free;
  47.   Layer3.Free;
  48. end;
  49.  
  50. procedure TForm1.FormCreate(Sender: TObject);
  51. begin
  52.   BlendSoftLight;
  53. end;
  54.  
  55. end.
  56.  

Any help appreciated prior
Regards 

Sanem

  • Full Member
  • ***
  • Posts: 179
Re: Blend image problem in BGRA bitmap with opacity
« Reply #17 on: August 18, 2016, 10:34:26 am »
When I use below method to get pixels values and compare them , I got results that shows that there is a constant difference between each R G B values of each pixel of two pictures of BGRA and PS SoftLightBlend results, but the constant difference is not something I can understand...
any IDEA??

Thank you

Here is my code:
Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.DisplayPixelsValues;
  3. var
  4.   BGRALayer, PSLayer: TBGRABitmap;
  5.   j, i: integer;
  6.   BGRAColor, PSColor: TBGRAPixel;
  7. begin
  8.   BGRALayer := TBGRABitmap.Create('Pics' + PathDelim + 'BlendSoftLight_BGRA.png');
  9.   PSLayer := TBGRABitmap.Create('Pics' + PathDelim + 'BlendSoftLight_PS.png');
  10.   for i := 0 to BGRALayer.Width - 1 do
  11.   begin
  12.     for j := 0 to BGRALayer.Height - 1 do
  13.     begin
  14.       WriteLn('Counters: ', i, ' , ', j);
  15.       BGRAColor := BGRALayer.GetPixel(i, j);
  16.       PSColor := PSLayer.GetPixel(i, j);
  17.       WriteLn('BGRA: ', BGRAColor.red, ' , ', BGRAColor.green, ' , ', BGRAColor.blue, ' , ', BGRAColor.alpha);
  18.       WriteLn('PS  : ', PSColor.red, ' , ', PSColor.green, ' , ', PSColor.blue, ' , ', PSColor.alpha);
  19.       WriteLn();
  20.     end;
  21.   end;
  22.   BGRALayer.Free;
  23.   PSLayer.Free;
  24. end;  
  25.  


And you can see some of its results in Screenshot attached.
« Last Edit: August 18, 2016, 10:56:54 am by simin_sh »

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Blend image problem in BGRA bitmap with opacity
« Reply #18 on: August 18, 2016, 11:02:23 am »
Interesting. Here is the difference between BGRA and PS softlight. In blue when BGRA values are lower and in red when BGRA values are higher.

It is not significant for the left side (less than 1 or 2) and significant for the right side.

For some reason the algorithm I have used for SoftLight is different from SVG specification and PS SoftLight looks more like SVG specification.

You can try to tweak that by going in ByteSoftLightInline function in blendpixelinline.inc. Some code is commented out.
Conscience is the debugger of the mind

Sanem

  • Full Member
  • ***
  • Posts: 179
Re: Blend image problem in BGRA bitmap with opacity
« Reply #19 on: August 18, 2016, 12:12:29 pm »
Interesting. Here is the difference between BGRA and PS softlight. In blue when BGRA values are lower and in red when BGRA values are higher.

It is not significant for the left side (less than 1 or 2) and significant for the right side.

For some reason the algorithm I have used for SoftLight is different from SVG specification and PS SoftLight looks more like SVG specification.

You can try to tweak that by going in ByteSoftLightInline function in blendpixelinline.inc. Some code is commented out.


Thank you again Circular, yep now the SoftLightBlend in BGRA and Photoshop are exactly same, when I used SVG specification, instead of that first formula.

RWC

  • Jr. Member
  • **
  • Posts: 92
Re: Blend image problem in BGRA bitmap with opacity
« Reply #20 on: August 18, 2016, 01:55:31 pm »
@simin_sh: I could see the BGRA blacks extended further down than the PS but was curious to see the difference as a curve shape too so converted your images to a spectrum palette. SVG looks spot-on.
Image > Mode > Grayscale > Discard Color Info > ok.
Image > Mode > Indexed Color > Image > Mode > Color Table > Spectrum.
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

Sanem

  • Full Member
  • ***
  • Posts: 179
Re: Blend image problem in BGRA bitmap with opacity
« Reply #21 on: August 18, 2016, 02:18:42 pm »
@simin_sh: I could see the BGRA blacks extended further down than the PS but was curious to see the difference as a curve shape too so converted your images to a spectrum palette. SVG looks spot-on.
Image > Mode > Grayscale > Discard Color Info > ok.
Image > Mode > Indexed Color > Image > Mode > Color Table > Spectrum.

Interesting! And now when I do the same for my new Blend Results I can see better the fact that they are exactly same.

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Blend image problem in BGRA bitmap with opacity
« Reply #22 on: August 18, 2016, 03:19:17 pm »
I have added boSvgSoftLight blend mode on Git.
Conscience is the debugger of the mind

Sanem

  • Full Member
  • ***
  • Posts: 179
Re: Blend image problem in BGRA bitmap with opacity
« Reply #23 on: August 18, 2016, 03:28:18 pm »
I have added boSvgSoftLight blend mode on Git.


G R E A T

 

TinyPortal © 2005-2018