Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
139
Merge Requests
139
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
a6bbe886
Commit
a6bbe886
authored
Feb 12, 2020
by
Gabriel Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_document_scanner: Extend code to apply filters in image with Caman
parent
1454d77f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
55 deletions
+43
-55
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/rjs_gadget_document_scanner_js.js
...ateItem/web_page_module/rjs_gadget_document_scanner_js.js
+41
-53
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/rjs_gadget_document_scanner_js.xml
...teItem/web_page_module/rjs_gadget_document_scanner_js.xml
+2
-2
No files found.
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/rjs_gadget_document_scanner_js.js
View file @
a6bbe886
/*jslint indent: 2, unparam: true */
/*jslint indent: 2, unparam: true */
/*global rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData, Caman*/
/*global rJS, RSVP, window, document, navigator, Cropper, Promise, JSON, jIO, promiseEventListener, domsugar, createImageBitmap, FormData, Caman
, URL, File
*/
(
function
(
rJS
,
RSVP
,
window
,
document
,
navigator
,
Cropper
,
Promise
,
JSON
,
jIO
,
promiseEventListener
,
domsugar
,
createImageBitmap
,
FormData
,
Caman
)
{
(
function
(
rJS
,
RSVP
,
window
,
document
,
navigator
,
Cropper
,
Promise
,
JSON
,
jIO
,
promiseEventListener
,
domsugar
,
createImageBitmap
,
FormData
,
Caman
,
URL
,
File
)
{
"
use strict
"
;
"
use strict
"
;
//////////////////////////////////////////////////
//////////////////////////////////////////////////
...
@@ -50,7 +50,7 @@
...
@@ -50,7 +50,7 @@
return
new
RSVP
.
Promise
(
waitForStream
,
canceller
);
return
new
RSVP
.
Promise
(
waitForStream
,
canceller
);
}
}
function
handleCropper
(
gadget
,
element
,
data
,
settings
,
callback
)
{
function
handleCropper
(
element
,
data
,
callback
)
{
var
cropper
,
var
cropper
,
queue
=
new
RSVP
.
Queue
(),
queue
=
new
RSVP
.
Queue
(),
img
=
domsugar
(
"
img
"
),
img
=
domsugar
(
"
img
"
),
...
@@ -60,50 +60,6 @@
...
@@ -60,50 +60,6 @@
cropper
.
destroy
();
cropper
.
destroy
();
}
}
if
(
settings
.
brightness
||
settings
.
contrast
||
settings
.
enable_greyscale
||
settings
.
compression
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
new
Promise
(
function
(
resolve
)
{
Caman
(
canvas
,
element
,
function
()
{
if
(
settings
.
brightness
!==
0
)
{
this
.
brightness
(
data
.
brightness
);
}
if
(
settings
.
contrast
!==
0
)
{
this
.
contrast
(
data
.
contrast
);
}
if
(
settings
.
enable_greyscale
)
{
this
.
greyscale
();
}
this
.
render
(
function
()
{
resolve
(
canvas
.
toDataURL
(
"
image/jpeg
"
,
settings
.
compression
));
});
});
});
})
.
push
(
function
(
data_str
)
{
img
.
setAttribute
(
"
src
"
,
data_str
);
// creating Cropper is asynchronous
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
cropper
=
new
Cropper
(
img
,
{
data
:
data
,
ready
:
function
()
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
callback
(
cropper
);
})
.
push
(
undefined
,
function
(
error
)
{
if
(
!
(
error
instanceof
RSVP
.
CancellationError
))
{
canceller
();
reject
(
error
);
}
});
}
});
},
canceller
);
});
}
// creating Cropper is asynchronous
// creating Cropper is asynchronous
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
cropper
=
new
Cropper
(
element
,
{
cropper
=
new
Cropper
(
element
,
{
...
@@ -337,7 +293,10 @@
...
@@ -337,7 +293,10 @@
// Capture the media stream
// Capture the media stream
function
captureAndRenderPicture
(
gadget
)
{
function
captureAndRenderPicture
(
gadget
)
{
var
image_capture
=
new
window
.
ImageCapture
(
var
file
,
settings
=
gadget
.
state
.
preferred_image_settings_data
,
data
=
gadget
.
state
.
preferred_cropped_canvas_data
,
image_capture
=
new
window
.
ImageCapture
(
gadget
.
element
.
querySelector
(
'
video
'
).
srcObject
.
getVideoTracks
()[
0
]
gadget
.
element
.
querySelector
(
'
video
'
).
srcObject
.
getVideoTracks
()[
0
]
),
),
div
;
div
;
...
@@ -351,6 +310,38 @@
...
@@ -351,6 +310,38 @@
})
})
.
push
(
function
(
blob
)
{
.
push
(
function
(
blob
)
{
gadget
.
detached_promise_dict
.
media_stream
.
cancel
(
'
Not needed anymore, as captured
'
);
gadget
.
detached_promise_dict
.
media_stream
.
cancel
(
'
Not needed anymore, as captured
'
);
if
(
settings
.
brightness
||
settings
.
contrast
||
settings
.
enable_greyscale
||
settings
.
compression
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsDataURL
(
blob
);
})
.
push
(
function
(
result
)
{
var
canvas
=
domsugar
(
'
canvas
'
,
{
'
class
'
:
'
canvas
'
});
return
new
Promise
(
function
(
resolve
)
{
// XXX the correct usage is `new Caman()` but the library does not support it
Caman
(
canvas
,
result
.
target
.
result
,
function
()
{
if
(
settings
.
brightness
&&
settings
.
brightness
!==
0
)
{
this
.
brightness
(
settings
.
brightness
);
}
if
(
settings
.
contrast
&&
settings
.
contrast
!==
0
)
{
this
.
contrast
(
settings
.
contrast
);
}
if
(
settings
.
enable_greyscale
)
{
this
.
greyscale
();
}
this
.
render
(
function
()
{
canvas
.
toBlob
(
function
(
blob
)
{
resolve
(
blob
);
});
});
});
});
});
}
else
{
return
blob
;
}
})
.
push
(
function
(
blob
)
{
return
RSVP
.
all
([
return
RSVP
.
all
([
gadget
.
getTranslationList
([
"
Delete
"
,
"
Save
"
]),
gadget
.
getTranslationList
([
"
Delete
"
,
"
Save
"
]),
createImageBitmap
(
blob
),
createImageBitmap
(
blob
),
...
@@ -361,7 +352,6 @@
...
@@ -361,7 +352,6 @@
var
bitmap
=
result_list
[
1
],
var
bitmap
=
result_list
[
1
],
canvas
=
domsugar
(
'
canvas
'
,
{
'
class
'
:
'
canvas
'
}),
canvas
=
domsugar
(
'
canvas
'
,
{
'
class
'
:
'
canvas
'
}),
defer
=
RSVP
.
defer
();
defer
=
RSVP
.
defer
();
// Prepare the cropper canvas
// Prepare the cropper canvas
canvas
.
width
=
bitmap
.
width
;
canvas
.
width
=
bitmap
.
width
;
canvas
.
height
=
bitmap
.
height
;
canvas
.
height
=
bitmap
.
height
;
...
@@ -393,10 +383,8 @@
...
@@ -393,10 +383,8 @@
gadget
.
element
.
replaceChild
(
div
,
gadget
.
element
.
firstElementChild
);
gadget
.
element
.
replaceChild
(
div
,
gadget
.
element
.
firstElementChild
);
addDetachedPromise
(
gadget
,
'
cropper
'
,
addDetachedPromise
(
gadget
,
'
cropper
'
,
handleCropper
(
gadget
,
handleCropper
(
canvas
,
canvas
,
gadget
.
state
.
preferred_cropped_canvas_data
,
gadget
.
state
.
preferred_cropped_canvas_data
,
gadget
.
state
.
preferred_image_settings_data
,
defer
.
resolve
));
defer
.
resolve
));
return
defer
.
promise
;
return
defer
.
promise
;
})
})
...
@@ -712,4 +700,4 @@
...
@@ -712,4 +700,4 @@
.
declareAcquiredMethod
(
"
getTranslationList
"
,
"
getTranslationList
"
);
.
declareAcquiredMethod
(
"
getTranslationList
"
,
"
getTranslationList
"
);
}(
rJS
,
RSVP
,
window
,
document
,
navigator
,
Cropper
,
Promise
,
JSON
,
jIO
,
promiseEventListener
,
domsugar
,
createImageBitmap
,
FormData
,
Caman
));
}(
rJS
,
RSVP
,
window
,
document
,
navigator
,
Cropper
,
Promise
,
JSON
,
jIO
,
promiseEventListener
,
domsugar
,
createImageBitmap
,
FormData
,
Caman
,
URL
,
File
));
\ No newline at end of file
\ No newline at end of file
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/rjs_gadget_document_scanner_js.xml
View file @
a6bbe886
...
@@ -244,7 +244,7 @@
...
@@ -244,7 +244,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
serial
</string>
</key>
<key>
<string>
serial
</string>
</key>
<value>
<string>
981.5
1308.5350.25326
</string>
</value>
<value>
<string>
981.5
2410.59293.63010
</string>
</value>
</item>
</item>
<item>
<item>
<key>
<string>
state
</string>
</key>
<key>
<string>
state
</string>
</key>
...
@@ -262,7 +262,7 @@
...
@@ -262,7 +262,7 @@
</tuple>
</tuple>
<state>
<state>
<tuple>
<tuple>
<float>
1581
468361.42
</float>
<float>
1581
534665.68
</float>
<string>
UTC
</string>
<string>
UTC
</string>
</tuple>
</tuple>
</state>
</state>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment