hidglobal / digitalpersona-devices

DigitalPersona Security Devices support library
https://hidglobal.github.io/digitalpersona-devices/index.html
MIT License
64 stars 41 forks source link

converted output from b64UrlTo64 to WSQ #59

Closed wanfahdiva closed 6 months ago

wanfahdiva commented 6 months ago

Is it possible to convert the output from b64UrlTo64 to WSQ format? so I tried this SDK using the example repo from https://github.com/ialeke/React-Fingerpint-Reader, and from this repo it only gives base64 output. is there another way to convert the output from base64 to WSQ format?

this the preview off sdk code using in thi repo:

const Fingerprint = window.Fingerprint

const FingerprintSdk = (function () {
    function FingerprintSdk() {
        this.sdk = new Fingerprint.WebApi()

        this.sdk.onSamplesAcquired = function(s) {
            samplesAcquired(s)
        }
    }

    FingerprintSdk.prototype.getDeviceList = function () { return this.sdk.enumerateDevices() }

    FingerprintSdk.prototype.startCapture = function () {
        this.sdk.startAcquisition(Fingerprint.SampleFormat.PngImage).then(function () {
            return console.log('Capturando huella')
        }, function (error) {
            return console.log('Error al comenzar la captura de huella')
        })
    }

    FingerprintSdk.prototype.stopCapture = function () {
        this.sdk.stopAcquisition().then(function () {
            return console.log('Captura de huella detenida')
        }, function (error) {
            return console.log('Error al detener la captura de huella')
        })
    }

    return FingerprintSdk
})()

function samplesAcquired(s){
        localStorage.setItem("imageSrc", "");
        let samples = JSON.parse(s.samples);
        localStorage.setItem("imageSrc", "data:image/png;base64," + Fingerprint.b64UrlTo64(samples[0]));
        let vDiv = document.getElementById('imagediv');
        vDiv.innerHTML = "";
        let image = document.createElement("img");
        image.id = "image";
        image.src = localStorage.getItem("imageSrc");
        vDiv.appendChild(image);
    // }
}

module.exports = { FingerprintSdk, Fingerprint }

thanks

a-bronx commented 6 months ago

Supported sample formats are following:

export enum SampleFormat {
    /** A raw fingerprint image (bitmap). */
    Raw = 1,
    /** A fingerprint feature set in a DigitalPersona proprietary format. To use with DigitalPersona fingerprint matching engine only. */
    Intermediate = 2,
    /** A fingerprint image compressed using Wavelet Scalar Quantization (WSQ) algotithm. */
    Compressed = 3,
    /** A fingerprint image in a Portable Network Graphics (PNG) format. */
    PngImage = 5,
}

In you code, change this.sdk.startAcquisition(Fingerprint.SampleFormat.PngImage) to this.sdk.startAcquisition(Fingerprint.SampleFormat.Compressed), and you'll get a Base64Url-encoded WSQ image.

wanfahdiva commented 5 months ago

thanks for the answer mr @a-bronx, but i have onemore question. how to display it on html image or save as file .wsq? is it possible?

a-bronx commented 5 months ago

how to display it on html image

As far as I know, browsers do not support WSQ images, there is even no MIME type for it. You can try MIME types for JPEG200 (image/jp2, image/jpx, image/jpm) which is also uses DWT, but I doubt it will work.

So for display purposes you may need to stick to PNG.

save as file .wsq?

Same as any other file, but as there is no known MIME type for WSQ, you'll probably need to save it as "unknown" file format, using MIME type like application-octet-stream (standard) or application/unknown (nonstandard) or just empty MIME type (also standard).

wanfahdiva commented 5 months ago

thank you for the answer mr @a-bronx