avcodec/tiff_common: rename TIFF enum constants

This makes the enum TiffTypes public by moving it to the public header
exif.h and renaming it to AVTiffDataType, as well as adding an AV_
prefix in front of each of the entry names. This allows callers to use
enum AVTiffDataType without pulling in all of tiff_common.h, as that
header is not public.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
This commit is contained in:
Leo Izen
2025-03-11 13:41:19 -04:00
parent a6b5a382dd
commit a99fff4e2d
7 changed files with 79 additions and 78 deletions

View File

@@ -180,17 +180,17 @@ static int exif_add_metadata(void *logctx, int count, int type,
"Invalid TIFF tag type 0 found for %s with size %d\n",
name, count);
return 0;
case TIFF_DOUBLE : return ff_tadd_doubles_metadata(count, name, sep, gb, le, metadata);
case TIFF_SSHORT : return ff_tadd_shorts_metadata(count, name, sep, gb, le, 1, metadata);
case TIFF_SHORT : return ff_tadd_shorts_metadata(count, name, sep, gb, le, 0, metadata);
case TIFF_SBYTE : return ff_tadd_bytes_metadata(count, name, sep, gb, le, 1, metadata);
case TIFF_BYTE :
case TIFF_UNDEFINED: return ff_tadd_bytes_metadata(count, name, sep, gb, le, 0, metadata);
case TIFF_STRING : return ff_tadd_string_metadata(count, name, gb, le, metadata);
case TIFF_SRATIONAL:
case TIFF_RATIONAL : return ff_tadd_rational_metadata(count, name, sep, gb, le, metadata);
case TIFF_SLONG :
case TIFF_LONG : return ff_tadd_long_metadata(count, name, sep, gb, le, metadata);
case AV_TIFF_DOUBLE : return ff_tadd_doubles_metadata(count, name, sep, gb, le, metadata);
case AV_TIFF_SSHORT : return ff_tadd_shorts_metadata(count, name, sep, gb, le, 1, metadata);
case AV_TIFF_SHORT : return ff_tadd_shorts_metadata(count, name, sep, gb, le, 0, metadata);
case AV_TIFF_SBYTE : return ff_tadd_bytes_metadata(count, name, sep, gb, le, 1, metadata);
case AV_TIFF_BYTE :
case AV_TIFF_UNDEFINED: return ff_tadd_bytes_metadata(count, name, sep, gb, le, 0, metadata);
case AV_TIFF_STRING : return ff_tadd_string_metadata(count, name, gb, le, metadata);
case AV_TIFF_SRATIONAL:
case AV_TIFF_RATIONAL : return ff_tadd_rational_metadata(count, name, sep, gb, le, metadata);
case AV_TIFF_SLONG :
case AV_TIFF_LONG : return ff_tadd_long_metadata(count, name, sep, gb, le, metadata);
default:
avpriv_request_sample(logctx, "TIFF tag type (%u)", type);
return 0;
@@ -203,7 +203,7 @@ static int exif_decode_tag(void *logctx, GetByteContext *gbytes, int le,
{
int ret, cur_pos;
unsigned id, count;
enum TiffTypes type;
enum AVTiffDataType type;
if (depth > 2) {
return 0;

View File

@@ -32,6 +32,23 @@
#include "libavutil/dict.h"
#include "bytestream.h"
/** Data type identifiers for TIFF tags */
enum AVTiffDataType {
AV_TIFF_BYTE = 1,
AV_TIFF_STRING,
AV_TIFF_SHORT,
AV_TIFF_LONG,
AV_TIFF_RATIONAL,
AV_TIFF_SBYTE,
AV_TIFF_UNDEFINED,
AV_TIFF_SSHORT,
AV_TIFF_SLONG,
AV_TIFF_SRATIONAL,
AV_TIFF_FLOAT,
AV_TIFF_DOUBLE,
AV_TIFF_IFD,
};
/** Recursively decodes all IFD's and
* adds included TAGS into the metadata dictionary. */
int avpriv_exif_decode_ifd(void *logctx, const uint8_t *buf, int size,

View File

@@ -273,9 +273,9 @@ static int add_metadata(int count, int type,
const char *name, const char *sep, TiffContext *s, AVFrame *frame)
{
switch(type) {
case TIFF_DOUBLE: return ff_tadd_doubles_metadata(count, name, sep, &s->gb, s->le, &frame->metadata);
case TIFF_SHORT : return ff_tadd_shorts_metadata(count, name, sep, &s->gb, s->le, 0, &frame->metadata);
case TIFF_STRING: return ff_tadd_string_metadata(count, name, &s->gb, s->le, &frame->metadata);
case AV_TIFF_DOUBLE: return ff_tadd_doubles_metadata(count, name, sep, &s->gb, s->le, &frame->metadata);
case AV_TIFF_SHORT : return ff_tadd_shorts_metadata(count, name, sep, &s->gb, s->le, 0, &frame->metadata);
case AV_TIFF_STRING: return ff_tadd_string_metadata(count, name, &s->gb, s->le, &frame->metadata);
default : return AVERROR_INVALIDDATA;
};
}
@@ -1271,12 +1271,12 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
off = bytestream2_tell(&s->gb);
if (count == 1) {
switch (type) {
case TIFF_BYTE:
case TIFF_SHORT:
case TIFF_LONG:
case AV_TIFF_BYTE:
case AV_TIFF_SHORT:
case AV_TIFF_LONG:
value = ff_tget(&s->gb, type, s->le);
break;
case TIFF_RATIONAL:
case AV_TIFF_RATIONAL:
value = ff_tget_long(&s->gb, s->le);
value2 = ff_tget_long(&s->gb, s->le);
if (!value2) {
@@ -1285,7 +1285,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
}
break;
case TIFF_STRING:
case AV_TIFF_STRING:
if (count <= 4) {
break;
}
@@ -1320,9 +1320,9 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
s->bpp = value;
else {
switch (type) {
case TIFF_BYTE:
case TIFF_SHORT:
case TIFF_LONG:
case AV_TIFF_BYTE:
case AV_TIFF_SHORT:
case AV_TIFF_LONG:
s->bpp = 0;
if (bytestream2_get_bytes_left(&s->gb) < type_sizes[type] * count)
return AVERROR_INVALIDDATA;
@@ -1389,7 +1389,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
}
break;
case TIFF_ROWSPERSTRIP:
if (!value || (type == TIFF_LONG && value == UINT_MAX))
if (!value || (type == AV_TIFF_LONG && value == UINT_MAX))
value = s->height;
s->rps = FFMIN(value, s->height);
break;
@@ -1470,7 +1470,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
return AVERROR_INVALIDDATA;
s->black_level[0] = value / (float)value2;
for (int i = 0; i < count && count > 1; i++) {
if (type == TIFF_RATIONAL) {
if (type == AV_TIFF_RATIONAL) {
value = ff_tget_long(&s->gb, s->le);
value2 = ff_tget_long(&s->gb, s->le);
if (!value2) {
@@ -1479,7 +1479,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
}
s->black_level[i] = value / (float)value2;
} else if (type == TIFF_SRATIONAL) {
} else if (type == AV_TIFF_SRATIONAL) {
int value = ff_tget_long(&s->gb, s->le);
int value2 = ff_tget_long(&s->gb, s->le);
if (!value2) {
@@ -1786,7 +1786,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
}
break;
case DNG_ANALOG_BALANCE:
if (type != TIFF_RATIONAL)
if (type != AV_TIFF_RATIONAL)
break;
for (int i = 0; i < 3; i++) {
@@ -1801,7 +1801,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
}
break;
case DNG_AS_SHOT_NEUTRAL:
if (type != TIFF_RATIONAL)
if (type != AV_TIFF_RATIONAL)
break;
for (int i = 0; i < 3; i++) {
@@ -1816,7 +1816,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
}
break;
case DNG_AS_SHOT_WHITE_XY:
if (type != TIFF_RATIONAL)
if (type != AV_TIFF_RATIONAL)
break;
for (int i = 0; i < 2; i++) {

View File

@@ -64,9 +64,9 @@ double ff_tget_double(GetByteContext *gb, int le)
unsigned ff_tget(GetByteContext *gb, int type, int le)
{
switch (type) {
case TIFF_BYTE: return bytestream2_get_byte(gb);
case TIFF_SHORT: return ff_tget_short(gb, le);
case TIFF_LONG: return ff_tget_long(gb, le);
case AV_TIFF_BYTE: return bytestream2_get_byte(gb);
case AV_TIFF_SHORT: return ff_tget_short(gb, le);
case AV_TIFF_LONG: return ff_tget_long(gb, le);
default: return UINT_MAX;
}
}
@@ -273,7 +273,7 @@ int ff_tread_tag(GetByteContext *gb, int le, unsigned *tag, unsigned *type,
// seek to offset if this is an IFD-tag or
// if count values do not fit into the offset value
if (ifd_tag || (*count > 4 || !(type_sizes[*type] * (*count) <= 4 || *type == TIFF_STRING))) {
if (ifd_tag || (*count > 4 || !(type_sizes[*type] * (*count) <= 4 || *type == AV_TIFF_STRING))) {
bytestream2_seek(gb, ff_tget_long (gb, le), SEEK_SET);
}

View File

@@ -31,23 +31,7 @@
#include <stdint.h>
#include "libavutil/dict.h"
#include "bytestream.h"
/** data type identifiers for TIFF tags */
enum TiffTypes {
TIFF_BYTE = 1,
TIFF_STRING,
TIFF_SHORT,
TIFF_LONG,
TIFF_RATIONAL,
TIFF_SBYTE,
TIFF_UNDEFINED,
TIFF_SSHORT,
TIFF_SLONG,
TIFF_SRATIONAL,
TIFF_FLOAT,
TIFF_DOUBLE,
TIFF_IFD
};
#include "exif.h"
/** sizes of various TIFF field types (string size = 100)*/
static const uint8_t type_sizes[14] = {

View File

@@ -105,7 +105,7 @@ static inline int check_size(TiffEncoderContext *s, uint64_t need)
* @param type type of values
* @param flip = 0 - normal copy, >0 - flip
*/
static void tnput(uint8_t **p, int n, const uint8_t *val, enum TiffTypes type,
static void tnput(uint8_t **p, int n, const uint8_t *val, enum AVTiffDataType type,
int flip)
{
int i;
@@ -126,7 +126,7 @@ static void tnput(uint8_t **p, int n, const uint8_t *val, enum TiffTypes type,
* @param ptr_val pointer to values
*/
static int add_entry(TiffEncoderContext *s, enum TiffTags tag,
enum TiffTypes type, int count, const void *ptr_val)
enum AVTiffDataType type, int count, const void *ptr_val)
{
uint8_t *entries_ptr = s->entries + 12 * s->num_entries;
@@ -150,12 +150,12 @@ static int add_entry(TiffEncoderContext *s, enum TiffTags tag,
}
static int add_entry1(TiffEncoderContext *s,
enum TiffTags tag, enum TiffTypes type, int val)
enum TiffTags tag, enum AVTiffDataType type, int val)
{
uint16_t w = val;
uint32_t dw = val;
return add_entry(s, tag, type, 1,
type == TIFF_SHORT ? (void *)&w : (void *)&dw);
type == AV_TIFF_SHORT ? (void *)&w : (void *)&dw);
}
/**
@@ -453,23 +453,23 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
s->num_entries = 0;
ADD_ENTRY1(s, TIFF_SUBFILE, TIFF_LONG, 0);
ADD_ENTRY1(s, TIFF_WIDTH, TIFF_LONG, s->width);
ADD_ENTRY1(s, TIFF_HEIGHT, TIFF_LONG, s->height);
ADD_ENTRY1(s, TIFF_SUBFILE, AV_TIFF_LONG, 0);
ADD_ENTRY1(s, TIFF_WIDTH, AV_TIFF_LONG, s->width);
ADD_ENTRY1(s, TIFF_HEIGHT, AV_TIFF_LONG, s->height);
if (s->bpp_tab_size)
ADD_ENTRY(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab);
ADD_ENTRY(s, TIFF_BPP, AV_TIFF_SHORT, s->bpp_tab_size, bpp_tab);
ADD_ENTRY1(s, TIFF_COMPR, TIFF_SHORT, s->compr);
ADD_ENTRY1(s, TIFF_PHOTOMETRIC, TIFF_SHORT, s->photometric_interpretation);
ADD_ENTRY(s, TIFF_STRIP_OFFS, TIFF_LONG, strips, s->strip_offsets);
ADD_ENTRY1(s, TIFF_COMPR, AV_TIFF_SHORT, s->compr);
ADD_ENTRY1(s, TIFF_PHOTOMETRIC, AV_TIFF_SHORT, s->photometric_interpretation);
ADD_ENTRY(s, TIFF_STRIP_OFFS, AV_TIFF_LONG, strips, s->strip_offsets);
if (s->bpp_tab_size)
ADD_ENTRY1(s, TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size);
ADD_ENTRY1(s, TIFF_SAMPLES_PER_PIXEL, AV_TIFF_SHORT, s->bpp_tab_size);
ADD_ENTRY1(s, TIFF_ROWSPERSTRIP, TIFF_LONG, s->rps);
ADD_ENTRY(s, TIFF_STRIP_SIZE, TIFF_LONG, strips, s->strip_sizes);
ADD_ENTRY(s, TIFF_XRES, TIFF_RATIONAL, 1, res);
ADD_ENTRY1(s, TIFF_ROWSPERSTRIP, AV_TIFF_LONG, s->rps);
ADD_ENTRY(s, TIFF_STRIP_SIZE, AV_TIFF_LONG, strips, s->strip_sizes);
ADD_ENTRY(s, TIFF_XRES, AV_TIFF_RATIONAL, 1, res);
if (avctx->sample_aspect_ratio.num > 0 &&
avctx->sample_aspect_ratio.den > 0) {
AVRational y = av_mul_q(av_make_q(s->dpi, 1),
@@ -477,11 +477,11 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
res[0] = y.num;
res[1] = y.den;
}
ADD_ENTRY(s, TIFF_YRES, TIFF_RATIONAL, 1, res);
ADD_ENTRY1(s, TIFF_RES_UNIT, TIFF_SHORT, 2);
ADD_ENTRY(s, TIFF_YRES, AV_TIFF_RATIONAL, 1, res);
ADD_ENTRY1(s, TIFF_RES_UNIT, AV_TIFF_SHORT, 2);
if (!(avctx->flags & AV_CODEC_FLAG_BITEXACT))
ADD_ENTRY(s, TIFF_SOFTWARE_NAME, TIFF_STRING,
ADD_ENTRY(s, TIFF_SOFTWARE_NAME, AV_TIFF_STRING,
strlen(LIBAVCODEC_IDENT) + 1, LIBAVCODEC_IDENT);
if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
@@ -492,17 +492,17 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
pal[i + 256] = ((rgb >> 8) & 0xff) * 257;
pal[i + 512] = (rgb & 0xff) * 257;
}
ADD_ENTRY(s, TIFF_PAL, TIFF_SHORT, 256 * 3, pal);
ADD_ENTRY(s, TIFF_PAL, AV_TIFF_SHORT, 256 * 3, pal);
}
if (alpha)
ADD_ENTRY1(s,TIFF_EXTRASAMPLES, TIFF_SHORT, 2);
ADD_ENTRY1(s,TIFF_EXTRASAMPLES, AV_TIFF_SHORT, 2);
if (is_yuv) {
/** according to CCIR Recommendation 601.1 */
uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 };
ADD_ENTRY(s, TIFF_YCBCR_SUBSAMPLING, TIFF_SHORT, 2, s->subsampling);
ADD_ENTRY(s, TIFF_YCBCR_SUBSAMPLING, AV_TIFF_SHORT, 2, s->subsampling);
if (avctx->chroma_sample_location == AVCHROMA_LOC_TOPLEFT)
ADD_ENTRY1(s, TIFF_YCBCR_POSITIONING, TIFF_SHORT, 2);
ADD_ENTRY(s, TIFF_REFERENCE_BW, TIFF_RATIONAL, 6, refbw);
ADD_ENTRY1(s, TIFF_YCBCR_POSITIONING, AV_TIFF_SHORT, 2);
ADD_ENTRY(s, TIFF_REFERENCE_BW, AV_TIFF_RATIONAL, 6, refbw);
}
// write offset to dir
bytestream_put_le32(&offset, ptr - pkt->data);

View File

@@ -429,7 +429,7 @@ static int read_header(AVFormatContext *avctx)
static void write_tiff_short(PutByteContext *pb, int tag, int value)
{
bytestream2_put_le16(pb, tag);
bytestream2_put_le16(pb, TIFF_SHORT);
bytestream2_put_le16(pb, AV_TIFF_SHORT);
bytestream2_put_le32(pb, 1);
bytestream2_put_le16(pb, value);
bytestream2_put_le16(pb, 0);
@@ -438,7 +438,7 @@ static void write_tiff_short(PutByteContext *pb, int tag, int value)
static void write_tiff_short2(PutByteContext *pb, int tag, int v1, int v2)
{
bytestream2_put_le16(pb, tag);
bytestream2_put_le16(pb, TIFF_SHORT);
bytestream2_put_le16(pb, AV_TIFF_SHORT);
bytestream2_put_le32(pb, 2);
bytestream2_put_le16(pb, v1);
bytestream2_put_le16(pb, v2);
@@ -447,7 +447,7 @@ static void write_tiff_short2(PutByteContext *pb, int tag, int v1, int v2)
static void write_tiff_long(PutByteContext *pb, int tag, int value)
{
bytestream2_put_le16(pb, tag);
bytestream2_put_le16(pb, TIFF_LONG);
bytestream2_put_le16(pb, AV_TIFF_LONG);
bytestream2_put_le32(pb, 1);
bytestream2_put_le32(pb, value);
}
@@ -455,7 +455,7 @@ static void write_tiff_long(PutByteContext *pb, int tag, int value)
static void write_tiff_byte4(PutByteContext *pb, int tag, int v1, int v2, int v3, int v4)
{
bytestream2_put_le16(pb, tag);
bytestream2_put_le16(pb, TIFF_BYTE);
bytestream2_put_le16(pb, AV_TIFF_BYTE);
bytestream2_put_le32(pb, 4);
bytestream2_put_byte(pb, v1);
bytestream2_put_byte(pb, v2);
@@ -506,7 +506,7 @@ static int get_packet_lj92(AVFormatContext *avctx, AVStream *st, AVIOContext *pb
write_tiff_long(pb, DNG_WHITE_LEVEL, mlv->white_level);
bytestream2_put_le16(pb, DNG_COLOR_MATRIX1);
bytestream2_put_le16(pb, TIFF_SRATIONAL);
bytestream2_put_le16(pb, AV_TIFF_SRATIONAL);
bytestream2_put_le32(pb, 9);
bytestream2_put_le32(pb, 0); /* matrixofs */
matrixofs = pb->buffer - 4;