aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/imgutils.c
Commit message (Collapse)AuthorAgeFilesLines
* avutil/imgutils: av_image_check_size2() ensure width and height fit in 32bitMichael Niedermayer2024-07-121-1/+1
| | | | | | width and height > 32bit is not supported and its easier to check in a central place Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/internal: Move avpriv_set_systematic_pal2 decl to imgutils_internal.hAndreas Rheinhardt2024-03-311-1/+0
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avutil/common: Don't auto-include mem.hAndreas Rheinhardt2024-03-311-0/+1
| | | | | | | | | | | 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>
* Revert "all: Don't set AVClass.item_name to its default value"Anton Khirnov2024-01-201-0/+1
| | | | | | | Some callers assume that item_name is always set, so this may be considered an API break. This reverts commit 0c6203c97a99f69dbaa6e4011d48c331e1111f5e.
* avutil/imgutils: fix half-float representation of 0.0625Marton Balint2024-01-041-1/+1
| | | | | | We don't have a 16-bit float Y format, so no fate changes. Signed-off-by: Marton Balint <cus@passwd.hu>
* all: Don't set AVClass.item_name to its default valueAndreas Rheinhardt2023-12-221-1/+0
| | | | | | | | Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9; also avoids relocations. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avutil/imgutils: add new function av_image_fill_color()Marton Balint2023-12-131-3/+3
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* avutil/imgutils: factorize a fill color functionMarton Balint2023-12-131-39/+64
| | | | | | In preparation for making it public. Signed-off-by: Marton Balint <cus@passwd.hu>
* avutil/imgutils: add support for 32bit pixel format for av_image_fill_black()Marton Balint2023-12-131-10/+23
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* avutil/imgutils: fix av_image_fill_black() for some pixel formatsMarton Balint2023-12-131-31/+18
| | | | | | | | | | | - Fixes YA formats, because previous code always assumed alpha as the 4th component. - Fixes PAL format (as long as 0 is black, as in a systematic palette), because previous code assumed it as limited Y. - Fixes XYZ format because it does not need nonzero chroma components - Fixes xv30be as the bitstream mode got merged to the non-bitstream mode. Signed-off-by: Marton Balint <cus@passwd.hu>
* avutil/imgutils: Constify some pointeesAndreas Rheinhardt2023-09-121-7/+7
| | | | | | | | This is done immediately without waiting for the next major bump just as in 9546b3a1cbcd94e9107f85c8f1d2175efc6cf083 and 4eaaa38d3dfb8863a62f3646a62e4098b1c078d5. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* imgutils: expose av_image_copy_plane_uc_from()Lynne2021-08-141-4/+4
| | | | | | | | | | | | The reason why the generic av_image_copy_uc_from() doesn't really fit in the case for Vulkan is because some planes may be copied via other methods (such as mapping GPU memory), and if they don't satisfy the strict alignment requirements, a gpu image->gpu buffer->cpu ram copy is performed. We need this for hwcontext_vulkan, and I think this will also be useful to API users like libplacebo who would rather not write a custom SIMD memcpy.
* avutil/imgutils: don't add offsets to NULL pointersJames Almer2021-05-121-0/+3
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avutil/pixdesc: Remove deprecated AV_PIX_FMT_FLAG_PSEUDOPALAndreas Rheinhardt2021-04-271-11/+4
| | | | | | | Deprecated in d6fc031caf64eed921bbdef86d79d56bfc2633b0. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avutil/imgutils: always zero data pointers in av_image_fill_pointers()James Almer2020-07-261-2/+2
| | | | | | | This restores the relevant behavior of the function as it was before 3a8e927176. Signed-off-by: James Almer <jamrial@gmail.com>
* avutil/imgutils: don't fill data pointers for missing planesJames Almer2020-07-261-1/+1
| | | | | | | | | | | The size for a previous plane doesn't signal the presence of another after it. If the plane is present, av_image_fill_plane_sizes() will have returned a size for it. Fixes a regression since 3a8e927176. Reported-by: Imad R. Faiad <irfaiad@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avutil/imgutils: add utility to get plane sizesBrian Kim2020-07-221-23/+75
| | | | | | | | | This utility helps avoid undefined behavior when doing things like checking how much memory we need to allocate for an image before we have allocated a buffer. Signed-off-by: Brian Kim <bkkim@google.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avutil/imgutils: remove dead assignmentMarton Balint2019-08-221-1/+0
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* lavu/imgutils: Use FFABS() instead of abs() for ptrdiff_t.Carl Eugen Hoyos2019-02-011-2/+2
| | | | | | | Fixes a warning with clang: libavutil/imgutils.c:314:16: warning: absolute value function 'abs' given an argument of type 'ptrdiff_t' (aka 'long') but has parameter of type 'int' which may cause truncation of value
* avutil/imgutils: Optimize memset_bytes() by using av_memcpy_backptr()Michael Niedermayer2019-01-201-22/+5
| | | | | | | | | | | | | This is strongly based on code by Marton Balint, and depends on the previous commit Fixes: Timeout Fixes: 11502/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WCMV_fuzzer-5664893810769920 Before: Executed clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WCMV_fuzzer-5664893810769920 in 11209 ms After: Executed clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WCMV_fuzzer-5664893810769920 in 4104 ms Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Reviewed-by: Marton Balint <cus@passwd.hu> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/pixdesc: deprecate AV_PIX_FMT_FLAG_PSEUDOPALwm42018-04-031-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PSEUDOPAL pixel formats are not paletted, but carried a palette with the intention of allowing code to treat unpaletted formats as paletted. The palette simply mapped the byte values to the resulting RGB values, making it some sort of LUT for RGB conversion. It was used for 1 byte formats only: RGB4_BYTE, BGR4_BYTE, RGB8, BGR8, GRAY8. The first 4 are awfully obscure, used only by some ancient bitmap formats. The last one, GRAY8, is more common, but its treatment is grossly incorrect. It considers full range GRAY8 only, so GRAY8 coming from typical Y video planes was not mapped to the correct RGB values. This cannot be fixed, because AVFrame.color_range can be freely changed at runtime, and there is nothing to ensure the pseudo palette is updated. Also, nothing actually used the PSEUDOPAL palette data, except xwdenc (trivially changed in the previous commit). All other code had to treat it as a special case, just to ignore or to propagate palette data. In conclusion, this was just a very strange old mechnaism that has no real justification to exist anymore (although it may have been nice and useful in the past). Now it's an artifact that makes the API harder to use: API users who allocate their own pixel data have to be aware that they need to allocate the palette, or FFmpeg will crash on them in _some_ situations. On top of this, there was no API to allocate the pseuo palette outside of av_frame_get_buffer(). This patch not only deprecates AV_PIX_FMT_FLAG_PSEUDOPAL, but also makes the pseudo palette optional. Nothing accesses it anymore, though if it's set, it's propagated. It's still allocated and initialized for compatibility with API users that rely on this feature. But new API users do not need to allocate it. This was an explicit goal of this patch. Most changes replace AV_PIX_FMT_FLAG_PSEUDOPAL with FF_PSEUDOPAL. I first tried #ifdefing all code, but it was a mess. The FF_PSEUDOPAL macro reduces the mess, and still allows defining FF_API_PSEUDOPAL to 0. Passes FATE with FF_API_PSEUDOPAL enabled and disabled. In addition, FATE passes with FF_API_PSEUDOPAL set to 1, but with allocation functions manually changed to not allocating a palette.
* Merge commit '97cfe1d8bd1968143e2ba9aa46ebe9504a835e24'James Almer2017-11-011-3/+4
|\ | | | | | | | | | | | | * commit '97cfe1d8bd1968143e2ba9aa46ebe9504a835e24': Convert all AVClass struct declarations to designated initializers. Merged-by: James Almer <jamrial@gmail.com>
| * Convert all AVClass struct declarations to designated initializers.Diego Biurrun2017-06-121-1/+8
| |
* | avutil/imgutils: Fix warning: missing braces around initializerMichael Niedermayer2017-09-161-1/+1
| | | | | | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | imgutils: add function to clear an image to blackwm42017-08-081-0/+167
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Black isn't always just memset(ptr, 0, size). Limited YUV in particular requires relatively non-obvious values, and filling a frame with repeating 0 bytes is disallowed in some contexts. With component sizes larger than 8 or packed YUV, this can become relatively complicated. So having a generic function for this seems helpful. In order to handle the complex cases in a generic way without destroying performance, this code attempts to compute a black pixel, and then uses that value to clear the image data quickly by using a function like memset. Common cases like yuv410p10 or rgba can't be handled with a simple memset, so there is some code to fill memory with 2/4/8 byte patterns. For the remaining cases, a generic slow fallback is used. Signed-off-by: Anton Khirnov <anton@khirnov.net> Merged from Libav commit 45df7adc1d9b7.
* | Merge commit 'd7bc52bf456deba0f32d9fe5c288ec441f1ebef5'Clément Bœsch2017-03-201-13/+62
|\| | | | | | | | | | | | | * commit 'd7bc52bf456deba0f32d9fe5c288ec441f1ebef5': imgutils: add a function for copying image data from GPU mapped memory Merged-by: Clément Bœsch <u@pkh.me>
| * imgutils: add a function for copying image data from GPU mapped memoryAnton Khirnov2016-08-311-13/+62
| | | | | | | | See https://software.intel.com/en-us/articles/copying-accelerated-video-decode-frame-buffers
| * lavu: add AV_CEIL_RSHIFT and use it in various placesClément Bœsch2016-01-111-1/+1
| | | | | | | | Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
* | avutil: Add av_image_check_size2()Michael Niedermayer2016-12-101-5/+24
| | | | | | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avutil/imgutils: Assert that the 2nd av_image_fill_linesizes() call in ↵Michael Niedermayer2016-02-281-1/+4
| | | | | | | | | | | | | | | | av_image_fill_linesizes() still succeeds Fixes CID1271742 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avutil/imgutils: remove special case for aligning the paletteMichael Niedermayer2016-02-141-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | This was suggested by wm4 and stefano. After this patch using align=1 the size used by various functions would not contain padding, while the palette would be aligned at align>1 This patch makes it required to use align>=4 if the palette is to be accessed as uint32 As a side-effect It fixes storing pal8 in nut with odd with&height Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avutil/imgutils: only align the palette in av_image_copy_to_buffer() if ↵Michael Niedermayer2016-02-131-0/+5
| | | | | | | | | | | | | | | | | | there is enough space This allows disabling the alignment by using a compact buffer Reviewed-by: Stefano Sabatini <stefasab@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avutil/imgutils: do not ignore align parameter for pseudo-pal in ↵Michael Niedermayer2016-02-131-1/+1
| | | | | | | | | | | | | | av_image_get_buffer_size() Reviewed-by: Stefano Sabatini <stefasab@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avutil: Rename FF_CEIL_COMPAT to AV_CEIL_COMPATDerek Buitenhuis2016-01-271-1/+1
| | | | | | | | | | | | | | | | | | | | Libav, for some reason, merged this as a public API function. This will aid in future merges. A define is left for backwards compat, just in case some person used it, since it is in a public header. Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
* | imgutils: Use designated initializers for AVClassTimothy Gu2015-11-231-2/+12
| | | | | | | | More readable and less breakable.
* | Merge commit '2268db2cd052674fde55c7d48b7a5098ce89b4ba'Hendrik Leppkes2015-09-081-2/+2
|\| | | | | | | | | | | | | * commit '2268db2cd052674fde55c7d48b7a5098ce89b4ba': lavu: Drop the {minus,plus}1 suffix from AVComponentDescriptor fields Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
| * lavu: Drop the {minus,plus}1 suffix from AVComponentDescriptor fieldsVittorio Giovara2015-09-071-5/+5
| | | | | | | | | | | | The new fields can be accessed directly and are more intelligible. Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
* | avutil/imgutils: Simplify pix_fmt validity check in av_image_get_linesize()Michael Niedermayer2015-06-121-1/+1
| | | | | | | | | | Found-by: Daemon404 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | imgutils: initialize palette padding bytes in av_image_allocAndreas Cadhalpun2015-05-131-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | av_image_fill_pointers always aligns the palette, but the padding bytes don't (and can't) get initialized in av_image_copy. Thus initialize them in av_image_alloc. This fixes 'Syscall param write(buf) points to uninitialised byte(s)' valgrind warnings. Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | avutil/imgutils: correctly check for negative SAR componentsMichael Niedermayer2015-02-281-1/+1
| | | | | | | | | | | | | | These could trigger assert failures previously Found-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge commit 'e2ad0b66fa273c5c823978e8f601f2c0d9ee42f8'Michael Niedermayer2015-01-151-15/+26
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit 'e2ad0b66fa273c5c823978e8f601f2c0d9ee42f8': imgutils: create misc functions for dealing with buffers Conflicts: doc/APIchanges libavcodec/avcodec.h libavcodec/avpicture.c libavutil/imgutils.c libavutil/imgutils.h libavutil/version.h See: e6674e46ecdd7aaa93d7f7d818eb1c8224b35eae Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * imgutils: create misc functions for dealing with buffersStefano Sabatini2015-01-141-0/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Move the lavc/imgconvert functions and rename them as follows: avpicture_get_size -> av_image_get_buffer_size() avpicture_fill -> av_image_fill_arrays() avpicture_layout -> av_image_copy_to_buffer() The new functions have an align parameter, which allows to define the linesize alignment assumed in the buffer (which is set or read). The names of the functions are consistent with the lavu/samples API (av_samples_get_buffer_size(), av_samples_fill_arrays()). A redundant check has been dropped from av_image_fill_arrays(). Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
* | lavu/imgutils: remove redundant and wrong check in av_image_fill_arraysStefano Sabatini2014-11-271-3/+0
| |
* | Merge commit '9e500efdbe0deeff1602500ebc229a0a6b6bb1a2'Michael Niedermayer2014-06-201-0/+23
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '9e500efdbe0deeff1602500ebc229a0a6b6bb1a2': Add av_image_check_sar() and use it to validate SAR Conflicts: libavcodec/dpx.c libavcodec/dvdec.c libavcodec/ffv1dec.c libavcodec/utils.c libavutil/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * Add av_image_check_sar() and use it to validate SARJustin Ruggles2014-06-201-0/+23
| |
* | Merge commit '4d8c28deab2488579f585406110b1be790896e59'Michael Niedermayer2014-05-271-1/+1
|\| | | | | | | | | | | | | | | | | | | | | * commit '4d8c28deab2488579f585406110b1be790896e59': imgutils: make systematic palette opaque. Conflicts: libavutil/imgutils.c See: 4d8c28deab2488579f585406110b1be790896e59 Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * imgutils: make systematic palette opaque.Carl Eugen Hoyos2014-05-251-1/+1
| | | | | | | | Signed-off-by: Anton Khirnov <anton@khirnov.net>
* | replace remaining PIX_FMT_* flags with AV_PIX_FMT_FLAG_*Michael Niedermayer2013-05-151-3/+3
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2013-05-151-9/+9
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: pixdesc: rename PIX_FMT_* flags to AV_PIX_FMT_FLAG_* Conflicts: doc/APIchanges libavcodec/avpicture.c libavcodec/ffv1dec.c libavcodec/ffv1enc.c libavcodec/imgconvert.c libavcodec/tiffenc.c libavfilter/vf_pixdesctest.c libavfilter/vf_scale.c libavutil/imgutils.c libavutil/pixdesc.c libavutil/version.h libswscale/swscale_internal.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * pixdesc: rename PIX_FMT_* flags to AV_PIX_FMT_FLAG_*Anton Khirnov2013-05-151-10/+10
| |