[FFmpeg-devel] [PATCH v6 2/2] avcodec/mjpegenc: support writing ICC profiles

Michael Niedermayer michael at niedermayer.cc
Thu Mar 24 20:12:23 EET 2022


On Thu, Mar 24, 2022 at 04:20:01PM +0100, Niklas Haas wrote:
> From: Niklas Haas <git at haasn.dev>
> 
> This is mostly straightforward. The major complication is that, as a
> result of the 16-bit chunk size limitation, ICC profiles may need to be
> split up into multiple chunks.
> 
> We also need to make sure to allocate enough extra space in the packet
> to fit the ICC profile, so modify both mpegvideo_enc.c and ljpegenc.c to
> take into account this extra overhead, failing cleanly if necessary.
> 
> Also add a FATE transcode test to ensure that the ICC profile gets
> written (and read) correctly. Note that this ICC profile is smaller than
> 64 kB, so this doesn't test the APP2 chunk re-arranging code at all.
> 
> Signed-off-by: Niklas Haas <git at haasn.dev>
> ---
> Difference to v2:
> - Added proper packet overhead size accounting
> - Moved ICC-profile-too-large bailout to allocation
> - Removed unnecessary `!frame` check
> - Use only legal static initializers
> - Use SIZE_SPECIFIER instead of %zu
> - Check for overflow
> - Add ffprobe dependency
> - Use byte-aligned pointer writing code instead of putbit
> ---
>  libavcodec/ljpegenc.c        |  6 ++--
>  libavcodec/mjpegenc.c        |  3 +-
>  libavcodec/mjpegenc_common.c | 66 ++++++++++++++++++++++++++++++++++--
>  libavcodec/mjpegenc_common.h |  4 ++-
>  libavcodec/mpegvideo_enc.c   |  4 ++-
>  tests/fate/image.mak         |  6 +++-
>  tests/ref/fate/jpg-icc       | 42 +++++++++++++++++++++++
>  7 files changed, 122 insertions(+), 9 deletions(-)
>  create mode 100644 tests/ref/fate/jpg-icc

[...]
> diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
> index 7b82644763..17103051a8 100644
> --- a/libavcodec/mjpegenc_common.c
> +++ b/libavcodec/mjpegenc_common.c
> @@ -131,8 +131,39 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p,
>      AV_WB16(ptr, size);
>  }
>  
> -static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p)
> +static const uint8_t icc_hdr_size = 16; /* ICC_PROFILE\0 tag + 4 bytes */

> +static const uint16_t icc_chunk_size = UINT16_MAX - icc_hdr_size;

libavcodec/mjpegenc_common.c:135:40: error: initializer element is not constant
 static const uint16_t icc_chunk_size = UINT16_MAX - icc_hdr_size;
                                        ^
CC	libavcodec/mp3_header_decompress_bsf.o


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20220324/a855b0dc/attachment.sig>


More information about the ffmpeg-devel mailing list