rexshijaku / pdf-qr.js

PDF QR-scanner entirely written in JavaScript.
MIT License
9 stars 5 forks source link

Handling uploads with high page dimensions. #1

Open rexshijaku opened 1 year ago

rexshijaku commented 1 year ago

When the initial page dimensions are for example 1800x2300, while scaling, as expected this size gets even larger, but when it reaches certain dimension/size decoding gets very slow!

Must be handled in some way, or at least a property of 'scale-anyway' must be introduced to configuration.

rexshijaku commented 1 year ago

As an initial solution we maybe can introduce a MAX_DECODING_TIME_IN_SECONDS variable, when it is reached, it stops the page from further decoding trials.

In postPdfJsPageRender function:

const decoding_start_time = new Date(); // current date and time
const code = QR_JS(
  imginfo.processImg,
  imginfo.imgWidth,
  imginfo.imgHeight,
  jsQR_configs
);
const decoding_end_time = new Date();
const diffInSeconds =
  (decoding_end_time.getTime() - decoding_start_time.getTime()) / 1000;

if (code) {
  setResult(code, finalResults, currentPage, scaled, settings);
  return resolve({
    isDone: true,
    message: "Ok found!",
    totalSeconds: diffInSeconds,
  });
} else {
  return resolve({
    isDone: false,
    message: "Not found!",
    totalSeconds: diffInSeconds,
  });
}

and then after the result is fetched:


  if (result.totalSeconds > MAX_DECODING_TIME_IN_SECONDS) {
    console.log("Scale process stopped [MAX SECONDS REACHED]...");
    break;
  }