View Single Post
Old 9th March 2011, 21:44   #15  |  Link
-Vit-
Registered User
 
Join Date: Jul 2010
Posts: 448
I didn't try the above script, but this works with the PointResize approach
[I don't like the mt_merge at the end, but had problems with chroma otherwise. BTW. it needs MaskTools alpha 45 or above as it uses the newer syntax for lutspa]
Code:
# Split into grid of given size
# size = grid x dimension, sizeY = grid y dimension (= x dimension by default)
# color = grid color in RGB (e.g. $00FF00 for green, defaults to black)
# xMod and yMod = dimension restrictions on clips (defaults to multiples of 4) [could calculate from clip type]
# Examples: GridSplit( 8 ) # 8x8 grid       GridSplit(5,3,$808080) # 5x3 grid, gray grid lines
function GridSplit( clip c, int size, int "sizeY", int "color", int "xMod", int "yMod" )
{
	xMod = default( xMod, 4 )
	yMod = default( yMod, 4 )
	sizeY = default( sizeY, size )
	color = default( color, $000000 )

	# Original dimensions
	w = c.Width()
	h = c.Height()

	# Dimensions with grid lines, but may not fit given mods
	nw = w + (w-1) / size
	nh = h + (h-1) / sizeY

	# Pad above dimensions to fit mods
	pw = ((nw + xMod - 1) / xMod) * xMod 
	ph = ((nh + yMod - 1) / yMod) * yMod 

	# Equivalent dimensions to above without grid lines - must pad to this size before rescale to ensure each
	# block of "size" pixels will map to exactly "size+1" pixels in result
	bw = float(size * pw) / (size+1)
	bh = float(sizeY * ph) / (sizeY+1)

	# Pad, then rescale using dimensions calculated. Also offset duplicated pixels to provide neat position for grid lines
	c.PointResize( pw, ph, 1 - 0.5/(size+1), 1 - 0.5/(sizeY+1), bw, bh )

	# Black out both grid and padded pixels
	gridCondition = "x 1 + " + string(size+1) + " % 0 == y 1 + " + string(sizeY+1) + " % 0 == | "
	paddedCondition = "x " + string(nw) + " >= y " + string(nh) + " >= | "
	grid = mt_lutspa( mode="absolute", expr=gridCondition + paddedCondition + "| 0 255 ?", U=1,V=1 )
	
	background = BlankClip( grid, color=color )
	mt_merge( background, last, grid, luma=true )

	return last
}

Last edited by -Vit-; 10th March 2011 at 03:41.
-Vit- is offline   Reply With Quote