* [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures
@ 2024-03-10 14:12 Andreas Rheinhardt
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 2/6] avcodec/tiff: Avoid duplicating strings Andreas Rheinhardt
` (5 more replies)
0 siblings, 6 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-03-10 14:12 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
For unknown geokey values, get_geokey_val() returns
"Unknown-%d" with val being used for %d. This string
is allocated and therefore all the known geokey values
(static strings) are strdup'ed. In case this fails
it is either ignored or treated as "Unknown-%d".
(Furthermore it is possible to call av_strdup(NULL),
although this is not documented to be legal.)
This commit changes this by only returning the static strings
in get_geokey_val(); the unknown handling and strdup'ing
is moved out of it.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/tiff.c | 35 ++++++++++++++++-------------------
1 file changed, 16 insertions(+), 19 deletions(-)
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index cb4d378753..4c7460cf41 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -36,6 +36,7 @@
#include <float.h>
#include "libavutil/attributes.h"
+#include "libavutil/avstring.h"
#include "libavutil/error.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
@@ -179,19 +180,17 @@ static const char *search_keyval(const TiffGeoTagKeyName *keys, int n, int id)
return NULL;
}
-static char *get_geokey_val(int key, int val)
+static const char *get_geokey_val(int key, uint16_t val)
{
- char *ap;
-
if (val == TIFF_GEO_KEY_UNDEFINED)
- return av_strdup("undefined");
+ return "undefined";
if (val == TIFF_GEO_KEY_USER_DEFINED)
- return av_strdup("User-Defined");
+ return "User-Defined";
#define RET_GEOKEY_VAL(TYPE, array)\
if (val >= TIFF_##TYPE##_OFFSET &&\
val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_codes))\
- return av_strdup(tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);
+ return tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET];
switch (key) {
case TIFF_GT_MODEL_TYPE_GEOKEY:
@@ -224,13 +223,9 @@ static char *get_geokey_val(int key, int val)
RET_GEOKEY_VAL(PRIME_MERIDIAN, prime_meridian);
break;
case TIFF_PROJECTED_CS_TYPE_GEOKEY:
- ap = av_strdup(search_keyval(tiff_proj_cs_type_codes, FF_ARRAY_ELEMS(tiff_proj_cs_type_codes), val));
- if(ap) return ap;
- break;
+ return search_keyval(tiff_proj_cs_type_codes, FF_ARRAY_ELEMS(tiff_proj_cs_type_codes), val);
case TIFF_PROJECTION_GEOKEY:
- ap = av_strdup(search_keyval(tiff_projection_codes, FF_ARRAY_ELEMS(tiff_projection_codes), val));
- if(ap) return ap;
- break;
+ return search_keyval(tiff_projection_codes, FF_ARRAY_ELEMS(tiff_projection_codes), val);
case TIFF_PROJ_COORD_TRANS_GEOKEY:
RET_GEOKEY_VAL(COORD_TRANS, coord_trans);
break;
@@ -241,10 +236,7 @@ static char *get_geokey_val(int key, int val)
}
- ap = av_malloc(14);
- if (ap)
- snprintf(ap, 14, "Unknown-%d", val);
- return ap;
+ return NULL;
}
static char *doubles2str(double *dp, int count, const char *sep)
@@ -1634,9 +1626,14 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
s->geotags[i].type = ff_tget_short(&s->gb, s->le);
s->geotags[i].count = ff_tget_short(&s->gb, s->le);
- if (!s->geotags[i].type)
- s->geotags[i].val = get_geokey_val(s->geotags[i].key, ff_tget_short(&s->gb, s->le));
- else
+ if (!s->geotags[i].type) {
+ uint16_t val = ff_tget_short(&s->gb, s->le);
+ const char *str = get_geokey_val(s->geotags[i].key, val);
+
+ s->geotags[i].val = str ? av_strdup(str) : av_asprintf("Unknown-%u", val);
+ if (!s->geotags[i].val)
+ return AVERROR(ENOMEM);
+ } else
s->geotags[i].offset = ff_tget_short(&s->gb, s->le);
}
break;
--
2.40.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 2/6] avcodec/tiff: Avoid duplicating strings
2024-03-10 14:12 [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures Andreas Rheinhardt
@ 2024-03-10 14:15 ` Andreas Rheinhardt
2024-03-10 15:34 ` Stefano Sabatini
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 3/6] avcodec/tiff: Don't check before av_freep() Andreas Rheinhardt
` (4 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-03-10 14:15 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/tiff.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 4c7460cf41..afa1289e27 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -2028,7 +2028,8 @@ again:
av_log(avctx, AV_LOG_WARNING, "Type of GeoTIFF key %d is wrong\n", s->geotags[i].key);
continue;
}
- ret = av_dict_set(&p->metadata, keyname, s->geotags[i].val, 0);
+ ret = av_dict_set(&p->metadata, keyname, s->geotags[i].val, AV_DICT_DONT_STRDUP_VAL);
+ s->geotags[i].val = NULL;
if (ret<0) {
av_log(avctx, AV_LOG_ERROR, "Writing metadata with key '%s' failed\n", keyname);
return ret;
--
2.40.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 3/6] avcodec/tiff: Don't check before av_freep()
2024-03-10 14:12 [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures Andreas Rheinhardt
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 2/6] avcodec/tiff: Avoid duplicating strings Andreas Rheinhardt
@ 2024-03-10 14:15 ` Andreas Rheinhardt
2024-03-10 15:38 ` Stefano Sabatini
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 4/6] avcodec/tiff: Improve inclusions Andreas Rheinhardt
` (3 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-03-10 14:15 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/tiff.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index afa1289e27..5d350f4e7e 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -132,11 +132,8 @@ static void tiff_set_type(TiffContext *s, enum TiffType tiff_type) {
static void free_geotags(TiffContext *const s)
{
- int i;
- for (i = 0; i < s->geotag_count; i++) {
- if (s->geotags[i].val)
- av_freep(&s->geotags[i].val);
- }
+ for (int i = 0; i < s->geotag_count; i++)
+ av_freep(&s->geotags[i].val);
av_freep(&s->geotags);
s->geotag_count = 0;
}
--
2.40.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 4/6] avcodec/tiff: Improve inclusions
2024-03-10 14:12 [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures Andreas Rheinhardt
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 2/6] avcodec/tiff: Avoid duplicating strings Andreas Rheinhardt
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 3/6] avcodec/tiff: Don't check before av_freep() Andreas Rheinhardt
@ 2024-03-10 14:15 ` Andreas Rheinhardt
2024-03-10 15:44 ` Stefano Sabatini
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 5/6] avcodec/tiff_data: Avoid relocations for TiffGeoTagNameType Andreas Rheinhardt
` (2 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-03-10 14:15 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegdec.c | 1 -
libavcodec/tiff.c | 1 +
libavcodec/tiff.h | 3 ---
libavcodec/tiffenc.c | 3 +--
4 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 43b36d0a8f..c9409eac6c 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -52,7 +52,6 @@
#include "jpeglsdec.h"
#include "profiles.h"
#include "put_bits.h"
-#include "tiff.h"
#include "exif.h"
#include "bytestream.h"
#include "tiff_common.h"
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 5d350f4e7e..15e5edd93b 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -48,6 +48,7 @@
#include "faxcompr.h"
#include "lzw.h"
#include "tiff.h"
+#include "tiff_common.h"
#include "tiff_data.h"
#include "mjpegdec.h"
#include "thread.h"
diff --git a/libavcodec/tiff.h b/libavcodec/tiff.h
index e67c59abad..2dd21dea52 100644
--- a/libavcodec/tiff.h
+++ b/libavcodec/tiff.h
@@ -30,9 +30,6 @@
#ifndef AVCODEC_TIFF_H
#define AVCODEC_TIFF_H
-#include <stdint.h>
-#include "tiff_common.h"
-
/** TIFF types in ascenting priority (last in the list is highest) */
enum TiffType {
/** TIFF image based on the TIFF 6.0 or TIFF/EP (ISO 12234-2) specifications */
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index dfe308ee17..7c3c03f1f3 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -30,7 +30,6 @@
#include <zlib.h>
#endif
-#include "libavutil/imgutils.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
@@ -39,9 +38,9 @@
#include "codec_internal.h"
#include "encode.h"
#include "lzw.h"
-#include "put_bits.h"
#include "rle.h"
#include "tiff.h"
+#include "tiff_common.h"
#include "version.h"
#define TIFF_MAX_ENTRY 32
--
2.40.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 5/6] avcodec/tiff_data: Avoid relocations for TiffGeoTagNameType
2024-03-10 14:12 [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures Andreas Rheinhardt
` (2 preceding siblings ...)
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 4/6] avcodec/tiff: Improve inclusions Andreas Rheinhardt
@ 2024-03-10 14:15 ` Andreas Rheinhardt
2024-03-14 10:46 ` Andreas Rheinhardt
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 6/6] avcodec/tiff_data: Remove incorrect GeoTIFF entries Andreas Rheinhardt
2024-03-10 15:25 ` [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures Stefano Sabatini
5 siblings, 1 reply; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-03-10 14:15 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Instead store all the strings in one continugous string
(with internal \0) and use offsets to access the actual
substrings. This replaces the pointers to the strings
and therefore avoids relocations (and on x64, it actually
shrinks TiffGeoTagNameType by reusing padding to store
the offset field).
This saves 720B of .data.rel.ro and 1080B of .rela.dyn
(containing the relocation records) here while increasing
.rodata by 384B.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
I also have patches for the remaining tables, but am not
satisfied with them yet.
libavcodec/tiff.c | 28 +++++----
libavcodec/tiff.h | 5 --
libavcodec/tiff_data.h | 129 ++++++++++++++++++++++++-----------------
3 files changed, 92 insertions(+), 70 deletions(-)
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 15e5edd93b..004db89c6b 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -139,27 +139,31 @@ static void free_geotags(TiffContext *const s)
s->geotag_count = 0;
}
-#define RET_GEOKEY(TYPE, array, element)\
+static const char *get_geokey_name(int key)
+{
+#define RET_GEOKEY_STR(TYPE, array)\
if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\
- return tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element;
+ return tiff_##array##_name_type_string + tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].offset;
-static const char *get_geokey_name(int key)
-{
- RET_GEOKEY(VERT, vert, name);
- RET_GEOKEY(PROJ, proj, name);
- RET_GEOKEY(GEOG, geog, name);
- RET_GEOKEY(CONF, conf, name);
+ RET_GEOKEY_STR(VERT, vert);
+ RET_GEOKEY_STR(PROJ, proj);
+ RET_GEOKEY_STR(GEOG, geog);
+ RET_GEOKEY_STR(CONF, conf);
return NULL;
}
static int get_geokey_type(int key)
{
- RET_GEOKEY(VERT, vert, type);
- RET_GEOKEY(PROJ, proj, type);
- RET_GEOKEY(GEOG, geog, type);
- RET_GEOKEY(CONF, conf, type);
+#define RET_GEOKEY_TYPE(TYPE, array)\
+ if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
+ key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\
+ return tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].type;
+ RET_GEOKEY_TYPE(VERT, vert);
+ RET_GEOKEY_TYPE(PROJ, proj);
+ RET_GEOKEY_TYPE(GEOG, geog);
+ RET_GEOKEY_TYPE(CONF, conf);
return AVERROR_INVALIDDATA;
}
diff --git a/libavcodec/tiff.h b/libavcodec/tiff.h
index 2dd21dea52..12afcfa6e5 100644
--- a/libavcodec/tiff.h
+++ b/libavcodec/tiff.h
@@ -222,9 +222,4 @@ typedef struct TiffGeoTagKeyName {
const char *const name;
} TiffGeoTagKeyName;
-typedef struct TiffGeoTagNameType {
- const char *const name;
- const enum TiffGeoTagType type;
-} TiffGeoTagNameType;
-
#endif /* AVCODEC_TIFF_H */
diff --git a/libavcodec/tiff_data.h b/libavcodec/tiff_data.h
index 9b123ca8df..9ed46d31af 100644
--- a/libavcodec/tiff_data.h
+++ b/libavcodec/tiff_data.h
@@ -32,66 +32,89 @@
#include "tiff.h"
+typedef struct TiffGeoTagNameType {
+ enum TiffGeoTagType type;
+ unsigned offset;
+} TiffGeoTagNameType;
+
#define TIFF_CONF_KEY_ID_OFFSET 1024
-static const TiffGeoTagNameType tiff_conf_name_type_map[] = {
- {"GTModelTypeGeoKey", GEOTIFF_SHORT },
- {"GTRasterTypeGeoKey", GEOTIFF_SHORT },
- {"GTCitationGeoKey", GEOTIFF_STRING}
-};
+#define CONF_NAME_TYPE_MAP(KEY) \
+ KEY(GTModelTypeGeoKey, SHORT ) \
+ KEY(GTRasterTypeGeoKey, SHORT ) \
+ KEY(GTCitationGeoKey, STRING) \
#define TIFF_GEOG_KEY_ID_OFFSET 2048
-static const TiffGeoTagNameType tiff_geog_name_type_map[] = {
- {"GeographicTypeGeoKey", GEOTIFF_SHORT },
- {"GeogCitationGeoKey", GEOTIFF_STRING},
- {"GeogGeodeticDatumGeoKey", GEOTIFF_SHORT },
- {"GeogPrimeMeridianGeoKey", GEOTIFF_SHORT },
- {"GeogLinearUnitsGeoKey", GEOTIFF_SHORT },
- {"GeogLinearUnitSizeGeoKey", GEOTIFF_DOUBLE},
- {"GeogAngularUnitsGeoKey", GEOTIFF_SHORT },
- {"GeogAngularUnitSizeGeoKey", GEOTIFF_DOUBLE},
- {"GeogEllipsoidGeoKey", GEOTIFF_SHORT },
- {"GeogSemiMajorAxisGeoKey", GEOTIFF_DOUBLE},
- {"GeogSemiMinorAxisGeoKey", GEOTIFF_DOUBLE},
- {"GeogInvFlatteningGeoKey", GEOTIFF_DOUBLE},
- {"GeogAzimuthUnitsGeoKey", GEOTIFF_SHORT },
- {"GeogPrimeMeridianLongGeoKey", GEOTIFF_DOUBLE}
-};
+#define GEOG_NAME_TYPE_MAP(KEY) \
+ KEY(GeographicTypeGeoKey, SHORT ) \
+ KEY(GeogCitationGeoKey, STRING) \
+ KEY(GeogGeodeticDatumGeoKey, SHORT ) \
+ KEY(GeogPrimeMeridianGeoKey, SHORT ) \
+ KEY(GeogLinearUnitsGeoKey, SHORT ) \
+ KEY(GeogLinearUnitSizeGeoKey, DOUBLE) \
+ KEY(GeogAngularUnitsGeoKey, SHORT ) \
+ KEY(GeogAngularUnitSizeGeoKey, DOUBLE) \
+ KEY(GeogEllipsoidGeoKey, SHORT ) \
+ KEY(GeogSemiMajorAxisGeoKey, DOUBLE) \
+ KEY(GeogSemiMinorAxisGeoKey, DOUBLE) \
+ KEY(GeogInvFlatteningGeoKey, DOUBLE) \
+ KEY(GeogAzimuthUnitsGeoKey, SHORT ) \
+ KEY(GeogPrimeMeridianLongGeoKey, DOUBLE) \
#define TIFF_PROJ_KEY_ID_OFFSET 3072
-static const TiffGeoTagNameType tiff_proj_name_type_map[] = {
- {"ProjectedCSTypeGeoKey", GEOTIFF_SHORT },
- {"PCSCitationGeoKey", GEOTIFF_STRING},
- {"ProjectionGeoKey", GEOTIFF_SHORT },
- {"ProjCoordTransGeoKey", GEOTIFF_SHORT },
- {"ProjLinearUnitsGeoKey", GEOTIFF_SHORT },
- {"ProjLinearUnitSizeGeoKey", GEOTIFF_DOUBLE},
- {"ProjStdParallel1GeoKey", GEOTIFF_DOUBLE},
- {"ProjStdParallel2GeoKey", GEOTIFF_DOUBLE},
- {"ProjNatOriginLongGeoKey", GEOTIFF_DOUBLE},
- {"ProjNatOriginLatGeoKey", GEOTIFF_DOUBLE},
- {"ProjFalseEastingGeoKey", GEOTIFF_DOUBLE},
- {"ProjFalseNorthingGeoKey", GEOTIFF_DOUBLE},
- {"ProjFalseOriginLongGeoKey", GEOTIFF_DOUBLE},
- {"ProjFalseOriginLatGeoKey", GEOTIFF_DOUBLE},
- {"ProjFalseOriginEastingGeoKey", GEOTIFF_DOUBLE},
- {"ProjFalseOriginNorthingGeoKey", GEOTIFF_DOUBLE},
- {"ProjCenterLongGeoKey", GEOTIFF_DOUBLE},
- {"ProjCenterLatGeoKey", GEOTIFF_DOUBLE},
- {"ProjCenterEastingGeoKey", GEOTIFF_DOUBLE},
- {"ProjCenterNorthingGeoKey", GEOTIFF_DOUBLE},
- {"ProjScaleAtNatOriginGeoKey", GEOTIFF_DOUBLE},
- {"ProjScaleAtCenterGeoKey", GEOTIFF_DOUBLE},
- {"ProjAzimuthAngleGeoKey", GEOTIFF_DOUBLE},
- {"ProjStraightVertPoleLongGeoKey", GEOTIFF_DOUBLE}
-};
+#define PROJ_NAME_TYPE_MAP(KEY) \
+ KEY(ProjectedCSTypeGeoKey, SHORT ) \
+ KEY(PCSCitationGeoKey, STRING) \
+ KEY(ProjectionGeoKey, SHORT ) \
+ KEY(ProjCoordTransGeoKey, SHORT ) \
+ KEY(ProjLinearUnitsGeoKey, SHORT ) \
+ KEY(ProjLinearUnitSizeGeoKey, DOUBLE) \
+ KEY(ProjStdParallel1GeoKey, DOUBLE) \
+ KEY(ProjStdParallel2GeoKey, DOUBLE) \
+ KEY(ProjNatOriginLongGeoKey, DOUBLE) \
+ KEY(ProjNatOriginLatGeoKey, DOUBLE) \
+ KEY(ProjFalseEastingGeoKey, DOUBLE) \
+ KEY(ProjFalseNorthingGeoKey, DOUBLE) \
+ KEY(ProjFalseOriginLongGeoKey, DOUBLE) \
+ KEY(ProjFalseOriginLatGeoKey, DOUBLE) \
+ KEY(ProjFalseOriginEastingGeoKey, DOUBLE) \
+ KEY(ProjFalseOriginNorthingGeoKey, DOUBLE) \
+ KEY(ProjCenterLongGeoKey, DOUBLE) \
+ KEY(ProjCenterLatGeoKey, DOUBLE) \
+ KEY(ProjCenterEastingGeoKey, DOUBLE) \
+ KEY(ProjCenterNorthingGeoKey, DOUBLE) \
+ KEY(ProjScaleAtNatOriginGeoKey, DOUBLE) \
+ KEY(ProjScaleAtCenterGeoKey, DOUBLE) \
+ KEY(ProjAzimuthAngleGeoKey, DOUBLE) \
+ KEY(ProjStraightVertPoleLongGeoKey, DOUBLE) \
#define TIFF_VERT_KEY_ID_OFFSET 4096
-static const TiffGeoTagNameType tiff_vert_name_type_map[] = {
- {"VerticalCSTypeGeoKey", GEOTIFF_SHORT },
- {"VerticalCitationGeoKey", GEOTIFF_STRING},
- {"VerticalDatumGeoKey", GEOTIFF_SHORT },
- {"VerticalUnitsGeoKey", GEOTIFF_SHORT }
-};
+#define VERT_NAME_TYPE_MAP(KEY) \
+ KEY(VerticalCSTypeGeoKey, SHORT ) \
+ KEY(VerticalCitationGeoKey, STRING) \
+ KEY(VerticalDatumGeoKey, SHORT ) \
+ KEY(VerticalUnitsGeoKey, SHORT ) \
+
+#define ADD_OFFSET(NAME, TYPE) \
+ NAME ## _OFFSET, \
+ NAME ## _END = NAME ## _OFFSET + sizeof(#NAME) - 1, \
+
+#define STRING(NAME, TYPE) #NAME "\0"
+
+#define ENTRY(NAME, TYPE) { .type = GEOTIFF_ ## TYPE, .offset = NAME ## _OFFSET },
+#define NAME_TYPE_MAP(NAME, name) \
+ enum { \
+ NAME ## _NAME_TYPE_MAP(ADD_OFFSET) \
+ }; \
+ static const TiffGeoTagNameType tiff_ ## name ## _name_type_map[] = { \
+ NAME ## _NAME_TYPE_MAP(ENTRY) \
+ }; \
+ static const char *const tiff_ ## name ## _name_type_string = \
+ NAME ## _NAME_TYPE_MAP(STRING)
+
+NAME_TYPE_MAP(CONF, conf);
+NAME_TYPE_MAP(GEOG, geog);
+NAME_TYPE_MAP(PROJ, proj);
+NAME_TYPE_MAP(VERT, vert);
#define TIFF_GEO_KEY_UNDEFINED 0
#define TIFF_GEO_KEY_USER_DEFINED 32767
--
2.40.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 6/6] avcodec/tiff_data: Remove incorrect GeoTIFF entries
2024-03-10 14:12 [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures Andreas Rheinhardt
` (3 preceding siblings ...)
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 5/6] avcodec/tiff_data: Avoid relocations for TiffGeoTagNameType Andreas Rheinhardt
@ 2024-03-10 14:15 ` Andreas Rheinhardt
2024-03-10 15:25 ` [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures Stefano Sabatini
5 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-03-10 14:15 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
They are incorrect according to [1]. They also share keys with valid
entries, so that it is unspecified which entry bsearch returns
in this case. Fix this by removing the incorrect values.
[1]: https://www.earthdata.nasa.gov/s3fs-public/imported/19-008r4.pdf
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/tiff_data.h | 4 ----
1 file changed, 4 deletions(-)
diff --git a/libavcodec/tiff_data.h b/libavcodec/tiff_data.h
index 9ed46d31af..1742ccf60f 100644
--- a/libavcodec/tiff_data.h
+++ b/libavcodec/tiff_data.h
@@ -804,13 +804,9 @@ static const TiffGeoTagKeyName tiff_proj_cs_type_codes[] = {
{26771, "PCS_NAD27_Illinois_East"},
{26772, "PCS_NAD27_Illinois_West"},
{26773, "PCS_NAD27_Indiana_East"},
- {26774, "PCS_NAD27_BLM_14N_feet"},
{26774, "PCS_NAD27_Indiana_West"},
- {26775, "PCS_NAD27_BLM_15N_feet"},
{26775, "PCS_NAD27_Iowa_North"},
- {26776, "PCS_NAD27_BLM_16N_feet"},
{26776, "PCS_NAD27_Iowa_South"},
- {26777, "PCS_NAD27_BLM_17N_feet"},
{26777, "PCS_NAD27_Kansas_North"},
{26778, "PCS_NAD27_Kansas_South"},
{26779, "PCS_NAD27_Kentucky_North"},
--
2.40.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures
2024-03-10 14:12 [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures Andreas Rheinhardt
` (4 preceding siblings ...)
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 6/6] avcodec/tiff_data: Remove incorrect GeoTIFF entries Andreas Rheinhardt
@ 2024-03-10 15:25 ` Stefano Sabatini
5 siblings, 0 replies; 13+ messages in thread
From: Stefano Sabatini @ 2024-03-10 15:25 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Andreas Rheinhardt
On date Sunday 2024-03-10 15:12:16 +0100, Andreas Rheinhardt wrote:
> For unknown geokey values, get_geokey_val() returns
> "Unknown-%d" with val being used for %d. This string
> is allocated and therefore all the known geokey values
> (static strings) are strdup'ed. In case this fails
> it is either ignored or treated as "Unknown-%d".
> (Furthermore it is possible to call av_strdup(NULL),
> although this is not documented to be legal.)
>
> This commit changes this by only returning the static strings
> in get_geokey_val(); the unknown handling and strdup'ing
> is moved out of it.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavcodec/tiff.c | 35 ++++++++++++++++-------------------
> 1 file changed, 16 insertions(+), 19 deletions(-)
>
> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> index cb4d378753..4c7460cf41 100644
> --- a/libavcodec/tiff.c
> +++ b/libavcodec/tiff.c
> @@ -36,6 +36,7 @@
> #include <float.h>
>
> #include "libavutil/attributes.h"
> +#include "libavutil/avstring.h"
> #include "libavutil/error.h"
> #include "libavutil/intreadwrite.h"
> #include "libavutil/opt.h"
> @@ -179,19 +180,17 @@ static const char *search_keyval(const TiffGeoTagKeyName *keys, int n, int id)
> return NULL;
> }
>
> -static char *get_geokey_val(int key, int val)
> +static const char *get_geokey_val(int key, uint16_t val)
> {
> - char *ap;
> -
> if (val == TIFF_GEO_KEY_UNDEFINED)
> - return av_strdup("undefined");
> + return "undefined";
> if (val == TIFF_GEO_KEY_USER_DEFINED)
> - return av_strdup("User-Defined");
> + return "User-Defined";
>
> #define RET_GEOKEY_VAL(TYPE, array)\
> if (val >= TIFF_##TYPE##_OFFSET &&\
> val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_codes))\
> - return av_strdup(tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);
> + return tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET];
>
> switch (key) {
> case TIFF_GT_MODEL_TYPE_GEOKEY:
> @@ -224,13 +223,9 @@ static char *get_geokey_val(int key, int val)
> RET_GEOKEY_VAL(PRIME_MERIDIAN, prime_meridian);
> break;
> case TIFF_PROJECTED_CS_TYPE_GEOKEY:
> - ap = av_strdup(search_keyval(tiff_proj_cs_type_codes, FF_ARRAY_ELEMS(tiff_proj_cs_type_codes), val));
> - if(ap) return ap;
> - break;
> + return search_keyval(tiff_proj_cs_type_codes, FF_ARRAY_ELEMS(tiff_proj_cs_type_codes), val);
> case TIFF_PROJECTION_GEOKEY:
> - ap = av_strdup(search_keyval(tiff_projection_codes, FF_ARRAY_ELEMS(tiff_projection_codes), val));
> - if(ap) return ap;
> - break;
> + return search_keyval(tiff_projection_codes, FF_ARRAY_ELEMS(tiff_projection_codes), val);
> case TIFF_PROJ_COORD_TRANS_GEOKEY:
> RET_GEOKEY_VAL(COORD_TRANS, coord_trans);
> break;
> @@ -241,10 +236,7 @@ static char *get_geokey_val(int key, int val)
>
> }
>
> - ap = av_malloc(14);
> - if (ap)
> - snprintf(ap, 14, "Unknown-%d", val);
> - return ap;
> + return NULL;
> }
>
> static char *doubles2str(double *dp, int count, const char *sep)
> @@ -1634,9 +1626,14 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
> s->geotags[i].type = ff_tget_short(&s->gb, s->le);
> s->geotags[i].count = ff_tget_short(&s->gb, s->le);
>
> - if (!s->geotags[i].type)
> - s->geotags[i].val = get_geokey_val(s->geotags[i].key, ff_tget_short(&s->gb, s->le));
> - else
> + if (!s->geotags[i].type) {
> + uint16_t val = ff_tget_short(&s->gb, s->le);
> + const char *str = get_geokey_val(s->geotags[i].key, val);
> +
> + s->geotags[i].val = str ? av_strdup(str) : av_asprintf("Unknown-%u", val);
> + if (!s->geotags[i].val)
> + return AVERROR(ENOMEM);
> + } else
> s->geotags[i].offset = ff_tget_short(&s->gb, s->le);
nit++: you migth factorize the ff_tget_short call
> }
> break;
LGTM.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/6] avcodec/tiff: Avoid duplicating strings
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 2/6] avcodec/tiff: Avoid duplicating strings Andreas Rheinhardt
@ 2024-03-10 15:34 ` Stefano Sabatini
0 siblings, 0 replies; 13+ messages in thread
From: Stefano Sabatini @ 2024-03-10 15:34 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Andreas Rheinhardt
On date Sunday 2024-03-10 15:15:00 +0100, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavcodec/tiff.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> index 4c7460cf41..afa1289e27 100644
> --- a/libavcodec/tiff.c
> +++ b/libavcodec/tiff.c
> @@ -2028,7 +2028,8 @@ again:
> av_log(avctx, AV_LOG_WARNING, "Type of GeoTIFF key %d is wrong\n", s->geotags[i].key);
> continue;
> }
> - ret = av_dict_set(&p->metadata, keyname, s->geotags[i].val, 0);
> + ret = av_dict_set(&p->metadata, keyname, s->geotags[i].val, AV_DICT_DONT_STRDUP_VAL);
> + s->geotags[i].val = NULL;
> if (ret<0) {
> av_log(avctx, AV_LOG_ERROR, "Writing metadata with key '%s' failed\n", keyname);
> return ret;
Should be OK, thanks.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/6] avcodec/tiff: Don't check before av_freep()
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 3/6] avcodec/tiff: Don't check before av_freep() Andreas Rheinhardt
@ 2024-03-10 15:38 ` Stefano Sabatini
0 siblings, 0 replies; 13+ messages in thread
From: Stefano Sabatini @ 2024-03-10 15:38 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Andreas Rheinhardt
On date Sunday 2024-03-10 15:15:01 +0100, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavcodec/tiff.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
LGTM, thanks.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH 4/6] avcodec/tiff: Improve inclusions
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 4/6] avcodec/tiff: Improve inclusions Andreas Rheinhardt
@ 2024-03-10 15:44 ` Stefano Sabatini
2024-03-10 16:06 ` Andreas Rheinhardt
0 siblings, 1 reply; 13+ messages in thread
From: Stefano Sabatini @ 2024-03-10 15:44 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Andreas Rheinhardt
On date Sunday 2024-03-10 15:15:02 +0100, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavcodec/mjpegdec.c | 1 -
> libavcodec/tiff.c | 1 +
> libavcodec/tiff.h | 3 ---
> libavcodec/tiffenc.c | 3 +--
> 4 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> index 43b36d0a8f..c9409eac6c 100644
> --- a/libavcodec/mjpegdec.c
> +++ b/libavcodec/mjpegdec.c
> @@ -52,7 +52,6 @@
> #include "jpeglsdec.h"
> #include "profiles.h"
> #include "put_bits.h"
> -#include "tiff.h"
> #include "exif.h"
> #include "bytestream.h"
> #include "tiff_common.h"
> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> index 5d350f4e7e..15e5edd93b 100644
> --- a/libavcodec/tiff.c
> +++ b/libavcodec/tiff.c
> @@ -48,6 +48,7 @@
> #include "faxcompr.h"
> #include "lzw.h"
> #include "tiff.h"
> +#include "tiff_common.h"
> #include "tiff_data.h"
> #include "mjpegdec.h"
> #include "thread.h"
> diff --git a/libavcodec/tiff.h b/libavcodec/tiff.h
> index e67c59abad..2dd21dea52 100644
> --- a/libavcodec/tiff.h
> +++ b/libavcodec/tiff.h
> @@ -30,9 +30,6 @@
> #ifndef AVCODEC_TIFF_H
> #define AVCODEC_TIFF_H
>
> -#include <stdint.h>
> -#include "tiff_common.h"
why? there are cases where only tiff.h must be used?
[...]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH 4/6] avcodec/tiff: Improve inclusions
2024-03-10 15:44 ` Stefano Sabatini
@ 2024-03-10 16:06 ` Andreas Rheinhardt
2024-03-11 15:39 ` Stefano Sabatini
0 siblings, 1 reply; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-03-10 16:06 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Stefano Sabatini:
> On date Sunday 2024-03-10 15:15:02 +0100, Andreas Rheinhardt wrote:
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>> libavcodec/mjpegdec.c | 1 -
>> libavcodec/tiff.c | 1 +
>> libavcodec/tiff.h | 3 ---
>> libavcodec/tiffenc.c | 3 +--
>> 4 files changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
>> index 43b36d0a8f..c9409eac6c 100644
>> --- a/libavcodec/mjpegdec.c
>> +++ b/libavcodec/mjpegdec.c
>> @@ -52,7 +52,6 @@
>> #include "jpeglsdec.h"
>> #include "profiles.h"
>> #include "put_bits.h"
>> -#include "tiff.h"
>> #include "exif.h"
>> #include "bytestream.h"
>> #include "tiff_common.h"
>> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
>> index 5d350f4e7e..15e5edd93b 100644
>> --- a/libavcodec/tiff.c
>> +++ b/libavcodec/tiff.c
>> @@ -48,6 +48,7 @@
>> #include "faxcompr.h"
>> #include "lzw.h"
>> #include "tiff.h"
>> +#include "tiff_common.h"
>> #include "tiff_data.h"
>> #include "mjpegdec.h"
>> #include "thread.h"
>> diff --git a/libavcodec/tiff.h b/libavcodec/tiff.h
>> index e67c59abad..2dd21dea52 100644
>> --- a/libavcodec/tiff.h
>> +++ b/libavcodec/tiff.h
>> @@ -30,9 +30,6 @@
>> #ifndef AVCODEC_TIFF_H
>> #define AVCODEC_TIFF_H
>>
>> -#include <stdint.h>
>
>> -#include "tiff_common.h"
>
> why? there are cases where only tiff.h must be used?
>
Must? Like in most header matters, this is not a question of "must".
tiff.h provides (mostly) TIFF related defines that are independent of
any particular implementation, whereas tiff_common.h mostly provides
auxiliary functions for decoder/parser (the encoder only uses
type_sizes*). And not even all of these need it: faxcompr only needs
tiff.h, not tiff_common.h and mjpegdec.c needs only tiff_common.h.
- Andreas
*: This array uses a weird value for strings; the encoder has a size
table of its own with a different value at this position and uses
type_sizes at only one place.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH 4/6] avcodec/tiff: Improve inclusions
2024-03-10 16:06 ` Andreas Rheinhardt
@ 2024-03-11 15:39 ` Stefano Sabatini
0 siblings, 0 replies; 13+ messages in thread
From: Stefano Sabatini @ 2024-03-11 15:39 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On date Sunday 2024-03-10 17:06:18 +0100, Andreas Rheinhardt wrote:
> Stefano Sabatini:
> >> diff --git a/libavcodec/tiff.h b/libavcodec/tiff.h
> >> index e67c59abad..2dd21dea52 100644
> >> --- a/libavcodec/tiff.h
> >> +++ b/libavcodec/tiff.h
> >> @@ -30,9 +30,6 @@
> >> #ifndef AVCODEC_TIFF_H
> >> #define AVCODEC_TIFF_H
> >>
> >> -#include <stdint.h>
> >
> >> -#include "tiff_common.h"
> >
> > why? there are cases where only tiff.h must be used?
> >
>
> Must? Like in most header matters, this is not a question of "must".
> tiff.h provides (mostly) TIFF related defines that are independent of
> any particular implementation, whereas tiff_common.h mostly provides
> auxiliary functions for decoder/parser (the encoder only uses
> type_sizes*). And not even all of these need it: faxcompr only needs
> tiff.h, not tiff_common.h and mjpegdec.c needs only tiff_common.h.
Makes sense, patch LGTM.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH 5/6] avcodec/tiff_data: Avoid relocations for TiffGeoTagNameType
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 5/6] avcodec/tiff_data: Avoid relocations for TiffGeoTagNameType Andreas Rheinhardt
@ 2024-03-14 10:46 ` Andreas Rheinhardt
0 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-03-14 10:46 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> Instead store all the strings in one continugous string
> (with internal \0) and use offsets to access the actual
> substrings. This replaces the pointers to the strings
> and therefore avoids relocations (and on x64, it actually
> shrinks TiffGeoTagNameType by reusing padding to store
> the offset field).
>
> This saves 720B of .data.rel.ro and 1080B of .rela.dyn
> (containing the relocation records) here while increasing
> .rodata by 384B.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> I also have patches for the remaining tables, but am not
> satisfied with them yet.
>
> libavcodec/tiff.c | 28 +++++----
> libavcodec/tiff.h | 5 --
> libavcodec/tiff_data.h | 129 ++++++++++++++++++++++++-----------------
> 3 files changed, 92 insertions(+), 70 deletions(-)
>
> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> index 15e5edd93b..004db89c6b 100644
> --- a/libavcodec/tiff.c
> +++ b/libavcodec/tiff.c
> @@ -139,27 +139,31 @@ static void free_geotags(TiffContext *const s)
> s->geotag_count = 0;
> }
>
> -#define RET_GEOKEY(TYPE, array, element)\
> +static const char *get_geokey_name(int key)
> +{
> +#define RET_GEOKEY_STR(TYPE, array)\
> if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
> key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\
> - return tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element;
> + return tiff_##array##_name_type_string + tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].offset;
>
> -static const char *get_geokey_name(int key)
> -{
> - RET_GEOKEY(VERT, vert, name);
> - RET_GEOKEY(PROJ, proj, name);
> - RET_GEOKEY(GEOG, geog, name);
> - RET_GEOKEY(CONF, conf, name);
> + RET_GEOKEY_STR(VERT, vert);
> + RET_GEOKEY_STR(PROJ, proj);
> + RET_GEOKEY_STR(GEOG, geog);
> + RET_GEOKEY_STR(CONF, conf);
>
> return NULL;
> }
>
> static int get_geokey_type(int key)
> {
> - RET_GEOKEY(VERT, vert, type);
> - RET_GEOKEY(PROJ, proj, type);
> - RET_GEOKEY(GEOG, geog, type);
> - RET_GEOKEY(CONF, conf, type);
> +#define RET_GEOKEY_TYPE(TYPE, array)\
> + if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
> + key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\
> + return tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].type;
> + RET_GEOKEY_TYPE(VERT, vert);
> + RET_GEOKEY_TYPE(PROJ, proj);
> + RET_GEOKEY_TYPE(GEOG, geog);
> + RET_GEOKEY_TYPE(CONF, conf);
>
> return AVERROR_INVALIDDATA;
> }
> diff --git a/libavcodec/tiff.h b/libavcodec/tiff.h
> index 2dd21dea52..12afcfa6e5 100644
> --- a/libavcodec/tiff.h
> +++ b/libavcodec/tiff.h
> @@ -222,9 +222,4 @@ typedef struct TiffGeoTagKeyName {
> const char *const name;
> } TiffGeoTagKeyName;
>
> -typedef struct TiffGeoTagNameType {
> - const char *const name;
> - const enum TiffGeoTagType type;
> -} TiffGeoTagNameType;
> -
> #endif /* AVCODEC_TIFF_H */
> diff --git a/libavcodec/tiff_data.h b/libavcodec/tiff_data.h
> index 9b123ca8df..9ed46d31af 100644
> --- a/libavcodec/tiff_data.h
> +++ b/libavcodec/tiff_data.h
> @@ -32,66 +32,89 @@
>
> #include "tiff.h"
>
> +typedef struct TiffGeoTagNameType {
> + enum TiffGeoTagType type;
> + unsigned offset;
> +} TiffGeoTagNameType;
> +
> #define TIFF_CONF_KEY_ID_OFFSET 1024
> -static const TiffGeoTagNameType tiff_conf_name_type_map[] = {
> - {"GTModelTypeGeoKey", GEOTIFF_SHORT },
> - {"GTRasterTypeGeoKey", GEOTIFF_SHORT },
> - {"GTCitationGeoKey", GEOTIFF_STRING}
> -};
> +#define CONF_NAME_TYPE_MAP(KEY) \
> + KEY(GTModelTypeGeoKey, SHORT ) \
> + KEY(GTRasterTypeGeoKey, SHORT ) \
> + KEY(GTCitationGeoKey, STRING) \
>
> #define TIFF_GEOG_KEY_ID_OFFSET 2048
> -static const TiffGeoTagNameType tiff_geog_name_type_map[] = {
> - {"GeographicTypeGeoKey", GEOTIFF_SHORT },
> - {"GeogCitationGeoKey", GEOTIFF_STRING},
> - {"GeogGeodeticDatumGeoKey", GEOTIFF_SHORT },
> - {"GeogPrimeMeridianGeoKey", GEOTIFF_SHORT },
> - {"GeogLinearUnitsGeoKey", GEOTIFF_SHORT },
> - {"GeogLinearUnitSizeGeoKey", GEOTIFF_DOUBLE},
> - {"GeogAngularUnitsGeoKey", GEOTIFF_SHORT },
> - {"GeogAngularUnitSizeGeoKey", GEOTIFF_DOUBLE},
> - {"GeogEllipsoidGeoKey", GEOTIFF_SHORT },
> - {"GeogSemiMajorAxisGeoKey", GEOTIFF_DOUBLE},
> - {"GeogSemiMinorAxisGeoKey", GEOTIFF_DOUBLE},
> - {"GeogInvFlatteningGeoKey", GEOTIFF_DOUBLE},
> - {"GeogAzimuthUnitsGeoKey", GEOTIFF_SHORT },
> - {"GeogPrimeMeridianLongGeoKey", GEOTIFF_DOUBLE}
> -};
> +#define GEOG_NAME_TYPE_MAP(KEY) \
> + KEY(GeographicTypeGeoKey, SHORT ) \
> + KEY(GeogCitationGeoKey, STRING) \
> + KEY(GeogGeodeticDatumGeoKey, SHORT ) \
> + KEY(GeogPrimeMeridianGeoKey, SHORT ) \
> + KEY(GeogLinearUnitsGeoKey, SHORT ) \
> + KEY(GeogLinearUnitSizeGeoKey, DOUBLE) \
> + KEY(GeogAngularUnitsGeoKey, SHORT ) \
> + KEY(GeogAngularUnitSizeGeoKey, DOUBLE) \
> + KEY(GeogEllipsoidGeoKey, SHORT ) \
> + KEY(GeogSemiMajorAxisGeoKey, DOUBLE) \
> + KEY(GeogSemiMinorAxisGeoKey, DOUBLE) \
> + KEY(GeogInvFlatteningGeoKey, DOUBLE) \
> + KEY(GeogAzimuthUnitsGeoKey, SHORT ) \
> + KEY(GeogPrimeMeridianLongGeoKey, DOUBLE) \
>
> #define TIFF_PROJ_KEY_ID_OFFSET 3072
> -static const TiffGeoTagNameType tiff_proj_name_type_map[] = {
> - {"ProjectedCSTypeGeoKey", GEOTIFF_SHORT },
> - {"PCSCitationGeoKey", GEOTIFF_STRING},
> - {"ProjectionGeoKey", GEOTIFF_SHORT },
> - {"ProjCoordTransGeoKey", GEOTIFF_SHORT },
> - {"ProjLinearUnitsGeoKey", GEOTIFF_SHORT },
> - {"ProjLinearUnitSizeGeoKey", GEOTIFF_DOUBLE},
> - {"ProjStdParallel1GeoKey", GEOTIFF_DOUBLE},
> - {"ProjStdParallel2GeoKey", GEOTIFF_DOUBLE},
> - {"ProjNatOriginLongGeoKey", GEOTIFF_DOUBLE},
> - {"ProjNatOriginLatGeoKey", GEOTIFF_DOUBLE},
> - {"ProjFalseEastingGeoKey", GEOTIFF_DOUBLE},
> - {"ProjFalseNorthingGeoKey", GEOTIFF_DOUBLE},
> - {"ProjFalseOriginLongGeoKey", GEOTIFF_DOUBLE},
> - {"ProjFalseOriginLatGeoKey", GEOTIFF_DOUBLE},
> - {"ProjFalseOriginEastingGeoKey", GEOTIFF_DOUBLE},
> - {"ProjFalseOriginNorthingGeoKey", GEOTIFF_DOUBLE},
> - {"ProjCenterLongGeoKey", GEOTIFF_DOUBLE},
> - {"ProjCenterLatGeoKey", GEOTIFF_DOUBLE},
> - {"ProjCenterEastingGeoKey", GEOTIFF_DOUBLE},
> - {"ProjCenterNorthingGeoKey", GEOTIFF_DOUBLE},
> - {"ProjScaleAtNatOriginGeoKey", GEOTIFF_DOUBLE},
> - {"ProjScaleAtCenterGeoKey", GEOTIFF_DOUBLE},
> - {"ProjAzimuthAngleGeoKey", GEOTIFF_DOUBLE},
> - {"ProjStraightVertPoleLongGeoKey", GEOTIFF_DOUBLE}
> -};
> +#define PROJ_NAME_TYPE_MAP(KEY) \
> + KEY(ProjectedCSTypeGeoKey, SHORT ) \
> + KEY(PCSCitationGeoKey, STRING) \
> + KEY(ProjectionGeoKey, SHORT ) \
> + KEY(ProjCoordTransGeoKey, SHORT ) \
> + KEY(ProjLinearUnitsGeoKey, SHORT ) \
> + KEY(ProjLinearUnitSizeGeoKey, DOUBLE) \
> + KEY(ProjStdParallel1GeoKey, DOUBLE) \
> + KEY(ProjStdParallel2GeoKey, DOUBLE) \
> + KEY(ProjNatOriginLongGeoKey, DOUBLE) \
> + KEY(ProjNatOriginLatGeoKey, DOUBLE) \
> + KEY(ProjFalseEastingGeoKey, DOUBLE) \
> + KEY(ProjFalseNorthingGeoKey, DOUBLE) \
> + KEY(ProjFalseOriginLongGeoKey, DOUBLE) \
> + KEY(ProjFalseOriginLatGeoKey, DOUBLE) \
> + KEY(ProjFalseOriginEastingGeoKey, DOUBLE) \
> + KEY(ProjFalseOriginNorthingGeoKey, DOUBLE) \
> + KEY(ProjCenterLongGeoKey, DOUBLE) \
> + KEY(ProjCenterLatGeoKey, DOUBLE) \
> + KEY(ProjCenterEastingGeoKey, DOUBLE) \
> + KEY(ProjCenterNorthingGeoKey, DOUBLE) \
> + KEY(ProjScaleAtNatOriginGeoKey, DOUBLE) \
> + KEY(ProjScaleAtCenterGeoKey, DOUBLE) \
> + KEY(ProjAzimuthAngleGeoKey, DOUBLE) \
> + KEY(ProjStraightVertPoleLongGeoKey, DOUBLE) \
>
> #define TIFF_VERT_KEY_ID_OFFSET 4096
> -static const TiffGeoTagNameType tiff_vert_name_type_map[] = {
> - {"VerticalCSTypeGeoKey", GEOTIFF_SHORT },
> - {"VerticalCitationGeoKey", GEOTIFF_STRING},
> - {"VerticalDatumGeoKey", GEOTIFF_SHORT },
> - {"VerticalUnitsGeoKey", GEOTIFF_SHORT }
> -};
> +#define VERT_NAME_TYPE_MAP(KEY) \
> + KEY(VerticalCSTypeGeoKey, SHORT ) \
> + KEY(VerticalCitationGeoKey, STRING) \
> + KEY(VerticalDatumGeoKey, SHORT ) \
> + KEY(VerticalUnitsGeoKey, SHORT ) \
> +
> +#define ADD_OFFSET(NAME, TYPE) \
> + NAME ## _OFFSET, \
> + NAME ## _END = NAME ## _OFFSET + sizeof(#NAME) - 1, \
> +
> +#define STRING(NAME, TYPE) #NAME "\0"
> +
> +#define ENTRY(NAME, TYPE) { .type = GEOTIFF_ ## TYPE, .offset = NAME ## _OFFSET },
> +#define NAME_TYPE_MAP(NAME, name) \
> + enum { \
> + NAME ## _NAME_TYPE_MAP(ADD_OFFSET) \
> + }; \
> + static const TiffGeoTagNameType tiff_ ## name ## _name_type_map[] = { \
> + NAME ## _NAME_TYPE_MAP(ENTRY) \
> + }; \
> + static const char *const tiff_ ## name ## _name_type_string = \
> + NAME ## _NAME_TYPE_MAP(STRING)
> +
> +NAME_TYPE_MAP(CONF, conf);
> +NAME_TYPE_MAP(GEOG, geog);
> +NAME_TYPE_MAP(PROJ, proj);
> +NAME_TYPE_MAP(VERT, vert);
>
> #define TIFF_GEO_KEY_UNDEFINED 0
> #define TIFF_GEO_KEY_USER_DEFINED 32767
Will apply the two remaining patches of this patchset tonight unless
there are objections.
- Andreas
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2024-03-14 10:47 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-10 14:12 [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures Andreas Rheinhardt
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 2/6] avcodec/tiff: Avoid duplicating strings Andreas Rheinhardt
2024-03-10 15:34 ` Stefano Sabatini
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 3/6] avcodec/tiff: Don't check before av_freep() Andreas Rheinhardt
2024-03-10 15:38 ` Stefano Sabatini
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 4/6] avcodec/tiff: Improve inclusions Andreas Rheinhardt
2024-03-10 15:44 ` Stefano Sabatini
2024-03-10 16:06 ` Andreas Rheinhardt
2024-03-11 15:39 ` Stefano Sabatini
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 5/6] avcodec/tiff_data: Avoid relocations for TiffGeoTagNameType Andreas Rheinhardt
2024-03-14 10:46 ` Andreas Rheinhardt
2024-03-10 14:15 ` [FFmpeg-devel] [PATCH 6/6] avcodec/tiff_data: Remove incorrect GeoTIFF entries Andreas Rheinhardt
2024-03-10 15:25 ` [FFmpeg-devel] [PATCH 1/6] avcodec/tiff: Fix handling of av_strdup() failures Stefano Sabatini
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