jcupitt / vipsdisp

Tiny libvips / gtk+4 image viewer
MIT License
143 stars 11 forks source link

Support HiDPI displays #9

Closed earboxer closed 2 years ago

earboxer commented 2 years ago

When using a HiDPI display (2x scale), the base image which is being viewed is a (much) lower resolution than desired.

So, the low resolution image is scaled up and it looks ugly.

(don't mind my semi-transparent windows and lack of checkerboard background: I like to theme [your] app)

Desktop at 2X Scaling

Desktop at 1X Scaling

I'm not sure where to start, but (after some direction), I'd love to work on this (and the SVG DPI upscaling as well).

jcupitt commented 2 years ago

Hi @earboxer,

Yes, SVG zoom support is very basic at the moment, this would be a good thing to fix. PDF is the same. They both render at the default 72 DPI, and it looks pretty bad.

The svgload operator has a scale property you can use to zoom the image, so I think you need to link that up to pyramid levels. svgload can zoom up to 65535 x 65535 pixels (sadly, Cairo has a hard limit at this size), so I would find a scale factor which produced an image just smaller than this and pretend that was the base size of the pyramid. Maybe just set the base value of scale to eg. 100 to start with and try to find the best value later.

  1. You need to change tile_source_open() to add a case for SVG linking level (0 is full res, 1 is a x2 reduction, etc.) to scale.

  2. In tile_source_new_from_source() you need to spot SVGs and fill out the pyramid structure. I would copy-paste the code for openslide and adapt it slightly.

(just guessing what would be needed, perhaps it's more complex)

jcupitt commented 2 years ago

I did a very quick proof of concept hack for this: https://github.com/jcupitt/vipsdisp/compare/master...svg-zoom-poc

It needs quite a bit of cleaning up, but it seems to work.

There is some hitching when you cross a pyramid boundary, I'll see if anything can be done of the libvips side to improve it.

jcupitt commented 2 years ago

... I pushed a change to libvips master which speeds up SVG zooming quite a bit.

earboxer commented 2 years ago

Thanks for the tips. As for that branch, well it implements something.

183 seconds to go

Maybe my svg is a little more complex than SVGs you've tested with.

Ideally, vipsdisp would continue to have better startup and runtime performance compared to eog, or I'd just use eog as it already looks better :stuck_out_tongue: .

I'll do some more poking around.

jcupitt commented 2 years ago

Try with git master libvips -- it opens your SVG instantly for me, and pan and zoom is very quick.

There does seem to be a scaling issue with the E1/D5 in the top left, which is odd.

jcupitt commented 2 years ago

Ah, eog has the same scaling issue, so I guess it's a librsvg bug.

jcupitt commented 2 years ago

There seems to be an annoying leak somewhere, I can get memuse up to 1gb with a few minutes of panning and zooming on your SVG.

jcupitt commented 2 years ago

I got annoyed with the checkerboard, so I added a thing to master to let you swap the background texture. It makes your SVG look a lot nicer.

jcupitt commented 2 years ago

v2.4 is out now with much (much!) better SVG support. Your music example is now quite a bit faster and smoother than eog. It has a thing to change the background as well.