Skip to content
Snippets Groups Projects
Commit 0debe0b0 authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

starting raster mask

parent 322e38ba
Branches
No related tags found
No related merge requests found
// //
// image mask // raster mask
// //
// Neil Gershenfeld // Neil Gershenfeld
// (c) Massachusetts Institute of Technology 2017 // (c) Massachusetts Institute of Technology 2017
...@@ -20,7 +20,7 @@ var mod = {} ...@@ -20,7 +20,7 @@ var mod = {}
// //
// name // name
// //
var name = 'image mask' var name = 'raster mask'
// //
// initialization // initialization
// //
...@@ -39,12 +39,15 @@ var inputs = { ...@@ -39,12 +39,15 @@ var inputs = {
event:function(evt){ event:function(evt){
mod.image = evt.detail mod.image = evt.detail
mod.labelspan.style.fontWeight = 'bold' mod.labelspan.style.fontWeight = 'bold'
var ctx = mod.convert.getContext("2d")
ctx.canvas.width = mod.image.width
ctx.canvas.height = mod.image.height
}}, }},
palette:{type:'text', palette:{type:'text',
event:function(evt){ event:function(evt){
mod.palette = JSON.parse(evt.detail) mod.palette = JSON.parse(evt.detail)
}}, }},
path:{type:'array', mask:{type:'RGBA',
event:function(evt){ event:function(evt){
make_mask(evt.detail) make_mask(evt.detail)
}}} }}}
...@@ -70,6 +73,11 @@ var outputs = { ...@@ -70,6 +73,11 @@ var outputs = {
var interface = function(div){ var interface = function(div){
mod.div = div mod.div = div
// //
// off-screen conversion canvas
//
var canvas = document.createElement('canvas')
mod.convert = canvas
//
// button // button
// //
var btn = document.createElement('button') var btn = document.createElement('button')
...@@ -223,8 +231,24 @@ function save_mask(path) { ...@@ -223,8 +231,24 @@ function save_mask(path) {
text.setAttribute('dy','.2') text.setAttribute('dy','.2')
text.textContent = name text.textContent = name
svg.appendChild(text) svg.appendChild(text)
// //
// mask // raster mask
//
var ctx = mod.convert.getContext("2d")
ctx.putImageData(imgdata,0,0)
var href = mod.convert.toDataURL()
var img = document.createElementNS(svgNS,'image')
img.setAttribute('id',mod.div.id+'svgimg')
img.setAttribute('x','1.5')
img.setAttribute('y','1.5')
img.setAttribute('width',imgwidth)
img.setAttribute('height',imgheight)
img.setAttributeNS('http://www.w3.org/1999/xlink','href',href)
svg.appendChild(img)
//
// vector mask
// //
var g = document.createElementNS(svgNS,'g') var g = document.createElementNS(svgNS,'g')
svg.appendChild(g) svg.appendChild(g)
...@@ -256,6 +280,7 @@ function save_mask(path) { ...@@ -256,6 +280,7 @@ function save_mask(path) {
g.appendChild(polyline) g.appendChild(polyline)
} }
} }
// //
// file // file
// //
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment