Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static const int WAYPOINT_COUNT = ${nodes.length};
`
fileData += `static const Position AIR_WAYPOINTS[] = {
{${startPos.x}.5f, ${startPos.y}.5f},
{${endPos.x}.5f, ${endPos.y}.5f}
};
static const int AIR_WAYPOINT_COUNT = 2;
`
// Generate waves
let waves = []
png = PNG.sync.read(fs.readFileSync("rawAssets/waves.png"));
for (let y = 0; y < png.height; ++y)
{
let x = 0
let wave = []
for (; x < png.width; ++x)
{
let k = (y * png.width + x) * 4
let r = png.data[k + 0];
let g = png.data[k + 1];
let b = png.data[k + 2];
if (x == 0 && r == 0 && g == 0 && b == 0) break
if (r == 255 && g == 0 && b == 255)
{
wave.push({
function compareImages (actualBuffer, expectedBuffer, mimeType) {
if (!actualBuffer || !(actualBuffer instanceof Buffer)) {
return { errorMessage: 'Actual result should be Buffer.' }
}
const actual =
mimeType === 'image/png'
? PNG.sync.read(actualBuffer)
: jpeg.decode(actualBuffer)
const expected =
mimeType === 'image/png'
? PNG.sync.read(expectedBuffer)
: jpeg.decode(expectedBuffer)
if (expected.width !== actual.width || expected.height !== actual.height) {
return {
errorMessage: `Sizes differ: expected image ${expected.width}px X ${
expected.height
}px, but got ${actual.width}px X ${actual.height}px. `
}
}
const diff = new PNG({ width: expected.width, height: expected.height })
const count = pixelmatch(
expected.data,
actual.data,
diff.data,
expected.width,
expected.height,
{ threshold: 0.1 }
function compareImages(actualBuffer, expectedBuffer, mimeType) {
if (!actualBuffer || !(actualBuffer instanceof Buffer))
return { errorMessage: 'Actual result should be Buffer.' };
const actual = mimeType === 'image/png' ? PNG.sync.read(actualBuffer) : jpeg.decode(actualBuffer);
const expected = mimeType === 'image/png' ? PNG.sync.read(expectedBuffer) : jpeg.decode(expectedBuffer);
if (expected.width !== actual.width || expected.height !== actual.height) {
return {
errorMessage: `Sizes differ: expected image ${expected.width}px X ${expected.height}px, but got ${actual.width}px X ${actual.height}px. `
};
}
const diff = new PNG({width: expected.width, height: expected.height});
const count = pixelmatch(expected.data, actual.data, diff.data, expected.width, expected.height, {threshold: 0.1});
return count > 0 ? { diff: PNG.sync.write(diff) } : null;
}
function checkPngJs(data, values) {
const img = PNG.sync.read(Buffer.from(data, data.byteOffset, data.length));
var newValues = Object.assign({}, values);
if (newValues.bitDepth !== undefined) {
newValues.depth = newValues.bitDepth;
delete newValues.bitDepth;
}
if (newValues.colourType !== undefined) {
newValues.colorType = newValues.colourType;
delete newValues.colourType;
}
check(img, newValues);
}
function computeImageDifferences (referenceBuffer, actualBuffer, diffFilename) {
const referenceImage = PNG.sync.read(referenceBuffer)
const actualImage = PNG.sync.read(actualBuffer)
const { width, height } = referenceImage
const diff = new PNG({ width, height })
const numDiffPixels = pixelmatch(referenceImage.data, actualImage.data, diff.data, width, height, { threshold: 0.1 })
fs.writeFileSync(diffFilename, PNG.sync.write(diff))
return numDiffPixels
}
beforeEach(() => {
testPngBuffer = PNG.sync.write(initPic(100, 50));
});
it('returns the unmodified original buffer if the clip corresponds to the actual size', done => {
return;
}
let error = new TractorError(`Visual Regression failed for ${filePath}`);
if (imagesAreSameSize(baselinePNG, changesPNG)) {
const diffPixelCount = pixelmatch(baselinePNG.data, changesPNG.data, diffPNG.data, width, height, { threshold: 0.1 });
if (diffPixelCount === 0) {
return;
}
} else {
error = new TractorError(`New screenshot for ${filePath} is not the same size as baseline.`);
}
diffPNGFile = diffPNGFile || new DiffPNGFile(diffsPath, fileStructure);
await diffPNGFile.save(PNG.sync.write(diffPNG));
throw error;
}
export default () => ({
mime: { [MIME_TYPE]: ['png'] },
constants: {
MIME_PNG: MIME_TYPE,
PNG_FILTER_AUTO,
PNG_FILTER_NONE,
PNG_FILTER_SUB,
PNG_FILTER_UP,
PNG_FILTER_AVERAGE,
PNG_FILTER_PATH
},
hasAlpha: { [MIME_TYPE]: true },
decoders: { [MIME_TYPE]: PNG.sync.read },
encoders: {
[MIME_TYPE]: data => {
const png = new PNG({
width: data.bitmap.width,
height: data.bitmap.height
});
png.data = data.bitmap.data;
return PNG.sync.write(png, {
width: data.bitmap.width,
height: data.bitmap.height,
deflateLevel: data._deflateLevel,
deflateStrategy: data._deflateStrategy,
filterType: data._filterType,
colorType:
async printImageBuffer(buffer) {
try {
var png = PNG.sync.read(buffer);
let buff = this.printer.printImageBuffer(png.width, png.height, png.data);
this.append(buff);
return buff;
} catch(error) {
throw error;
}
}
module.exports = (actual: any, expected: any, diffFile: any): number => {
if (!actual || !fs.existsSync(actual)) {
throw new Error(`Actual file is required, cannot get [${actual}] file`);
}
if (!expected || !fs.existsSync(expected)) {
throw new Error(`Expected file is required, cannot get [${expected}] file`);
}
const imageActual = PNG.sync.read(fs.readFileSync(actual));
const imageExpected = PNG.sync.read(fs.readFileSync(expected));
const diff = new PNG({ width: imageExpected.width, height: imageExpected.height });
const differentPixelsCount = pixelmatch(
imageActual.data,
imageExpected.data,
diff.data,
imageActual.width,
imageActual.height,
{ threshold: 0.1 },
);
if (diffFile) {
diff.pack().pipe(fs.createWriteStream(diffFile));
}