1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-11-23 21:54:53 +02:00

avcodec/tiff: decode TIFF non-image-data tags into EXIF metadata struct

This commit will cause TIFF files to store their tags in the EXIF
struct so tags such as orientation can be transfered to other formats
(such as PNG) in a way that doesn't corrupt the IFD.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
This commit is contained in:
Leo Izen
2025-04-09 13:07:49 -04:00
parent 93a8091015
commit 1e816ebefe
2 changed files with 37 additions and 1 deletions

View File

@@ -47,6 +47,7 @@
#include "bytestream.h"
#include "codec_internal.h"
#include "decode.h"
#include "exif_internal.h"
#include "faxcompr.h"
#include "lzw.h"
#include "tiff.h"
@@ -124,6 +125,8 @@ typedef struct TiffContext {
int geotag_count;
TiffGeoTag *geotags;
AVExifMetadata exif_meta;
} TiffContext;
static const float d65_white[3] = { 0.950456f, 1.f, 1.088754f };
@@ -1937,6 +1940,12 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
int is_dng;
int has_tile_bits, has_strip_bits;
av_exif_free(&s->exif_meta);
/* this will not parse the image data */
ret = av_exif_parse_buffer(avctx, avpkt->data, avpkt->size, &s->exif_meta, AV_EXIF_TIFF_HEADER);
if (ret < 0)
av_log(avctx, AV_LOG_ERROR, "could not parse EXIF data: %s\n", av_err2str(ret));
bytestream2_init(&s->gb, avpkt->data, avpkt->size);
// parse image header
@@ -2402,6 +2411,10 @@ again:
}
}
ret = ff_exif_attach_ifd(avctx, p, &s->exif_meta);
if (ret < 0)
av_log(avctx, AV_LOG_ERROR, "error attaching EXIF ifd: %s\n", av_err2str(ret));
*got_frame = 1;
return avpkt->size;
@@ -2450,6 +2463,7 @@ static av_cold int tiff_end(AVCodecContext *avctx)
TiffContext *const s = avctx->priv_data;
free_geotags(s);
av_exif_free(&s->exif_meta);
ff_lzw_decode_close(&s->lzw);
av_freep(&s->deinvert_buf);

View File

@@ -32,5 +32,27 @@ color_transfer=unknown
chroma_location=unspecified
TAG:document_name=image_small.tiff
TAG:page_number= 0 / 1
TAG:software=ImageMagick 6.5.8-0 2010-02-09 Q16 http://www.imagemagick.org
TAG:0x0129= 0, 1
TAG:ImageWidth= 200
TAG:ImageLength= 112
TAG:BitsPerSample= 8, 8, 8
TAG:Compression= 1
TAG:PhotometricInterpretation= 2
TAG:0x010A= 1
TAG:0x010D=image_small.tiff
TAG:StripOffsets= 8, 7808, 15608, 23408, 31208, 39008, 46808, 54608
62408
TAG:Orientation= 1
TAG:SamplesPerPixel= 3
TAG:RowsPerStrip= 13
TAG:StripByteCounts= 7800, 7800, 7800, 7800, 7800, 7800, 7800, 7800
4800
TAG:XResolution=1188833536:16777216
TAG:YResolution=1188833536:16777216
TAG:PlanarConfiguration= 1
TAG:ResolutionUnit= 3
TAG:Software=ImageMagick 6.5.8-0 2010-02-09 Q16 http://www.imagemagick.org
[SIDE_DATA]
side_data_type=EXIF metadata
[/SIDE_DATA]
[/FRAME]