Skip to content
Snippets Groups Projects
Commit 7d32cb29 authored by Igor Markin's avatar Igor Markin
Browse files

Add build

parent c82e2cf9
No related branches found
No related tags found
No related merge requests found
......@@ -8,12 +8,12 @@ export interface RSAKeys {
privateKeyPEM: string;
}
export interface ICryptoService {
encryptAESGCM?: (data: string) => Promise<AESGCMOutput>;
decryptAESGCM?: (data: ArrayBuffer, key: ArrayBuffer, iv: ArrayBuffer) => Promise<string>;
generateRSAKeys?: () => Promise<RSAKeys>;
encryptRSA?: (publicKeyPEM: string, data: ArrayBuffer) => Promise<ArrayBuffer>;
decryptRSA?: (privateKeyPEM: string, data: ArrayBuffer) => Promise<ArrayBuffer>;
signRSA?: (privateKeyPEM: string, data: ArrayBuffer) => Promise<ArrayBuffer>;
verifyRSASignature?: (publicKeyPEM: string, data: ArrayBuffer, signature: ArrayBuffer) => Promise<boolean>;
SHA256?: (string: string) => Promise<ArrayBuffer>;
encryptAESGCM: (data: string) => Promise<AESGCMOutput>;
decryptAESGCM: (data: ArrayBuffer, key: ArrayBuffer, iv: ArrayBuffer) => Promise<string>;
generateRSAKeys: () => Promise<RSAKeys>;
encryptRSA: (publicKeyPEM: string, data: ArrayBuffer) => Promise<ArrayBuffer>;
decryptRSA: (privateKeyPEM: string, data: ArrayBuffer) => Promise<ArrayBuffer>;
signRSA: (privateKeyPEM: string, data: ArrayBuffer) => Promise<ArrayBuffer>;
verifyRSASignature: (publicKeyPEM: string, data: ArrayBuffer, signature: ArrayBuffer) => Promise<boolean>;
SHA256: (string: string) => Promise<ArrayBuffer>;
}
......@@ -10,8 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", { value: true });
const findChromakeyBoundaries = (width, height, imageData, chromakeyWidth, chromakeyHeight) => {
const maskSize = 50;
const totalSum = maskSize * maskSize * 255;
const maskSizeX = chromakeyWidth;
const maskSizeY = chromakeyHeight;
const totalSum = maskSizeX * maskSizeY * 255;
const matrixR = [];
const matrixG = [];
const matrixB = [];
......@@ -25,6 +26,11 @@ const findChromakeyBoundaries = (width, height, imageData, chromakeyWidth, chrom
matrixB[i][j] = 0;
}
}
const maxDistance = Math.sqrt(3 * totalSum * totalSum);
const suitableSimilarity = 0.6;
let bestSimilarity = 0;
let bestX = -1;
let bestY = -1;
for (let x = 0; x < width; x++) {
for (let y = 0; y < height; y++) {
const index = (y * width + x) * 4;
......@@ -49,27 +55,36 @@ const findChromakeyBoundaries = (width, height, imageData, chromakeyWidth, chrom
matrixG[x][y] -= matrixG[x - 1][y - 1];
matrixB[x][y] -= matrixB[x - 1][y - 1];
}
if (x >= maskSize && y >= maskSize) {
if (x >= maskSizeX && y >= maskSizeY) {
const tempSumR = matrixR[x][y] +
matrixR[x - maskSize][y - maskSize] -
(matrixR[x - maskSize][y] + matrixR[x][y - maskSize]);
matrixR[x - maskSizeX][y - maskSizeY] -
(matrixR[x - maskSizeX][y] + matrixR[x][y - maskSizeY]);
const tempSumG = matrixG[x][y] +
matrixG[x - maskSize][y - maskSize] -
(matrixG[x - maskSize][y] + matrixG[x][y - maskSize]);
matrixG[x - maskSizeX][y - maskSizeY] -
(matrixG[x - maskSizeX][y] + matrixG[x][y - maskSizeY]);
const tempSumB = matrixB[x][y] +
matrixB[x - maskSize][y - maskSize] -
(matrixB[x - maskSize][y] + matrixB[x][y - maskSize]);
if (tempSumR === 0 && tempSumG === totalSum && tempSumB === 0) {
return {
fromL: x - maskSize,
fromT: y - maskSize,
toL: x - maskSize + chromakeyWidth,
toT: y - maskSize + chromakeyHeight,
};
matrixB[x - maskSizeX][y - maskSizeY] -
(matrixB[x - maskSizeX][y] + matrixB[x][y - maskSizeY]);
const distance = Math.sqrt(Math.pow(0 - tempSumR, 2) +
Math.pow(totalSum - tempSumG, 2) +
Math.pow(0 - tempSumB, 2));
const similarity = 1 - distance / maxDistance;
if (similarity > bestSimilarity) {
bestX = x;
bestY = y;
bestSimilarity = similarity;
}
}
}
}
if (bestX >= 0 && bestY >= 0 && bestSimilarity > suitableSimilarity) {
return {
fromL: bestX - maskSizeX,
fromT: bestY - maskSizeY,
toL: bestX - maskSizeX + chromakeyWidth,
toT: bestY - maskSizeY + chromakeyHeight,
};
}
return { fromL: -1, fromT: -1, toL: -1, toT: -1 };
};
const putQrCodeOnChromakeyTemplate = (qrCodeImageBase64, templateImageBase64, placeholderWidth, placeholderHeight, scale = 1) => __awaiter(void 0, void 0, void 0, function* () {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment