mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-26 10:33:15 +03:00
Support multiple monitors in QR scan
This commit is contained in:
parent
46fa7d8f6d
commit
e7a45abe7b
@ -142,12 +142,12 @@ class Controller(object):
|
||||
return b32decode(key)
|
||||
|
||||
|
||||
def parse_qr(self, image):
|
||||
data = b64decode(image['data'])
|
||||
image = PixelImage(data, image['width'], image['height'])
|
||||
for qr in qrparse.parse_qr_codes(image, 2):
|
||||
return parse_uri(qrdecode.decode_qr_data(qr))
|
||||
return ""
|
||||
def parse_qr(self, screenshots):
|
||||
for s in screenshots:
|
||||
data = b64decode(s['data'])
|
||||
image = PixelImage(data, s['width'], s['height'])
|
||||
for qr in qrparse.parse_qr_codes(image, 2):
|
||||
return parse_uri(qrdecode.decode_qr_data(qr))
|
||||
|
||||
|
||||
class PixelImage(object):
|
||||
|
@ -195,7 +195,7 @@ Python {
|
||||
do_call('yubikey.controller.delete_credential', [credential, passwordKey])
|
||||
}
|
||||
|
||||
function parseQr(image, cb){
|
||||
do_call('yubikey.controller.parse_qr', [image], cb)
|
||||
function parseQr(screenShots, cb){
|
||||
do_call('yubikey.controller.parse_qr', [screenShots], cb)
|
||||
}
|
||||
}
|
||||
|
54
screenshot.h
54
screenshot.h
@ -10,34 +10,38 @@ public:
|
||||
explicit ScreenShot () : QObject() {}
|
||||
|
||||
// Take a screenshot, convert it to a bitarray and return it with some metadata
|
||||
Q_INVOKABLE QVariantMap capture() {
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
QPixmap screenShotPixMap = screen->grabWindow(0);
|
||||
QImage image = screenShotPixMap.toImage();
|
||||
|
||||
// Monochrome, no dither
|
||||
image = image.convertToFormat(QImage::Format_Mono, Qt::ThresholdDither);
|
||||
|
||||
// Iterate over all pixels
|
||||
QByteArray imageArray;
|
||||
for (int row = 0; row < image.height(); ++row) {
|
||||
for (int col = 0; col < image.width(); ++col) {
|
||||
QRgb px = image.pixel(col, row);
|
||||
|
||||
// If black 1 else 0
|
||||
if (px == 0xFF000000) {
|
||||
imageArray.append((char) 1);
|
||||
} else {
|
||||
imageArray.append((char) 0);
|
||||
Q_INVOKABLE QVariantList capture() {
|
||||
QList<QScreen*> screens = QGuiApplication::screens();
|
||||
QScreen *screen;
|
||||
QVariantList maps;
|
||||
// Iterate the screens
|
||||
for (int i = 0; i < screens.length(); i++) {
|
||||
screen = screens.at(i);
|
||||
// Screen geometry
|
||||
QRect g = screen->geometry();
|
||||
QPixmap screenShot = screen->grabWindow(0, g.x(), g.y(), g.width(), g.height());
|
||||
// Monochrome, no dither
|
||||
QImage image = screenShot.toImage();
|
||||
image = image.convertToFormat(QImage::Format_Mono, Qt::ThresholdDither);
|
||||
// Get all pixels as 1 (black) or 0 (white)
|
||||
QByteArray imageArray;
|
||||
for (int row = 0; row < image.height(); ++row) {
|
||||
for (int col = 0; col < image.width(); ++col) {
|
||||
QRgb px = image.pixel(col, row);
|
||||
if (px == 0xFF000000) {
|
||||
imageArray.append((char) 1);
|
||||
} else {
|
||||
imageArray.append((char) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
QVariantMap map;
|
||||
map.insert("width", image.width());
|
||||
map.insert("height", image.height());
|
||||
map.insert("data", QString(imageArray.toBase64()));
|
||||
maps.append(map);
|
||||
}
|
||||
|
||||
QVariantMap map;
|
||||
map.insert("width", image.width());
|
||||
map.insert("height", image.height());
|
||||
map.insert("data", QString(imageArray.toBase64()));
|
||||
return map;
|
||||
return maps;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user