Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/mks-scalers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `mks2013` and `mks2021` (Magic Kernel Sharp) scale filters
11 changes: 11 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5920,6 +5920,17 @@ them.
set to ``0.0`` and ``0.5`` respectively. This filter is sharper than
``mitchell``, but prone to ringing.

``mks2013``
Magic Kernel Sharp 2013. The quadratic B-spline ("magic kernel")
combined with a sharpening step, expressed as a single kernel with a
support of radius 2.5. See https://johncostella.com/magic/ for details.

``mks2021``
Magic Kernel Sharp 2021. A refinement of ``mks2013`` with a flatter
frequency response (support of radius 4.5), making it closer to true
interpolation, at a slightly higher cost and with marginally more

@arch1t3cht arch1t3cht Jul 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true interpolation is confusing language IMO, since it can be understood to imply that there is some objectively correct sort of interpolation. If this is about the kernel being (close to) interpolatory, i.e. a resample to the same res being the identity, then interpolatory might be the better wording.

ringing.

``oversample``
A version of nearest neighbour that (naively) oversamples pixels, so
that pixels overlapping edges get linearly interpolated instead of
Expand Down
33 changes: 33 additions & 0 deletions video/out/filter_kernels.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,36 @@ static double spline64(params *p, double x)
}
}

// Magic Kernel Sharp family: the quadratic B-spline ("magic kernel")
// See https://johncostella.com/magic/
static double magic_sharp_2013(double x)
{
// quadric(x) convolved with {-1/4, +3/2, -1/4}
if (x < 0.5)
return 17.0/16.0 - 7.0/4.0 * (x * x);
if (x < 1.5)
return (x * x) - 11.0/4.0 * x + 7.0/4.0;
if (x < 2.5) {
x -= 5.0/2.0;
return -1.0/8.0 * (x * x);
}
return 0.0;
}

static double mks2013(params *p, double x)
{
// Scaled to mks2013(0) == 1
return 16.0/17.0 * magic_sharp_2013(x);
}

static double mks2021(params *p, double x)
{
// magic_sharp_2013(x) convolved with {+1/36, 0, +34/36, 0, +1/36},
// scaled to mks2021(0) == 1
return (magic_sharp_2013(fabs(x - 2.0)) + 34.0 * magic_sharp_2013(x) +
magic_sharp_2013(x + 2.0)) * 16.0/577.0;
}

static double gaussian(params *p, double x)
{
return exp(-2.0 * x * x / p->params[0]);
Expand Down Expand Up @@ -420,6 +450,9 @@ const struct filter_kernel mp_filter_kernels[] = {
{{SCALER_EWA_ROBIDOUXSHARP, 2,cubic_bc,
.params = {6 / (13 + 7 * M_SQRT2), 7 / (2 + 12 * M_SQRT2)}},
.polar = true},
// Magic Kernel Sharp filters, see https://johncostella.com/magic/
{{SCALER_MKS2013, 2.5, mks2013}},
{{SCALER_MKS2021, 4.5, mks2021}},
// Miscellaneous filters
{{SCALER_BOX, 1, box, .resizable = true}},
{{SCALER_NEAREST, 0.5, box}},
Expand Down
2 changes: 2 additions & 0 deletions video/out/filter_kernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ enum scaler_filter {
SCALER_ROBIDOUXSHARP,
SCALER_EWA_ROBIDOUX,
SCALER_EWA_ROBIDOUXSHARP,
SCALER_MKS2013,
SCALER_MKS2021,
SCALER_BOX,
SCALER_NEAREST,
SCALER_TRIANGLE,
Expand Down
2 changes: 2 additions & 0 deletions video/out/gpu/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ struct gl_video {
{"mitchell", SCALER_MITCHELL}, \
{"robidoux", SCALER_ROBIDOUX}, \
{"robidouxsharp", SCALER_ROBIDOUXSHARP}, \
{"mks2013", SCALER_MKS2013}, \
{"mks2021", SCALER_MKS2021}, \
{"box", SCALER_BOX}, \
{"nearest", SCALER_NEAREST}, \
{"triangle", SCALER_TRIANGLE}, \
Expand Down
Loading