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
acca33cf
Commit
acca33cf
authored
7 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
starting compare worker
parent
903f5933
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/image/motion detect
+60
-40
60 additions, 40 deletions
modules/image/motion detect
with
60 additions
and
40 deletions
modules/image/motion detect
+
60
−
40
View file @
acca33cf
...
...
@@ -36,11 +36,14 @@ var inputs = {
image:{type:'RGBA',
event:function(evt){
var ctx = mod.img.getContext("2d")
var lastctx = mod.lastimg.getContext("2d")
lastctx.canvas.width = ctx.canvas.width
lastctx.canvas.height = ctx.canvas.height
lastctx.drawImage(mod.img,0,0)
ctx.canvas.width = evt.detail.width
ctx.canvas.height = evt.detail.height
ctx.putImageData(evt.detail,0,0)
mod.pxtext.nodeValue = evt.detail.width+' x '+evt.detail.height+' px'
convert_image()
compare_images()
}}}
//
// outputs
...
...
@@ -81,6 +84,11 @@ var interface = function(div){
var canvas = document.createElement('canvas')
mod.img = canvas
//
// off-screen last image canvas
//
var canvas = document.createElement('canvas')
mod.lastimg = canvas
//
// view button
//
var btn = document.createElement('button')
...
...
@@ -139,12 +147,21 @@ function timeout() {
outputs.trigger.event()
setTimeout(timeout,parseFloat(mod.time.value)*1000)
}
function convert_image() {
//
// preview
//
function compare_images() {
mod.change.nodeValue = Date.now()
var blob = new Blob(['('+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)
...
...
@@ -160,26 +177,29 @@ function convert_image() {
var ctx = mod.canvas.getContext("2d")
ctx.clearRect(0,0,mod.canvas.width,mod.canvas.height)
ctx.drawImage(mod.img,x0,y0,wd,hd)
webworker.terminate()
})
var ctx = mod.img.getContext("2d")
var img = ctx.getImageData(0,0,mod.img.width,mod.img.height)
var ctx = mod.lastimg.getContext("2d")
var lastimg = ctx.getImageData(0,0,mod.img.width,mod.img.height)
var t = parseFloat(mod.threshold.value)
//
// convert and save
//
mod.img.toBlob(function(blob){
var url = URL.createObjectURL(blob)
var link = document.createElement('a')
link.download = mod.nametext.value
link.href = url
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
},'image/png')
// transfer?
//
webworker.postMessage({
height:mod.img.height,width:mod.img.width,threshold:t,
buffer:img.data.buffer,lastbuffer:lastimg.data.buffer})
}
function update_info() {
mod.dpi = parseFloat(mod.dpitext.value)
mod.mmtext.nodeValue = (25.4*mod.img.width/mod.dpi).toFixed(3)
+' x '+(25.4*mod.img.height/mod.dpi).toFixed(3)+' mm'
mod.intext.nodeValue = (mod.img.width/mod.dpi).toFixed(3)
+' x '+(mod.img.height/mod.dpi).toFixed(3)+' in'
function worker() {
self.addEventListener('message',function(evt) {
var h = evt.data.height
var w = evt.data.width
var t = evt.data.threshold
var buf = new Uint8ClampedArray(evt.data.buffer)
var lastbuf = new Uint8ClampedArray(evt.data.lastbuffer)
self.postMessage({buffer:buf.buffer})
})
}
// return values
//
...
...
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