Lazarus

Programming => LCL => Topic started by: d-_-b on August 15, 2019, 12:49:18 am

Title: mbColorLib TmbDeskPickerButton returning wrong color. [With Suggested Fix]
Post by: d-_-b on August 15, 2019, 12:49:18 am
Hi,

Someone in irc reported an issue with the mbColorLib TmbDeskPickerButton returning the wrong color on Windows. Eg, you select black(0) and it returns 65793(RGB: 010101).

I debugged the problem and realised `TScreenForm` with a `AlphaBlendValue := 1` affects the `ScreenWin.GetDesktopColor` (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/mbColorLib/ScreenWin.pas#l54) method.

Setting `TScreenForm.AlphaBlendValue := 0` does not work because this "hide" the window so no selection can take place. Also calling `TScreenForm.Hide`, then `GetDesktopColor`, and then `TScreenForm.Show` creates a lot of flickering on screen.

So I then decided to rename `ScreenWin.GetDesktopColor` (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/mbColorLib/ScreenWin.pas#l54) to `ScreenWin.GetScreenColor` and add a private method to `TScreenForm` as follow and that seems to do the trick:

Code: Pascal  [Select][+][-]
  1. function TScreenForm.GetDesktopColor(const X, Y: Integer): TColor;
  2. begin
  3.   {$IFDEF MSWINDOWS}
  4.   AlphaBlendValue:= 0;
  5.   {$ENDIF}
  6.   Result := GetScreenColor(X, Y);
  7.   {$IFDEF MSWINDOWS}
  8.   AlphaBlendValue:= 1;
  9.   {$ENDIF}
  10. end;

I don't have the lcl components source code checked out on my machine so I just modified mbColorLib I sourced from OPM.

But I think we need to be aware of the problem and hopefully apply my suggested fix to it, after someone also confirms this was the issue.

Hence this post,

Thanks.

edit: added OS Target switch to suggested change to only affect Windows Platforms.
Title: Re: mbColorLib TmbDeskPickerButton returning wrong color. [With Suggested Fix]
Post by: jamie on August 15, 2019, 01:59:14 am
if you are doing direct screen reading, RGB values in some cases are backwards.

I don't know what else to tell you.

Title: Re: mbColorLib TmbDeskPickerButton returning wrong color. [With Suggested Fix]
Post by: d-_-b on August 15, 2019, 04:40:50 am
I don't know what else to tell you.

Have a look at a visual demo of the problem and my solution linked to a TCheckBox to enable/disable the bug. (https://imgur.com/a/Y0p9Yb1)

You will see on the first selection the black return as 010101(due to TScreenForm) and the second selection as 000000 because I change AlphaBlendValue := 0 as suggested.
Title: Re: mbColorLib TmbDeskPickerButton returning wrong color. [With Suggested Fix]
Post by: wp on August 15, 2019, 12:29:10 pm
Applied your fix, thank you. In addition, I use a temporary bitmap now which seems to be essential for Linux qt because otherwise the colorpicker always reports white (25,255,255) there. Please test.
Title: Re: mbColorLib TmbDeskPickerButton returning wrong color. [With Suggested Fix]
Post by: d-_-b on August 19, 2019, 04:41:35 pm
wp thanks for the quick fix! The user tested and seems happy.

I have another suggestion, when I look at the code to show the form (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/mbColorLib/ScreenWin.pas#l127) I saw it only takes the primary screen width and height into account. Should that not be changed to:

Code: Pascal  [Select][+][-]
  1. procedure TScreenForm.FormShow(Sender: TObject);
  2. begin
  3.   Width := Screen.DesktopWidth;
  4.   Height := Screen.DesktopHeight;
  5.   Left := Screen.DesktopLeft;
  6.   Top := Screen.DesktopTop;
  7. end;

to cover the whole desktop area?
Title: Re: mbColorLib TmbDeskPickerButton returning wrong color. [With Suggested Fix]
Post by: wp on August 19, 2019, 06:07:05 pm
Done. I cannot test with multiple monitors. Please test yourself and report back.
TinyPortal © 2005-2018