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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Ramos Carreño
erp5
Commits
db287a77
Commit
db287a77
authored
Mar 31, 2020
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_document_scanner: reduce number of createImageBitmap calls
parent
fa3f859e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
63 deletions
+35
-63
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/scanner_gadget_document_scanner_js.js
...tem/web_page_module/scanner_gadget_document_scanner_js.js
+33
-61
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/scanner_gadget_document_scanner_js.xml
...em/web_page_module/scanner_gadget_document_scanner_js.xml
+2
-2
No files found.
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/scanner_gadget_document_scanner_js.js
View file @
db287a77
...
@@ -418,19 +418,36 @@
...
@@ -418,19 +418,36 @@
});
});
}
}
function
fixPhotoOrientation
(
blob
)
{
function
fixPhotoOrientationSizeColor
(
blob
,
original_width
,
original_height
,
settings
)
{
var
orientation
;
var
orientation
;
return
getOrientation
(
blob
)
return
getOrientation
(
blob
)
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
orientation
=
result
;
orientation
=
result
;
var
expected_width
=
2000
,
bitmap_options
,
div
;
// If orientation is correct, return the original blob
// If orientation is correct, return the original blob
if
((
orientation
<
2
)
||
(
8
<
orientation
))
{
// and size is small
// no color correction is expected
if
(((
orientation
<
2
)
||
(
8
<
orientation
))
&&
(
original_width
<
expected_width
)
&&
(
!
(
settings
.
brightness
||
settings
.
contrast
||
settings
.
enable_greyscale
)))
{
return
blob
;
return
blob
;
}
}
if
(
expected_width
<
original_width
)
{
bitmap_options
=
{
resizeWidth
:
expected_width
,
// resizeHeight: expected_height,
resizeQuality
:
'
high
'
};
}
// Else, transform the image
// Else, transform the image
return
new
RSVP
.
Queue
(
createImageBitmap
(
blob
))
return
new
RSVP
.
Queue
(
createImageBitmap
(
blob
,
bitmap_options
))
.
push
(
function
(
bitmap
)
{
.
push
(
function
(
bitmap
)
{
var
height
=
bitmap
.
height
,
var
height
=
bitmap
.
height
,
...
@@ -438,6 +455,10 @@
...
@@ -438,6 +455,10 @@
canvas
=
domsugar
(
'
canvas
'
),
canvas
=
domsugar
(
'
canvas
'
),
ctx
;
ctx
;
// Caman expect the canvas to be in a container
// in order to replace it when resizing
div
=
domsugar
(
'
div
'
,
[
canvas
]);
if
(
4
<
orientation
&&
orientation
<
9
)
{
if
(
4
<
orientation
&&
orientation
<
9
)
{
canvas
.
width
=
height
;
canvas
.
width
=
height
;
canvas
.
height
=
width
;
canvas
.
height
=
width
;
...
@@ -475,57 +496,14 @@
...
@@ -475,57 +496,14 @@
break
;
break
;
}
}
ctx
.
drawImage
(
bitmap
,
0
,
0
);
ctx
.
drawImage
(
bitmap
,
0
,
0
);
return
promiseCanvasToBlob
(
canvas
);
});
});
}
function
fixPhotoColor
(
blob
,
settings
)
{
if
(
!
(
settings
.
brightness
||
settings
.
contrast
||
settings
.
enable_greyscale
))
{
return
blob
;
}
var
div
;
return
new
RSVP
.
Queue
(
createImageBitmap
(
blob
))
.
push
(
function
(
bitmap
)
{
var
canvas
=
domsugar
(
'
canvas
'
);
// Caman expect the canvas to be in a container
// in order to replace it when resizing
div
=
domsugar
(
'
div
'
,
[
canvas
]);
canvas
.
width
=
bitmap
.
width
;
canvas
.
height
=
bitmap
.
height
;
canvas
.
getContext
(
'
2d
'
).
drawImage
(
bitmap
,
0
,
0
);
if
(
settings
.
brightness
||
settings
.
contrast
||
settings
.
enable_greyscale
)
{
return
handleCaman
(
canvas
,
settings
);
return
handleCaman
(
canvas
,
settings
);
}
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
promiseCanvasToBlob
(
div
.
firstElementChild
);
return
promiseCanvasToBlob
(
div
.
firstElementChild
);
});
});
}
function
resizePhoto
(
blob
,
original_width
,
original_height
)
{
var
expected_width
=
2000
;
if
(
original_width
<
expected_width
)
{
return
blob
;
}
// expected_height = parseInt((original_height * expected_width) / original_width);
// alert(expected_width + ' ' + expected_height);
return
new
RSVP
.
Queue
(
createImageBitmap
(
blob
,
{
resizeWidth
:
expected_width
,
// resizeHeight: expected_height,
resizeQuality
:
'
high
'
}))
.
push
(
function
(
bitmap
)
{
var
canvas
=
domsugar
(
'
canvas
'
);
canvas
.
width
=
bitmap
.
width
;
canvas
.
height
=
bitmap
.
height
;
canvas
.
getContext
(
'
2d
'
).
drawImage
(
bitmap
,
0
,
0
);
return
promiseCanvasToBlob
(
canvas
);
});
});
}
}
...
@@ -575,15 +553,9 @@
...
@@ -575,15 +553,9 @@
})
})
.
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
'
);
return
resizePhoto
(
blob
,
original_width
,
original_height
);
return
fixPhotoOrientationSizeColor
(
blob
,
original_width
,
original_height
,
settings
);
})
})
.
push
(
function
(
blob
)
{
return
fixPhotoOrientation
(
blob
);
})
.
push
(
function
(
blob
)
{
return
fixPhotoColor
(
blob
,
settings
);
})
.
push
(
function
(
blob
)
{
.
push
(
function
(
blob
)
{
blob_url
=
URL
.
createObjectURL
(
blob
);
blob_url
=
URL
.
createObjectURL
(
blob
);
return
RSVP
.
all
([
return
RSVP
.
all
([
...
...
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/scanner_gadget_document_scanner_js.xml
View file @
db287a77
...
@@ -244,7 +244,7 @@
...
@@ -244,7 +244,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
serial
</string>
</key>
<key>
<string>
serial
</string>
</key>
<value>
<string>
982.58
354.63381.1604
</string>
</value>
<value>
<string>
982.58
483.10473.65433
</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>
158565
0508.06
</float>
<float>
158565
8339.7
</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