1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avcodec/tiff_data: Avoid relocations for TiffGeoTagNameType

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>
This commit is contained in:
Andreas Rheinhardt 2024-03-09 16:12:26 +01:00
parent ad6347fc37
commit 282812d6dc
3 changed files with 93 additions and 71 deletions

View File

@ -139,27 +139,31 @@ static void free_geotags(TiffContext *const s)
s->geotag_count = 0; s->geotag_count = 0;
} }
#define RET_GEOKEY(TYPE, array, element)\
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;
static const char *get_geokey_name(int key) static const char *get_geokey_name(int key)
{ {
RET_GEOKEY(VERT, vert, name); #define RET_GEOKEY_STR(TYPE, array)\
RET_GEOKEY(PROJ, proj, name); if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
RET_GEOKEY(GEOG, geog, name); key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\
RET_GEOKEY(CONF, conf, name); return tiff_##array##_name_type_string + tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].offset;
RET_GEOKEY_STR(VERT, vert);
RET_GEOKEY_STR(PROJ, proj);
RET_GEOKEY_STR(GEOG, geog);
RET_GEOKEY_STR(CONF, conf);
return NULL; return NULL;
} }
static int get_geokey_type(int key) static int get_geokey_type(int key)
{ {
RET_GEOKEY(VERT, vert, type); #define RET_GEOKEY_TYPE(TYPE, array)\
RET_GEOKEY(PROJ, proj, type); if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
RET_GEOKEY(GEOG, geog, type); key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\
RET_GEOKEY(CONF, conf, type); 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; return AVERROR_INVALIDDATA;
} }

View File

@ -222,9 +222,4 @@ typedef struct TiffGeoTagKeyName {
const char *const name; const char *const name;
} TiffGeoTagKeyName; } TiffGeoTagKeyName;
typedef struct TiffGeoTagNameType {
const char *const name;
const enum TiffGeoTagType type;
} TiffGeoTagNameType;
#endif /* AVCODEC_TIFF_H */ #endif /* AVCODEC_TIFF_H */

View File

@ -32,66 +32,89 @@
#include "tiff.h" #include "tiff.h"
typedef struct TiffGeoTagNameType {
enum TiffGeoTagType type;
unsigned offset;
} TiffGeoTagNameType;
#define TIFF_CONF_KEY_ID_OFFSET 1024 #define TIFF_CONF_KEY_ID_OFFSET 1024
static const TiffGeoTagNameType tiff_conf_name_type_map[] = { #define CONF_NAME_TYPE_MAP(KEY) \
{"GTModelTypeGeoKey", GEOTIFF_SHORT }, KEY(GTModelTypeGeoKey, SHORT ) \
{"GTRasterTypeGeoKey", GEOTIFF_SHORT }, KEY(GTRasterTypeGeoKey, SHORT ) \
{"GTCitationGeoKey", GEOTIFF_STRING} KEY(GTCitationGeoKey, STRING) \
};
#define TIFF_GEOG_KEY_ID_OFFSET 2048 #define TIFF_GEOG_KEY_ID_OFFSET 2048
static const TiffGeoTagNameType tiff_geog_name_type_map[] = { #define GEOG_NAME_TYPE_MAP(KEY) \
{"GeographicTypeGeoKey", GEOTIFF_SHORT }, KEY(GeographicTypeGeoKey, SHORT ) \
{"GeogCitationGeoKey", GEOTIFF_STRING}, KEY(GeogCitationGeoKey, STRING) \
{"GeogGeodeticDatumGeoKey", GEOTIFF_SHORT }, KEY(GeogGeodeticDatumGeoKey, SHORT ) \
{"GeogPrimeMeridianGeoKey", GEOTIFF_SHORT }, KEY(GeogPrimeMeridianGeoKey, SHORT ) \
{"GeogLinearUnitsGeoKey", GEOTIFF_SHORT }, KEY(GeogLinearUnitsGeoKey, SHORT ) \
{"GeogLinearUnitSizeGeoKey", GEOTIFF_DOUBLE}, KEY(GeogLinearUnitSizeGeoKey, DOUBLE) \
{"GeogAngularUnitsGeoKey", GEOTIFF_SHORT }, KEY(GeogAngularUnitsGeoKey, SHORT ) \
{"GeogAngularUnitSizeGeoKey", GEOTIFF_DOUBLE}, KEY(GeogAngularUnitSizeGeoKey, DOUBLE) \
{"GeogEllipsoidGeoKey", GEOTIFF_SHORT }, KEY(GeogEllipsoidGeoKey, SHORT ) \
{"GeogSemiMajorAxisGeoKey", GEOTIFF_DOUBLE}, KEY(GeogSemiMajorAxisGeoKey, DOUBLE) \
{"GeogSemiMinorAxisGeoKey", GEOTIFF_DOUBLE}, KEY(GeogSemiMinorAxisGeoKey, DOUBLE) \
{"GeogInvFlatteningGeoKey", GEOTIFF_DOUBLE}, KEY(GeogInvFlatteningGeoKey, DOUBLE) \
{"GeogAzimuthUnitsGeoKey", GEOTIFF_SHORT }, KEY(GeogAzimuthUnitsGeoKey, SHORT ) \
{"GeogPrimeMeridianLongGeoKey", GEOTIFF_DOUBLE} KEY(GeogPrimeMeridianLongGeoKey, DOUBLE) \
};
#define TIFF_PROJ_KEY_ID_OFFSET 3072 #define TIFF_PROJ_KEY_ID_OFFSET 3072
static const TiffGeoTagNameType tiff_proj_name_type_map[] = { #define PROJ_NAME_TYPE_MAP(KEY) \
{"ProjectedCSTypeGeoKey", GEOTIFF_SHORT }, KEY(ProjectedCSTypeGeoKey, SHORT ) \
{"PCSCitationGeoKey", GEOTIFF_STRING}, KEY(PCSCitationGeoKey, STRING) \
{"ProjectionGeoKey", GEOTIFF_SHORT }, KEY(ProjectionGeoKey, SHORT ) \
{"ProjCoordTransGeoKey", GEOTIFF_SHORT }, KEY(ProjCoordTransGeoKey, SHORT ) \
{"ProjLinearUnitsGeoKey", GEOTIFF_SHORT }, KEY(ProjLinearUnitsGeoKey, SHORT ) \
{"ProjLinearUnitSizeGeoKey", GEOTIFF_DOUBLE}, KEY(ProjLinearUnitSizeGeoKey, DOUBLE) \
{"ProjStdParallel1GeoKey", GEOTIFF_DOUBLE}, KEY(ProjStdParallel1GeoKey, DOUBLE) \
{"ProjStdParallel2GeoKey", GEOTIFF_DOUBLE}, KEY(ProjStdParallel2GeoKey, DOUBLE) \
{"ProjNatOriginLongGeoKey", GEOTIFF_DOUBLE}, KEY(ProjNatOriginLongGeoKey, DOUBLE) \
{"ProjNatOriginLatGeoKey", GEOTIFF_DOUBLE}, KEY(ProjNatOriginLatGeoKey, DOUBLE) \
{"ProjFalseEastingGeoKey", GEOTIFF_DOUBLE}, KEY(ProjFalseEastingGeoKey, DOUBLE) \
{"ProjFalseNorthingGeoKey", GEOTIFF_DOUBLE}, KEY(ProjFalseNorthingGeoKey, DOUBLE) \
{"ProjFalseOriginLongGeoKey", GEOTIFF_DOUBLE}, KEY(ProjFalseOriginLongGeoKey, DOUBLE) \
{"ProjFalseOriginLatGeoKey", GEOTIFF_DOUBLE}, KEY(ProjFalseOriginLatGeoKey, DOUBLE) \
{"ProjFalseOriginEastingGeoKey", GEOTIFF_DOUBLE}, KEY(ProjFalseOriginEastingGeoKey, DOUBLE) \
{"ProjFalseOriginNorthingGeoKey", GEOTIFF_DOUBLE}, KEY(ProjFalseOriginNorthingGeoKey, DOUBLE) \
{"ProjCenterLongGeoKey", GEOTIFF_DOUBLE}, KEY(ProjCenterLongGeoKey, DOUBLE) \
{"ProjCenterLatGeoKey", GEOTIFF_DOUBLE}, KEY(ProjCenterLatGeoKey, DOUBLE) \
{"ProjCenterEastingGeoKey", GEOTIFF_DOUBLE}, KEY(ProjCenterEastingGeoKey, DOUBLE) \
{"ProjCenterNorthingGeoKey", GEOTIFF_DOUBLE}, KEY(ProjCenterNorthingGeoKey, DOUBLE) \
{"ProjScaleAtNatOriginGeoKey", GEOTIFF_DOUBLE}, KEY(ProjScaleAtNatOriginGeoKey, DOUBLE) \
{"ProjScaleAtCenterGeoKey", GEOTIFF_DOUBLE}, KEY(ProjScaleAtCenterGeoKey, DOUBLE) \
{"ProjAzimuthAngleGeoKey", GEOTIFF_DOUBLE}, KEY(ProjAzimuthAngleGeoKey, DOUBLE) \
{"ProjStraightVertPoleLongGeoKey", GEOTIFF_DOUBLE} KEY(ProjStraightVertPoleLongGeoKey, DOUBLE) \
};
#define TIFF_VERT_KEY_ID_OFFSET 4096 #define TIFF_VERT_KEY_ID_OFFSET 4096
static const TiffGeoTagNameType tiff_vert_name_type_map[] = { #define VERT_NAME_TYPE_MAP(KEY) \
{"VerticalCSTypeGeoKey", GEOTIFF_SHORT }, KEY(VerticalCSTypeGeoKey, SHORT ) \
{"VerticalCitationGeoKey", GEOTIFF_STRING}, KEY(VerticalCitationGeoKey, STRING) \
{"VerticalDatumGeoKey", GEOTIFF_SHORT }, KEY(VerticalDatumGeoKey, SHORT ) \
{"VerticalUnitsGeoKey", GEOTIFF_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_UNDEFINED 0
#define TIFF_GEO_KEY_USER_DEFINED 32767 #define TIFF_GEO_KEY_USER_DEFINED 32767