106 lines
14 KiB
JavaScript
106 lines
14 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.cropScreenshot = exports.calculateClipInfo = exports.getClipInfoByCropDimensions = exports.getClipInfoByMarkPosition = exports.calculateMarkPosition = exports.markSeedToId = void 0;
|
|
const utils_1 = require("./utils");
|
|
const limit_number_1 = __importDefault(require("../utils/limit-number"));
|
|
const promisified_functions_1 = require("../utils/promisified-functions");
|
|
const test_run_1 = require("../errors/test-run/");
|
|
const constants_1 = require("./constants");
|
|
const MARK_SEED_ERROR_THRESHOLD = 10;
|
|
const WHITE_COLOR_PART = 255;
|
|
const BLACK_COLOR_PART = 0;
|
|
function markSeedToId(markSeed) {
|
|
let id = 0;
|
|
for (let i = 0; i < constants_1.MARK_LENGTH; i++)
|
|
id = id * 2 + (markSeed[i * constants_1.MARK_BYTES_PER_PIXEL] ? 1 : 0);
|
|
return id;
|
|
}
|
|
exports.markSeedToId = markSeedToId;
|
|
function getCorrectedColorPart(colorPart) {
|
|
const isWhite = colorPart > WHITE_COLOR_PART - MARK_SEED_ERROR_THRESHOLD;
|
|
const isBlack = colorPart < MARK_SEED_ERROR_THRESHOLD;
|
|
if (isBlack)
|
|
return BLACK_COLOR_PART;
|
|
if (isWhite)
|
|
return WHITE_COLOR_PART;
|
|
return colorPart;
|
|
}
|
|
async function validateClipInfo(clipInfo, path) {
|
|
const clipWidth = clipInfo.clipRight - clipInfo.clipLeft;
|
|
const clipHeight = clipInfo.clipBottom - clipInfo.clipTop;
|
|
if (clipWidth <= 0 || clipHeight <= 0) {
|
|
await (0, promisified_functions_1.deleteFile)(path);
|
|
throw new test_run_1.InvalidElementScreenshotDimensionsError(clipWidth, clipHeight);
|
|
}
|
|
}
|
|
function calculateMarkPosition(pngImage, markSeed) {
|
|
const mark = Buffer.from(markSeed);
|
|
const filtImg = Buffer.from(pngImage.data);
|
|
for (let i = 0; i < filtImg.length; i++)
|
|
filtImg[i] = getCorrectedColorPart(filtImg[i]);
|
|
const markIndex = filtImg.indexOf(mark);
|
|
if (markIndex < 0)
|
|
return null;
|
|
const endPosition = markIndex / constants_1.MARK_BYTES_PER_PIXEL + constants_1.MARK_LENGTH + constants_1.MARK_RIGHT_MARGIN;
|
|
const x = endPosition % pngImage.width || pngImage.width;
|
|
const y = (endPosition - x) / pngImage.width + 1;
|
|
return { x, y };
|
|
}
|
|
exports.calculateMarkPosition = calculateMarkPosition;
|
|
function getClipInfoByMarkPosition(markPosition, { width, height }) {
|
|
const { x, y } = markPosition;
|
|
const clipRight = x;
|
|
const clipBottom = y;
|
|
const clipLeft = clipRight - width;
|
|
const clipTop = clipBottom - height;
|
|
return {
|
|
clipLeft,
|
|
clipTop,
|
|
clipRight,
|
|
clipBottom,
|
|
};
|
|
}
|
|
exports.getClipInfoByMarkPosition = getClipInfoByMarkPosition;
|
|
function getClipInfoByCropDimensions({ clipRight, clipLeft, clipBottom, clipTop }, cropDimensions) {
|
|
if (cropDimensions) {
|
|
const { right, top, bottom, left } = cropDimensions;
|
|
clipRight = (0, limit_number_1.default)(clipLeft + right, clipLeft, clipRight);
|
|
clipBottom = (0, limit_number_1.default)(clipTop + bottom, clipTop, clipBottom);
|
|
clipLeft = (0, limit_number_1.default)(clipLeft + left, clipLeft, clipRight);
|
|
clipTop = (0, limit_number_1.default)(clipTop + top, clipTop, clipBottom);
|
|
}
|
|
return {
|
|
clipLeft,
|
|
clipTop,
|
|
clipRight,
|
|
clipBottom,
|
|
};
|
|
}
|
|
exports.getClipInfoByCropDimensions = getClipInfoByCropDimensions;
|
|
function calculateClipInfo(pngImage, markSeedPosition, clientAreaDimensions, cropDimensions) {
|
|
let clipInfo = {
|
|
clipRight: pngImage.width,
|
|
clipBottom: pngImage.height,
|
|
clipLeft: 0,
|
|
clipTop: 0,
|
|
};
|
|
if (markSeedPosition && clientAreaDimensions)
|
|
clipInfo = getClipInfoByMarkPosition(markSeedPosition, clientAreaDimensions);
|
|
clipInfo = getClipInfoByCropDimensions(clipInfo, cropDimensions);
|
|
if (markSeedPosition && markSeedPosition.y === clipInfo.clipBottom)
|
|
clipInfo.clipBottom--;
|
|
return clipInfo;
|
|
}
|
|
exports.calculateClipInfo = calculateClipInfo;
|
|
async function cropScreenshot(image, { path, markSeedPosition, clientAreaDimensions, cropDimensions }) {
|
|
if (!markSeedPosition && !cropDimensions)
|
|
return null;
|
|
const clip = calculateClipInfo(image, markSeedPosition, clientAreaDimensions, cropDimensions);
|
|
await validateClipInfo(clip, path);
|
|
return (0, utils_1.copyImagePart)(image, clip);
|
|
}
|
|
exports.cropScreenshot = cropScreenshot;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JvcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zY3JlZW5zaG90cy9jcm9wLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLG1DQUF3QztBQUN4Qyx5RUFBZ0Q7QUFDaEQsMEVBQTREO0FBQzVELGtEQUE4RTtBQUM5RSwyQ0FJcUI7QUFFckIsTUFBTSx5QkFBeUIsR0FBRyxFQUFFLENBQUM7QUFDckMsTUFBTSxnQkFBZ0IsR0FBWSxHQUFHLENBQUM7QUFDdEMsTUFBTSxnQkFBZ0IsR0FBWSxDQUFDLENBQUM7QUFFcEMsU0FBZ0IsWUFBWSxDQUFFLFFBQVE7SUFDbEMsSUFBSSxFQUFFLEdBQUcsQ0FBQyxDQUFDO0lBRVgsS0FBSyxJQUFJLENBQUMsR0FBRyxDQUFDLEVBQUUsQ0FBQyxHQUFHLHVCQUFXLEVBQUUsQ0FBQyxFQUFFO1FBQ2hDLEVBQUUsR0FBRyxFQUFFLEdBQUcsQ0FBQyxHQUFHLENBQUMsUUFBUSxDQUFDLENBQUMsR0FBRyxnQ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