[FFmpeg-devel] [PATCH v2 2/3] pngdec: expose gAMA and cHRM chunks as side data
James Almer
jamrial at gmail.com
Mon Sep 25 22:52:22 EEST 2017
On 9/25/2017 4:28 PM, Rostislav Pehlivanov wrote:
> Signed-off-by: Rostislav Pehlivanov <atomnuker at gmail.com>
> ---
> libavcodec/pngdec.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 48 insertions(+)
>
> diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
> index 0d6612ccca..2d005f90fc 100644
> --- a/libavcodec/pngdec.c
> +++ b/libavcodec/pngdec.c
> @@ -25,6 +25,7 @@
> #include "libavutil/bprint.h"
> #include "libavutil/imgutils.h"
> #include "libavutil/stereo3d.h"
> +#include "libavutil/mastering_display_metadata.h"
>
> #include "avcodec.h"
> #include "bytestream.h"
> @@ -1287,6 +1288,53 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
> goto fail;
> break;
> }
> + case MKTAG('c', 'H', 'R', 'M'): {
> + AVMasteringDisplayMetadata *mdm = av_mastering_display_metadata_create_side_data(p);
> + if (!mdm) {
> + ret = AVERROR(ENOMEM);
> + goto fail;
> + }
> +
> + mdm->white_point[0].num = bytestream2_get_be32(&s->gb);
> + mdm->white_point[0].den = 100000;
> + mdm->white_point[1].num = bytestream2_get_be32(&s->gb);
> + mdm->white_point[1].den = 100000;
> +
> + /* Red primaries */
> + mdm->display_primaries[0][0].num = bytestream2_get_be32(&s->gb);
> + mdm->display_primaries[0][0].den = 100000;
> + mdm->display_primaries[0][1].num = bytestream2_get_be32(&s->gb);
> + mdm->display_primaries[0][1].den = 100000;
> +
> + /* Green primaries */
> + mdm->display_primaries[1][0].num = bytestream2_get_be32(&s->gb);
> + mdm->display_primaries[1][0].den = 100000;
> + mdm->display_primaries[1][1].num = bytestream2_get_be32(&s->gb);
> + mdm->display_primaries[1][1].den = 100000;
> +
> + /* Blue primaries */
> + mdm->display_primaries[2][0].num = bytestream2_get_be32(&s->gb);
> + mdm->display_primaries[2][0].den = 100000;
> + mdm->display_primaries[2][1].num = bytestream2_get_be32(&s->gb);
> + mdm->display_primaries[2][1].den = 100000;
Consider using av_make_q(). It should make this shorter and cleaner.
> +
> + mdm->has_primaries = 1;
> + bytestream2_skip(&s->gb, 4); /* crc */
Unrelated to this patch, but not doing CRC checks on demand (that is,
when err_detect enables it) seems like bad practice, especially for
lossless codecs.
> + break;
> + }
> + case MKTAG('g', 'A', 'M', 'A'): {
> + AVFrameSideData *sd = av_frame_new_side_data(p, AV_FRAME_DATA_GAMMA, sizeof(AVRational));
> + AVRational *gamma = (AVRational *)sd->data;
sd may be NULL. The check below should be first.
> + if (!sd) {
> + ret = AVERROR(ENOMEM);
> + goto fail;
> + }
> +
> + gamma->num = bytestream2_get_be32(&s->gb);
> + gamma->den = 100000;
> + bytestream2_skip(&s->gb, 4); /* crc */
> + break;
> + }
> case MKTAG('I', 'E', 'N', 'D'):
> if (!(s->pic_state & PNG_ALLIMAGE))
> av_log(avctx, AV_LOG_ERROR, "IEND without all image\n");
>
More information about the ffmpeg-devel
mailing list