Recent

Author Topic: mbColorLib TmbDeskPickerButton returning wrong color. [With Suggested Fix]  (Read 199 times)

d-_-b

  • New member
  • *
  • Posts: 20
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` 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` 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.
« Last Edit: August 15, 2019, 01:26:13 am by d-_-b »
Code: Pascal  [Select]
  1. mov     ax,0013h
  2. int     10h
Denthor thanks for the vga programming tutorials | Download all tutorials

jamie

  • Hero Member
  • *****
  • Posts: 1759
if you are doing direct screen reading, RGB values in some cases are backwards.

I don't know what else to tell you.


d-_-b

  • New member
  • *
  • Posts: 20
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.

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.
Code: Pascal  [Select]
  1. mov     ax,0013h
  2. int     10h
Denthor thanks for the vga programming tutorials | Download all tutorials

wp

  • Hero Member
  • *****
  • Posts: 5998
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.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

d-_-b

  • New member
  • *
  • Posts: 20
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 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?
Code: Pascal  [Select]
  1. mov     ax,0013h
  2. int     10h
Denthor thanks for the vga programming tutorials | Download all tutorials

wp

  • Hero Member
  • *****
  • Posts: 5998
Done. I cannot test with multiple monitors. Please test yourself and report back.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10