Bug 478290

Summary: enlarged cursor pixelated and blurry
Product: [Plasma] kwin Reporter: fanzhuyifan
Component: generalAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED NOT A BUG    
Severity: minor CC: andrea.ippo, eamonnrea, linuxero789, nate, timaadu756
Priority: NOR Keywords: qt6
Version: git master   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description fanzhuyifan 2023-12-09 05:17:27 UTC
SUMMARY
***
NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***


STEPS TO REPRODUCE
1. enable shake cursor effect
2. shake cursor

OBSERVED RESULT
The enlarged cursor is pixelated and blurry

EXPECTED RESULT
The enlarged cursor is sharp and crisp

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.90.90
KDE Frameworks Version: 5.246.0
Qt Version: 6.6.1
Kernel Version: 6.6.4-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 20 × 13th Gen Intel® Core™ i9-13900H
Memory: 15.2 GiB of RAM
Graphics Processor: Mesa Intel® Graphics
Manufacturer: ASUSTeK COMPUTER INC.
Product Name: ROG Zephyrus G16 GU603VV_GU603VV
System Version: 1.0

ADDITIONAL INFORMATION
Comment 1 Nate Graham 2023-12-11 22:46:06 UTC
Yep, that's what happens when you take a pixmap image and enlarge it to many times its size :)
Comment 2 Andrea Ippolito 2024-02-27 14:20:58 UTC
(In reply to Nate Graham from comment #1)
> Yep, that's what happens when you take a pixmap image and enlarge it to many
> times its size :)

Allow me to say tho, it looks a bit ugly/unrefined. Compare this to macOS:

https://www.youtube.com/watch?v=U5n-JE7r_8g

Isn't it possible to somehow replace the graphical resource on the fly so that instead of zooming in a small image, you just load a higher-res one?

I'm probably making this easier than it is... :D

Thanks
Comment 3 Nate Graham 2024-02-27 18:47:40 UTC
Indeed. :) What we need to do is move to vector cursors which scale up nicely, but this would entail breaking compatibility with xcursor themes (of which there are *many*), which are raster images and therefore look pixelated or blurry when blown up like this. It would be nice, but breaking the existing spec would mean no more cursor customizations until a new vector-based spec was created and the entire universe of cursor theme artists ported their themes it (which would probably be never, until and unless everyone else moved to the new spec too).

It's unfortunately an example of how allowing customization and theming can actually hold back progress.
Comment 4 fanzhuyifan 2024-02-27 18:50:16 UTC
Is it possible that some smart scale-up algorithm wouldn't have this pixelated look? But that might be too much work just for some pixels...
Comment 5 Nate Graham 2024-02-27 18:55:20 UTC
Yeah, I'm sure there are better upscaling algorithms, and for a long time I've wanted to use one for compositor-upscaled windows. However for that use case the original image only generally needs to be upscaled by a maximum of 2-2.5x, whereas for the cursor it needs to be upscaled 10x or more! So the quality requirements here are more demanding.
Comment 6 fanzhuyifan 2024-02-27 19:03:20 UTC
(In reply to Nate Graham from comment #5)
> Yeah, I'm sure there are better upscaling algorithms, and for a long time
> I've wanted to use one for compositor-upscaled windows. However for that use
> case the original image only generally needs to be upscaled by a maximum of
> 2-2.5x, whereas for the cursor it needs to be upscaled 10x or more! So the
> quality requirements here are more demanding.

Here is a comparison here on wikipedia: https://en.wikipedia.org/wiki/Comparison_gallery_of_image_scaling_algorithms

I think Edge-directed interpolation might work well for our purporses.
Comment 7 Nate Graham 2024-02-27 19:05:38 UTC
"Deep convolutional neural networks using perceptual loss" looks the best, so clearly what we need is to write an AI upscaler just for the cursor. 🤪
Comment 8 fanzhuyifan 2024-02-27 19:08:26 UTC
(In reply to Nate Graham from comment #3)
> Indeed. :) What we need to do is move to vector cursors which scale up
> nicely, but this would entail breaking compatibility with xcursor themes (of
> which there are *many*), which are raster images and therefore look
> pixelated or blurry when blown up like this. It would be nice, but breaking
> the existing spec would mean no more cursor customizations until a new
> vector-based spec was created and the entire universe of cursor theme
> artists ported their themes it (which would probably be never, until and
> unless everyone else moved to the new spec too).
> 
> It's unfortunately an example of how allowing customization and theming can
> actually hold back progress.

What if there is some easy tool that converts xcursor themes to SVGs? That seems feasible based on the wikipedia page, "Image tracing".
Comment 9 fanzhuyifan 2024-03-10 20:49:30 UTC
*** Bug 483160 has been marked as a duplicate of this bug. ***
Comment 10 fanzhuyifan 2024-03-10 20:53:36 UTC
*** Bug 483095 has been marked as a duplicate of this bug. ***
Comment 11 fanzhuyifan 2024-03-21 16:52:36 UTC
*** Bug 484166 has been marked as a duplicate of this bug. ***
Comment 12 Elkin Cruz 2024-03-23 16:28:30 UTC
If I'm not wrong, the current strategy is to enlarge the cursor's image while maintaining its "size" (the cursor's size is kept constant while its magnifying factor increases). The size of some cursors can be changed (System Settings -> Colors & Themes -> Cursors -> Size), and they look crisp when large.

So, another strategy to create less blurry enlarged cursors is to: change the cursor size to something large AND change the magnifying factor to something small so that the cursor looks the same as before, then proceed to magnify the cursor by increasing the magnifying factor. At the end of the animation the size of the cursor could be restored.