1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 15:22:09 +00:00
mpv/video
wm4 3909e4cdfc filter_kernels: replace AGG-based code
This commit replaces code based on AGG, taken from this source file:

http://vector-agg.cvs.sourceforge.net/viewvc/vector-agg/agg-2.5/include/agg_image_filters.h

The intention is that filter_kernels.c can be relicensed to LGPL or BSD.
Because the AGG author died, full replacement is the only way to achieve
it.

This affects only some filter functions. These are exclusively
mathematical functions for computing filter coefficients. (Other parts
in filter_kernel.c were originally written by me, with heavy additions
and refactoring done by other mpv contributors.) While the code is
mostly just well-known mathematical formulas written down in C form,
AGG copyright could perhaps be claimed anyway.

To remove the AGG code, I replaced it with the filter functions from:

https://github.com/glumpy/glumpy/blob/master/glumpy/library/build-spatial-filters.py

These functions conveniently compute exactly the same thing in mpv,
Glumpy, AGG (and about anything that will filter images using the same
mathematical principles).

First I ported the Python code in the file to C. Then I replaced all
functions in filter_kernels.c with this code that could be replaced.
Then I investigated whether the remaining functions were based on AGG
code and took appropriate action:

hanning(), hamming(), quadric(), bicubic(), kaiser(), blackman(),
spline16(), spline36(), gaussian(), sinc() were taken straight from
Glumpy.

For sinc(), re-add the "fabs(x) < 1e-8" check, which was added in commit
586dc557 for unknown reasons.

gaussian() loses its filter parameter for some reason. (Well, who cares,
not my problem.)

The really awkward thing is that the text for hanning() and hamming()
does not change. In theory these functions are now based on Glumpy code,
but it seems like this can be neither proven nor denied. (The same
happened in some other cases with at least a few lines of code.)

sphinx() was added in commit 586dc557, and looks suspiciously like
sinc() as well. Replace the first 3 lines of the body with the ported
function (of which 2 lines do not change; the first uses code only in
mpv, and the second is just "return 1.0;"). The 4th line is only similar
on an abstract level (and that because of the mathematical relation
between these functions). Although the original sinc() was probably used
as template for it, with the other lines replaced, I don't think you
could make the claim that it falls under AGG copyright.

jinc() was added in commit 26baf5b9, but the code for it might be based
on sinc(). Rewrite it based on the "new" sinc(). Some of the same
remarks as with sphinx() apply.

cubic_bc() was ported from Glumpy's Mitchell(). (As far as I'm aware,
with the default parameters it's called "the" Mitchell-Netravali filter,
but in mpv this function is used to generate a whole group of filters.)

spline64() was added in commit a8b67c66, and was probably derived from
spline36(). Re-derive it from the "new" spline36().

triangle() could be considered derived from the original bilinear().
This is this in the original commit:

    static double bilinear(kernel *k, double x)
    {
        return 1.0 - x;
    }

This _might_ be based on AGG's image_filter_bilinear:

    struct image_filter_bilinear
    {
        static double radius() { return 1.0; }
        static double calc_weight(double x)
        {
            return 1.0 - x;
        }
    };

Considering that the "framework" was written by me, and the only part
from AGG taken is "return 1.0 - x;", and this part is trivial and was
later thoroughly replaced, this is probably not under the AGG copyright.

I'm hoping this doesn't introduce regressions. But the main focus is not
being productive anyway, and I didn't rigorously check unintended
changes in functionality.
2016-01-06 18:46:56 +01:00
..
decode vaapi: add VP9 profile entires 2015-12-20 10:40:06 +01:00
filter vf_yadif: change defaults 2015-12-21 22:05:40 +01:00
out filter_kernels: replace AGG-based code 2016-01-06 18:46:56 +01:00
csputils.c vo_opengl: fix gray playback 2015-12-26 18:36:55 +01:00
csputils.h csputils: update MP_STEREO3D_COUNT 2015-12-19 08:34:46 +01:00
d3d.h
fmt-conversion.c sub: find GBRP format automatically when rendering to RGB 2015-12-24 16:42:21 +01:00
fmt-conversion.h
gpu_memcpy.c video: refactor GPU memcpy usage 2015-09-25 19:18:16 +02:00
gpu_memcpy.h video: refactor GPU memcpy usage 2015-09-25 19:18:16 +02:00
hwdec.h video: remove VDA support 2015-09-28 22:03:14 +02:00
image_writer.c video: switch from using display aspect to sample aspect 2015-12-19 20:45:36 +01:00
image_writer.h
img_format.c sub: find GBRP format automatically when rendering to RGB 2015-12-24 16:42:21 +01:00
img_format.h sub: find GBRP format automatically when rendering to RGB 2015-12-24 16:42:21 +01:00
img_fourcc.h
mp_image_pool.c
mp_image_pool.h
mp_image.c video: switch from using display aspect to sample aspect 2015-12-19 20:45:36 +01:00
mp_image.h video: switch from using display aspect to sample aspect 2015-12-19 20:45:36 +01:00
sws_utils.c video: switch from using display aspect to sample aspect 2015-12-19 20:45:36 +01:00
sws_utils.h
vaapi.c Remove some VLAs 2015-11-06 21:12:20 +01:00
vaapi.h vaapi: drop non-existing FourCC 2015-10-17 14:20:53 +02:00
vdpau_functions.inc
vdpau_mixer.c csputils: rename "yuv2rgb" functions 2015-12-09 00:23:36 +01:00
vdpau_mixer.h
vdpau.c video: switch from using display aspect to sample aspect 2015-12-19 20:45:36 +01:00
vdpau.h