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
19f52a09
Commit
19f52a09
authored
Sep 5, 2018
by
Tomás Vega
Browse files
Options
Downloads
Patches
Plain Diff
horizontal flip for double sided boards
parent
6e07f046
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/read/png
+87
-2
87 additions, 2 deletions
modules/read/png
with
87 additions
and
2 deletions
modules/read/png
+
87
−
2
View file @
19f52a09
...
...
@@ -5,7 +5,7 @@
// (c) Massachusetts Institute of Technology 2015,6
//
// This work may be reproduced, modified, distributed, performed, and
// displayed for any purpose, but must acknowledge the
mods
// displayed for any purpose, but must acknowledge the
fab modules
// project. Copyright is retained and must be preserved. The work is
// provided as is; no warranty is provided, and users accept all
// liability.
...
...
@@ -139,6 +139,18 @@ var interface = function(div){
div.appendChild(btn)
div.appendChild(document.createElement('br'))
//
// flip button
//
var flip_btn = document.createElement('button')
flip_btn.style.padding = mods.ui.padding
flip_btn.style.margin = 1
flip_btn.appendChild(document.createTextNode('flip'))
flip_btn.addEventListener('click',function(){
flip_image()
})
div.appendChild(flip_btn)
div.appendChild(document.createElement('br'))
//
// info div
//
var info = document.createElement('div')
...
...
@@ -334,10 +346,83 @@ function worker() {
})
}
//
// flip image
//
function flip_image() {
var blob = new Blob(['('+flip_worker.toString()+'())'])
var url = window.URL.createObjectURL(blob)
var webworker = new Worker(url)
webworker.addEventListener('message',function(evt) {
window.URL.revokeObjectURL(url)
var h = mod.img.height
var w = mod.img.width
var buf = new Uint8ClampedArray(evt.data.buffer)
var imgdata = new ImageData(buf,w,h)
var ctx = mod.img.getContext("2d")
ctx.putImageData(imgdata,0,0)
if (w > h) {
var x0 = 0
var y0 = mod.canvas.height*.5*(1-h/w)
var wd = mod.canvas.width
var hd = mod.canvas.width*h/w
}
else {
var x0 = mod.canvas.width*.5*(1-w/h)
var y0 = 0
var wd = mod.canvas.height*w/h
var hd = mod.canvas.height
}
var ctx = mod.canvas.getContext("2d")
ctx.drawImage(mod.img,x0,y0,wd,hd)
webworker.terminate()
outputs.image.event()
})
var ctx = mod.canvas.getContext("2d")
ctx.clearRect(0,0,mod.canvas.width,mod.canvas.height)
var h = mod.img.height
var w = mod.img.width
var ctx = mod.img.getContext("2d")
var img = ctx.getImageData(0,0,w,h)
webworker.postMessage({
height:img.height,width:img.width,buffer:img.data.buffer},
[img.data.buffer])
}
function flip_worker() {
self.addEventListener('message',function(evt) {
var h = evt.data.height
var w = evt.data.width
var buf = new Uint8ClampedArray(evt.data.buffer)
var index = 0
for (var row = 0; row < h; ++row) {
for (var col = 0; col < w/2; ++col) {
index = (h-1-row)*w*4+col*4
r_index = (h-1-row)*w*4+(w-1-col)*4
temp_1 = buf[index+0]
temp_2 = buf[index+1]
temp_3 = buf[index+2]
buf[index+0]
= buf[r_index+0]
buf[index+1]
= buf[r_index+1]
buf[index+2]
= buf[r_index+2]
buf[r_index+0]
= temp_1
buf[r_index+1]
= temp_2
buf[r_index+2]
= temp_3
buf[index+3] = 255
buf[r_index+3] = 255
}
}
self.postMessage({buffer:buf.buffer},[buf.buffer])
})
}
//
// return values
//
return ({
mod:mod,
name:name,
init:init,
inputs:inputs,
...
...
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
register
or
sign in
to comment