 # @runtime noflo-nodejs
 # @name SCDDetect
 
-compute = (canvas, cascade, callback) ->
-  ctx = canvas.getContext '2d'
-  imageData = ctx.getImageData 0, 0, canvas.width, canvas.height
-  data = imageData.data
+writeCanvasTempFile = (canvas, callback) ->
   tmpFile = new temporary.File
 
   rs = canvas.pngStream()

    out: 'out'
    forwardGroups: true
    async: true
  , (payload, groups, out, callback) ->
    if not c.params.cascade
      cascade = path.join __dirname, '../cascades/face.sqlite3'
    else
      cascade = c.params.cascade
    compute payload, cascade, (err, val) ->
      return callback err if err
      out.send val
      do callback
  c

    ws.once 'close', ->
      fs.fsync fd, ->
        try
          callback null, tmpFile
        catch error
          callback error
          tmpFile.unlink()
  rs.pipe ws

runScdDetect = (tmpFile, cascade, callback) ->
  bin = path.join __dirname, '../build/Release/scddetect'
  exec "#{bin} #{tmpFile.path} #{cascade}", (err, stdout, stderr) ->
    if err
