View Single Post
Old 13th April 2019, 22:20   #2  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,883
What you are looking for is ResizeKAR:

In your case, just use:

Code:
ResizeKAR(1366, 768, "BicubicResize")
By the way, I suggest you to use LanczosResize as resizing kernel over Bicubic.

Code:
# ResizeKAR() - May 8th, 2008
#  Resize the source keeping the aspect ratio, by adding a border when needed.
# 
# Input:
#  clip c: input clip.
#  int width: output width
#  int height: output height
# Optional:
#  string ResizeMethod: Default(BilinearResize)
#  int BackgroundColor: Default($000000)
#  bool NoBorders: Resizes without adding borders. Default(False)
# 
# Notes:
#  Respects ColorSpace Restrictions

function ResizeKAR(clip c, int width, int height, string "ResizeMethod", int "BackgroundColor", bool "NoBorders")
{
	BackgroundColor = Default(BackgroundColor, $000000)
	ResizeMethod = Default(ResizeMethod, "BilinearResize")
	NoBorders = Default(NoBorders, False)
	
	ratioS = Float(width(c))/Float(height(c))
	ratioD = Float(width)/Float(height)
	newW = Round(height*ratioS/2)*2
	newH = Round(width/ratioS/2)*2

	BorderH = (NoBorders==True) ? 0 : Round((height-newH)/2)
	BorderW = (NoBorders==True) ? 0 : Round((width-newW)/2)
	
	#Dest Higher Then Source; Dest Wider Then Source; Same Ratio
	c = 
	\	(ratioS>ratioD) ? 
	\	Eval(ResizeMethod + "(c, " + String(width) + ", " + String(newH) + ")").
	\	AddBorders(0, BorderH, 0, BorderH, BackgroundColor) :
	\	(ratioS<ratioD) ? 
	\	Eval(ResizeMethod + "(c, " + String(newW) + ", " + String(height) + ")").
	\	AddBorders(BorderW, 0, BorderW, 0, BackgroundColor) :
	\	(ratioS==ratioD) ?
	\	Eval(ResizeMethod + "(c, " + String(width) + ", " + String(height) + ")" ) :
	\	nop()
	
	#fix 1px changes, works only with 4:4:4
	c = 
	\	(IsRGB(c)) && (width>width(c)) && (NoBorders==false) ? c.AddBorders(0, 0, 1, 0) : 
	\	(IsRGB(c)) && (height>height(c)) && (NoBorders==false) ? c.AddBorders(0, 0, 0, 1) : 
	\	c
	return c
}
FranceBB is offline   Reply With Quote