-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(qr): noExcavate option, react support
- Loading branch information
Showing
25 changed files
with
237 additions
and
85 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { BitMatrix } from "./typing/types"; | ||
|
||
/** | ||
* Finders require different UI representation, so we zero-fill finders and draw them later | ||
*/ | ||
export function zeroFillFinders(matrix: BitMatrix): BitMatrix { | ||
matrix = structuredClone(matrix); // avoid mutating input arg | ||
const N = matrix.length; | ||
const zeroPixel = 0; | ||
// squares | ||
for (let i = -3; i <= 3; i++) { | ||
for (let j = -3; j <= 3; j++) { | ||
matrix[3 + i][3 + j] = zeroPixel; | ||
matrix[3 + i][N - 4 + j] = zeroPixel; | ||
matrix[N - 4 + i][3 + j] = zeroPixel; | ||
} | ||
} | ||
// border | ||
for (let i = 0; i < 8; i++) { | ||
matrix[7][i] = | ||
matrix[i][7] = | ||
matrix[7][N - i - 1] = | ||
matrix[i][N - 8] = | ||
matrix[N - 8][i] = | ||
matrix[N - 1 - i][7] = | ||
zeroPixel; | ||
} | ||
return matrix; | ||
} | ||
|
||
/** | ||
* Before we insert logo in the QR we need to clear pixels under the logo. This function clears pixels | ||
*/ | ||
export function clearMatrixCenter(matrix: BitMatrix, widthPct: number, heightPct: number): BitMatrix { | ||
matrix = structuredClone(matrix); // avoid mutating input arg | ||
|
||
// TODO: Here's a homegrown formula, perhaps could be simplified | ||
const mW = matrix.length; | ||
const cW = Math.ceil(((mW * widthPct) / 100 + (mW % 2)) / 2) * 2 - (mW % 2); | ||
const mH = matrix[0]?.length ?? 0; | ||
const cH = Math.ceil(((mH * heightPct) / 100 + (mH % 2)) / 2) * 2 - (mH % 2); | ||
|
||
// Given the formula, these must be whole numbers, but round anyway to account for js EPSILON | ||
const clearStartX = Math.round((mW - cW) / 2); | ||
const clearStartY = Math.round((mH - cH) / 2); | ||
|
||
for (let x = clearStartX; x < clearStartX + cW; x += 1) { | ||
for (let y = clearStartY; y < clearStartY + cH; y += 1) { | ||
matrix[x][y] = 0; | ||
} | ||
} | ||
return matrix; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.