|
|
Subscribe / Log in / New account

Oversampling, or scaling down

Oversampling, or scaling down

Posted Nov 12, 2014 15:31 UTC (Wed) by epa (subscriber, #39769)
Parent article: High-DPI displays and Linux

One way to get the sizing you want is to render at a higher pixel size than the real size of the display, and then scale everything down (in hardware) to fit. For example, the 15" Macbook Pro, in its default configuration with Mac OS X, renders at 3840x2400 and then scales by 0.75 to output at 2880x1800. This is done so that on the software side everything can be exactly doubled, giving 'screen real estate' equivalent to an ordinary 1920x1200 display. Getting the applications to render at 1.5x scaling would cause all sorts of pixel jaggies and other nastiness; 2x is much easier to manage and then the video hardware smoothly scales down.

You can also set this up on Windows with some Nvidia cards; again you render to a higher resolution and then the card scales it down for the display. This can be used by obsessive gamers to get the highest possible video quality (a bigger image scaled down will have, in effect, the best possible anti-aliasing) but could also be useful when your monitors have a mixture of dots-per-inch and you want things to appear roughly the same size on each.

Is this kind of oversampling supported on Linux? Could the editor's laptop 2560x1440 display be driven as a virtual 3840x2160 framebuffer and then scaled by 2/3 in hardware?


to post comments

Oversampling, or scaling down

Posted Nov 12, 2014 15:47 UTC (Wed) by juhah (subscriber, #32930) [Link] (6 responses)

xrandr --output <out> --scale 0.75x0.75

Oversampling, or scaling down

Posted Nov 12, 2014 17:41 UTC (Wed) by grunch (subscriber, #16603) [Link]

This article came at a most fortuitous moment. I recently acquired a Lenovo W540, and was on the verge of using it as mainly a compile server for my Gentoo boxes. Between the pixel density and the silly "click pad" thingy I was pretty frustrated.

I had previously used the GNOME tweak tool to change the scaling factor to 2, but gave up too quickly when I encountered the huge magnification issue. And I hadn't even explored the use of xrandr to set the screen scale for the laptop display. Thanks for the enlightening article and comments: life's getting back to "normal" for me with this device!

Oversampling, or scaling down

Posted Nov 13, 2014 8:50 UTC (Thu) by jengelh (guest, #33263) [Link] (2 responses)

xrandr --dpi 120

Oversampling, or scaling down

Posted Nov 13, 2014 12:41 UTC (Thu) by tcourbon (guest, #60669) [Link] (1 responses)

This never seemed to work for me since it didn't change anything on display when I used to try it. It looked like xrandr did not took the new value in account.

Oversampling, or scaling down

Posted Nov 15, 2014 18:03 UTC (Sat) by jospoortvliet (guest, #33164) [Link]

Xrandr works, but I believe GNOME ignores dpi settings. KDE apps obey it so you get a message if you use both. But you can configure dpi for KDE apps, not sure about GNOME.

Oversampling, or scaling down

Posted Nov 13, 2014 10:01 UTC (Thu) by arekm (guest, #4846) [Link] (1 responses)

To "downgrade" 3200x1800 to 1920x1080 on dell xps 15 I need to use:

$ cat /etc/X11/kdm/Xsetup
#! /bin/sh
# Xsetup - run as root before the login dialog appears

/usr/bin/xrandr --dpi 141
/usr/bin/xrandr --output eDP1 --scale 0.6x0.6

Unfortunately:
- tk doesn't suppor HiDPI at all (http://core.tcl.tk/tk/tktview/0917069c05e9c354a27c8105a7a...)
- same for GRUB2 (http://savannah.gnu.org/bugs/?42525)
- same for google-chrome/chromium-browser (https://code.google.com/p/chromium/issues/detail?id=143619)

so the only option now is to "downgrade" to 1920x1080

Oversampling, or scaling down

Posted Nov 13, 2014 16:20 UTC (Thu) by xbobx (subscriber, #51363) [Link]

> tk doesn't suppor HiDPI at all

I think Tk will correctly honor the DPI by default, but ignore DPI if a font size is a negative value. I know this because years ago after a distro update tkdiff started to render at different sizes on my different-DPI monitors, rather than scaling to approximately the same size. I tracked it down to a "bugfix" where somebody changed the default font size to a negative size in order to work around situations where the DPI was set incorrectly (sigh).

Oversampling, or scaling down

Posted Nov 12, 2014 16:42 UTC (Wed) by ken (subscriber, #625) [Link] (10 responses)

As a user of a mac book pro 15 retina I seriously doubt that what you describe is actually happening. It renders directly to 2880x1800 and no additional scaling. that display resolution was done so that you simply double the 1440x600, exactly so you can avoid any fractional scaling values.

perhaps if you insist of running in 1920x1080 it renders in double and then scale back into 2880x1800. but that mode is not something I think anybody would actually want to use.

Oversampling, or scaling down

Posted Nov 12, 2014 17:10 UTC (Wed) by epa (subscriber, #39769) [Link] (9 responses)

If you set the resolution in system preferences to 1920x1200 then it renders to 3840x2400 and scales by 0.75 - see for example http://forums.macrumors.com/showthread.php?t=1665672

I had assumed this was the default setup but that may not be the case, sorry.

Oversampling, or scaling down

Posted Nov 12, 2014 21:07 UTC (Wed) by luto (guest, #39314) [Link] (8 responses)

How does scaling non-high-dpi-aware applications up by a factor of 2 and then down by a factor of 0.75 produce better, let alone different, results from just scaling it up by a factor of 1.5 in the first place?

Oversampling, or scaling down

Posted Nov 13, 2014 2:14 UTC (Thu) by danielkza (subscriber, #66161) [Link] (5 responses)

Many applications can't render fractional pixel sizes, they need integer multipliers, which forces you to render at 2x then scale-down later.

Oversampling, or scaling down

Posted Nov 13, 2014 2:22 UTC (Thu) by luto (guest, #39314) [Link] (4 responses)

Huh?

If an application thinks it's rendering a 100px x 100px window, then presumably all the drawing APIs need to act as though it really is rendering a 100px x 100px window. I assume that this means that applications render into an intermediate buffer, which is then scaled.

Now if an application wants to draw text, and that text will render at higher resolution, and the drawing API won't freak out about the pixels having subpixels, then I can imagine that rendering into a buffer with an integer multiple higher resolution could work, and that downscaling makes sense.

If not, then I still don't see why scaling 100x100 to 200x200 and then to 150x150 makes sense.

Oversampling, or scaling down

Posted Nov 13, 2014 2:35 UTC (Thu) by danielkza (subscriber, #66161) [Link] (3 responses)

What happens with a 101x101px window that gets scaled to 151,5x151,5 pixels? X11 does not handle fractional window sizes. The same will apply to subwindows and controls, to window decorations, and maybe even other things. Fractional scaling in itself is definitely not impossible, but it is mostly impractical due to all the corner cases it might produce.

Oversampling, or scaling down

Posted Nov 13, 2014 2:38 UTC (Thu) by luto (guest, #39314) [Link] (1 responses)

But the alleged Apple approach of scaling up to 2x and then down to 0.75x has exactly the same problem, right?

Oversampling, or scaling down

Posted Nov 13, 2014 15:41 UTC (Thu) by zyga (subscriber, #81533) [Link]

No, because you scale up by x2 and there are no fractional parts to worry about so you get good picture. Then you scale the entire full-screen buffer by 0.75 to get another picture.

This is distinctively different from scaling individual drawing operations by 1.5

Oversampling, or scaling down

Posted Nov 15, 2014 20:11 UTC (Sat) by javispedro (guest, #83660) [Link]

But no one uses X11 subwindows any longer, or so we heard from Wayland developers! </ironic>

On a more serious matter: With Wayland, Gtk+ becomes the owner of the surface, and thus the problem of how you actually render all of your non-integer cordinate widgets becomes Gtk's problem (or OpenGL's).

So this excuse no longer works in a Wayland scenario. Qt has non-integer scaling ratios and they work quite OK.

Oversampling, or scaling down

Posted Nov 13, 2014 11:46 UTC (Thu) by epa (subscriber, #39769) [Link]

If you ask the application to scale by 1.5 then it may produce nasty jaggies in resized icons because they're being crudely scaled up with nearest-neighbour (not anti-aliased). Or it may end up with off-by-one drawing mistakes: if one box is 101 pixels wide and it gets scaled to 151.5, do you round up or down? The drawing code doesn't get much testing under odd scaling factors so it is unlikely to just work.

An integer scaling factor of 2 is much easier to handle: an icon can be exactly pixel-doubled and still look clean. It won't be high res, of course, but at least a one-pixel line in the original will always be exactly two pixels wide in the scaled version. (By contrast, if you scale by 1.5 using a not-very-intelligent algorithm, a one-pixel line could end up either one or two pixels wide depending on its position in the image.)

Then once the application has rendered at 2x scaling, which most are able to manage at least passably, the GPU scales everything by 0.75 using a reasonably good scaling method which anti-aliases and doesn't suffer artefacts from rounding to exact pixel boundaries.

At least, the above is my conjecture based on the fact that Apple chose to do it this way (at least when a 'virtual res' of 1920x1200 is selected). It matches my experience using high-dpi displays in Windows, where a font scaling of 150% looks nasty in many apps but 200% works well enough.

Oversampling, or scaling down

Posted Nov 14, 2014 6:44 UTC (Fri) by ploxiln (subscriber, #58395) [Link]

On OS X, Hi-DPI capable applications render at twice the quality when rendering 2x (in each dimension of course). They're not really "resolution independent", they don't support arbitrary dpi, they just do 1x or 2x. Virtually all applications now at least support 2x text through OS X's CoreText or whatever, and most render fully at 2x quality.

So when they're scaled from 2x to 1.5x, they have extra detail in the 2x pixels, which is then combined/sampled for a much smoother 1.5x scale from the "reference pixel size".

It's a pretty clever way to get more applications to more easily support reasonably Hi-DPI display, IMHO. Just support 2x, and with all that detail the OS can scale that a bit and still have it look good.

Oversampling, or scaling down

Posted Nov 13, 2014 3:22 UTC (Thu) by roc (subscriber, #30627) [Link] (8 responses)

As the developer responsible for high-DPI layout and rendering in Firefox for several years, contrary to my expectations it has turned out that scaling by fractional amounts such as 1.5x is not significantly worse/harder than scaling by an integer.

Oversampling, or scaling down

Posted Nov 13, 2014 11:46 UTC (Thu) by alankila (guest, #47141) [Link]

Yeah, I'd say that if you have a regularity in the expansion then the problem is far simpler. e.g 1.5x scaling implies that each 2 pixels turns into 3 pixels, so you will have fairly uniform result without too prominent moire-like artifacts over it. But as the period grows longer, then I predict that the associated problems become more severe as well.

Oversampling, or scaling down

Posted Nov 13, 2014 11:51 UTC (Thu) by epa (subscriber, #39769) [Link] (6 responses)

It's not much harder to scale by 1.5. You have thought about it, written code which handles it, and at done at least some basic testing. As you say it's not that big a deal.

However there are many legacy applications whose developers never thought about the issue of scaling (let alone by fractional amounts) and which were never tested under such a setup. It would be a mistake to think that you can set a factor of 1.5 and have all of them just work. Perhaps most would, but those that don't handle it properly will turn out fugly or totally unusable.

Therefore, the approach that maximizes compatibility with older software is always to scale by integer multiples. Even then, some older programs misrender (perhaps rendering one part of the window at scaled size while another part is unscaled), but most of the time you get a usable result.

Oversampling, or scaling down

Posted Nov 14, 2014 10:04 UTC (Fri) by roc (subscriber, #30627) [Link] (5 responses)

I mean Firefox scales arbitrary Web pages by fractional scales and they almost always look fine. Those Web pages use complex layouts and generally were not tested over a range of scale factors.

Oversampling, or scaling down

Posted Nov 18, 2014 5:32 UTC (Tue) by quotemstr (subscriber, #45331) [Link] (4 responses)

Thank you. It's frustrating how some people say that "$X is impossible!", and then when confronted with an existence proof of $X, just reiterate the claim that "$X is impossible!".

Fractional scaling in practice works fine; thanks for implementing it in Firefox. I hope the Wayland people come around: for some hardware (like mine), fractional scaling is precisely the right thing. Not everyone owns a Macbook.

If the Wayland developers persist in supporting only integer scaling factors, I suspect desktop environments will just hardcode 1x scaling and make toolkits do fractional scaling, which will be a mess all around.

Oversampling, or scaling down

Posted Nov 19, 2014 9:28 UTC (Wed) by epa (subscriber, #39769) [Link] (3 responses)

I think the point is that there's an existence proof of many legacy programs from the 2000s and 1990s which produce a nasty-looking mess when asked to scale by 3/2 (let alone, say, 4/3). That does not negate the existence of a large body of carefully written programs (of which Firefox is one) which handle arbitrary scaling perfectly. But it is (I presume) the reason why Apple chose to scale by an integer factor and then resize in the GPU if necessary. I quite agree, if starting from scratch then arbitrary dpi need to be supported.

On Linux, the legacy programs may often be ones using X11 server-side fonts. Currently X ships with 75dpi and 100dpi bitmap fonts. If it included 150dpi and 200dpi sets, programs like xterm could use those and so scale up nicely.

Oversampling, or scaling down

Posted Nov 20, 2014 21:48 UTC (Thu) by quotemstr (subscriber, #45331) [Link] (2 responses)

Firefox manages to render plenty of legacy websites that were not designed to be resolution-independent and scale them by fractional values. *That's* the point.

Oversampling, or scaling down

Posted Nov 20, 2014 22:16 UTC (Thu) by dlang (guest, #313) [Link]

HTML is designed to be resolution independent

A lot of web designers have been working hard ever since to undermine this design, but they have had limited success

Oversampling, or scaling down

Posted Nov 21, 2014 11:26 UTC (Fri) by epa (subscriber, #39769) [Link]

An HTML document is not a computer program and does not contain code for scaling glyphs or icons to a particular size. Firefox is, and contains well-written code for those tasks. You may as well say that plenty of legacy Microsoft Word documents can be scaled by fractional values when viewed in Microsoft Word.

Grab a PC running Windows 7 box and set it to 150% font scaling, then try a random assortment of third party software written before 2010. You will see the mess I am talking about - and I assume the situation with older Mac OS X programs is the same.

It is great that Firefox scales well and I quite agree it proves that scaling by an arbitrary factor is *not difficult*. That has very little bearing on whether existing programs, which exist in binary only form and cannot be modified, implement non-integer scaling reasonably. Even if 90% do so, ten per cent do not.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds