hyprwm / Hyprland

Hyprland is an independent, highly customizable, dynamic tiling Wayland compositor that doesn't sacrifice on its looks.
https://hyprland.org
BSD 3-Clause "New" or "Revised" License
21.71k stars 901 forks source link

Anamorphic scaling #4608

Open cjuniorfox opened 9 months ago

cjuniorfox commented 9 months ago

Description

In some cases, worth setting up anamorphic scaling, like when you're using an NTSC like CRT and setting up output models to deal with. The pixel clock for the horizontal resolution needs to be at least double the original horizontal resolution to have the proper timing for the blanking interval. So, you could have unusual output modes like 1440x240. To obtain the 720x480 output from that mode, you need to scale the horizontal resolution in half while scaling double the vertical resolution. On X11, the scaling works well. You can play around on X11 using the Python script chvideo.py that I wrote originally for the Raspberry Pi but works ok on X11 if you add the '-m' flag.

vaxerski commented 9 months ago

what?

cjuniorfox commented 9 months ago

Let me explain. If you're using one of these HDMI to Component adapters, it's possible to hook up the computer to an old CRT television via component cables. This adapter is great because it doesn't do any downscaling of so. Instead, it converts that signaling from digital to analog, just converting the color space from what HDMI is working with to YPbPr, which is great for some use cases but demands the OS to handle the signal to feed the TV set. The parameters for using this kind of TV set are tightly bound to precise signaling timings. In particular the back porch, front porch, and blanking interval. The timing needs to be very precise or you could harm the image quality or don't have an image at all.

So, for instance, to set up a compatible NTSC Standard resolution (720x488 interlaced), in the first moment, the modeline parameters were supposed to be like this: "720x488_30" 13.712213 720 741 805 871 488 494 501 525 +HSync -VSync Interlace But you will end up with a longer back porch signal than was supposed to be, overlapping the blanking interval, which harms the image quality and causes issues with the synchronization.

To handle this, then you need to double the pixel clock, which effectively doubles the horizontal resolution, ending up with the following modeline: "1440x488_30" 27.420750 1440 1482 1611 1741 488 494 501 525 +HSync -VSync Interlace That way, the TV image is perfect but is anamorphic, everything is "squeezed" horizontally So, the solution on X, is scaling down the horizontal resolution while maintaining the vertical one, using the command below (after creating the intended modeline):

xrandr --output HDMI-1 --mode 1440x488_30 --scale 0.5x1

Works on X, but I don't have an equivalent way to do the same on Hyprland.

More details about at the project https://github.com/cjuniorfox/retropie-crt/

vaxerski commented 9 months ago

you can do that when mirroring, technically, as mirroring will stretch the image to fit.

cjuniorfox commented 9 months ago

Makes sense. The framebuffer will be created with specs for the main screen, while the second display will mirror the content from the same framebuffer. Is my assumption correct?

Assuming I'm right, could I create a "fake display" within expected specs and mirror this "fake screen"?

vaxerski commented 9 months ago

(not exactly but the analogy works 1:1 so yes) and yes