Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #quadratura v1.0 by mirkosp
- #Substitutes the outer clip's selected area with the same area in the inner clip.
- #Make sure outer and inner clips are of the same resolution and colourspace.
- #If sources are, for example, both YUV, but with different subsampling, the filter
- #will still work with the avisynth's default behaviour to determine which subsampling will be used.
- #x, y, w, and h work as with avisynth's crop to determine the area.
- #In order to allow odd values to be used with YUV sources, I am using Overlay.
- #However, since overlay would internally convert RGB sources to YUV,
- #I am using it only if the sources are YUV to avoid colourspace conversions,
- #which means that the opacity parameter is ignored with RGB sources.
- #If you want to overlay them so badly, convert to YUV yourself before using this script.
- #I don't want to be responsible for incorrect RGB->YUV conversions,
- #even more so because they're lossy and should be avoided if not necessary.
- #For fine tuning of the area, turn on show.
- function quadratura (clip outer, clip inner, int "x", int "y", int "w", int "h", float "opacity", bool "show") {
- x = default(x,0)
- y = default(y,0)
- w = default(w,outer.width)
- h = default(h,outer.height)
- opacity = default(opacity,1.0)
- show = default(show,false)
- #brainfarts check
- x = (x < 0) ? 0 : x
- x = (x > outer.width) ? outer.width : x
- y = (y < 0) ? 0 : y
- y = (y > outer.height) ? 0 : y
- w = (w < -(outer.width)) ? (outer.width-x) : w
- w = (w > (outer.width-x)) ? (outer.width-x) : w
- h = (h < -(outer.height)) ? (outer.height-y) : h
- h = (h > (outer.height-y)) ? (outer.height-y) : h
- opacity = (opacity < 0) ? 0 : (opacity > 1) ? 1 : opacity
- assert(outer.width == inner.width, "Outer and inner clips must have the same width.")
- assert(outer.height == inner.height, "Outer and inner clips must have the same height.")
- assert(outer.isrgb == inner.isrgb, "Outer and inner clips must have the same colourspace.")
- assert((x > (w+outer.width)) ? (w <=0) : (x < (w + outer.width)), "Dude... wait, what? Check x and w.")
- assert((y > (h+outer.height)) ? (h <=0) : (y < (h + outer.height)), "Dude... wait, what? Check y and h.")
- assert((x <> 0) || (y <> 0) || (( w <> inner.width) && (w <> 0)) || ((h <> inner.height) && (h <> 0)), "Just keep inner, bro.")
- #I don't want to handle all of the special cases, so I'll be doing this instead
- co = outer.isrgb ? outer : blankclip(outer,outer.framecount,color=$000000,pixel_type="RGB32")
- ci = inner.isrgb ? (show ? outer.invert() : inner) : blankclip(inner,inner.framecount,color=$FFFFFF,pixel_type="RGB32")
- co = co.addborders(2,2,2,2)
- ci = ci.addborders(2,2,2,2)
- x = x+2
- y = y+2
- w = (w > 0) ? w : w-2
- h = (h > 0) ? h : h-2
- #now stuff happens, though maybe it could happen faster
- cs = stackvertical(co.crop(0,0,0,y),stackhorizontal(co.crop(0,y,x,h),ci.crop(x,y,w,h),co.crop(((w > 0) ? x+w : (co.width)+w),y,0,h)),co.crop(0,((h > 0) ? y+h : (co.height)+h),0,0))
- cs = cs.crop(2,2,-2,-2)
- return outer.isrgb ? cs : overlay(outer,(show ? outer.invert : inner),opacity=(show ? 1.0 : opacity),mask=cs)
- }
- #this mod doesn't use overlay, so it doesn't incur in the overlay bug of overlay() and mt_merge()
- function quadraturamod (clip outer, clip inner, int "x", int "y", int "w", int "h", float "opacity", bool "show") {
- x = default(x,0)
- y = default(y,0)
- w = default(w,outer.width)
- h = default(h,outer.height)
- opacity = default(opacity,1.0)
- show = default(show,false)
- #brainfarts check
- x = (x < 0) ? 0 : x
- x = (x > outer.width) ? outer.width : x
- y = (y < 0) ? 0 : y
- y = (y > outer.height) ? 0 : y
- w = (w < -(outer.width)) ? (outer.width-x) : w
- w = (w > (outer.width-x)) ? (outer.width-x) : w
- h = (h < -(outer.height)) ? (outer.height-y) : h
- h = (h > (outer.height-y)) ? (outer.height-y) : h
- opacity = (opacity < 0) ? 0 : (opacity > 1) ? 1 : opacity
- assert(outer.width == inner.width, "Outer and inner clips must have the same width.")
- assert(outer.height == inner.height, "Outer and inner clips must have the same height.")
- assert(outer.isrgb == inner.isrgb, "Outer and inner clips must have the same colourspace.")
- assert((x > (w+outer.width)) ? (w <=0) : (x < (w + outer.width)), "Dude... wait, what? Check x and w.")
- assert((y > (h+outer.height)) ? (h <=0) : (y < (h + outer.height)), "Dude... wait, what? Check y and h.")
- assert((x <> 0) || (y <> 0) || (( w <> inner.width) && (w <> 0)) || ((h <> inner.height) && (h <> 0)), "Just keep inner, bro.")
- #I don't want to handle all of the special cases, so I'll be doing this instead
- co = outer
- ci = show ? outer.invert() : inner
- co = co.addborders(2,2,2,2)
- ci = ci.addborders(2,2,2,2)
- x = x+2
- y = y+2
- w = (w > 0) ? w : w-2
- h = (h > 0) ? h : h-2
- #now stuff happens, though maybe it could happen faster
- cs = stackvertical(co.crop(0,0,0,y),stackhorizontal(co.crop(0,y,x,h),ci.crop(x,y,w,h),co.crop(((w > 0) ? x+w : (co.width)+w),y,0,h)),co.crop(0,((h > 0) ? y+h : (co.height)+h),0,0))
- cs = cs.crop(2,2,-2,-2)
- return cs
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement