My life as a square (pixel)


The shape of the Windows screen pixel has changed over the years. It has always had a rectangular shape, but the ratio of height to width has varied. (Someday, somebody will come up with a display adapter with hexagonal or triangular pixels, and then everything will fall apart.)

Our story begins with the Color Graphics Adapter, better known by the abbreviation CGA. Depending on the video mode, your pixels could be 1:1.2 in 320×200 color mode (all aspect ratios are given in the form width:height for some reason), or 1:2.4 in 640×200 monochrome mode. Windows used the monochrome mode because the colors available in color mode were pretty useless. You could have black, white, hot pink, and aqua; or you could have black, brown, orange-red and green (no white!). Hideous colors no matter how you slice it.

The next major advancement in display adapter technology was the Enhanced Graphics Adapter (EGA), which brought you a stunning 16 colors in a 640×350 grid with an aspect ratio of 1.83:1. But for the step forward in terms of color, you also took a step backwards into the insanity of planar video modes. EGA memory was arranged in planes, and what's worse, each plane had the same memory address! You had to use other registers to program the video card to tell it which plane you wanted to talk to when you accessed a specific memory address. (And the memory behaved differently depending on whether you were reading from it or writing to it.)

Next to arrive was VGA, the Video Graphics Array. (I like how the names of all the display adapters are largely meaningless.) VGA brought us square pixels, if you used them at 640×480 resolution (which is what Windows did). Finally, you had a display adapter where a stair-step pattern actually gave you a 45-degree line.

Pretty much every display adapter since VGA has supported square pixels, and pretty much every display driver preferred those square modes instead of the non-square modes. If you go into the Windows Display control panel, you can force one of the weird non-square modes, but all of the standard dimensions (800×600, 1280×1024, etc.) use square pixels.

Okay, so how does a program obtain the pixel aspect ratio? You start by getting a device context (or if you're really clever, an information context) for the device you are interested in, and then ask for the ASPECTX and ASPECTY device capabilities. These capabilities tell you the relative width and height of a pixel. If the x-aspect and y-aspect are equal, then you have square pixels. If not, then their ratio tells you the aspect ratio.

As a special bonus, there is also the ASPECTXY device capability, which is the length of the diagonal of a pixel, relative to the other aspect values. This is something you can calculate yourself based on the other two metrics, but it's provided as a courtesy. Let x be the value of the ASPECTX device capability, y be the value for ASPECTY, and h be the value for ASPECTXY (h for hypotenuse). Then the values are related by the formula

h² = x² + y²

(Of course, there will be rounding errors since all the device capabilities are integers.)

Now that non-square pixels have been pretty much entirely replaced by square pixels in the past fifteen years, I wonder how many programs will start looking weird once a display with non-square pixels is reintroduced to the world of Windows. With newer and more unusual form factors for PCs coming out all the time, it's perhaps just a matter of time before a non-square-pixel display becomes the new must-have device. (And that time appears to have come: Pixels on HD TVs are not always square.)

The reality of non-square pixels explains why most metrics come in both horizontal and vertical versions.

Comments (32)
  1. John says:

    One day, they are going to fix this blog software so that links to comments work.  One day…

  2. I remember that back when I did some graphics in QB4.5 the fact that almost any SCREEN mode had nonsquare pixel ratios made me quite upset. Fortunately I had a VGA card, so when I found SCREEN 12 I forgot about all the other modes.

    Uh, there's still the KB article… support.microsoft.com/…/en "640 x 480 pixel very high-resolution graphics.", read today it's quite funny :)

  3. GregM says:

    If the resolution's aspect ratio doesn't match your monitor's aspect ratio (8:5 for widescreen monitors and 4:3 for standard monitors), then the pixels aren't square.  Much to my annoyance, one of those standard resolutions, 1280×1024, does not have square pixels, as its aspect ratio is 5:4.  If you want square pixels, you need 1280×960, which very few cards support.  I had one for a while, but that was a long time ago.  Fortunately, I then moved up to 1600×1200, which is back to square pixels again, and then 1920×1200 on widescreen monitors.  The software that I write allows entering your monitor dimensions so that we can deal with these non-square pixels, so that a circle actually looks round on your screen, and also so that we can make a 6" circle at a scale of 1:1 actually be 6" on your screen.

  4. Marquess says:

    “all aspect ratios are given in the form width:height for some reason”

    Well, 2D coordinates specify the width first and the height second. It would be kinda silly if the biggest coordinate on a 480×640 display would be addressed as (640,480), wouldn't it?

  5. Philip says:

    Hexagonal pixels make a lot of sense. If you build a screen with square pixels, you can display horizontal/vertical signals with a 2px wavelength perfectly well (i.e. alternating on/off columns or rows), but the worst case is diagonal signals where the minimum wavelength is sqrt(2)*2px. Rotate a high-frequency signal (e.g. small sharp text) by 45 degrees and it will turn into a blurred mess, because the pixels are 41% larger (lower resolution) in the diagonal direction.

    Hexagons have a much smaller difference between their best and worst directions – I believe they're optimal among all tiling patterns. So replace the screen's square pixels with the same number of hexagons, and you get the best possible worst-case resolution. Admittedly it's less good for straight horizontal and vertical lines, but it'd be great for photographs and for the modern world of rounded corners and GPU effects.

    But triangular pixels? That's just crazy.

  6. Tom says:

    @GregM: Monitors with native 1280×1024 resolution are indeed 5:4, not 4:3.  Take out a ruler and measure one.

    Many widescreen monitors are 16:9 rather than 16:10 (or, as you prefer, 8:5).  Largely because the manufacturer can then reuse panels designed for HDTVs.

  7. JamesW says:

    You can always split your hexagonal tiling into a triangular tiling. So, triangles can do everything that hexagons can, but also let you operate at a finer level.

  8. Ridley says:

    Pretty sure that first CGA resolution should be 320×200, not 240 :)

    [Fixed, thanks. -Raymond]

    The old CGA I remember supported a green/yellow/black/red mode… I might be misremembering though, my first computer was EGA (still have my EGA/VGA programmer's reference guide…)

  9. Philip says:

    JamesW: I was assuming the number of pixels (and the area of each pixel) was a constant (probably determined by the hardware cost). If you are able to split each hexagon into six triangles, each with a sixth of the original hexagon's area, you could instead replace each hexagon with six smaller hexagons and you'd have even finer resolution.

  10. Many more caps says:

    Using ASPECTX and ASPECTY sounds straight-forward, except that there is LOGPIXELSX/Y, and HORZ/VERTSIZE+HORZ/VERTRES, two more ways to apparently do the same thing. I know that LOGPIXELSX/Y can be modified by the user and is by default 96, regardless of the display, but I am at a loss to decide which function to use when. There is also SCALINGFACTORX/Y, but I guess that's only for printers?

    Arno

  11. Bob says:

    @Ridley: Yeah, it was 320×200. And you're being kind to CGA. The two palettes were (in EGA/VGA/QBColor terms) 0/2/4/6 (old-style brown) and 0/11/13/15, though as I recall you could map color 0 (normally black) to any of the 16 standard colors.

  12. @Philip: the six triangles of each hexagon could actually be exploited as subpixels, it would be quite an intelligent solution.

  13. Adrian says:

    If you deal with printers, you still have to worry about non-square pixels — and broken drivers.  I remember having to put shims in for certain drivers that forgot to swap their horizontal and vertical resolutions when you switched from portrait to landscape in the middle of a print job.

    And I've always wondered how to specify the lfHeight field when you're displaying rotated text on a device with non-square pixels.  Empirically, there seems to be no "right" way, as different drivers handle it differently.

  14. GregM says:

    "@GregM: Monitors with native 1280×1024 resolution are indeed 5:4, not 4:3.  Take out a ruler and measure one."

    Tom, this was long before LCD panels.

    "Many widescreen monitors are 16:9 rather than 16:10 (or, as you prefer, 8:5).  Largely because the manufacturer can then reuse panels designed for HDTVs."

    True, I have both sitting in front of me right now.  My notebook and main monitor are 1920×1200, and the multitouch one is 1920×1080.

  15. Roger says:

    Then there was ICL's EGA adaptor.  (ICL was a large UK computer company.)  It had an extra row at the bottom of the screen where you could put additional messages.  One use was using the computer in an office environment and it would integrate with the phone system displaying caller and similar information in that extra row.  Of course almost no programs knew about the extra area so they didn't clear it when changing the screen contents leaving all sorts of detritus there.

    You are probably wondering how the telephony program ran at the same time as your office applications since MS-DOS didn't support multi-tasking.  The answer is MS-DOS version 4.  Not what was released as the MS-DOS 4 we all know today, but an earlier release named MS-DOS 4 done by Microsoft for ICL (and Apricot I believe) that did support multi-tasking.

  16. rs says:

    If you go into the Windows Display control panel, you can force one of the weird non-square modes

    Does this depend on the driver or hardware? I just did EnumDisplaySettings/ChangeDisplaySettings on my machine and got ASPECTX=36, ASPECTY=36, HORZSIZE=320, VERTSIZE=240 for all display modes (26). Is there a way to set ASPECTX and ASPECTY to different values for testing programs?

  17. Leo Davidson says:

    I run Win7 Media Center through my plasma TV which has rectangular pixels. It's 16:9 with native res of 1280×768.

    I have to run Windows at 1280×720 instead of the native res as otherwise all video content gets squashed.

    Anyone know if Media Center (and the MPEG2 decoder if relevant) understand rectangular pixels? I've always assumed they simply don't but maybe the OS just doesn't realise the display's aspect and I need to force the information in somewhere.

  18. Yuhong Bao says:

    "You are probably wondering how the telephony program ran at the same time as your office applications since MS-DOS didn't support multi-tasking.  The answer is MS-DOS version 4.  Not what was released as the MS-DOS 4 we all know today, but an earlier release named MS-DOS 4 done by Microsoft for ICL (and Apricot I believe) that did support multi-tasking."

    Yes, Larry Osterman wrote about it sometimes.

  19. Gabe says:

    Back in the old days, a CGA card plugged into a CGA monitor, so any program talking to a CGA device knew the dimensions of each pixel. The EGA, VGA, and XGA (8514) were the same way. Once monitors came out that could show arbitrary resolutions, it became nearly impossible to tell the size of a pixel on the monitor, and you had to rely on the user telling you (and short of that, assume 96dpi square pixels).

  20. Stephane says:

    "Pixel" is a fuzzy notion, something that only exists for convenience. In the real world, there are only dots.

    Many digital camera displays use a setup where even rows have RGRGRGRG… dots (no blue), and odd rows have GBGBGBGB… dots (not red). Each dot being usually about square. It's pretty hard to come up with a pleasing notion of pixel in these conditions.

  21. MP says:

    640×350 grid with an aspect ratio of 1.83:1

    Shouldn't that be 1:1.37?

  22. fowl says:

    @Leo Davidson

    Does this help? a.yfrog.com/…/pixelaspectratio.png

  23. fowl says:

    They're not all together consistently named.

    en.wikipedia.org/…/File:Vector_Video_Standards2.svg

    Notice the 3 "WXGA"'s

  24. Jonathan says:

    I never understood why "Super-VGA" went with the weird 1280*1024 res (on 4:3 CRTs). Maybe it was so you could fix a 24-bit frame buffer on a 4MB card. That was certainly the motivation for the Mac's 1152*864 res, which is almost exactly 1 megapixel.

    VGA also had the handy mode 0x13, which was 320*200*256colors, which was really easy to program to – 1 byte = 1 pixel. The pixels were 1.2:1 though, like CGA.

    And let's not forget the unofficial "Mode X", which could get 320*240*256 out of VGA, and even 320*480 with 1:2 aspect ratio (or 360X480 with 9:16 aspect ratio). It sure benefited games like Pinball Fantasies or Scorched Earth.

    en.wikipedia.org/…/Mode_X

  25. zahical says:

    I wonder how we got this far in comments on an article containing the words "pixel" and "square" in the same sentence without mentioning the "A Pixel Is Not A Little Square" memo by Microsoft's own Alvy Ray Smith.

    (The missing link http://www.alvyray.com/…/6_pixel.pdf)

  26. Erzengel says:

    The Sims 2, I think, provides circle pixels as an option. I sometimes wondered what the pixel shader looked like that allowed them to do that (and sometimes I wondered what was the point of doing that, too)

  27. Drak says:

    @Erzengel:

    Never had a CM8833 CGA monitor? The pixels on it were sort of faded around the edges, making them look round. I always preferred that because it was kind-of a built in anti-aliasing. I always thought PCs with vga had too 'well-defined' pixels making everything look jagged.

    Of course, these days, with more pixels / inch it's not so bad anymore :)

  28. I fondly remember how the Acorn BBC Micro did it. The non-text screeen modes all had a virtual size of 1280×1024, which was way oversize anything we'd ever need back then. No matter what size or shape the actual pixels were, you would always get the right image when running the same draw-line commands within the virtual screen.

    They also put the 0,0 pixel in the lower left, cartesian like. It seemed very odd when I moved to other machines which had 0,0 in the top left.

  29. Leo Davidson says:

    @fowl

    Thanks for the suggestion. I hadn't noticed that before in Media Player. Unfortunately, it doesn't seem to affect Media Center (at least not playback of MPEG2 DVB-T digital TV, which still comes out assuming square pixels).

  30. TuxMan says:

    What about the hercules graphics adapter? With a resolution of 720×348 and the ability to work as a CGA Adapter with an emulator software. Only monochrome but it didn't really matter. It was programable with e.g. QuickBasic/Basic PDS (Screen 3 and using a special driver).

  31. TuxMan says:

    What about the hercules graphics adapter? With a resolution of 720×348 and the ability to work as a CGA Adapter with an emulator software. Only monochrome but it didn't really matter. It was programable with e.g. QuickBasic/Basic PDS (Screen 3 and using a special driver).

Comments are closed.

Skip to main content