View Single Post
Old 27th November 2011, 22:35   #1  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
PARResize() | PAR-aware resizing function

PARResize() is useful for standards conversions and arbitrary anamorphic pixel resizing.

It can automatically detect the "correct" input and output PAR using the assumptions here. Or you can specify SourcePAR or TargetPAR as a decimal or fraction string.

It operates in two modes: Boxing=true (default) will add borders to achieve the target dimensions. When Boxing=false, it will crop the source to match the PAR-compensated target dimensions.

100% AviSynth, no dependent DLLs required.
Download it here

Code:
#####################################################################################################
# PARResize()
# 2011/11/29
#####################################################################################################
#
# Parameters:
#
# TargetWidth, TargetHeight [integer]
#       These determine the output width and height
# SourcePAR, TargetPAR [string or float]
#       These determine the PAR of the input and output, respectively
#       Legal vales are either a floating decimal PAR (ex: SourcePAR=0.909091) or a string
#       The allowed string values are:
#               "" (default)
#                       A blank string will set the corresponding PAR automatically, assuming 4:3 DAR
#               "ws"
#                       A value of "ws" (widescreen) will set the corresponding PAR automatically, assuming 16:9 DAR
#               Fractional String
#                       You can also use fractions as strings (Example: SourcePAR="10/11", TargetPAR="40/33")
# Boxing [boolean]
#       When Boxing=true (default), borders will be added to achieve the TargetWidth or Height as needed
#       When false, PARResize will crop the source as needed to achieve the target DAR
# Color [int]
#       The Color parameter determines the border color when Boxing=true
# CropBias [float]
#       When CropBias=0.5 (default), any cropping of the source will be symmetrical
#       Setting it lower (minimum is 0.0) will show more of the source's left or top, cropping more from the right or bottom
#       Setting it higher (minimum is 1.0) will show more of the source's right or bottom, cropping more from the left or top
#       CropBias has no effect if Boxing=true
#
#####################################################################################################
Examples:
Code:
# Assume 4:3 input and resize to 4:3 NTSC DVD
PARResize(720, 480, SourcePAR="", TargetPAR="")

# Assume widescreen input and output
PARResize(720, 480, SourcePAR="ws", TargetPAR="ws")

# Use arbitrary PARs
PARResize(176, 576, SourcePAR=1.0, TargetPAR="472/81")

# Assume an HD source, convert to widescreen DVD specs
# Here, Boxing=false will crop a few lines from the source before scaling to fill the width
PARResize(720, 576, "ws", "ws", Boxing=false)

# Assume an HD source, convert to 4:3 DVD specs
# Here, Boxing=false will crop the sides to fit the screen
PARResize(720, 576, "ws" , "", false)

#  Set the letterboxing color to white
PARResize(704, 480, color=$FFFFFF)
I have tested it with standard input/output. More testing is needed for odd-sized sources and output and arbitrary PARs. There is some sanity-checking... you can also set debug=true to see what is going on behind the scenes with the numbers.

Last edited by vampiredom; 29th November 2011 at 22:37. Reason: revision 2011/11/29 - fixed a bug
vampiredom is offline   Reply With Quote