summaryrefslogtreecommitdiff
path: root/libavfilter/vf_paletteuse.c
Commit message (Collapse)AuthorAge
* avutil/common: Don't auto-include mem.hAndreas Rheinhardt2024-03-31
| | | | | | | | | | | There are lots of files that don't need it: The number of object files that actually need it went down from 2011 to 884 here. Keep it for external users in order to not cause breakages. Also improve the other headers a bit while just at it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* all: use designated initializers for AVOption.unitAnton Khirnov2024-02-14
| | | | | | | | | | | | | | | | | | | | | | | | Makes it robust against adding fields before it, which will be useful in following commits. Majority of the patch generated by the following Coccinelle script: @@ typedef AVOption; identifier arr_name; initializer list il; initializer list[8] il1; expression tail; @@ AVOption arr_name[] = { il, { il1, - tail + .unit = tail }, ... }; with some manual changes, as the script: * has trouble with options defined inside macros * sometimes does not handle options under an #else branch * sometimes swallows whitespace
* avfilter: use ptrdiff_t instead of int for linesizePaul B Mahol2023-09-22
| | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* all: Use av_frame_replace() where appropriateAndreas Rheinhardt2023-09-10
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter/internal: Don't include formats.hAndreas Rheinhardt2023-08-07
| | | | | | | | | internal.h doesn't rely on it; instead include it directly in every user that needs it (a filter needing it is basically equivalent to it using FILTER_QUERY_FUNC, i.e. a majority of filters doesn't need it). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter/internal: Don't include video.hAndreas Rheinhardt2023-08-07
| | | | | | | | | | | internal.h does not depend on video.h (and should not depend on it) and therefore should not include video.h at all; instead all users of video.h should include it directly. Doing so also avoids unnecessary video.h inclusions in files that don't need it, like most audio filters. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter: use ff_inlink_make_frame_writable()Paul B Mahol2023-02-12
|
* avfilter/paletteuse: use explicit key indexes in set_frame_lutClément Bœsch2023-01-03
|
* avfilter/paletteuse: add atkinson ditheringClément Bœsch2023-01-03
| | | | | | | | | Atkinson according to https://bisqwit.iki.fi/jutut/kuvat/ordered_dither/error_diffusion.txt: * 1 1 / 8 1 1 1 1
* avfilter/paletteuse: add burkes ditheringClément Bœsch2023-01-03
| | | | | | | | Burkes according to https://bisqwit.iki.fi/jutut/kuvat/ordered_dither/error_diffusion.txt: * 8 4 2 4 8 4 2 / 32
* avfilter/paletteuse: add sierra3 ditheringClément Bœsch2023-01-03
| | | | | | | | | Sierra3 according to https://bisqwit.iki.fi/jutut/kuvat/ordered_dither/error_diffusion.txt: * 5 3 2 4 5 4 2 2 3 2 / 32
* avfilter/palette{gen,use}: misc for-loop cosmeticsClément Bœsch2023-01-03
|
* avfilter/paletteuse: move r,g,b computation in a more local scopeClément Bœsch2023-01-03
|
* avfilter/paletteuse: remove mean error toolClément Bœsch2023-01-03
| | | | This belongs in another filter.
* avfilter/paletteuse: remove alternative search methodsClément Bœsch2023-01-03
| | | | | This is a maintenance pain more than anything. It appears to make the code slightly faster as a side effect.
* avfilter/paletteuse: switch to recursive methodClément Bœsch2023-01-03
| | | | | | It appears faster than the iterative method on my machine (1.06x faster), so I'm guessing compilers improved over time (the iterative version was slightly faster in the past).
* avfilter/paletteuse: use lowbias32 for color hashingClément Bœsch2023-01-03
| | | | Impact is more negligible than previous commit but still faster (1.02x).
* avfilter/palette{gen,use}: update Copyright after recent changesClément Bœsch2023-01-03
|
* avfilter/paletteuse: switch to a perceptual modelClément Bœsch2023-01-03
| | | | | Now the selection of the color is based on a distance built around human perception of color instead of the unreliable sRGB triplet one.
* avfilter/paletteuse: remove redundant alpha conditionClément Bœsch2023-01-03
| | | | This is redundant with a != 0xff below.
* avfilter/paletteuse: remove unused alpha split dimensionClément Bœsch2023-01-03
| | | | | | The equalities in the w{r,g,b} range checks make sure longest is never 0. Even if the alpha ended up being selected in get_next_color() it would cause underread memory accesses in its caller (colormap_insert).
* avfilter/paletteuse: name target color arg consistently in colormap functionsClément Bœsch2023-01-03
|
* avfilter/paletteuse: switch from u8[4] to u32 for color codeClément Bœsch2023-01-03
| | | | | This change simplifies the code quite a bit and make it consistent with how it's done in palettegen.
* avfilter/palette{gen,use}: simplify a few alpha masksClément Bœsch2023-01-03
|
* avfilter/palette{gen,use}: revert support palettes with alphaClément Bœsch2023-01-03
| | | | | | | | | | | | | | | | | | | | | | | This reverts commit dea673d0d548c864ec85f9260d8900d944ef7a2a. This change cannot work for several reasons, the most obvious ones are: - the alpha is being part of the scoring of the color difference, even though we can not interpret the alpha as part of the perception of the color (we don't even know if it's premultiplied or postmultiplied) - the colors are averaged with their alpha value which simply cannot work The command proposed in the original thread of the patch actually produces a completely broken file: ffmpeg -y -loglevel verbose -i fate-suite/apng/o_sample.png -filter_complex "split[split1][split2];[split1]palettegen=max_colors=254:use_alpha=1[pal1];[split2][pal1]paletteuse=use_alpha=1" -frames:v 1 out.png We can see that many color pixels are off, but more importantly some colors have a random alpha value: https://imgur.com/eFQ2UK7 I don't see any easy fix for this unfortunately, the approach appears to be flawed by design.
* avutil/internal: Move avpriv-file API to a header of its ownAndreas Rheinhardt2022-09-03
| | | | | | | It is not used by the large majority of files that include lavu/internal.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* Switch uses of av_fopen_utf8 to avpriv_fopen_utf8Martin Storsjö2022-05-23
| | | | | | The former has been deprecated. Signed-off-by: Martin Storsjö <martin@martin.st>
* vf_paletteuse: fix color cache lookup for Bayer dithering mode.Rudolf Polzer2022-01-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To trigger this bug, use `paletteuse=dither=bayer:bayer_scale=0`; you will see that adjacent pixel lines will use the same dither pattern, instead of being shifted from each other by 32 units (0x20). One way to demostrate the bug is: $ convert -size 64x256 gradient:black-white -rotate 270 grad.png $ echo 'P2 2 1 255 0 255' > bw.pnm $ ffmpeg -i grad.png -filter_complex 'movie=bw.pnm,scale=256x1[bw]; [0:v][bw]paletteuse=dither=bayer:bayer_scale=0' gradbw.png Previously: https://www.rm.cloudns.org/img/uploaded/0bd152c11b9cd99e5945115534b1bdde.png Now: https://www.rm.cloudns.org/img/uploaded/89caaa5e36c38bc2c01755b30811f969.png This was caused by passing inconsistent color vs (a,r,g,b) parameters to color_get(), and NBITS being 5 meaning actually hitting the same cache node does happen in this case, but ONLY if bayer_scale is zero. The fix is passing the correct color value to color_get(). Also added a previous-failing FATE test; image comparison of the first frame: Previously: https://www.rm.cloudns.org/img/uploaded/d0ff9db8d8a7d8a3b8b88bbe92bf5fed.png Now: https://www.rm.cloudns.org/img/uploaded/a72389707e719b5cd1c58916a9e79ca8.png (on this less synthetic test image, the bug basically causes noise from cache hits vs misses) Tested: FATE passes, which exercises this filter but at the default bayer_scale. Reviewed-by: Paul B Mahol <onemda@gmail.com>
* avfilter/vf_paletteuse: Add missing parenthesesAndreas Rheinhardt2021-11-27
| | | | | | | | Fixes a mistake in dea673d0d548c864ec85f9260d8900d944ef7a2a. GCC emitted a -Wint-in-bool-context warning because of that. Reviewed-by: Soft Works <softworkz@hotmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter/vf_palette(gen|use): support palettes with alphaSoft Works2021-10-13
|
* avfilter: Replace query_formats callback with union of list and callbackAndreas Rheinhardt2021-10-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If one looks at the many query_formats callbacks in existence, one will immediately recognize that there is one type of default callback for video and a slightly different default callback for audio: It is "return ff_set_common_formats_from_list(ctx, pix_fmts);" for video with a filter-specific pix_fmts list. For audio, it is the same with a filter-specific sample_fmts list together with ff_set_common_all_samplerates() and ff_set_common_all_channel_counts(). This commit allows to remove the boilerplate query_formats callbacks by replacing said callback with a union consisting the old callback and pointers for pixel and sample format arrays. For the not uncommon case in which these lists only contain a single entry (besides the sentinel) enum AVPixelFormat and enum AVSampleFormat fields are also added to the union to store them directly in the AVFilter, thereby avoiding a relocation. The state of said union will be contained in a new, dedicated AVFilter field (the nb_inputs and nb_outputs fields have been shrunk to uint8_t in order to create a hole for this new field; this is no problem, as the maximum of all the nb_inputs is four; for nb_outputs it is only two). The state's default value coincides with the earlier default of query_formats being unset, namely that the filter accepts all formats (and also sample rates and channel counts/layouts for audio) provided that these properties agree coincide for all inputs and outputs. By using different union members for audio and video filters the type-unsafety of using the same functions for audio and video lists will furthermore be more confined to formats.c than before. When the new fields are used, they will also avoid allocations: Currently something nearly equivalent to ff_default_query_formats() is called after every successful call to a query_formats callback; yet in the common case that the newly allocated AVFilterFormats are not used at all (namely if there are no free links) these newly allocated AVFilterFormats are freed again without ever being used. Filters no longer using the callback will not exhibit this any more. Reviewed-by: Paul B Mahol <onemda@gmail.com> Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter/avfilter: Add numbers of (in|out)pads directly to AVFilterAndreas Rheinhardt2021-08-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Up until now, an AVFilter's lists of input and output AVFilterPads were terminated by a sentinel and the only way to get the length of these lists was by using avfilter_pad_count(). This has two drawbacks: first, sizeof(AVFilterPad) is not negligible (i.e. 64B on 64bit systems); second, getting the size involves a function call instead of just reading the data. This commit therefore changes this. The sentinels are removed and new private fields nb_inputs and nb_outputs are added to AVFilter that contain the number of elements of the respective AVFilterPad array. Given that AVFilter.(in|out)puts are the only arrays of zero-terminated AVFilterPads an API user has access to (AVFilterContext.(in|out)put_pads are not zero-terminated and they already have a size field) the argument to avfilter_pad_count() is always one of these lists, so it just has to find the filter the list belongs to and read said number. This is slower than before, but a replacement function that just reads the internal numbers that users are expected to switch to will be added soon; and furthermore, avfilter_pad_count() is probably never called in hot loops anyway. This saves about 49KiB from the binary; notice that these sentinels are not in .bss despite being zeroed: they are in .data.rel.ro due to the non-sentinels. Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter/vf_paletteuse: do not use in dithering transparent palettePaul B Mahol2021-08-19
|
* avfilter/vf_paletteuse: fix some integer overflowsPaul B Mahol2021-08-19
|
* avfilter/vf_paletteuse: do not sort transparency colorPaul B Mahol2021-08-19
| | | | | Make last palette entry always transparent color. Fixes wrong filtered output with new=1 option set.
* avfilter/vf_paletteuse: Remove redundant freeing codeAndreas Rheinhardt2021-08-15
| | | | | | AVFilter.uninit is called automatically if init fails. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter: Constify all AVFiltersAndreas Rheinhardt2021-04-27
| | | | | | | This is possible now that the next-API is gone. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avfilter/vf_paletteuse: Fix left shift outside of range of intAndreas Rheinhardt2021-03-28
| | | | | | | by keeping the variable uint32_t which in this situation is the natural type anyway. This affected the FATE-test filter-paletteuse-sierra2_4a. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* lavfi: regroup formats lists in a single structure.Nicolas George2020-09-08
| | | | | | | | | | | | | | | It will allow to refernce it as a whole without clunky macros. Most of the changes have been automatically made with sed: sed -i ' s/-> *in_formats/->incfg.formats/g; s/-> *out_formats/->outcfg.formats/g; s/-> *in_channel_layouts/->incfg.channel_layouts/g; s/-> *out_channel_layouts/->outcfg.channel_layouts/g; s/-> *in_samplerates/->incfg.samplerates/g; s/-> *out_samplerates/->outcfg.samplerates/g; ' src/libavfilter/*(.)
* avfilter/vf_paletteuse: Fix leaks of AVFilterFormats on errorAndreas Rheinhardt2020-08-23
| | | | | | | | | | | | | | | | | | | | | | The paletteuse's query_formats function allocated three AVFilterFormats before storing them permanently. If allocating one of them failed, the three AVFilterFormats structures would be freed with av_freep() which does not free separately allocated subelements (namely the formats array) which leak. Furthermore, if storing one of the first two fails, the function simply returns and the ones not yet stored leak. These leaks have been fixed by only creating a new AVFilterFormats after the last one has already been permanently stored. Furthermore, it is enough to check whether the elements have been properly stored as ff_formats_ref() by design returns AVERROR(ENOMEM) if it is provided a NULL AVFilterFormats *. Fixes Coverity issues #1270818 and #1270819. Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avfilter/vf_paletteuse: Forward error codesAndreas Rheinhardt2020-03-24
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* remove CHAR_MIN/CHAR_MAX usagePaul B Mahol2020-03-17
| | | | It is not needed at all.
* avfilter/vf_paletteuse: Fix potential double-free of AVFrameAndreas Rheinhardt2020-02-08
| | | | | | | | | | | | | | | | | | apply_palette() would free an AVFrame given to it only via an AVFrame * (and not via AVFrame **) in three of its four exists (namely in the normal path and in two error paths). So upon error the caller has no way to know whether the frame has already been freed or not; load_apply_palette(), the only caller, opted to free the frame in this scenario. This commit changes this by making apply_palette not freeing the frame at all, which is left to load_apply_palette(). Fixes Coverity issue #1452434. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avfilter/vf_paletteuse: don't constantly free and realloc internal framesJames Almer2019-01-17
| | | | | Reviewed-by: Clément Bœsch <u@pkh.me> Signed-off-by: James Almer <jamrial@gmail.com>
* avfilter/vf_paletteuse: fix flags for alpha_threshold optionPaul B Mahol2018-12-11
|
* vf_paletteuse: Don't free the second frame from ↵Derek Buitenhuis2018-01-03
| | | | | | | | ff_framesync_dualinput_get_writable on error This fixes a double free in he error case. Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
* vf_paletteuse: Add error checking to apply_paletteDerek Buitenhuis2018-01-03
| | | | | | | This fixes a segfault caused by passing NULL to ff_filter_frame when an error occurs. Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
* lavfi/paletteuse: check get_color return valueTimo Rothenpieler2017-11-13
| | | | Fixes CID #1420396
* lavfi/paletteuse: fix debug_kdtree after aba926e7dClément Bœsch2017-10-28
|
* lavfi/paletteuse: fix debug_mean_error after aba926e7dClément Bœsch2017-10-28
|