aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/pngdec.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/pngdec: avoid hard failure on illegal sBIT chunksLeo Izen2025-02-091-8/+10
| | | | | | | | If a malformed chunk like sBIT appears but otherwise the stream is still parseable, we should print a warning and skip it rather than failing with an error. Signed-off-by: Leo Izen <leo.izen@gmail.com>
* avcodec/png{dec,enc}: update mDCV and cLLI chunk capitalizationLeo Izen2024-12-091-5/+7
| | | | | | | | | | | The PNGv3 Specification Draft [1] has changed the capitalization of mDCV and cLLI chunks (formerly mDCv and cLLi). This patch updates FFmpeg to work with the new chunk names while retaining decode-side compatibility with files created using the old names. [1]: https://w3c.github.io/png/ Signed-off-by: Leo Izen <leo.izen@gmail.com>
* avcodec/pngdec: use 8-bit sBIT cap for indexed PNGs per specLeo Izen2024-07-301-1/+1
| | | | | | | | | | | | | | The PNG specification[1] says that sBIT entries must be at most the bit depth specified in IHDR, unless the PNG is indexed-color, in which case sBIT must be between 1 and 8. We should not reject valid sBITs on PNGs with indexed color. [1]: https://www.w3.org/TR/png-3/#11sBIT Regression since 84b454935fae2633a8a5dd075e22393f3e8f932f. Signed-off-by: Leo Izen <leo.izen@gmail.com> Reported-by: Ramiro Polla <ramiro.polla@gmail.com>
* avcodec/png: more informative error message for invalid sBIT sizeLeo Izen2024-07-181-1/+4
| | | | | | | If the sBIT chunk size is invalid, we should print a more informative error message rather than return an error and print nothing. Signed-off-by: Leo Izen <leo.izen@gmail.com>
* avcodec/pngdec: avoid erroring with sBIT on indexed-color imagesLeo Izen2024-07-181-1/+1
| | | | | | | | | | | | Indexed color images use three colors for sBIT, but the function ff_png_get_nb_channels returns 1 in this case. We should avoid erroring out on valid files in this scenario. Regression since 84b454935fae2633a8a5dd075e22393f3e8f932f. Signed-off-by: Leo Izen <leo.izen@gmail.com> Reported-by: Ramiro Polla <ramiro.polla@gmail.com> Reviewed-by: Marton Balint <cus@passwd.hu>
* avcodec/pngdec: fix mDCv typoLeo Izen2024-07-031-26/+27
| | | | | | | | | | | | When mDCv support was added, there was a typo in both variable names and also the MKTAG itself, incorrectly listing it as mDVc. The tag name stands for Mastering Display Color Volume so mDCv is correct. See other files such as av1dec.c which uses mdcv. Typo originally introduced in c7a57b0f70f8d1574aa0f0dbe98db85d8ac91c76. Signed-off-by: Leo Izen <leo.izen@gmail.com> Reported-by: Ramiro Polla <ramiro.polla@gmail.com>
* avcodec: use the renamed av_zero_extendJames Almer2024-06-131-1/+1
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/pngdec: Check last AVFrame before derefMichael Niedermayer2024-04-271-1/+1
| | | | | | | | Fixes: NULL pointer dereference Fixes: 68184/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APNG_fuzzer-4926478069334016 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/pngdec: Switch to ProgressFramesAndreas Rheinhardt2024-04-191-40/+27
| | | | | | | | Avoids implicit av_frame_ref() and therefore allocations and error checks. It also avoids explicitly allocating the AVFrames (done implicitly when getting the buffer). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Remove FF_CODEC_CAP_ALLOCATE_PROGRESSAndreas Rheinhardt2024-04-191-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before commit f025b8e110b36c1cdb4fb56c4cd57aeca1767b5b, every frame-threaded decoder used ThreadFrames, even when they did not have any inter-frame dependencies at all. In order to distinguish those decoders that need the AVBuffer for progress communication from those that do not (to avoid the allocation for the latter), the former decoders were marked with the FF_CODEC_CAP_ALLOCATE_PROGRESS internal codec cap. Yet distinguishing these two can be done in a more natural way: Don't use ThreadFrames when not needed and split ff_thread_get_buffer() into a core function that calls the user's get_buffer2 callback and a wrapper around it that also allocates the progress AVBuffer. This has been done in 02220b88fc38ef9dd4f2d519f5d3e4151258b60c and since that commit the ALLOCATE_PROGRESS cap was nearly redundant. The only exception was WebP and VP8. WebP can contain VP8 and uses the VP8 decoder directly (i.e. they share the same AVCodecContext). Both decoders are frame-threaded and VP8 has inter-frame dependencies (in general, not in valid WebP) and therefore the ALLOCATE_PROGRESS cap. In order to avoid allocating progress in case of a frame-threaded WebP decoder the cap and the check for the cap has been kept in place. Yet now the VP8 decoder has been switched to use ProgressFrames and therefore there is just no reason any more for this check and the cap. This commit therefore removes both. Also change the value of FF_CODEC_CAP_USES_PROGRESSFRAMES to leave no gaps. 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>
* lavc/*dec: use side data preference for mastering display/content light metadataAnton Khirnov2024-03-081-23/+31
|
* avcodec/pngdec: respect side data preferenceNiklas Haas2024-03-081-5/+10
|
* avcodec/pngdec: read cLLi and mDVc chunksLeo Izen2024-02-111-0/+63
| | | | | | | | | | These chunks contain the Content Light Level Information and the Mastering Display Color Volume information that FFmpeg already supports as AVFrameSideData. This patch adds support for the png decoder to read these chunks if present and attach the corresponding side data to the decoded frame. Signed-off-by: Leo Izen <leo.izen@gmail.com>
* avcodec/pngdec: improve handling of bad cICP range tagsLeo Izen2023-12-221-11/+12
| | | | | | | | | | | | | | | FFmpeg doesn't support tv-range RGB throughout most of its pipeline, so we should keep the warning. However, in case something does support it we should at least keep it tagged properly. Additionally, the encoder writes this tag if the space is tagged as such so this makes a round trip work as it should. Also, PNG doesn't support nonzero matrices but we only warn and ignore in that case, so we have no reason to error out for illegal cICP ranges either (i.e. greater than 1). Signed-off-by: Leo Izen <leo.izen@gmail.com> Reported-by: Kacper Michajłow <kasper93@gmail.com>
* avcodec/pthread_frame: Remove ff_thread_release_buffer()Andreas Rheinhardt2023-10-221-7/+7
| | | | | | | | | | | | | | It is unnecessary since the removal of non-thread-safe callbacks in e0786a8eeb9e7c8feb057e83f284491f0a87e463. Since then, the AVCodecContext has only been used as logcontext. Removing ff_thread_release_buffer() allowed to remove AVCodecContext* parameters from several other functions (not only unref functions, but also e.g. ff_h264_ref_picture() which calls ff_h264_unref_picture() on error). Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/pngdec: Do not pass AVFrame into global header decodeMichael Niedermayer2023-05-061-1/+6
| | | | | | | | | | | The global header should not contain a frame, and decoding it would result in leaks Fixes: memleak Fixes: 45982/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APNG_fuzzer-6603443149340672 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/pngdec: remove AVFrame argument from decode_iccp_chunk()Michael Niedermayer2023-05-061-2/+2
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec: use the new AVFrame key_frame flag in all decoders and encodersJames Almer2023-05-041-1/+1
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec: use the new AVFrame interlace flags in all decoders and encodersJames Almer2023-05-041-1/+1
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/pngdec: support sBIT chunksLeo Izen2023-04-011-0/+48
| | | | | | | | Add support for reading sBIT chunks, which mark the significant bit depth of the PNG file. This passes the metadata using the field bits_per_raw_sample of AVCodecContext. Signed-off-by: Leo Izen <leo.izen@gmail.com>
* avcodec/pngdec: read colorspace info when decoding with AVDISCARD_ALLLeo Izen2023-02-281-50/+86
| | | | | These chunks are lightweight and it's useful information to have when running ffmpeg -i or ffprobe, for example.
* avcodec/pngdec: dont skip/read chunk twiceMichael Niedermayer2023-02-231-0/+1
| | | | | | | | Fixes: out of array access Fixes: 48567/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PNG_fuzzer-6668158952144896.fuzz Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/pngdec: Check deloco index more exactlyMichael Niedermayer2023-02-231-1/+1
| | | | | | | | | | Fixes: out of array access: Fixes: 48567/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PNG_fuzzer-6716193709096960 Alternatively it should be possible to limit this to 3 plane RGB 8 /16bit to ensure the size is what it should be Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/png: support cICP chunksLeo Izen2023-01-251-3/+32
| | | | | | | | | | | | | | | | | | | | | This commit adds both decode and encode support for cICP chunks, which allow a PNG image's pixel data to be tagged by any of the enum values in H.273, without an ICC profile. Upon decode, if a cICP chunk is present, the PNG decoder will tag output AVFrames with the resulting enum color, and ignore iCCP, sRGB, gAMA, and cHRM chunks, as per the spec. Upon encode, if the color space is known and specified, and it is not sRGB, the PNG encoder will output a cICP chunk containing the color space. If the color space is sRGB, then it will output an sRGB chunk instead of a cICP chunk. If the color space of the input is not unspecified, it will not output a cICP chunk tagging the PNG as unspecified. In either the sRGB case or the non-SRGB case, gAMA and cHRM are still written as fallbacks provided the info is known. Signed-off-by: Leo Izen <leo.izen@gmail.com>
* avcodec/pngdec: support decoding sRGB chunksLeo Izen2023-01-251-2/+12
| | | | | | | | | | | | | | | If an sRGB chunk is present in the PNG file, this commit will cause the png decoder to ignore the cHRM and gAMA chunks and tag the resulting AVFrames with BT.709 primaries, and ISO/IEC 61966-2-1 transfer. If these tags are present in the AVFrame, pngenc.c already writes this chunk, so no change was needed on the encode-side. The PNG spec does not define what happens if sRGB and iCCP are present at the same time, it just recommends that this not happen. As of this patch, the decoder will have the ICC profile take precedence, and it will not tag the pixel data as sRGB. Signed-off-by: Leo Izen <leo.izen@gmail.com>
* avcodec/png: use libavutil/csp.h for cHRM chunksLeo Izen2023-01-251-20/+26
| | | | | | | | | | | | | | | | | | | | | | | | The cHRM chunk is descriptive. That is, it describes the primaries that should be used to interpret the pixel data in the PNG file. This is notably different from Mastering Display Metadata, which describes which subset of the presented gamut is relevant. MDM describes a gamut and says colors outside the gamut are not required to be preserved, but it does not actually describe the gamut that the pixel data from the frame resides in. Thus, to decode a cHRM chunk present in a PNG file to Mastering Display Metadata is incorrect. This commit changes this behavior so the cHRM chunk, if present, is decoded to color metadata. For example, if the cHRM chunk describes BT.709 primaries, the resulting AVFrame will be tagged with AVCOL_PRI_BT709, as a description of its pixel data. To do this, it utilizes libavutil/csp.h, which exposes a funcction av_csp_primaries_id_from_desc, to detect which enum value accurately describes the white point and primaries represented by the cHRM chunk. This commit also changes pngenc.c to utilize the libavuitl/csp.h API, since it previously duplicated code contained in that API. Instead, taking advantage of the API that exists makes more sense. pngenc.c does properly utilize the color tags rather than incorrectly using MDM, so that required no change. Signed-off-by: Leo Izen <leo.izen@gmail.com>
* avcodec/pngdec: Mark damaged frames as finishedAndreas Rheinhardt2022-11-251-2/+4
| | | | | | | Fixes the deadlock reported in ticket #10071. Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/(ffv1|h264|png|snow)dec: Remove comment out DRAW_HORIZ_BAND capAndreas Rheinhardt2022-10-201-2/+2
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/pngdec: Don't use unsigned for width, heightAndreas Rheinhardt2022-10-041-1/+1
| | | | | | | | | Otherwise p->linesize[0] * y will be evaluated as an unsigned which leads to segfaults in case linesize is negative. This happens in the apng-dispose-previous FATE-test in case one makes get_buffer return pictures with negative linesizes. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Add macros for update_thread_context(_for_user)Andreas Rheinhardt2022-09-031-2/+2
| | | | | | | | | It reduces typing: Before this patch, there were 11 callbacks that exceeded the 80 char line length limit; now there are zero. It also allows to remove ONLY_IF_THREADS_ENABLED() in libavutil/internal.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Add macro to set AVCodec.long_nameAndreas Rheinhardt2022-09-031-2/+2
| | | | | | | | It reduces typing: Before this patch, there were 105 codecs whose long_name-definition exceeded the 80 char line length limit. Now there are only nine of them. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/internal: Move ff_set_dimensions() to decode.hAndreas Rheinhardt2022-08-271-1/+1
| | | | | | | | | Decoder-only, as the dimensions are set by the user when encoding. Also fixup the other headers a bit while removing unnecessary internal.h inclusions. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/pngdec: Improve decoding text chunksAndreas Rheinhardt2022-08-231-3/+4
| | | | | | | By checking immediately whether the first allocation was successfull one can simplify the cleanup code in case of errors. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/pngdec: Use char* instead of uint8_t* for textAndreas Rheinhardt2022-08-231-9/+10
| | | | | | Also stop casting const away. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/pngdec: Use internal AVBPrint string when parsing chunksAndreas Rheinhardt2022-08-231-5/+3
| | | | | | One saves an allocation in case the string fits into the buffer. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/pngdec: Fix APNG_DISPOSE_OP_BACKGROUNDAndreas Rheinhardt2022-08-231-50/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | APNG works with a single reference frame and an output frame. According to the spec, decoding APNG works by decoding the current IDAT/fdAT chunks (which decodes to a rectangular subregion of the whole image region), followed by either overwriting the region of the output frame with the newly decoded data or by blending the newly decoded data with the data from the reference frame onto the current subregion of the output frame. The remainder of the output frame is just copied from the reference frame. Then the reference frame might be left untouched (APNG_DISPOSE_OP_PREVIOUS), it might be replaced by the output frame (APNG_DISPOSE_OP_NONE) or the rectangular subregion corresponding to the just decoded frame has to be reset to black (APNG_DISPOSE_OP_BACKGROUND). The latter case is not handled correctly by our decoder: It only performs resetting the rectangle in the reference frame when decoding the next frame; and since commit b593abda6c642cb0c3959752dd235c2faf66837f it does not reset the reference frame permanently, but only temporarily (i.e. it only affects decoding the frame after the frame with APNG_DISPOSE_OP_BACKGROUND). This is a problem if the frame after the APNG_DISPOSE_OP_BACKGROUND frame uses APNG_DISPOSE_OP_PREVIOUS, because then the frame after the APNG_DISPOSE_OP_PREVIOUS frame has an incorrect reference frame. (If it is not followed by an APNG_DISPOSE_OP_PREVIOUS frame, the decoder only keeps a reference to the output frame, which is ok.) This commit fixes this by being much closer to the spec than the earlier code: Resetting the background is no longer postponed until the next frame; instead it is applied to the reference frame. Fixes ticket #9602. (For multithreaded decoding it was actually already broken since commit 5663301560d77486c7f7c03c1aa5f542fab23c24.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: add cap for ICC profile supportNiklas Haas2022-07-301-2/+4
| | | | | | | | | | | | | | | | | | | | | | Codecs that can read/write ICC profiles deserve a special capability so the common logic in encode.c/decode.c can decide whether or not there needs to be any special handling for ICC profiles. The motivation here is to be able to use it to decide whether or not an ICC profile needs to be generated in the encode path, but it might as well get added to decoders as well for purely informative reasons. It's not entirely clear to me whether the "thp" and "smvjpeg" variants of "mjpeg" should have this capability set or not, given that the code technically supports it but I somehow doubt these files may contain them. In either case, this cap is purely informative for decoders so it doesn't matter too much either way. It's also not entirely clear whether the "amv" encoder should signal ICC profile support, but again erring on the side of caution, we probably *shouldn't* be generating (and encoding!) ICC profiles for this type of media file. Signed-off-by: Niklas Haas <git@haasn.dev>
* avcodec: Make init-threadsafety the defaultAndreas Rheinhardt2022-07-181-2/+2
| | | | | | | | | | | and remove FF_CODEC_CAP_INIT_THREADSAFE All our native codecs are already init-threadsafe (only wrappers for external libraries and hwaccels are typically not marked as init-threadsafe yet), so it is only natural for this to also be the default state. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/apng: Add APNG_FCTL_CHUNK_SIZE defineAndreas Rheinhardt2022-07-091-1/+1
| | | | | | Also use it where appropriate. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Use union for FFCodec decode/encode callbacksAndreas Rheinhardt2022-04-051-2/+2
| | | | | | | | | | | This is possible, because every given FFCodec has to implement exactly one of these. Doing so decreases sizeof(FFCodec) and therefore decreases the size of the binary. Notice that in case of position-independent code the decrease is in .data.rel.ro, so that this translates to decreased memory consumption. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Make FFCodec.decode use AVFrame*Andreas Rheinhardt2022-04-051-8/+4
| | | | | | | | This increases type-safety by avoiding conversions from/through void*. It also avoids the boilerplate "AVFrame *frame = data;" line for non-subtitle decoders. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Add FFCodec, hide internal part of AVCodecAndreas Rheinhardt2022-03-211-12/+12
| | | | | | | | | | | | | | | | Up until now, codec.h contains both public and private parts of AVCodec. This exposes the internals of AVCodec to users and leads them into the temptation of actually using them and forces us to forward-declare structures and types that users can't use at all. This commit changes this by adding a new structure FFCodec to codec_internal.h that extends AVCodec, i.e. contains the public AVCodec as first member; the private fields of AVCodec are moved to this structure, leaving codec.h clean. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.hAndreas Rheinhardt2022-03-211-0/+1
| | | | | | | | | | Also move FF_CODEC_TAGS_END as well as struct AVCodecDefault. This reduces the amount of files that have to include internal.h (which comes with quite a lot of indirect inclusions), as e.g. most encoders don't need it. It is furthemore in preparation for moving the private part of AVCodec out of the public codec.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/pngdec: Don't open and close z_streams unnecessarilyAndreas Rheinhardt2022-03-191-62/+46
| | | | | | | | Instead reuse and reset a single z_stream. Also use FFZStream in decode_zbuf(), because it has nicer error messages. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* configure: Use a separate config_components.h header for $ALL_COMPONENTSMartin Storsjö2022-03-161-0/+2
| | | | | | | | This avoids unnecessary rebuilds of most source files if only the list of enabled components has changed, but not the other properties of the build, set in config.h. Signed-off-by: Martin Storsjö <martin@martin.st>
* avcodec/pngdec: support alpha blending for palette apngPaul B Mahol2022-03-081-29/+32
| | | | Update clock test, as PAL8 apngs are now decoded as RGBA.
* avcodec/pngdec: Cleanup generically on init failureAndreas Rheinhardt2022-02-111-6/+3
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/threadframe: Add ff_thread_(get|release)_ext_buffer()Andreas Rheinhardt2022-02-091-8/+9
| | | | | | | | | These will be used by the codecs that need allocated progress and is in preparation for no longer using ThreadFrame by the codecs that don't. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/thread: Move ff_thread_(await|report)_progress to new headerAndreas Rheinhardt2022-02-091-0/+1
| | | | | | | | | | This is in preparation for further commits that will stop using ThreadFrame for frame-threaded codecs that don't use ff_thread_(await|report)_progress(); the API for those codecs having inter-frame depdendencies will live in threadframe.h. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>