1 line
79 KiB
Plaintext
1 line
79 KiB
Plaintext
|
|
{"version":3,"file":"dom-BnEjxmqU.js","sources":["../../node_modules/qr/decode.js","../../node_modules/qr/dom.js"],"sourcesContent":["/*!\nCopyright (c) 2023 Paul Miller (paulmillr.com)\nThe library paulmillr-qr is dual-licensed under the Apache 2.0 OR MIT license.\nYou can select a license of your choice.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n/**\n * Methods for decoding (reading) QR code patterns.\n * @module\n * @example\n```js\n\n```\n */\nimport { Bitmap, utils } from \"./index.js\";\nconst { best, bin, drawTemplate, fillArr, info, interleave, validateVersion, zigzag } = utils;\n// Constants\nconst MAX_BITS_ERROR = 3; // Up to 3 bit errors in version/format\nconst GRAYSCALE_BLOCK_SIZE = 8;\nconst GRAYSCALE_RANGE = 24;\nconst PATTERN_VARIANCE = 2;\nconst PATTERN_VARIANCE_DIAGONAL = 1.333;\nconst PATTERN_MIN_CONFIRMATIONS = 2;\nconst DETECT_MIN_ROW_SKIP = 3;\n// TODO: move to index, nearby with bitmap and other graph related stuff?\nconst int = (n) => n >>> 0;\n// distance ^ 2\nconst distance2 = (p1, p2) => {\n const x = p1.x - p2.x;\n const y = p1.y - p2.y;\n return x * x + y * y;\n};\nconst distance = (p1, p2) => Math.sqrt(distance2(p1, p2));\nconst sum = (lst) => lst.reduce((acc, i) => acc + i);\nconst pointIncr = (p, incr) => {\n p.x += incr.x;\n p.y += incr.y;\n};\nconst pointNeg = (p) => ({ x: -p.x, y: -p.y });\nconst pointMirror = (p) => ({ x: p.y, y: p.x });\nconst pointClone = (p) => ({ x: p.x, y: p.y });\nconst pointInt = (p) => ({ x: int(p.x), y: int(p.y) });\nconst pointAdd = (a, b) => ({ x: a.x + b.x, y: a.y + b.y });\nfunction cap(value, min, max) {\n return Math.max(Math.min(value, max || value), min || value);\n}\nconst getBytesPerPixel = (img) => {\n const perPixel = img.data.length / (img.width * img.height);\n if (perPixel === 3 || perPixel === 4)\n return perPixel; // RGB or RGBA\n throw new Error(`Unknown image format, bytes per pixel=${perPixel}`);\n};\n/**\n * Convert to grayscale. The function is the most expensive part of decoding:\n * it takes up to 90% of time. TODO: check gamma correction / sqr.\n */\nfunction toBitmap(img) {\n const bytesPerPixel = getBytesPerPixel(img);\n const brightness = new Uint8Array(img.height * img.width);\n for (let i = 0, j = 0, d = img.data; i < d.length; i += bytesPerPixel) {\n const r = d[i];\n const g = d[i + 1];\n const b = d[i + 2];\n brightness[j++] = int((r + 2 * g + b) / 4) & 0xff;\n }\n // Convert to bitmap\n const block = GRAYSCALE_BLOCK_SIZE;\n if (img.width < block * 5 || img.height < block * 5)\n throw new Error('image too small');\n const bWidth = Math.ceil(img.width / block);\n const bHeight = Math.ceil(img.height / block);\n const maxY = img.height - block;\n const maxX = img.width - block;\n const blocks = new Uint8Array(bWidth * bHeight);\n for (let y = 0; y < bHeight; y++) {\n const yPos = cap(y * block, 0, maxY);\n for (let x = 0; x < bWidth; x++) {\n const xPos = cap(x * block, 0, maxX);\n let sum = 0;\n let min = 0xff;\n let max = 0;\n for (let yy = 0, pos = yPos * img.width + xPos; yy < block; yy = yy + 1, pos = pos + img.width) {\n for (let xx = 0; xx < block; xx++) {\n const pixel = brightness[pos + xx];\n sum += pixel;\n min = Math.min(min, pixel);\n max = Math.max(max, pixel);\n }\n }\n // Average brightness of block\n let avera
|