お前らのショボイAvisynthスクリプト貼ってくださいpart2
function residue(int "a", int "b") { return ( a -(floor(a/b) * b) ) } # 剰余 r = a - q * b
function quotient(int "a", int "b") { return floor(a/b) } # 商
function lcm(int "a", int "b") { return ( (a * b) / gcm(a,b) ) } # 最小公倍数 a * b = gcm(a, b) * lcm(a, b)
# 最大公約数 gcm(a, b) = gcm(b, r)
function gcm(int "a", int "b", int "to")
{
to = default(to, 30)
_a = (a > b) ? a : b
_b = (a > b) ? b : a
r = residue(_a, _b)
return (r == 0) || (to == 0) ? b : gcm2(_b, r, to) }
function gcm2(int "a", int "b", int "to") {
to = to - 1
r = residue(a, b)
a = (r != 0) ? b : a
b = (r != 0) ? r : b
return gcm(a, b, to)
}
function PARCrop(clip clip, int "mode", int "sar", string "crop_opt", string "dar", int "n", int "offset",
\ bool "interlaced", int "PAR_width",int "PAR_height", int "DAR_width", int "DAR_height", bool "show")
{
mode = default(mode, 1)
sar = default(sar, 14)
crop_opt = default(crop_opt, "0,0,0,0")
dar = default(dar, "16:9")
n = default(n, 2)
offset = default(offset, 0)
interlaced = default(interlaced, false)
show = default(show, true)
w = ( (sar == 3) || (sar == 5) ) && ( (dar == "4:3") || (dar == "16:9") ) ? 22 * n : 1
h = ( (sar == 3) || (sar == 5) ) && ( (dar == "4:3") || (dar == "16:9") ) ? 15 * n : 1
w = (sar == 14) && (dar == "16:9") ? 4 * n : w
h = (sar == 14) && (dar == "16:9") ? 3 * n : h
w = (sar == 14) && (dar == "4:3") ? 1 * n : w
h = (sar == 14) && (dar == "4:3") ? 1 * n : h
w = (sar == 1) && (dar == "16:9") ? 16 * n : w
h = (sar == 1) && (dar == "16:9") ? 9 * n : h
w = (sar == 1) && (dar == "4:3") ? 4 * n : w
h = (sar == 1) && (dar == "4:3") ? 3 * n : h
w = (sar == 11) && (dar == "16:9") ? 176 * n : w
h = (sar == 11) && (dar == "16:9") ? 135 * n : h
w = (sar == 11) && (dar == "4:3") ? 44 * n : w
h = (sar == 11) && (dar == "4:3") ? 15 * n : h
w = (sar == 17) && (dar == "16:9") ? 704 * n : w
h = (sar == 17) && (dar == "16:9") ? 405 * n : h
w = (sar == 17) && (dar == "4:3") ? 176 * n : w
h = (sar == 17) && (dar == "4:3") ? 135 * n : h
w = ( defined(PAR_width) == true) ? n * ( (DAR_width * PAR_height)
\ / gcm(DAR_width * PAR_height, DAR_height * PAR_width) ) : w
h = ( defined(PAR_width) == true) ? n * ( (DAR_height * PAR_width)
\ / gcm(DAR_width * PAR_height, DAR_height * PAR_width) ) : h
Clip = (clip.isYV12 == true) && (interlaced == true) && (n == 1)
\ ? clip.ConverttoRGB24(interlaced=true)
\ : (n == 1) ? clip.ConverttoRGB24
\ : clip
clip = Eval( "clip.Crop(" + string(crop_opt) + ")" )
x = (mode == 1) ? clip.width : clip.height
z = (mode == 1) ? w : h
q = quotient(x, z)
r = residue (x, z)
x = x - r # new_x xが wの倍数になるよう修正
x_q = quotient(r, 2)
x_r = residue (r, 2) # 1 or 0
y = (mode == 1) ? h * q : w * q # new_y
_y = (mode == 1) ? clip.height - y : clip.width - y
y_q = quotient(_y, 2)
y_r = residue (_y, 2)
clip = (mode == 1) ? clip.Crop( x_q + x_r, y_q + y_r - offset, -x_q, -(y_q + offset) )
\ : clip.Crop( y_q + y_r -offset, x_q + x_r, -(y_q + offset), -x_q )
clip2 = clip.Subtitle("DAR_width x PAR_height " + string(w) + " / " + string(h) + " DAR_height x PAR_width", align=2)
(mode == 1) ? Clip2.Subtitle( string(x) + " x " + string(y) + ": Crop(" + string(int(x_q + x_r)) +", "
\ + string(int(y_q + y_r - offset)) + ", -" + string(x_q) + ", -" + string(y_q + offset) + ")", align=5)
\ : clip2.Subtitle( string(y) + " * " + string(x) + ": Crop(" + string(int(y_q + y_r -offset)) +", "
\ + string(int(x_q + x_r)) + ", -" + string(y_q + offset) + ", -" + string(x_q) + ")", align=5)
return (show == false) ? clip : last
}
Cropで整数解を求めるための関数。