LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 03-17-2024, 06:02 PM   #1
KISSAndStable
LQ Newbie
 
Registered: Oct 2020
Distribution: Slackware
Posts: 20

Rep: Reputation: Disabled
Compensating for non-square pixels


COMPENSATING FOR NON-SQUARE PIXELS

Computer programs make the assumption that the pixels on a screen are exactly square: that the width and the height of each pixel take up the same space on the screen. On real screens, that's not always true.

Of course, whether that matters is up to you. The following is an outline of A) how an X server can tell you whether your pixels are square; and B) how to tell at least some programs to compensate if they're not.

HOW AN X SERVER CAN TELL YOU WHETHER YOUR PIXELS ARE SQUARE

Code:
xdpyinfo | grep resolution
resolution:    384x386 dots per inch
On this (imaginary) screen, 384 'dots' (pixels) fill one inch of *width*, but it takes 386 pixels to fill one inch of *height*.

This means that the pixels on our imaginary screen are not square. Our pixels are a little wide, compared to their height. It takes fewer of our pixels to make a width, more of them to make a height.

DO YOU CARE?

Our imaginary pixels are about 0.5 percent wider than they are high. Their widths take up slightly more screen area than their heights.

In our imaginary example, a program that draws a square of 384x384 pixels will display a figure that fills 1 inch of the *width* of our imaginary screen, but 0.9948 inch of its height.

Does that matter? Does it matter on your screen for figures 10 times that size? Only your own eyes can tell you.

A MISTAKE I MADE, BUT THE CORRECTION STILL WORKS IN IMAGEMAGICK

If the X server tells you that you have non-square pixels, you have non-square pixels.

Previously I thought that you can tell gtk3 (and gtk4) programs, as well as QT5 programs, to compensate for non-square pixels, but I was probably wrong.

There's a difference between "display ratio" and "pixel ratio" that I had not previously taken into account.

I now think that gtk3, gtk4, and QT5 programs only adjust display ration (they adjust width and height simultaneously, by the same amount).

That means that they will not compensate for pixel ratio (which is the ratio of width/height in pixels, and thus requires width and height to be capable of being adjusted independently).

However, ImageMagick can still compensate for non-square pixels, in the manner I describe here.

By the way, non-square pixels that have the opposite problem than our too-wide pixels -- non-square pixels that are not wide enough -- have a similar treatment that will not be outlined here.

In our example, by our previously derived xdpyinfo ("resolution: 384x386 dots per inch") our pixels are too wide by 386/384.

The inverse of 386/384 is 384/386, which gives us our correction factor.

If programs apply this correction factor to widths, while not touching heights, we compensate for our too-wide pixels.

So:

Code:
echo "384/386" | bc -l
0.99481865284974093264
We need to pare down our widths by 0.99481865284974093264. That's too long a number! It turns out that a correction factor of 0.9948 is more than accurate enough for (say) a real-world 3840x2160 pixel screen.

Here's how we instruct ImageMagick to display images with the width correction.

Code:
display -resize 99.48%x100% [our image]
(99.48% == 0.9948)

We can also make images bigger or smaller that carry over the correction without additional calculation. For instance:

Code:
magick [our image] -resize 99.48%x100% - | display -resize 3800x1920 -
Code:
magick [our image] -resize 99.48%x100% - | display -resize 300% -

Last edited by KISSAndStable; 03-17-2024 at 07:15 PM.
 
Old 03-18-2024, 05:31 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,309

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
They don't matter whether they're slightly off or not. Can you watch NTSC, PAL, or SECAM television programs or is your attention drawn to the mess on the screen? I bet you can, unless you make a conscious effort to detach yourself from the program and watch the tv picture instead.

NTSC is low resolution (525p) 60Hz interlaced (= 30Hz screen refresh) and each alternate pass is tinted red or blue by any signal ghosting going on. TV signal ghosting is like audio echo. The eyes & ears mush it all together, and you can see the game/whatever, because your eyes filter it out.

PAL is 625p @50 HZ interlaced and it learned from NTSC. So each alternate line it tinted red. then blue and the eyes much that together.

SECAM learned from both systems, and does 819p and is probably the best of the lot. But it too, relies on video distortions being fudged by the human eye. The human eye does the job quite nicely.

By comparison with transmitted signals monitors are more precise. I strongly suggest you stop obsessing about pixel shape. The only place a pixel shape has any effect will be a tiny percentage of distortion on colour changes. And your eyes lie to you about much bigger things than that. Enjoy the pictures on your monitor, relax, and don't obsess about unimportant details.
 
Old 03-18-2024, 12:30 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,662
Blog Entries: 4

Rep: Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942
Typically, with all monitors, the pixels are square. And, increasingly, the colors are (or can easily be) calibrated.

However, if you are producing video, intended (say ...) to be watched on some sort of "portable video player device" – as I actually do with museum kiosks – you do need to be aware of how "lesser, cheaper" equipment might still work. And, you very much need to look at your final intended result on the actual device(s). Likewise if you are making audio for cheap MP3 players – yes, they're still out there.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Circle square; How draw/compute w square pixels? Trigonometry, language rico001 Programming 6 04-27-2016 04:48 PM
[SOLVED] in Fedora 11 square screen have not adjust square of monitor. us_ed Linux - Hardware 27 10-05-2010 12:35 PM
Compensating for spaces cerin Linux - Newbie 2 01-10-2006 05:33 AM
Strange mouse resolution ? 2 pixels by 2 pixels Creak Linux - General 8 04-18-2004 07:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 11:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration