From: Leo Izen <leo.izen@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Leo Izen <leo.izen@gmail.com>
Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/pngdec: parse eXIf chunk
Date: Tue, 13 Feb 2024 16:24:55 -0500
Message-ID: <20240213212456.167386-3-leo.izen@gmail.com> (raw)
In-Reply-To: <20240213212456.167386-1-leo.izen@gmail.com>
Add support to parse eXIf chunks using the new EXIF framework.
Signed-off-by: Leo Izen <leo.izen@gmail.com>
---
libavcodec/pngdec.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 026da30c25..e7951d1802 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -38,6 +38,7 @@
#include "bytestream.h"
#include "codec_internal.h"
#include "decode.h"
+#include "exif_internal.h"
#include "apng.h"
#include "png.h"
#include "pngdsp.h"
@@ -123,6 +124,7 @@ typedef struct PNGDecContext {
int pass_row_size; /* decompress row size of the current pass */
int y;
FFZStream zstream;
+ AVBufferRef *exif_data;
} PNGDecContext;
/* Mask to determine which pixels are valid in a pass */
@@ -652,6 +654,26 @@ static int decode_phys_chunk(AVCodecContext *avctx, PNGDecContext *s,
return 0;
}
+static int decode_exif_chunk(AVCodecContext *avctx, PNGDecContext *s,
+ GetByteContext *gb)
+{
+ if (!(s->hdr_state & PNG_IHDR)) {
+ av_log(avctx, AV_LOG_ERROR, "eXIf before IHDR\n");
+ return AVERROR_INVALIDDATA;
+ }
+ if (s->pic_state & PNG_IDAT) {
+ av_log(avctx, AV_LOG_ERROR, "eXIf after IDAT\n");
+ return AVERROR_INVALIDDATA;
+ }
+ av_buffer_unref(&s->exif_data);
+ s->exif_data = av_buffer_alloc(bytestream2_get_bytes_left(gb));
+ if (!s->exif_data)
+ return AVERROR(ENOMEM);
+ bytestream2_get_buffer(gb, s->exif_data->data, s->exif_data->size);
+
+ return 0;
+}
+
/*
* This populates AVCodecContext fields so it must be called before
* ff_thread_finish_setup() to avoid a race condition with respect to the
@@ -890,6 +912,12 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s,
p->flags |= AV_FRAME_FLAG_KEY;
p->flags |= AV_FRAME_FLAG_INTERLACED * !!s->interlace_type;
+ if (s->exif_data) {
+ ret = ff_exif_attach(avctx, p, &s->exif_data);
+ if (ret < 0)
+ return ret;
+ }
+
if ((ret = populate_avctx_color_fields(avctx, p)) < 0)
return ret;
ff_thread_finish_setup(avctx);
@@ -1571,6 +1599,12 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
s->mdvc_max_lum = bytestream2_get_be32u(&gb_chunk);
s->mdvc_min_lum = bytestream2_get_be32u(&gb_chunk);
break;
+ case MKTAG('e', 'X', 'I', 'f'): {
+ ret = decode_exif_chunk(avctx, s, &gb_chunk);
+ if (ret < 0)
+ goto fail;
+ break;
+ }
case MKTAG('I', 'E', 'N', 'D'):
if (!(s->pic_state & PNG_ALLIMAGE))
av_log(avctx, AV_LOG_ERROR, "IEND without all image\n");
@@ -1907,6 +1941,7 @@ static av_cold int png_dec_end(AVCodecContext *avctx)
s->tmp_row_size = 0;
av_freep(&s->iccp_data);
+ av_buffer_unref(&s->exif_data);
av_dict_free(&s->frame_metadata);
ff_inflate_end(&s->zstream);
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-02-13 21:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-13 21:24 [FFmpeg-devel] [PATCH 0/3] [RFC] EXIF overhaul Leo Izen
2024-02-13 21:24 ` [FFmpeg-devel] [PATCH 1/3] various: change EXIF metadata into AVFrameSideData Leo Izen
2024-02-13 21:24 ` Leo Izen [this message]
2024-02-13 21:24 ` [FFmpeg-devel] [PATCH 3/3] avcodec/pngenc: write eXIf chunks Leo Izen
2024-02-14 18:38 ` Michael Niedermayer
2024-02-14 18:53 ` Andreas Rheinhardt
2024-02-15 8:19 ` Leo Izen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240213212456.167386-3-leo.izen@gmail.com \
--to=leo.izen@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git