04-16-2024 02:55 PM
Another user reported this issue and I decided to investigate. The help for the Create Cursor From File VI states the following:
(Linux) The file must have a .png extension. You cannot use animated cursors. Cursors are monochrome, and the shape of the cursor is determined by the how you set the transparency around the .png file.
Based on that I have created this very simple 2-bits per pixel PNG with transparency:
After I ran the VI to set the cursor to that image (attached), I received this:
Easy to see that white is interpreted as black. Everything else including the mask works fine. Tried on every possible PNG's with depths from 1 to 32 bpp with and without various palettes attached. It always works the same way. My current LabVIEW on Linux (Ubuntu) is 2020, so also tried in LabVIEW 8.5 on ancient SuSE 9.1 (was a supported combo back in the day). The same.
After some heavy debugging I'm inclined to think it's a bug rather than a "by design" behaviour. The Xlib API does not deny displaying black-and-white cursors. I successfully used that to change the cursor, using two X BitMap images (.xbm) generated from the same initial image.
The VI with the images is attached. Both black and white are displayed properly. Unfortunately pure Xlib calls cannot be a workaround here, because I cannot tell LabVIEW that it should not revert the cursor on each occasion and must use the set one. (LabVIEW uses some internal table to remember cursors). Besides of that I tested the ICreateCursor internal function, that seems to be no longer exported. It sets the cursor from two 16x16 px memory bitmaps, nothing else is needed.
Both black and white are displayed properly too, so the issue is neither OS nor LabVIEW limitation.
As I see, LabVIEW runs this piece of code on the right (Create Cursor From File VI -> CreatePremadeFileCursor -> ICreatePremadeFileCursor -> ICreatePixmap):
The DSNewPClr allocates the image sized buffer, filled with 0's, the OurXCreatePixmapFromData creates the pixmap out of that buffer, the mask is created onwards and everything is fed into the XCreatePixmapCursor. The actual content is not taken into account, the mask is just applied onto the black rectangle. Did I get it right?
Linux becomes more popular these days, but this VI feels very outdated. There are X Cursor Extensions for a while, that allow for multicolor cursors. Something definitely wants to be reviewed/rewritten.