Opened 4 years ago

Closed 4 years ago

#11989 closed defect (fixed)

Cursor images get their colors inverted on Ubuntu

Reported by: cool-RR Owned by:
Priority: normal Milestone:
Component: wxGTK Version: oldstable-latest
Keywords: cursors, cursor Cc: baribaud.christophe@…
Blocked By: Blocking:
Patch: yes

Description

When setting a custom cursor image on Ubuntu, the image's colors get inverted (i.e. negative image.)

Runnable sample:
Run cursor_test.py. It shows a frame. When you put the mouse on the frame you see a cursor of an open hand. When you click it, it toggles to the other cursor, of a closed hand. When you click again, it toggles again.

This works fine on Windows, but on Ubuntu both cursors appear with their colors inverted.

Attachments (5)

corrupted_cursors.zip download (8.8 KB) - added by cool-RR 4 years ago.
Runnable sample
cursor-image.png download (489 bytes) - added by robind 4 years ago.
cursor-msw.png download (1.2 KB) - added by robind 4 years ago.
cursor-gtk.png download (1.1 KB) - added by robind 4 years ago.
wxWidgets-2.8_gtk_cursor.patch download (768 bytes) - added by cbaribaud 4 years ago.
fix proposal

Download all attachments as: .zip

Change History (15)

Changed 4 years ago by cool-RR

Runnable sample

comment:1 Changed 4 years ago by robind

  • Component changed from wxPython to wxGTK

comment:2 follow-up: Changed 4 years ago by vadz

Would be great to have a C++ test case for this. Don't we already do something similar in the image sample?

comment:3 Changed 4 years ago by cool-RR

Hey vadz,

I don't program C++ so I can't help you with that.

comment:4 in reply to: ↑ 2 Changed 4 years ago by robind

  • Status changed from new to confirmed

Replying to vadz:

Would be great to have a C++ test case for this. Don't we already do something similar in the image sample?

Not that I've been able to find. The key factor here is that wxCursor(const wxImage&) is being used. After a quick grep in the samples folder all I could find were instances of wxCursor(int). On wxGTK creating a cursor from an image results in pixels colors being swapped.

It doesn't appear to be a simple black/white substitution, but may be related to the mask in some way. It looks like all the pixels that were black in the source image become some foreground color, and all remaining unmasked pixels are set to black. I'll attach the image used in the wxPython demo and a couple screenshots to show what I mean.

Changed 4 years ago by robind

Changed 4 years ago by robind

Changed 4 years ago by robind

Changed 4 years ago by cbaribaud

fix proposal

comment:5 Changed 4 years ago by cbaribaud

  • Cc baribaud.christophe@… added
  • Patch set
  • Version changed from 2.8.10 to 2.8-svn

I had the same issue when trying to create a cursor from an XPM include file for use on both wxMSG and wxGTK.
The code in gtk makes a wrong assumption: color 255,255,255 is converted into zeros when wxBitmap decreases the number of colors to two, so to the background color, so background and foreground colors are flipped.

I provided a patch to fix the issue (it worked for me on version 2.8.10 too)

comment:6 Changed 4 years ago by VZ

(In [65073]) Add test for a custom cursor to the image sample.

Load a cursor from PNG file to check that it appears as expected.

See #11989.

comment:7 Changed 4 years ago by vadz

I don't think this patch is correct because in 2.9.1 this works correctly even though the code in wxCursor itself didn't change since 2.8, you can check it by building the image sample after r65073.

So the bug is likely elsewhere and was fixed there (wherever it is) in 2.9 but not in 2.8.

comment:8 Changed 4 years ago by cbaribaud

The defect was indirectly fixed when adding the possibility of colored cursors, in 2.9 and in 2.8.11, it is a few lines before my patch which is, in this case, ignored (the method returns just before)

If, for any reason, the function gdk_display_supports_cursor_color returns false, the method wxCursor::wxCursor(const wxImage&) falls back to the old code, which contains the defect.

An option is to consider that gdk_display_supports_cursor_color will always be true, and that my patch deals with dead code. In this case, the defect may be considered fixed (and the dead code removed).

comment:9 Changed 4 years ago by vadz

Thanks for investigating and explaining this and sorry for dismissing your fix which turns out to be indeed correct, thanks once again for taking time to look at this.

I'll apply the fix as I don't know if it's safe to assume that all displays support colour cursors nowadays. It seems like they should but who knows...

comment:10 Changed 4 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [65107]) Correct creation of the mask for wxImage cursors in wxGTK.

The code created the monochrome bitmap used by wxCursor(wxImage) ctor
incorrectly resulting in bad cursor appearance. Use the right values for
foreground and background pixels (which are inversed compared to naive
expectations) to fix this.

Closes #11989.

Note: See TracTickets for help on using tickets.