View Single Post
Old 28th March 2020, 20:56   #3  |  Link
josemaria.alkala
Registered User
 
Join Date: Apr 2010
Posts: 16
I have done one with a naive implementation. It is not fast, but there is a lot of margin for improvement.

The filter would look like this in its current state:
Code:
import ../vapoursynth
import mymacro
import options
import strformat

newFilter("DrawFrame"):
  parameters:  
    inClip   clip           # Input video (mandatory)

  validation:
    # We assign the destination's frame size
    data.width  = data.vi.width.Natural
    data.height = data.vi.height.Natural

  processing:
    let dst = src.newVideoFrame(data.width, data.height)
    for i in 0..<srcNumPlanes:
      var srcPlane = src.getPlane(i)
      var dstPlane = dst.getPlane(i)
      for row in 0..<srcPlane.height:
          for col in 0..<srcPlane.width:
              var value:int = ( srcPlane.get(row-1,col-1) + 
                                srcPlane.get(row-1,col) * 2 + 
                                srcPlane.get(row-1,col+1) +
                                srcPlane.get(row,col-1) * 2 + 
                                srcPlane.get(row,col) * 4 + 
                                srcPlane.get(row,col+1) * 2 +
                                srcPlane.get(row+1,col-1) +
                                srcPlane.get(row+1,col) * 2 +
                                srcPlane.get(row+1,col+1) ).int
              dstPlane.set(row, col , (value / 16).uint8)
With a bit of metaprogramming could be done easier to the eyes and much faster.
josemaria.alkala is offline   Reply With Quote