summaryrefslogtreecommitdiff
path: root/libavutil/imgutils.c
Commit message (Collapse)AuthorAgeFilesLines
* 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
| |
* | lavu: add FF_CEIL_RSHIFT and use it in various places.Clément Bœsch2013-05-091-1/+1
| |
* | lavu/imgutils: add consistency checks to av_image_copy_plane()Stefano Sabatini2012-11-251-0/+3
| | | | | | | | | | | | | | Add assertions and abort in case of invalid |dst_linesize| < bytewidth or |src_linesize| < bytewidth. Avoid to silently corrupt memory.
* | replace av_log(0, by av_log(NULL,Michael Niedermayer2012-11-231-1/+1
| | | | | | | | | | | | The first parameter is a pointer and NULL is more correct Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | av_image_copy: check for av_image_get_linesize() failure.Michael Niedermayer2012-10-311-0/+4
| | | | | | | | | | Fixes CID703722 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2012-10-141-2/+2
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: avutil: Do not make ff_ symbols globally visible. avutil: Rename ff_set_systematic_pal2() ---> avpriv_set_systematic_pal2() build: tms470: work around glibc math.h problems configure: improve tms470 compiler usage with glibc Conflicts: libavcodec/bmpenc.c libavcodec/rawdec.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * avutil: Rename ff_set_systematic_pal2() ---> avpriv_set_systematic_pal2()Diego Biurrun2012-10-131-2/+2
| | | | | | | | Functions used across libraries should have avpriv_ and not ff_ prefixes.
* | avoid more "0xFF << 24" as it is considered a integer overflow in C99Michael Niedermayer2012-10-141-1/+1
| | | | | | | | | | | | missed these in my previous search and replace Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | imgutils: do not use av_pix_fmt_descriptors directlyPaul B Mahol2012-10-121-1/+5
| | | | | | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2012-10-121-10/+17
|\ \ | |/ | | | | | | | | | | | | | | | | * qatar/master: lavu,lavd: do not use av_pix_fmt_descriptors directly. Conflicts: libavutil/imgutils.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * lavu,lavd: do not use av_pix_fmt_descriptors directly.Anton Khirnov2012-10-121-9/+15
| |
* | Merge commit '716d413c13981da15323c7a3821860536eefdbbb'Michael Niedermayer2012-10-081-17/+17
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '716d413c13981da15323c7a3821860536eefdbbb': Replace PIX_FMT_* -> AV_PIX_FMT_*, PixelFormat -> AVPixelFormat Conflicts: doc/examples/muxing.c ffmpeg.h ffmpeg_filter.c ffmpeg_opt.c ffplay.c ffprobe.c libavcodec/8bps.c libavcodec/aasc.c libavcodec/aura.c libavcodec/avcodec.h libavcodec/avs.c libavcodec/bfi.c libavcodec/bmp.c libavcodec/bmpenc.c libavcodec/c93.c libavcodec/cscd.c libavcodec/cyuv.c libavcodec/dpx.c libavcodec/dpxenc.c libavcodec/eatgv.c libavcodec/escape124.c libavcodec/ffv1.c libavcodec/flashsv.c libavcodec/fraps.c libavcodec/h264.c libavcodec/huffyuv.c libavcodec/iff.c libavcodec/imgconvert.c libavcodec/indeo3.c libavcodec/kmvc.c libavcodec/libopenjpegdec.c libavcodec/libopenjpegenc.c libavcodec/libx264.c libavcodec/ljpegenc.c libavcodec/mjpegdec.c libavcodec/mjpegenc.c libavcodec/motionpixels.c libavcodec/mpeg12.c libavcodec/mpeg12enc.c libavcodec/mpeg4videodec.c libavcodec/mpegvideo_enc.c libavcodec/pamenc.c libavcodec/pcxenc.c libavcodec/pgssubdec.c libavcodec/pngdec.c libavcodec/pngenc.c libavcodec/pnm.c libavcodec/pnmdec.c libavcodec/pnmenc.c libavcodec/ptx.c libavcodec/qdrw.c libavcodec/qpeg.c libavcodec/qtrleenc.c libavcodec/raw.c libavcodec/rawdec.c libavcodec/rl2.c libavcodec/sgidec.c libavcodec/sgienc.c libavcodec/snowdec.c libavcodec/snowenc.c libavcodec/sunrast.c libavcodec/targa.c libavcodec/targaenc.c libavcodec/tiff.c libavcodec/tiffenc.c libavcodec/tmv.c libavcodec/truemotion2.c libavcodec/utils.c libavcodec/vb.c libavcodec/vp3.c libavcodec/wnv1.c libavcodec/xl.c libavcodec/xwddec.c libavcodec/xwdenc.c libavcodec/yop.c libavdevice/v4l2.c libavdevice/x11grab.c libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/buffersrc.c libavfilter/drawutils.c libavfilter/formats.c libavfilter/src_movie.c libavfilter/vf_ass.c libavfilter/vf_drawtext.c libavfilter/vf_fade.c libavfilter/vf_format.c libavfilter/vf_hflip.c libavfilter/vf_lut.c libavfilter/vf_overlay.c libavfilter/vf_pad.c libavfilter/vf_scale.c libavfilter/vf_transpose.c libavfilter/vf_yadif.c libavfilter/video.c libavfilter/vsrc_testsrc.c libavformat/movenc.c libavformat/mxf.h libavformat/utils.c libavformat/yuv4mpeg.c libavutil/imgutils.c libavutil/pixdesc.c libswscale/input.c libswscale/output.c libswscale/swscale_internal.h libswscale/swscale_unscaled.c libswscale/utils.c libswscale/x86/swscale_template.c libswscale/x86/yuv2rgb.c libswscale/x86/yuv2rgb_template.c libswscale/yuv2rgb.c Merged-by: Michael Niedermayer <michaelni@gmx.at>