sharp/test/unit/median.js
Lovell Fuller b36237ddcb Switch linter from semistandard to biome
Uses the recommended rules apart from complexity/useArrowFunction,
which would affect about 1700 lines of code with little benefit
right now. This is something that can be addressed over time.
2025-09-18 21:18:31 +01:00

53 lines
1.1 KiB
JavaScript

// Copyright 2013 Lovell Fuller and others.
// SPDX-License-Identifier: Apache-2.0
const assert = require('node:assert');
const sharp = require('../../');
const row = [0, 3, 15, 63, 127, 255];
const input = Buffer.from(Array.from(row, () => row).flat());
const raw = {
width: 6,
height: 6,
channels: 1
};
describe('Median filter', function () {
it('default window (3x3)', async () => {
const data = await sharp(input, { raw })
.median()
.toColourspace('b-w')
.raw()
.toBuffer();
assert.deepStrictEqual(data.subarray(0, 6), Buffer.from(row));
});
it('3x3 window', async () => {
const data = await sharp(input, { raw })
.median(3)
.toColourspace('b-w')
.raw()
.toBuffer();
assert.deepStrictEqual(data.subarray(0, 6), Buffer.from(row));
});
it('5x5 window', async () => {
const data = await sharp(input, { raw })
.median(5)
.toColourspace('b-w')
.raw()
.toBuffer();
assert.deepStrictEqual(data.subarray(0, 6), Buffer.from(row));
});
it('invalid radius', () => {
assert.throws(() => {
sharp().median(0.1);
});
});
});