[FFmpeg-devel] [PATCH v4] pngdec: expose gAMA and cHRM chunks as side/meta data
James Almer
jamrial at gmail.com
Thu Nov 9 03:19:11 EET 2017
On 11/8/2017 9:25 PM, Rostislav Pehlivanov wrote:
> Signed-off-by: Rostislav Pehlivanov <atomnuker at gmail.com>
> ---
> libavcodec/pngdec.c | 30 +++++++++++++++++++++++++++++-
> 1 file changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
> index 0d6612ccca..aef0d95819 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"
> @@ -1165,7 +1166,7 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
> AVDictionary **metadatap = NULL;
> uint32_t tag, length;
> int decode_next_dat = 0;
> - int ret;
> + int i, ret;
>
> for (;;) {
> length = bytestream2_get_bytes_left(&s->gb);
> @@ -1287,6 +1288,33 @@ 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] = av_make_q(bytestream2_get_be32(&s->gb), 100000);
> + mdm->white_point[1] = av_make_q(bytestream2_get_be32(&s->gb), 100000);
> +
> + /* RGB Primaries */
> + for (i = 0; i < 3; i++) {
> + mdm->display_primaries[i][0] = av_make_q(bytestream2_get_be32(&s->gb), 100000);
> + mdm->display_primaries[i][1] = av_make_q(bytestream2_get_be32(&s->gb), 100000);
> + }
> +
> + mdm->has_primaries = 1;
> + bytestream2_skip(&s->gb, 4); /* crc */
> + break;
> + }
> + case MKTAG('g', 'A', 'M', 'A'): {
> + av_dict_set_int(&p->metadata, "gamma_num", bytestream2_get_be32(&s->gb), 0);
> + av_dict_set_int(&p->metadata, "gamma_den", 100000, 0);
You should use snprintf or the AVBPrint API to write a rational value in
the "x/y" or "x:y" form as single string entry to use with av_dict_set()
instead.
Having two metadata entries for a single rational value seems unwieldy.
See ff_tadd_rational_metadata() in tiff_common.c for an example of this
using AVBPrint.
> +
> + 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