summaryrefslogtreecommitdiff
path: root/libavfilter/vf_paletteuse.c
Commit message (Collapse)AuthorAge
* 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
|
* lavfi/paletteuse: fix debug_accuracy after aba926e7dClément Bœsch2017-10-28
|
* lavfi/paletteuse: simplify color get function prototypesClément Bœsch2017-10-28
|
* lavfi/paletteuse: move "new" option before debugging optionsClément Bœsch2017-10-28
|
* lavfi/paletteuse: fix to support transparencyBjorn Roche2017-10-28
| | | | | | | | | | | | | | | | | | This patch enables paletteuse to identify the transparency in incoming video and tag transparent pixels on outgoing video with the correct index from the palette. This requires tracking the transparency index in the palette, establishing an alpha threshold below which a pixel is considered transparent and above which the pixel is considered opaque, and additional changes to track the alpha value throughout the conversion process. This change is a partial fix for https://trac.ffmpeg.org/ticket/4443 However, animated GIFs are still output incorrectly due to a bug in gif optimization which does not correctly handle transparency. Signed-off-by: Clément Bœsch <u@pkh.me>
* lavfi: Rename local variables "main" as "master".Carl Eugen Hoyos2017-10-07
| | | | | Silences several warnings: main is usually a function
* lavfi: rename framesync2 to framesync.Nicolas George2017-09-12
|
* lavfi/vf_paletteuse: convert to framesync2.Nicolas George2017-08-29
|
* avfilter/vf_paletteuse: silence warning about misaligned indentationPaul B Mahol2017-04-10
| | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* Fix all -Wformat warnings raised by DJGPPClément Bœsch2017-03-29
|
* lavfi: split frame_count between input and output.Nicolas George2016-11-13
| | | | | | | | | | | | AVFilterLink.frame_count is supposed to count the number of frames that were passed on the link, but with min_samples, that number is not always the same for the source and destination filters. With the addition of a FIFO on the link, the difference will become more significant. Split the variable in two: frame_count_in counts the number of frames that entered the link, frame_count_out counts the number of frames that were sent to the destination filter.
* avfilter/vf_paletteuse: add option to use new palette for each output framePaul B Mahol2016-09-07
|
* avfilter/vf_paletteuse: enable skip_initial_unpairedMichael Niedermayer2016-06-26
| | | | | | | | | Fixes crash due to unprocessed input being passed through This fixes the last segfault caused by mixing 3.0 and 3.1 libs and applications Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avfilter/all: propagate errors of functions from avfilter/formatsGanesh Ajjanagadde2015-10-14
| | | | | | | | | | | | | | | | | | Many of the functions from avfilter/formats can return errors, usually AVERROR(ENOMEM). This propagates the return values. All of these were found by using av_warn_unused_result, demonstrating its utility. Tested with FATE. I am least sure of the changes to avfilter/filtergraph, since I don't know what/how reduce_format is intended to behave and how it should react to errors. Fixes: CID 1325680, 1325679, 1325678. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Previous version Reviewed-by: Nicolas George <george@nsup.org> Previous version Reviewed-by: Clément Bœsch <u@pkh.me> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* avfilter/paletteuse: use AV_OPT_TYPE_BOOL for mean_err and debug_accuracy optionClément Bœsch2015-09-09
|
* Replace av_dlog with ff_dlog.Ronald S. Bultje2015-08-18
| | | | | ff_dlog checks compilability, and is non-public. av_dlog is deprecated and no longer exists if FF_API_DLOG=0.
* avfilter/vf_paletteuse: indent fix after 7ccc5848Clément Bœsch2015-03-05
|
* avfilter/vf_paletteuse: Use int where AVERROR can be returnedMichael Niedermayer2015-03-05
| | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* avfilter/paletteuse: use AV_QSORT()Clément Bœsch2015-02-26
| | | | See previous commit for a rationale.
* avfilter/palette{gen,use}: add CopyrightClément Bœsch2015-02-23
|
* avfilter/paletteuse: add diff_modeClément Bœsch2015-02-23
|
* avfilter/paletteuse: fix error dithering accuracyClément Bœsch2015-02-23
|
* avfilter/paletteuse: fix leak in case of errorClément Bœsch2015-02-18
| | | | Fixes CID1270819
* avfilter/paletteuse: raise cache size from 64k to 512kClément Bœsch2015-02-17
| | | | (or 32k to 256k in 32-bit)
* avfilter: add paletteuse filterClément Bœsch2015-02-14