Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Toolkit
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Web Component Framework
Toolkit
Commits
1d9f1a5b
Commit
1d9f1a5b
authored
4 years ago
by
Steinwender, Tamara
Browse files
Options
Downloads
Patches
Plain Diff
Add clipping mask to QR code reader
parent
3d486a07
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/qr-code-scanner/README.md
+3
-1
3 additions, 1 deletion
packages/qr-code-scanner/README.md
packages/qr-code-scanner/src/qr-code-scanner.js
+55
-4
55 additions, 4 deletions
packages/qr-code-scanner/src/qr-code-scanner.js
with
58 additions
and
5 deletions
packages/qr-code-scanner/README.md
+
3
−
1
View file @
1d9f1a5b
...
@@ -28,8 +28,10 @@ The colors are from css vars (`--dbp-success-bg-color` and `--dbp-danger-bg-colo
...
@@ -28,8 +28,10 @@ The colors are from css vars (`--dbp-success-bg-color` and `--dbp-danger-bg-colo
a box under the video canvas with the read QR code data
a box under the video canvas with the read QR code data
-
example
`<dbp-qr-code-scanner show-output></dbp-qr-code-scanner>`
-
example
`<dbp-qr-code-scanner show-output></dbp-qr-code-scanner>`
-
`stop-scan`
(optional, default:
`false`
): set to
`true`
when you don't want to start the QR code reader immediatly
-
`stop-scan`
(optional, default:
`false`
): set to
`true`
when you don't want to start the QR code reader immediatly
after loaded. This attribute is also used to stop the QR code reader if you don't need it anymore.
after loaded. This attribute is also used to stop the QR code reader
or
if you don't need it anymore.
-
example
`<dbp-qr-code-scanner stop-scan></dbp-qr-code-scanner>`
-
example
`<dbp-qr-code-scanner stop-scan></dbp-qr-code-scanner>`
-
`clip-mask`
(optional, default:
`true`
): set to
`false`
when you don't want to use a QR code reader with a mask for better perfomance
-
example
`<dbp-qr-code-scanner clip-mask></dbp-qr-code-scanner>`
## Events
## Events
...
...
This diff is collapsed.
Click to expand it.
packages/qr-code-scanner/src/qr-code-scanner.js
+
55
−
4
View file @
1d9f1a5b
...
@@ -29,6 +29,8 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
...
@@ -29,6 +29,8 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
this
.
activeCamera
=
''
;
this
.
activeCamera
=
''
;
this
.
sourceChanged
=
false
;
this
.
sourceChanged
=
false
;
this
.
clipMask
=
true
;
}
}
static
get
scopedElements
()
{
static
get
scopedElements
()
{
...
@@ -53,7 +55,8 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
...
@@ -53,7 +55,8 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
showOutput
:
{
type
:
Boolean
,
attribute
:
'
show-output
'
},
showOutput
:
{
type
:
Boolean
,
attribute
:
'
show-output
'
},
stopScan
:
{
type
:
Boolean
,
attribute
:
'
stop-scan
'
},
stopScan
:
{
type
:
Boolean
,
attribute
:
'
stop-scan
'
},
activeCamera
:
{
type
:
String
,
attribute
:
false
},
activeCamera
:
{
type
:
String
,
attribute
:
false
},
sourceChanged
:
{
type
:
Boolean
,
attribute
:
false
}
sourceChanged
:
{
type
:
Boolean
,
attribute
:
false
},
slipMask
:
{
type
:
Boolean
,
attribute
:
'
clip-mask
'
}
};
};
}
}
...
@@ -248,15 +251,63 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
...
@@ -248,15 +251,63 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
canvasElement
.
height
=
video
.
videoHeight
;
canvasElement
.
height
=
video
.
videoHeight
;
canvasElement
.
width
=
video
.
videoWidth
;
canvasElement
.
width
=
video
.
videoWidth
;
canvas
.
drawImage
(
video
,
0
,
0
,
canvasElement
.
width
,
canvasElement
.
height
);
canvas
.
drawImage
(
video
,
0
,
0
,
canvasElement
.
width
,
canvasElement
.
height
);
var
imageData
=
canvas
.
getImageData
(
0
,
0
,
canvasElement
.
width
,
canvasElement
.
height
);
// TODO smaller input size and make an overlay where no scan happens
let
maskWidth
=
0
;
let
maskHeight
=
0
;
let
maskStartX
=
canvasElement
.
width
;
let
maskStartY
=
canvasElement
.
height
;
let
imageData
=
canvas
.
getImageData
(
0
,
0
,
canvasElement
.
width
,
canvasElement
.
height
)
if
(
that
.
clipMask
)
{
//draw mask
maskWidth
=
500
;
maskHeight
=
500
;
maskStartX
=
canvasElement
.
width
/
2
-
maskWidth
/
2
;
maskStartY
=
canvasElement
.
height
/
2
-
maskHeight
/
2
;
canvas
.
beginPath
();
canvas
.
fillStyle
=
"
#0000006e
"
;
canvas
.
moveTo
(
0
,
0
);
canvas
.
lineTo
(
0
,
canvasElement
.
width
);
canvas
.
lineTo
(
canvasElement
.
width
,
canvasElement
.
height
);
canvas
.
lineTo
(
canvasElement
.
width
,
0
);
canvas
.
rect
(
maskStartX
,
maskStartY
,
maskWidth
,
maskHeight
);
canvas
.
fill
();
imageData
=
canvas
.
getImageData
(
maskStartX
,
maskStartY
,
maskWidth
,
maskHeight
);
}
var
code
=
jsQR
(
imageData
.
data
,
imageData
.
width
,
imageData
.
height
,
{
var
code
=
jsQR
(
imageData
.
data
,
imageData
.
width
,
imageData
.
height
,
{
inversionAttempts
:
"
dontInvert
"
,
inversionAttempts
:
"
dontInvert
"
,
});
});
if
(
code
)
{
if
(
code
)
{
drawLine
(
code
.
location
.
topLeftCorner
,
code
.
location
.
topRightCorner
,
color
);
let
topLeftCorner
=
code
.
location
.
topLeftCorner
;
let
topRightCorner
=
code
.
location
.
topRightCorner
;
let
bottomRightCorner
=
code
.
location
.
bottomRightCorner
;
let
bottomLeftCorner
=
code
.
location
.
bottomLeftCorner
;
if
(
that
.
clipMask
)
{
topLeftCorner
.
x
+=
maskStartX
;
topLeftCorner
.
y
+=
maskStartY
;
topRightCorner
.
x
+=
maskStartX
;
topRightCorner
.
y
+=
maskStartY
;
bottomRightCorner
.
x
+=
maskStartX
;
bottomRightCorner
.
y
+=
maskStartY
;
bottomLeftCorner
.
x
+=
maskStartX
;
bottomLeftCorner
.
y
+=
maskStartY
;
}
drawLine
(
topLeftCorner
,
topRightCorner
,
color
);
drawLine
(
topRightCorner
,
bottomRightCorner
,
color
);
drawLine
(
bottomRightCorner
,
bottomLeftCorner
,
color
);
drawLine
(
bottomLeftCorner
,
topLeftCorner
,
color
);
/*drawLine(code.location.topLeftCorner, code.location.topRightCorner, color);
drawLine(code.location.topRightCorner, code.location.bottomRightCorner, color);
drawLine(code.location.topRightCorner, code.location.bottomRightCorner, color);
drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner, color);
drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner, color);
drawLine
(
code
.
location
.
bottomLeftCorner
,
code
.
location
.
topLeftCorner
,
color
);
drawLine(code.location.bottomLeftCorner, code.location.topLeftCorner, color);
*/
outputMessage
.
hidden
=
true
;
outputMessage
.
hidden
=
true
;
outputData
.
parentElement
.
hidden
=
false
;
outputData
.
parentElement
.
hidden
=
false
;
outputData
.
innerText
=
code
.
data
;
outputData
.
innerText
=
code
.
data
;
...
...
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