View Single Post
Old 21st September 2015, 17:34   #11  |  Link
Desbreko
Registered User
 
Desbreko's Avatar
 
Join Date: Feb 2015
Posts: 55
If the resolution is odd, it will put an extra pixel of padding on the bottom and right sides as needed.

Now that I take another look, the Round function in the left and top variable assignments isn't needed since, again, it's dividing two ints and any remainder is automatically truncated. So those lines could be simplified to this:

left = (hpad-w)/2
top = (vpad-h)/2

Or, if you want the extra padding on the top and left sides instead, you could change them to this:

left = ceil((hpad-w)/2.0)
top = ceil((vpad-h)/2.0)

To crop the padding, here's a function that takes a target width and height and crops the sides of the clip evenly to reach that resolution:

Code:
function CropEven(clip input, int target_width, int target_height)
{
w = input.Width()
h = input.Height()
hcrop = w-target_width
vcrop = h-target_height

lcrop = Floor(hcrop/2.0)
tcrop = Floor(vcrop/2.0)
rcrop = Ceil(hcrop/2.0)
bcrop = Ceil(vcrop/2.0)

return input.Crop(lcrop, tcrop, -rcrop, -bcrop)
}
Like the padtomod function, it will crop the extra pixels off the bottom and right sides if the target resolution is odd. If you want it to crop them from the top and left instead, you can swap the Floor and Ceil calls.
__________________
Twitter, AviSynth scripts
Desbreko is offline   Reply With Quote