2018-12-20 15:45:23 +01:00
/ * *
* @ author j433866 [ j433866 @ gmail . com ]
* @ copyright Crown Copyright 2018
* @ license Apache - 2.0
* /
2019-07-09 13:23:59 +02:00
import Operation from "../Operation.mjs" ;
import OperationError from "../errors/OperationError.mjs" ;
2019-03-13 10:20:13 +01:00
import { isImage } from "../lib/FileType.mjs" ;
2019-07-09 13:23:59 +02:00
import { parseQrCode } from "../lib/QRCode.mjs" ;
2018-12-20 15:45:23 +01:00
/ * *
* Parse QR Code operation
* /
class ParseQRCode extends Operation {
/ * *
* ParseQRCode constructor
* /
constructor ( ) {
super ( ) ;
this . name = "Parse QR Code" ;
this . module = "Image" ;
2018-12-25 22:54:38 +01:00
this . description = "Reads an image file and attempts to detect and read a Quick Response (QR) code from the image.<br><br><u>Normalise Image</u><br>Attempts to normalise the image before parsing it to improve detection of a QR code." ;
2018-12-20 15:45:23 +01:00
this . infoURL = "https://wikipedia.org/wiki/QR_code" ;
2019-04-01 11:54:46 +02:00
this . inputType = "ArrayBuffer" ;
2018-12-20 15:45:23 +01:00
this . outputType = "string" ;
2018-12-21 12:24:31 +01:00
this . args = [
{
"name" : "Normalise image" ,
"type" : "boolean" ,
2018-12-25 22:54:38 +01:00
"value" : false
2018-12-21 12:24:31 +01:00
}
] ;
2020-03-24 12:06:37 +01:00
this . checks = [
{
"pattern" : "^(?:\\xff\\xd8\\xff|\\x89\\x50\\x4e\\x47|\\x47\\x49\\x46|.{8}\\x57\\x45\\x42\\x50|\\x42\\x4d)" ,
"flags" : "" ,
"args" : [ false ] ,
"useful" : true
2019-03-07 14:35:37 +01:00
}
2020-03-24 12:06:37 +01:00
] ;
2018-12-20 15:45:23 +01:00
}
/ * *
2019-04-01 11:54:46 +02:00
* @ param { ArrayBuffer } input
2018-12-20 15:45:23 +01:00
* @ param { Object [ ] } args
* @ returns { string }
* /
async run ( input , args ) {
2018-12-21 12:24:31 +01:00
const [ normalise ] = args ;
2018-12-25 22:54:38 +01:00
2019-09-04 14:54:59 +02:00
if ( ! isImage ( input ) ) {
2018-12-20 15:45:23 +01:00
throw new OperationError ( "Invalid file type." ) ;
}
2019-03-07 14:21:26 +01:00
return await parseQrCode ( input , normalise ) ;
2018-12-20 15:45:23 +01:00
}
}
export default ParseQRCode ;