const img = await jimp.read('./qrcode.jpg');
const formats = [BarcodeFormat.QR_CODE];
const hints = new Map();
hints.set(DecodeHintType.POSSIBLE_FORMATS, formats);
hints.set(DecodeHintType.TRY_HARDER, true);
const reader = new MultiFormatReader();
reader.setHints(hints);
const imageData = img.bitmap;
const len = imageData.width * imageData.height;
const luminancesUint8Array = new Uint8ClampedArray(len);
for (let i = 0; i < len; i++) {
luminancesUint8Array[i] =
((imageData.data[i * 4] + imageData.data[i * 4 + 1] * 2 + imageData.data[i * 4 + 2]) / 4) & 0xff;
}
const luminanceSource = new RGBLuminanceSource(luminancesUint8Array, imageData.width, imageData.height);
const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
const decoded = reader.decode(binaryBitmap);