History

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.

Andreas Rheinhardt committed 2 years ago

Commit 282812d1 parent ad6347f3 files · +92 −70Browse files

Showing the changes to libavcodec (3 of 3 files). Show all

Unified · Split

3 files
  1. libavcodec/tiff.c +16 −12
  2. libavcodec/tiff.h +0 −5
  3. libavcodec/tiff_data.h +76 −53
libavcodec/tiff.c+16−12
@@ -139,27 +139,31 @@ static void free_geotags(TiffContext *const s) · 138 unmodified lines
139 s->geotag_count = 0;139 s->geotag_count = 0;
140}140}
141 141
142#define RET_GEOKEY(TYPE, array, element)\142static const char *get_geokey_name(int key)
143{
144#define RET_GEOKEY_STR(TYPE, array)\
143 if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\145 if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
144 key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\146 key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\
145 return tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element;147 return tiff_##array##_name_type_string + tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].offset;
146 148
147static const char *get_geokey_name(int key)149 RET_GEOKEY_STR(VERT, vert);
148{150 RET_GEOKEY_STR(PROJ, proj);
149 RET_GEOKEY(VERT, vert, name);151 RET_GEOKEY_STR(GEOG, geog);
150 RET_GEOKEY(PROJ, proj, name);152 RET_GEOKEY_STR(CONF, conf);
151 RET_GEOKEY(GEOG, geog, name);
152 RET_GEOKEY(CONF, conf, name);
153 153
154 return NULL;154 return NULL;
155}155}
156 156
157static int get_geokey_type(int key)157static int get_geokey_type(int key)
158{158{
159 RET_GEOKEY(VERT, vert, type);159#define RET_GEOKEY_TYPE(TYPE, array)\
160 RET_GEOKEY(PROJ, proj, type);160 if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
161 RET_GEOKEY(GEOG, geog, type);161 key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\
162 RET_GEOKEY(CONF, conf, type);162 return tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].type;
163 RET_GEOKEY_TYPE(VERT, vert);
164 RET_GEOKEY_TYPE(PROJ, proj);
165 RET_GEOKEY_TYPE(GEOG, geog);
166 RET_GEOKEY_TYPE(CONF, conf);
163 167
164 return AVERROR_INVALIDDATA;168 return AVERROR_INVALIDDATA;
165}169}
libavcodec/tiff.h+0−5
@@ -222,9 +222,4 @@ typedef struct TiffGeoTagKeyName { · 221 unmodified lines
222 const char *const name;222 const char *const name;
223} TiffGeoTagKeyName;223} TiffGeoTagKeyName;
224 224
225typedef struct TiffGeoTagNameType {
226 const char *const name;
227 const enum TiffGeoTagType type;
228} TiffGeoTagNameType;
229
230#endif /* AVCODEC_TIFF_H */225#endif /* AVCODEC_TIFF_H */
libavcodec/tiff_data.h+76−53
@@ -32,66 +32,89 @@ · 31 unmodified lines
32 32
33#include "tiff.h"33#include "tiff.h"
34 34
35typedef struct TiffGeoTagNameType {
36 enum TiffGeoTagType type;
37 unsigned offset;
38} TiffGeoTagNameType;
39
35#define TIFF_CONF_KEY_ID_OFFSET 102440#define TIFF_CONF_KEY_ID_OFFSET 1024
36static const TiffGeoTagNameType tiff_conf_name_type_map[] = {41#define CONF_NAME_TYPE_MAP(KEY) \
37 {"GTModelTypeGeoKey", GEOTIFF_SHORT },42 KEY(GTModelTypeGeoKey, SHORT ) \
38 {"GTRasterTypeGeoKey", GEOTIFF_SHORT },43 KEY(GTRasterTypeGeoKey, SHORT ) \
39 {"GTCitationGeoKey", GEOTIFF_STRING}44 KEY(GTCitationGeoKey, STRING) \
40};
41 45
42#define TIFF_GEOG_KEY_ID_OFFSET 204846#define TIFF_GEOG_KEY_ID_OFFSET 2048
43static const TiffGeoTagNameType tiff_geog_name_type_map[] = {47#define GEOG_NAME_TYPE_MAP(KEY) \
44 {"GeographicTypeGeoKey", GEOTIFF_SHORT },48 KEY(GeographicTypeGeoKey, SHORT ) \
45 {"GeogCitationGeoKey", GEOTIFF_STRING},49 KEY(GeogCitationGeoKey, STRING) \
46 {"GeogGeodeticDatumGeoKey", GEOTIFF_SHORT },50 KEY(GeogGeodeticDatumGeoKey, SHORT ) \
47 {"GeogPrimeMeridianGeoKey", GEOTIFF_SHORT },51 KEY(GeogPrimeMeridianGeoKey, SHORT ) \
48 {"GeogLinearUnitsGeoKey", GEOTIFF_SHORT },52 KEY(GeogLinearUnitsGeoKey, SHORT ) \
49 {"GeogLinearUnitSizeGeoKey", GEOTIFF_DOUBLE},53 KEY(GeogLinearUnitSizeGeoKey, DOUBLE) \
50 {"GeogAngularUnitsGeoKey", GEOTIFF_SHORT },54 KEY(GeogAngularUnitsGeoKey, SHORT ) \
51 {"GeogAngularUnitSizeGeoKey", GEOTIFF_DOUBLE},55 KEY(GeogAngularUnitSizeGeoKey, DOUBLE) \
52 {"GeogEllipsoidGeoKey", GEOTIFF_SHORT },56 KEY(GeogEllipsoidGeoKey, SHORT ) \
53 {"GeogSemiMajorAxisGeoKey", GEOTIFF_DOUBLE},57 KEY(GeogSemiMajorAxisGeoKey, DOUBLE) \
54 {"GeogSemiMinorAxisGeoKey", GEOTIFF_DOUBLE},58 KEY(GeogSemiMinorAxisGeoKey, DOUBLE) \
55 {"GeogInvFlatteningGeoKey", GEOTIFF_DOUBLE},59 KEY(GeogInvFlatteningGeoKey, DOUBLE) \
56 {"GeogAzimuthUnitsGeoKey", GEOTIFF_SHORT },60 KEY(GeogAzimuthUnitsGeoKey, SHORT ) \
57 {"GeogPrimeMeridianLongGeoKey", GEOTIFF_DOUBLE}61 KEY(GeogPrimeMeridianLongGeoKey, DOUBLE) \
58};
59 62
60#define TIFF_PROJ_KEY_ID_OFFSET 307263#define TIFF_PROJ_KEY_ID_OFFSET 3072
61static const TiffGeoTagNameType tiff_proj_name_type_map[] = {64#define PROJ_NAME_TYPE_MAP(KEY) \
62 {"ProjectedCSTypeGeoKey", GEOTIFF_SHORT },65 KEY(ProjectedCSTypeGeoKey, SHORT ) \
63 {"PCSCitationGeoKey", GEOTIFF_STRING},66 KEY(PCSCitationGeoKey, STRING) \
64 {"ProjectionGeoKey", GEOTIFF_SHORT },67 KEY(ProjectionGeoKey, SHORT ) \
65 {"ProjCoordTransGeoKey", GEOTIFF_SHORT },68 KEY(ProjCoordTransGeoKey, SHORT ) \
66 {"ProjLinearUnitsGeoKey", GEOTIFF_SHORT },69 KEY(ProjLinearUnitsGeoKey, SHORT ) \
67 {"ProjLinearUnitSizeGeoKey", GEOTIFF_DOUBLE},70 KEY(ProjLinearUnitSizeGeoKey, DOUBLE) \
68 {"ProjStdParallel1GeoKey", GEOTIFF_DOUBLE},71 KEY(ProjStdParallel1GeoKey, DOUBLE) \
69 {"ProjStdParallel2GeoKey", GEOTIFF_DOUBLE},72 KEY(ProjStdParallel2GeoKey, DOUBLE) \
70 {"ProjNatOriginLongGeoKey", GEOTIFF_DOUBLE},73 KEY(ProjNatOriginLongGeoKey, DOUBLE) \
71 {"ProjNatOriginLatGeoKey", GEOTIFF_DOUBLE},74 KEY(ProjNatOriginLatGeoKey, DOUBLE) \
72 {"ProjFalseEastingGeoKey", GEOTIFF_DOUBLE},75 KEY(ProjFalseEastingGeoKey, DOUBLE) \
73 {"ProjFalseNorthingGeoKey", GEOTIFF_DOUBLE},76 KEY(ProjFalseNorthingGeoKey, DOUBLE) \
74 {"ProjFalseOriginLongGeoKey", GEOTIFF_DOUBLE},77 KEY(ProjFalseOriginLongGeoKey, DOUBLE) \
75 {"ProjFalseOriginLatGeoKey", GEOTIFF_DOUBLE},78 KEY(ProjFalseOriginLatGeoKey, DOUBLE) \
76 {"ProjFalseOriginEastingGeoKey", GEOTIFF_DOUBLE},79 KEY(ProjFalseOriginEastingGeoKey, DOUBLE) \
77 {"ProjFalseOriginNorthingGeoKey", GEOTIFF_DOUBLE},80 KEY(ProjFalseOriginNorthingGeoKey, DOUBLE) \
78 {"ProjCenterLongGeoKey", GEOTIFF_DOUBLE},81 KEY(ProjCenterLongGeoKey, DOUBLE) \
79 {"ProjCenterLatGeoKey", GEOTIFF_DOUBLE},82 KEY(ProjCenterLatGeoKey, DOUBLE) \
80 {"ProjCenterEastingGeoKey", GEOTIFF_DOUBLE},83 KEY(ProjCenterEastingGeoKey, DOUBLE) \
81 {"ProjCenterNorthingGeoKey", GEOTIFF_DOUBLE},84 KEY(ProjCenterNorthingGeoKey, DOUBLE) \
82 {"ProjScaleAtNatOriginGeoKey", GEOTIFF_DOUBLE},85 KEY(ProjScaleAtNatOriginGeoKey, DOUBLE) \
83 {"ProjScaleAtCenterGeoKey", GEOTIFF_DOUBLE},86 KEY(ProjScaleAtCenterGeoKey, DOUBLE) \
84 {"ProjAzimuthAngleGeoKey", GEOTIFF_DOUBLE},87 KEY(ProjAzimuthAngleGeoKey, DOUBLE) \
85 {"ProjStraightVertPoleLongGeoKey", GEOTIFF_DOUBLE}88 KEY(ProjStraightVertPoleLongGeoKey, DOUBLE) \
86};
87 89
88#define TIFF_VERT_KEY_ID_OFFSET 409690#define TIFF_VERT_KEY_ID_OFFSET 4096
89static const TiffGeoTagNameType tiff_vert_name_type_map[] = {91#define VERT_NAME_TYPE_MAP(KEY) \
90 {"VerticalCSTypeGeoKey", GEOTIFF_SHORT },92 KEY(VerticalCSTypeGeoKey, SHORT ) \
91 {"VerticalCitationGeoKey", GEOTIFF_STRING},93 KEY(VerticalCitationGeoKey, STRING) \
92 {"VerticalDatumGeoKey", GEOTIFF_SHORT },94 KEY(VerticalDatumGeoKey, SHORT ) \
93 {"VerticalUnitsGeoKey", GEOTIFF_SHORT }95 KEY(VerticalUnitsGeoKey, SHORT ) \
94};96
97#define ADD_OFFSET(NAME, TYPE) \
98 NAME ## _OFFSET, \
99 NAME ## _END = NAME ## _OFFSET + sizeof(#NAME) - 1, \
100
101#define STRING(NAME, TYPE) #NAME "\0"
102
103#define ENTRY(NAME, TYPE) { .type = GEOTIFF_ ## TYPE, .offset = NAME ## _OFFSET },
104#define NAME_TYPE_MAP(NAME, name) \
105 enum { \
106 NAME ## _NAME_TYPE_MAP(ADD_OFFSET) \
107 }; \
108 static const TiffGeoTagNameType tiff_ ## name ## _name_type_map[] = { \
109 NAME ## _NAME_TYPE_MAP(ENTRY) \
110 }; \
111 static const char *const tiff_ ## name ## _name_type_string = \
112 NAME ## _NAME_TYPE_MAP(STRING)
113
114NAME_TYPE_MAP(CONF, conf);
115NAME_TYPE_MAP(GEOG, geog);
116NAME_TYPE_MAP(PROJ, proj);
117NAME_TYPE_MAP(VERT, vert);
95 118
96#define TIFF_GEO_KEY_UNDEFINED 0119#define TIFF_GEO_KEY_UNDEFINED 0
97#define TIFF_GEO_KEY_USER_DEFINED 32767120#define TIFF_GEO_KEY_USER_DEFINED 32767

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t