Recent

Author Topic: SOLVED: Loosing color of lines depending on angle (in Linux)  (Read 710 times)

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Starting from some recent time weird things started happen.
Lines the more loosing color the more they close to vertical.
Antialiasing does not help. It is in Linux. In Win10 all is fine.

Here is code. Create an Application project, put a Panel1 and Button1. Put this event for Button1
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var W,H:integer; C:TCanvas;
  3. begin
  4.   W:=360; H:=360;
  5.   Panel1.Width := W;
  6.   Panel1.Height := H;
  7.   C := Panel1.Canvas;
  8.   C.Brush.Color:=clGray;
  9.   C.FillRect(0,0,W,H);
  10.   C.AntialiasingMode:=amOn;
  11.   C.Pen.Color:=clRed;
  12.   C.Arc(20,20, 100, 100, 10,10,10,10);
  13.   C.Line(10,10, 10, 100);
  14.   C.Line(10,10, 100, 10);
  15.   C.Line(10,10, 100, 100);
  16. end;
  17.  

 
Crazy. The attached picture grabbed by Alt+PrtScr shows no artefacts!
I'll try to get another one. Or will save bitmap from the program.
« Last Edit: July 26, 2020, 01:09:52 pm by mm7 »

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Loosing color of lines depending on angle (in Linux)
« Reply #1 on: July 14, 2020, 12:36:47 am »
This time drawn to TBitmap.Canvas and saved to PNG.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var W,H:integer; C:TCanvas;  BM2: TBitmap;
  3. begin
  4.   W:=360; H:=360;
  5.   Panel2.Width := W;
  6.   Panel2.Height := H;
  7.  
  8.   BM2 := TBitmap.Create;
  9.   BM2.Width := W;
  10.   BM2.Height := H;
  11.  
  12.   C := BM2.Canvas;
  13.   C.Clear;
  14.   C.Brush.Color:= clGray;
  15.   C.FillRect(0,0,W,H);
  16.   C.AntialiasingMode:=amOn;
  17.   C.Pen.Color:=clRed;
  18.   C.Arc(20,20, 100, 100, 10,10,10,10);
  19.   C.Line(10,10, 10, 100);
  20.   C.Line(10,10, 100, 10);
  21.   C.Line(10,10, 100, 100);
  22.  
  23.   Panel2.Canvas.Draw(0,0, BM2);
  24.   BM2.SaveToFile('test.png');
  25.   BM2.Free;
  26. end;
  27.  

the image showed on screen weirdly, but in graph editor (Pinta), being zoomed 4 times it shows all lines pixels are red.
However I do not see any anti-aliasing in PNG.

So, I believe it is something wrong with my X11.
But why anti-aliasing does not work?
« Last Edit: July 14, 2020, 01:10:01 am by mm7 »

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Loosing color of lines depending on angle (in Linux)
« Reply #2 on: July 14, 2020, 01:13:53 am »
I've found that AntialiasingMode:=amOn; works when program is built for Gtk3.
However painting directly to Panel1.Canvas does not work.
It has to be TImage.
It works Panel1.Canvas, just needs to be in OnPaint event.

AntialiasingMode has no effect for Gtk2.

May be it is GTK2 issue.
« Last Edit: July 14, 2020, 04:02:35 am by mm7 »

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Loosing color of lines depending on angle (in Linux)
« Reply #3 on: July 24, 2020, 01:03:26 am »
I've done some research.
With GTK2 LCL calls gdk_draw_line which is deprecated from GDK v2.22

Antialising is set as just passive boolean field of TGtkDeviceContext object and is used only in StretchCopyArea method.

With GTK3 LCL calls cairo_line_to and cairo_stroke
Antialising works for lines (and anything else) unless it is unset by cairo_set_antialias.

But I am not sure how antialiasing worked well before something has changed. It looks like after some OS update.
Whatever works via GDK2 is not antialiased anymore.
Ubuntu 18.04 LTS


Handoko

  • Hero Member
  • *****
  • Posts: 3751
  • My goal: build my own game engine using Lazarus
Re: Loosing color of lines depending on angle (in Linux)
« Reply #4 on: July 24, 2020, 07:18:42 am »
Lines the more loosing color the more they close to vertical.
Antialiasing does not help. It is in Linux. In Win10 all is fine.

I don't get it. I tested your code on Lazarus 2.0.10 GTK2 Ubuntu Mate 20.04, it looks good.

Can you show us what the picture should look like and what is not correct so we can compare it.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6591
    • wiki
Re: Loosing color of lines depending on angle (in Linux)
« Reply #5 on: July 24, 2020, 12:11:09 pm »
What you mean by "loosing color"?

They disappear, become invisible?
They turn black? Or White?
They turn another color?

Maybe your OS uses sub-pixel, but has the wrong settings for your monitor?


mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Loosing color of lines depending on angle (in Linux)
« Reply #6 on: July 24, 2020, 01:17:24 pm »
Here is picture taken by phone. Not actual size due to attachment limitations here.
For some reason it is rotated 90dgr here. (the site does not honour picture metadata? I hold phone vertical.)
Please click to the pic to see it correct.

Yes it is sub-pixel artefacts.

My monitor is full HD 1920 x 1080
LG W2361V 23-inch Wide LCD TFT Monitor

Code: Pascal  [Select][+][-]
  1. $ xrandr
  2. Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
  3. VGA-1 disconnected (normal left inverted right x axis y axis)
  4. HDMI-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 510mm x 290mm
  5.    1920x1080     59.93*+  60.00  
  6.    1680x1050     59.88  
  7.    1280x1024     75.02    60.02  
  8.    1152x864      75.00  
  9.    1024x768      75.08    60.00  
  10.    832x624       74.55  
  11.    800x600       75.00    60.32    56.25  
  12.    640x480       75.00    60.00  
  13.    720x400       70.08  
  14.  
« Last Edit: July 24, 2020, 01:29:34 pm by mm7 »

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Loosing color of lines depending on angle (in Linux)
« Reply #7 on: July 24, 2020, 01:56:52 pm »
Thank you to hint me to check X11 and monitor settings!

 :-[ OMG!

I looked into monitor settings (that can be adjusted by buttons), it appeared that I've set Sharpness to max value 10.
This affects thin lines making them sub-pixel.
All became looking normal (eye pleasing) after I've reduced Sharpness to 4.

Sorry guys, it was not not Lazarus, not FPC, not X11, not drivers. Purely firmware settings.

The issue is closed.

totya

  • Hero Member
  • *****
  • Posts: 632
Re: Loosing color of lines depending on angle (in Linux)
« Reply #8 on: July 24, 2020, 02:39:19 pm »
If the screenshot picture is okay, but the monitor picture is bad, then certainly the problem is the monitor...  O:-)

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Loosing color of lines depending on angle (in Linux)
« Reply #9 on: July 24, 2020, 02:56:45 pm »
the screenshot picture was not okay viewed on my monitor.
It became "ok" after posted here, probably processed (reduced) by the site.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6591
    • wiki
Re: Loosing color of lines depending on angle (in Linux)
« Reply #10 on: July 24, 2020, 03:24:23 pm »
Well you can attach the picture in a zip. Then it wont be processed.
But if its sub-pixel it depends on the OS-settings AND monitor. And that means that the same image might work well on other peoples screens. Or be worse.

The order of sub-pixel depends on the monitor. If your OS thinks Blue is left-most, but if the monitor actually has blue in the middle, the results will be terrible.

If your monitor applies sharpening to sub-pixel painted images, that will also go wrong (at least my understanding).
Because the image provided by your OS combines 2 thirds of one pixel with 1 third of the next. => And sharpening will attempt to divide those pixels.


mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Loosing color of lines depending on angle (in Linux)
« Reply #11 on: July 25, 2020, 02:28:57 pm »
My OS is set to use native monitor's resolution 1920x1080.
It is connected via DVI (though it shows HDMI).
DVI is digital format, it sends 24 bit RGB pixel-by-pixel.
Here is no place for such distortion if the monitor just shows what video-card sent and thats it.

However, the monitor itself processes picture adding brightness, contrast, gamma processing and other "improvements". I.e. it can show all in sepia color  %).
(if interested you can look manual https://www.lg.com/ca_en/support/manuals?csSalesCode=W2361V-PF.ACC)

One of such "improvements" is Sharpness. Probably here it applies some mask that highlights gradients trying to make them even sharper. Here it goes to subpixel distortions.
This processing would make sense for analog signal. Or may be for movies. But for graphic work, drawings, it does not make sense. I believe I've minimized it by setting it somewhat in middle, to 5. Value 1 is a little bit blurry, 10 creates this subpixel distortion. 4 makes some antialiasing.

 

TinyPortal © 2005-2018