StainlessS
4th April 2017, 08:18
Hi guys,
I'm wondering if there is any consensus on a better resizer for downsizing ?
This pretty much seems to work ok, but would like recommendation for the actual downsizer (I guess might be used for upsize too).
# ResizePadded.avs
Function ResizePadded(clip clp,Int W, Int H,
\ Int "xMod",Int "yMod",
\ Float "Bicub_b",Float "Bicub_c",
\ Int "src_left", Int "src_top", Int "src_width", Int "src_height",
\ Bool "Pad_Rec601"
\ ) {
/*
https://forum.doom9.org/showthread.php?t=174496
Req RT_Stats, mt_Tools v2.0.
Intended for downsize, where return clip dimensions are modulo xMod,yMod but some of result frame (right and bottom) may be padding,
ie if resize to W=29,H=29, and xMod=4,yMod=4, then frame will be 32x32, x=0,y=0,w=29,h=29 is valid graphic,
but rightmost and bottom most 3 pixels are padding only.
For use where mask used to apply valid graphic using eg Overlay.
Any Padding area will be returned as BLACK (0 for RGB or Y of YUV [not rec601 16 unless Pad_Rec601==True]).
Args:-
W,H Output size for return clip
Same colorspace as input clip, output may be Right and Bottom padded to Black, to comply with xMod,yMod requirement.
xMod, Default = natural colorspace alignment requirement of input and output clips,
yMod eg for YV411:- xMod=4,yMod=1. YV12:- xMod=yMod=2. YV16/YUY2:- xMod=2,yMod=1. Y8/YV24/RGB/24/32:- xMod=yMod=1.
Bicub_b, BicubicResize() b and c args. (If supplied as args, BEST SUPPLY BOTH Bicub_b and Bicub_c)
Bicub_c Default:-
DownSize b = -0.5, c = 0.25, Groucho2004,Didée:- https://forum.doom9.org/showthread.php?p=1802716#post1802716
Upsize, b = 0.0, c = 0.5, Catmull-Rom spline, sharp.
Avisynth BicubicResize() defaults are:- b=1.0/3, c=1.0/3
src_left, Source clip area to resize, all default 0, meaning full frame, as in Crop(0,0,0,0).
src_top,
src_width,
src_height
Pad_Rec601 Default False.
We normally return any YUV padding as Black Y=0, will change to padding Y = 16 if this set true.
NOTE, If using this function for resizing mask for use with overlay, you are UNLIKELY to
want to change this to True (you may get ghosts in your overlays).
If resizing a graphic intended for Overlay clip (together with a mask), then it probably makes little/no
difference whether you set Pad_rec601 to true or false.
RGB padding is always returned as Black $000000.
*/
clp myName="ResizePadded: "
DefXmod = RT_ColorSpaceXMod DefYmod = RT_ColorSpaceYMod(Laced=False) # Natural ColorSpace alignment for input clip
xMod=Default(xMod,DefXmod) yMod=Default(yMod,DefYmod)
Assert(0 < xMod && xMod % DefXmod == 0, RT_String("%sIllegal xMod(%d, DefXMod=%d)",myName,xMod,DefXmod))
Assert(0 < yMod && yMod % DefYmod == 0, RT_String("%sIllegal yMod(%d, DefYMod=%d)",myName,yMod,DefYMod))
Bicub_b = Default(Bicub_b, (W<clp.Width) ? -0.5 : 0.0)
Bicub_c = Default(Bicub_c, (W<clp.Width) ? 0.25 : 0.5)
src_left = Default(src_left,0) src_top = Default(src_top,0) src_width = Default(src_width,0) src_height = Default(src_height,0)
Pad_Rec601 = Default(Pad_Rec601,False)
Assert(0 <= src_left < Width, RT_string("%s0 <= src_left(%d) < Width(%d)",myName,src_left,Width))
Assert(0 <= src_top < Height, RT_string("%s0 <= src_top(%d) < Height(%d)",myName,src_top,Height))
src_width = (src_width <= 0) ? width - src_left + src_width : src_width
src_height= (src_height <= 0) ? height - src_top + src_height : src_height
Assert(0 < src_width <= Width, RT_String("%s0 < src_width(%d) <= Width(%d)",myName,src_width,Width))
Assert(0 < src_height <= Height, RT_String("%s0 < src_height(%d) <= Height(%d)",myName,src_height,Height))
CanvasW=(W+xMod-1)/xMod*xMod CanvasH=(H+yMod-1)/yMod*yMod # O/P frame size (rounded up to next multiple of xMod,yMod if necessary)
iPadR=CanvasW-W iPadB=CanvasH-H # O/P padding pixels (Right and Bottom)
fPadR=Float(iPadR)*src_width/W fPadB=Float(iPadB)*src_height/H # Fractional pixels to reach into source clip to achieve padding.
BicubicResize(CanvasW, CanvasH, b=Bicub_b, c=Bicub_c ,
\ src_left = src_left, src_top = src_top,
\ src_width = src_width+fPadR, src_height = src_height+fPadB
\ )
# Padding to BLACK : Cannot use LetterBox for YUV as will be set to Y=16 not Y=0 [Unless Pad_Rec601=True, then OK].
Last = (0 == iPadR == iPadB) ? Last
\ : (IsRGB() || Pad_Rec601) ? Letterbox(0,iPadB,0,iPadR)
\ : mt_merge(Last,
\ Last.BlankClip(Color_Yuv=$008080),
\ Last.mt_lutspa(relative=false,expr=RT_String("x %d >= y %d >= | 255 0 ?",W,H),chroma="-128"),luma=true)
Return Last
}
EDIT: I'm quite happy to take the first suggestion (If wrong, I can blame it on someone else :) )
https://www.cosgan.de/images/smilie/set/001.gifhttps://www.cosgan.de/images/smilie/set/020.gifhttps://www.cosgan.de/images/smilie/set/016.gifhttps://www.cosgan.de/images/smilie/set/013.gifhttps://www.cosgan.de/images/smilie/set/023.gifhttps://www.cosgan.de/images/smilie/set/006.gifhttps://www.cosgan.de/images/smilie/set/005.gif
I'm wondering if there is any consensus on a better resizer for downsizing ?
This pretty much seems to work ok, but would like recommendation for the actual downsizer (I guess might be used for upsize too).
# ResizePadded.avs
Function ResizePadded(clip clp,Int W, Int H,
\ Int "xMod",Int "yMod",
\ Float "Bicub_b",Float "Bicub_c",
\ Int "src_left", Int "src_top", Int "src_width", Int "src_height",
\ Bool "Pad_Rec601"
\ ) {
/*
https://forum.doom9.org/showthread.php?t=174496
Req RT_Stats, mt_Tools v2.0.
Intended for downsize, where return clip dimensions are modulo xMod,yMod but some of result frame (right and bottom) may be padding,
ie if resize to W=29,H=29, and xMod=4,yMod=4, then frame will be 32x32, x=0,y=0,w=29,h=29 is valid graphic,
but rightmost and bottom most 3 pixels are padding only.
For use where mask used to apply valid graphic using eg Overlay.
Any Padding area will be returned as BLACK (0 for RGB or Y of YUV [not rec601 16 unless Pad_Rec601==True]).
Args:-
W,H Output size for return clip
Same colorspace as input clip, output may be Right and Bottom padded to Black, to comply with xMod,yMod requirement.
xMod, Default = natural colorspace alignment requirement of input and output clips,
yMod eg for YV411:- xMod=4,yMod=1. YV12:- xMod=yMod=2. YV16/YUY2:- xMod=2,yMod=1. Y8/YV24/RGB/24/32:- xMod=yMod=1.
Bicub_b, BicubicResize() b and c args. (If supplied as args, BEST SUPPLY BOTH Bicub_b and Bicub_c)
Bicub_c Default:-
DownSize b = -0.5, c = 0.25, Groucho2004,Didée:- https://forum.doom9.org/showthread.php?p=1802716#post1802716
Upsize, b = 0.0, c = 0.5, Catmull-Rom spline, sharp.
Avisynth BicubicResize() defaults are:- b=1.0/3, c=1.0/3
src_left, Source clip area to resize, all default 0, meaning full frame, as in Crop(0,0,0,0).
src_top,
src_width,
src_height
Pad_Rec601 Default False.
We normally return any YUV padding as Black Y=0, will change to padding Y = 16 if this set true.
NOTE, If using this function for resizing mask for use with overlay, you are UNLIKELY to
want to change this to True (you may get ghosts in your overlays).
If resizing a graphic intended for Overlay clip (together with a mask), then it probably makes little/no
difference whether you set Pad_rec601 to true or false.
RGB padding is always returned as Black $000000.
*/
clp myName="ResizePadded: "
DefXmod = RT_ColorSpaceXMod DefYmod = RT_ColorSpaceYMod(Laced=False) # Natural ColorSpace alignment for input clip
xMod=Default(xMod,DefXmod) yMod=Default(yMod,DefYmod)
Assert(0 < xMod && xMod % DefXmod == 0, RT_String("%sIllegal xMod(%d, DefXMod=%d)",myName,xMod,DefXmod))
Assert(0 < yMod && yMod % DefYmod == 0, RT_String("%sIllegal yMod(%d, DefYMod=%d)",myName,yMod,DefYMod))
Bicub_b = Default(Bicub_b, (W<clp.Width) ? -0.5 : 0.0)
Bicub_c = Default(Bicub_c, (W<clp.Width) ? 0.25 : 0.5)
src_left = Default(src_left,0) src_top = Default(src_top,0) src_width = Default(src_width,0) src_height = Default(src_height,0)
Pad_Rec601 = Default(Pad_Rec601,False)
Assert(0 <= src_left < Width, RT_string("%s0 <= src_left(%d) < Width(%d)",myName,src_left,Width))
Assert(0 <= src_top < Height, RT_string("%s0 <= src_top(%d) < Height(%d)",myName,src_top,Height))
src_width = (src_width <= 0) ? width - src_left + src_width : src_width
src_height= (src_height <= 0) ? height - src_top + src_height : src_height
Assert(0 < src_width <= Width, RT_String("%s0 < src_width(%d) <= Width(%d)",myName,src_width,Width))
Assert(0 < src_height <= Height, RT_String("%s0 < src_height(%d) <= Height(%d)",myName,src_height,Height))
CanvasW=(W+xMod-1)/xMod*xMod CanvasH=(H+yMod-1)/yMod*yMod # O/P frame size (rounded up to next multiple of xMod,yMod if necessary)
iPadR=CanvasW-W iPadB=CanvasH-H # O/P padding pixels (Right and Bottom)
fPadR=Float(iPadR)*src_width/W fPadB=Float(iPadB)*src_height/H # Fractional pixels to reach into source clip to achieve padding.
BicubicResize(CanvasW, CanvasH, b=Bicub_b, c=Bicub_c ,
\ src_left = src_left, src_top = src_top,
\ src_width = src_width+fPadR, src_height = src_height+fPadB
\ )
# Padding to BLACK : Cannot use LetterBox for YUV as will be set to Y=16 not Y=0 [Unless Pad_Rec601=True, then OK].
Last = (0 == iPadR == iPadB) ? Last
\ : (IsRGB() || Pad_Rec601) ? Letterbox(0,iPadB,0,iPadR)
\ : mt_merge(Last,
\ Last.BlankClip(Color_Yuv=$008080),
\ Last.mt_lutspa(relative=false,expr=RT_String("x %d >= y %d >= | 255 0 ?",W,H),chroma="-128"),luma=true)
Return Last
}
EDIT: I'm quite happy to take the first suggestion (If wrong, I can blame it on someone else :) )
https://www.cosgan.de/images/smilie/set/001.gifhttps://www.cosgan.de/images/smilie/set/020.gifhttps://www.cosgan.de/images/smilie/set/016.gifhttps://www.cosgan.de/images/smilie/set/013.gifhttps://www.cosgan.de/images/smilie/set/023.gifhttps://www.cosgan.de/images/smilie/set/006.gifhttps://www.cosgan.de/images/smilie/set/005.gif