Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mods
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
mods
Commits
76c79cc1
Commit
76c79cc1
authored
Jun 17, 2017
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
starting SVG masks
parent
407bdf6c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/image/palette
+71
-9
71 additions, 9 deletions
modules/image/palette
with
71 additions
and
9 deletions
modules/image/palette
+
71
−
9
View file @
76c79cc1
...
@@ -66,7 +66,15 @@ var inputs = {
...
@@ -66,7 +66,15 @@ var inputs = {
show_original()
show_original()
else
else
show_palette()
show_palette()
}}}
}
},
imageInfo:{type:'object',
event:function(evt){
mod.name = evt.detail.name
mod.dpi = evt.detail.dpi
}
}
}
//
//
// outputs
// outputs
//
//
...
@@ -227,7 +235,7 @@ var interface = function(div){
...
@@ -227,7 +235,7 @@ var interface = function(div){
btn.style.margin = 1
btn.style.margin = 1
btn.appendChild(document.createTextNode('masks'))
btn.appendChild(document.createTextNode('masks'))
btn.addEventListener('click',function(){
btn.addEventListener('click',function(){
save_masks()
save_
svg_
masks()
})
})
div.appendChild(btn)
div.appendChild(btn)
var btn = document.createElement('button')
var btn = document.createElement('button')
...
@@ -254,22 +262,76 @@ function save_image() {
...
@@ -254,22 +262,76 @@ function save_image() {
document.body.removeChild(a)
document.body.removeChild(a)
}
}
//
//
// save_masks
// save_svg_masks
//
//
function save_masks() {
function save_svg_masks() {
var svgNS = "http://www.w3.org/2000/svg"
var svg = document.createElementNS(svgNS,"svg")
svg.setAttributeNS("http://www.w3.org/2000/xmlns/",
"xmlns:xlink","http://www.w3.org/1999/xlink")
svg.setAttribute('width',100)
svg.setAttribute('height',100)
svg.style.backgroundColor = 'rgb(255,255,255)'
var g = document.createElementNS(svgNS,'g')
svg.appendChild(g)
var line = document.createElementNS('http://www.w3.org/2000/svg','line')
line.setAttribute('stroke','red')
line.setAttribute('stroke-width',1)
line.setAttribute('stroke-linecap','round')
var x1 = 0
var y1 = 0
var x2 = 100
var y2 = 100
line.setAttribute('x1',x1)
line.setAttribute('y1',y1)
line.setAttribute('x2',x2)
line.setAttribute('y2',y2)
svg.appendChild(line)
var text = document.createElementNS('http://www.w3.org/2000/svg','text')
text.setAttribute('x','10')
text.setAttribute('y','20')
text.setAttribute('fill','red')
text.textContent = 'palette'
svg.appendChild(text)
var circle = document.createElementNS('http://www.w3.org/2000/svg','circle')
circle.setAttribute('cx',25)
circle.setAttribute('cy',25)
circle.setAttribute('r',20)
circle.setAttribute('stroke','red')
circle.setAttribute('strokeWidth','red')
circle.setAttribute('fill','none')
svg.appendChild(circle)
var html = svg.outerHTML
var blob = new Blob([html],{type:"image/svg+xml;charset=utf-8"})
var url = URL.createObjectURL(blob)
var link = document.createElement('a')
link.href = url
link.download = "test.svg"
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
//
// save_raster_masks
//
function save_raster_masks() {
if (mod.originalspan.style.fontWeight == 'bold') {
if (mod.originalspan.style.fontWeight == 'bold') {
mod.originalspan.style.fontWeight = 'normal'
mod.originalspan.style.fontWeight = 'normal'
mod.palettespan.style.fontWeight = 'bold'
mod.palettespan.style.fontWeight = 'bold'
show_palette()
show_palette()
}
}
var palette = JSON.parse(mod.text.value)
var palette = JSON.parse(mod.text.value)
var blob = new Blob(['('+mask_worker.toString()+'())'])
var blob = new Blob(['('+
raster_
mask_worker.toString()+'())'])
var url = window.URL.createObjectURL(blob)
var url = window.URL.createObjectURL(blob)
save_mask(0)
save_
raster_
mask(0)
//
//
// save_mask
// save_mask
//
//
function save_mask(index) {
function save_
raster_
mask(index) {
var webworker = new Worker(url)
var webworker = new Worker(url)
webworker.addEventListener('message',function(evt) {
webworker.addEventListener('message',function(evt) {
var h = mod.img.height
var h = mod.img.height
...
@@ -305,9 +367,9 @@ function save_masks() {
...
@@ -305,9 +367,9 @@ function save_masks() {
buffer:img.data.buffer})
buffer:img.data.buffer})
}
}
//
//
// mask_worker
//
raster_
mask_worker
//
//
function mask_worker() {
function
raster_
mask_worker() {
self.addEventListener('message',function(evt) {
self.addEventListener('message',function(evt) {
var h = evt.data.height
var h = evt.data.height
var w = evt.data.width
var w = evt.data.width
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment