View Single Post
Old 17th March 2008, 13:39   #13  |  Link
mikeytown2
Resize Abuser
 
mikeytown2's Avatar
 
Join Date: Apr 2005
Location: Seattle, WA
Posts: 623
If anyone could explain why the picture likes to jump around when i use animate with zoombox, i would appreciate it. Or i guess i should ask why does this jump and zoom.dll not jump around? Any ideas on how i can fix it?

Code:
#SetMemoryMax(512)
#b = ImageSource("New Folder\testp2.png", end=99, fps=60)
b = colorbars().trim(0,99)

Animate(0, 99, "ZoomBoxer", b, 0.0, 0.0, 640.0, 480.0, 1, b, 320.0, 240.0, 640.0, 480.0, 1)
last + Animate(0, 99, "ZoomBoxer", b, 320.0, 240.0, 640.0, 480.0, 1, b, 416.0, 312.0, 480.0, 360.0, 1)
last + Animate(0, 99, "ZoomBoxer", b, 416.0, 312.0, 480.0, 360.0, 1, b, 0.0, 0.0, 640.0, 480.0, 1)
last + Animate(0, 99, "ZoomBoxer", b, 0.0, 0.0, 640.0, 480.0, 1, b, 288.0, 216.0, 352.0, 264.0, 1)

# ZoomBoxer() - March 17th, 2008
#  Put a "box" around a clip. Box can be used to zoom in or out.
# 
# Coordinates for ZoomBox:
#  float x1: upper left x cord
#  float y1: upper left y cord
#  float x2: lower right x cord
#  float y2: lower right y cord
# Optional Parameters
#  int IgnoreAR: 1 - Ignore Warnings; 0 - Show Warnings. Default=0, show warings
#  bool smooth: at the cost of speed (maybe quality) make zoom in's smoother. Default false
#  string Resizer: name of resize function. Default = BilinearResize
#  int w: output width
#  int h: output height
# 
# Notes
#  Aspect ratio for output and box must be the same.
#  Be aware of colors space restrictions.

Function ZoomBoxer(clip c, float x1, float y1, float x2, float y2, int "IgnoreAR", bool "smooth", string "Resizer", int "w", int "h")
{
	#set defaults
	w = Default(w, c.width())
	h = Default(h, c.height())
	Resizer = Default(Resizer, "BilinearResize")
	IgnoreAR = Default(IgnoreAR, 0)
	smooth = Default(smooth, false)
	wOut = c.width()
	hOut = c.height()
	
	#Check For Any Unreasonable Inputs
	Assert(x1<x2, "ZoomBox: Start x1[" + String(x1) + "] point larger then x2 Point[" + String(x2) + "]")
	Assert(y1<y2, "ZoomBox: Start y1[" + String(y1) + "] point larger then y2 Point[" + String(y2) + "]")
	Assert(IgnoreAR>0 || Float(x2-x1)/Float(y2-y1) == Float(w)/Float(h), "ZoomBox: Box Aspect Ratio [" + String(Float(x2-x1)/Float(y2-y1)) + "] does not equal clip output Aspect Ratio [" + string(Float(w)/Float(h)) + "]")
	
	#fix aspect ratio
	y3 = c.height()*(x2-x1)/Float(c.width())
	x3 = c.width()*(y2-y1)/Float(c.height())
	#x2=x3
	#y2=y3	
			
	#inverse zoomfactor, used to shrink or grow clip if needed
	zx = float(w)/float(x2-x1)
	zy = float(h)/float(y2-y1)
	#smoothA = smooth && zx>1 && zy>1 ? false : true
	#smooth = smooth ? smoothA : false

	#Shrink clip before for speed boost when zooming out, or blow up for smoother pic when zooming in.
	wOut = smooth || zx<1 ? zx*wOut : wOut
	x1 = smooth || zx<1 ? zx*x1 : x1
	x2 = smooth || zx<1 ? zx*x2 : x2
	hOut = smooth || zy<1 ? zy*hOut : hOut
	y1 = smooth || zy<1 ? zy*y1 : y1
	y2 = smooth || zy<1 ? zy*y2 : y2
	
	#Check ColorSpace
	x1 = c.IsYV12() || c.IsYUY2() ? Round(x1/2)*2 : x1
	x2 = c.IsYV12() || c.IsYUY2() ? Round(x2/2)*2 : x2
	y1 = c.IsYV12() || c.IsYUY2() ? Round(y1/2)*2 : y1
	y2 = c.IsYV12() || c.IsYUY2() ? Round(y2/2)*2 : y2
	wOut = c.IsYV12() || c.IsYUY2() ? Round(wOut/2)*2 : wOut
	hOut = c.IsYV12() || c.IsYUY2() ? Round(hOut/2)*2 : hOut
	
	#resize clip if needed
	c = Eval(Resizer + "(c," + String(Int(wOut)) + "," + String(Int(hOut)) + ")")
	
	#Add Borders If Needed
	left = x1<0 ? -x1 : 0
	top = y1<0 ? -y1 : 0
	right =  x2-c.width()>0 ? x2-c.width() : 0
	bottom =  y2-c.height()>0 ? y2-c.height() : 0
	d = AddBorders(c, Int(left)+8, Int(top)+8, Int(right)+8, Int(bottom)+8)
	
	#Crop If Needed
	left = x1 > 0 ? x1 : 0
	top = y1 > 0 ? y1 : 0	
	right = x2-c.width() < 0 ?  x2-c.width() : 0
	bottom = y2-c.height() < 0 ? y2-c.height() : 0
	
	d = Crop(d, Int(left)+8, Int(top)+8, Int(right)-8, Int(bottom)-8)
	#Resize for output
	Return Eval(Resizer + "(d," + String(w) + "," + String(h) + ")")#+ ",src_left=" + String(Int(left)+8) + ",src_top=" + String(Int(top)+8) + ",src_width=" + String(c.width() + right) + ",src_height=" + String(c.height() + bottom) + ")")
}
mikeytown2 is offline   Reply With Quote