FFmpeg
Loading...
Searching...
No Matches
exif.c
Go to the documentation of this file.
1/*
2 * EXIF metadata parser
3 * Copyright (c) 2013 Thilo Borgmann <thilo.borgmann _at_ mail.de>
4 * Copyright (c) 2024-2025 Leo Izen <leo.izen@gmail.com>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/**
24 * @file
25 * EXIF metadata parser
26 * @author Thilo Borgmann <thilo.borgmann _at_ mail.de>
27 * @author Leo Izen <leo.izen@gmail.com>
28 */
29
30#include <inttypes.h>
31
33#include "libavutil/avconfig.h"
34#include "libavutil/bprint.h"
35#include "libavutil/display.h"
37#include "libavutil/mem.h"
38
39#include "bytestream.h"
40#include "exif_internal.h"
41#include "tiff_common.h"
42
43#define EXIF_II_LONG 0x49492a00
44#define EXIF_MM_LONG 0x4d4d002a
45
46#define BASE_TAG_SIZE 12
47#define IFD_EXTRA_SIZE 6
48
49#define EXIF_TAG_NAME_LENGTH 32
50#define MAKERNOTE_TAG 0x927c
51#define ORIENTATION_TAG 0x112
52#define EXIFIFD_TAG 0x8769
53#define IMAGE_WIDTH_TAG 0x100
54#define IMAGE_LENGTH_TAG 0x101
55#define PIXEL_X_TAG 0xa002
56#define PIXEL_Y_TAG 0xa003
57
58struct exif_tag {
60 uint16_t id;
61};
62
63static const struct exif_tag tag_list[] = { // JEITA CP-3451 EXIF specification:
64 {"GPSVersionID", 0x00}, // <- Table 12 GPS Attribute Information
65 {"GPSLatitudeRef", 0x01},
66 {"GPSLatitude", 0x02},
67 {"GPSLongitudeRef", 0x03},
68 {"GPSLongitude", 0x04},
69 {"GPSAltitudeRef", 0x05},
70 {"GPSAltitude", 0x06},
71 {"GPSTimeStamp", 0x07},
72 {"GPSSatellites", 0x08},
73 {"GPSStatus", 0x09},
74 {"GPSMeasureMode", 0x0A},
75 {"GPSDOP", 0x0B},
76 {"GPSSpeedRef", 0x0C},
77 {"GPSSpeed", 0x0D},
78 {"GPSTrackRef", 0x0E},
79 {"GPSTrack", 0x0F},
80 {"GPSImgDirectionRef", 0x10},
81 {"GPSImgDirection", 0x11},
82 {"GPSMapDatum", 0x12},
83 {"GPSDestLatitudeRef", 0x13},
84 {"GPSDestLatitude", 0x14},
85 {"GPSDestLongitudeRef", 0x15},
86 {"GPSDestLongitude", 0x16},
87 {"GPSDestBearingRef", 0x17},
88 {"GPSDestBearing", 0x18},
89 {"GPSDestDistanceRef", 0x19},
90 {"GPSDestDistance", 0x1A},
91 {"GPSProcessingMethod", 0x1B},
92 {"GPSAreaInformation", 0x1C},
93 {"GPSDateStamp", 0x1D},
94 {"GPSDifferential", 0x1E},
95 {"ImageWidth", 0x100}, // <- Table 3 TIFF Rev. 6.0 Attribute Information Used in Exif
96 {"ImageLength", 0x101},
97 {"BitsPerSample", 0x102},
98 {"Compression", 0x103},
99 {"PhotometricInterpretation", 0x106},
100 {"Orientation", 0x112},
101 {"SamplesPerPixel", 0x115},
102 {"PlanarConfiguration", 0x11C},
103 {"YCbCrSubSampling", 0x212},
104 {"YCbCrPositioning", 0x213},
105 {"XResolution", 0x11A},
106 {"YResolution", 0x11B},
107 {"ResolutionUnit", 0x128},
108 {"StripOffsets", 0x111},
109 {"RowsPerStrip", 0x116},
110 {"StripByteCounts", 0x117},
111 {"JPEGInterchangeFormat", 0x201},
112 {"JPEGInterchangeFormatLength",0x202},
113 {"TransferFunction", 0x12D},
114 {"WhitePoint", 0x13E},
115 {"PrimaryChromaticities", 0x13F},
116 {"YCbCrCoefficients", 0x211},
117 {"ReferenceBlackWhite", 0x214},
118 {"DateTime", 0x132},
119 {"ImageDescription", 0x10E},
120 {"Make", 0x10F},
121 {"Model", 0x110},
122 {"Software", 0x131},
123 {"Artist", 0x13B},
124 {"Copyright", 0x8298},
125 {"InterColorProfile", 0x8773},
126 {"ExifVersion", 0x9000}, // <- Table 4 Exif IFD Attribute Information (1)
127 {"FlashpixVersion", 0xA000},
128 {"ColorSpace", 0xA001},
129 {"ComponentsConfiguration", 0x9101},
130 {"CompressedBitsPerPixel", 0x9102},
131 {"PixelXDimension", 0xA002},
132 {"PixelYDimension", 0xA003},
133 {"MakerNote", 0x927C},
134 {"UserComment", 0x9286},
135 {"RelatedSoundFile", 0xA004},
136 {"DateTimeOriginal", 0x9003},
137 {"DateTimeDigitized", 0x9004},
138 {"SubSecTime", 0x9290},
139 {"SubSecTimeOriginal", 0x9291},
140 {"SubSecTimeDigitized", 0x9292},
141 {"ImageUniqueID", 0xA420},
142 {"ExposureTime", 0x829A}, // <- Table 5 Exif IFD Attribute Information (2)
143 {"FNumber", 0x829D},
144 {"ExposureProgram", 0x8822},
145 {"SpectralSensitivity", 0x8824},
146 {"ISOSpeedRatings", 0x8827},
147 {"OECF", 0x8828},
148 {"ShutterSpeedValue", 0x9201},
149 {"ApertureValue", 0x9202},
150 {"BrightnessValue", 0x9203},
151 {"ExposureBiasValue", 0x9204},
152 {"MaxApertureValue", 0x9205},
153 {"SubjectDistance", 0x9206},
154 {"MeteringMode", 0x9207},
155 {"LightSource", 0x9208},
156 {"Flash", 0x9209},
157 {"FocalLength", 0x920A},
158 {"SubjectArea", 0x9214},
159 {"FlashEnergy", 0xA20B},
160 {"SpatialFrequencyResponse", 0xA20C},
161 {"FocalPlaneXResolution", 0xA20E},
162 {"FocalPlaneYResolution", 0xA20F},
163 {"FocalPlaneResolutionUnit", 0xA210},
164 {"SubjectLocation", 0xA214},
165 {"ExposureIndex", 0xA215},
166 {"SensingMethod", 0xA217},
167 {"FileSource", 0xA300},
168 {"SceneType", 0xA301},
169 {"CFAPattern", 0xA302},
170 {"CustomRendered", 0xA401},
171 {"ExposureMode", 0xA402},
172 {"WhiteBalance", 0xA403},
173 {"DigitalZoomRatio", 0xA404},
174 {"FocalLengthIn35mmFilm", 0xA405},
175 {"SceneCaptureType", 0xA406},
176 {"GainControl", 0xA407},
177 {"Contrast", 0xA408},
178 {"Saturation", 0xA409},
179 {"Sharpness", 0xA40A},
180 {"DeviceSettingDescription", 0xA40B},
181 {"SubjectDistanceRange", 0xA40C},
182
183 /* InteropIFD tags */
184 {"RelatedImageFileFormat", 0x1000},
185 {"RelatedImageWidth", 0x1001},
186 {"RelatedImageLength", 0x1002},
187
188 /* private EXIF tags */
189 {"PrintImageMatching", 0xC4A5}, // <- undocumented meaning
190
191 /* IFD tags */
192 {"ExifIFD", 0x8769}, // <- An IFD pointing to standard Exif metadata
193 {"GPSInfo", 0x8825}, // <- An IFD pointing to GPS Exif Metadata
194 {"InteropIFD", 0xA005}, // <- Table 13 Interoperability IFD Attribute Information
195 {"GlobalParametersIFD", 0x0190},
196 {"ProfileIFD", 0xc6f5},
197
198 /* Extra FFmpeg tags */
199 { "IFD1", 0xFFFC},
200 { "IFD2", 0xFFFB},
201 { "IFD3", 0xFFFA},
202 { "IFD4", 0xFFF9},
203 { "IFD5", 0xFFF8},
204 { "IFD6", 0xFFF7},
205 { "IFD7", 0xFFF6},
206 { "IFD8", 0xFFF5},
207 { "IFD9", 0xFFF4},
208 { "IFD10", 0xFFF3},
209 { "IFD11", 0xFFF2},
210 { "IFD12", 0xFFF1},
211 { "IFD13", 0xFFF0},
212 { "IFD14", 0xFFEF},
213 { "IFD15", 0xFFEE},
214 { "IFD16", 0xFFED},
215};
216
217/* same as type_sizes but with string == 1 */
218static const size_t exif_sizes[] = {
219 [0] = 0,
220 [AV_TIFF_BYTE] = 1,
221 [AV_TIFF_STRING] = 1,
222 [AV_TIFF_SHORT] = 2,
223 [AV_TIFF_LONG] = 4,
224 [AV_TIFF_RATIONAL] = 8,
225 [AV_TIFF_SBYTE] = 1,
226 [AV_TIFF_UNDEFINED] = 1,
227 [AV_TIFF_SSHORT] = 2,
228 [AV_TIFF_SLONG] = 4,
229 [AV_TIFF_SRATIONAL] = 8,
230 [AV_TIFF_FLOAT] = 4,
231 [AV_TIFF_DOUBLE] = 8,
232 [AV_TIFF_IFD] = 4,
233};
234
235const char *av_exif_get_tag_name(uint16_t id)
236{
237 for (size_t i = 0; i < FF_ARRAY_ELEMS(tag_list); i++) {
238 if (tag_list[i].id == id)
239 return tag_list[i].name;
240 }
241
242 return NULL;
243}
244
246{
247 if (!name)
248 return -1;
249
250 for (size_t i = 0; i < FF_ARRAY_ELEMS(tag_list); i++) {
251 if (!strcmp(tag_list[i].name, name))
252 return tag_list[i].id;
253 }
254
255 return -1;
256}
257
258static inline void tput16(PutByteContext *pb, const int le, const uint16_t value)
259{
260 le ? bytestream2_put_le16(pb, value) : bytestream2_put_be16(pb, value);
261}
262
263static inline void tput32(PutByteContext *pb, const int le, const uint32_t value)
264{
265 le ? bytestream2_put_le32(pb, value) : bytestream2_put_be32(pb, value);
266}
267
268static inline void tput64(PutByteContext *pb, const int le, const uint64_t value)
269{
270 le ? bytestream2_put_le64(pb, value) : bytestream2_put_be64(pb, value);
271}
272
273static int exif_read_values(void *logctx, GetByteContext *gb, int le,
274 size_t *bytes_left, AVExifEntry *entry)
275{
276 size_t payload_size = exif_sizes[entry->type] * entry->count;
277
278 if (payload_size > bytestream2_get_bytes_left(gb) || payload_size > *bytes_left)
279 return AVERROR_INVALIDDATA;
280 *bytes_left -= payload_size;
281
282 switch (entry->type) {
283 case AV_TIFF_SHORT:
284 case AV_TIFF_LONG:
285 entry->value.uint = av_calloc(entry->count, sizeof(*entry->value.uint));
286 break;
287 case AV_TIFF_SSHORT:
288 case AV_TIFF_SLONG:
289 entry->value.sint = av_calloc(entry->count, sizeof(*entry->value.sint));
290 break;
291 case AV_TIFF_DOUBLE:
292 case AV_TIFF_FLOAT:
293 entry->value.dbl = av_calloc(entry->count, sizeof(*entry->value.dbl));
294 break;
295 case AV_TIFF_RATIONAL:
297 entry->value.rat = av_calloc(entry->count, sizeof(*entry->value.rat));
298 break;
300 case AV_TIFF_BYTE:
301 entry->value.ubytes = av_mallocz(entry->count);
302 break;
303 case AV_TIFF_SBYTE:
304 entry->value.sbytes = av_mallocz(entry->count);
305 break;
306 case AV_TIFF_STRING:
307 entry->value.str = av_mallocz(entry->count + 1);
308 break;
309 case AV_TIFF_IFD:
310 av_log(logctx, AV_LOG_WARNING, "Bad IFD type for non-IFD tag\n");
311 return AVERROR_INVALIDDATA;
312 }
313 if (!entry->value.ptr)
314 return AVERROR(ENOMEM);
315 switch (entry->type) {
316 case AV_TIFF_SHORT:
317 for (size_t i = 0; i < entry->count; i++)
318 entry->value.uint[i] = ff_tget_short(gb, le);
319 break;
320 case AV_TIFF_LONG:
321 for (size_t i = 0; i < entry->count; i++)
322 entry->value.uint[i] = ff_tget_long(gb, le);
323 break;
324 case AV_TIFF_SSHORT:
325 for (size_t i = 0; i < entry->count; i++)
326 entry->value.sint[i] = (int16_t) ff_tget_short(gb, le);
327 break;
328 case AV_TIFF_SLONG:
329 for (size_t i = 0; i < entry->count; i++)
330 entry->value.sint[i] = (int32_t) ff_tget_long(gb, le);
331 break;
332 case AV_TIFF_DOUBLE:
333 for (size_t i = 0; i < entry->count; i++)
334 entry->value.dbl[i] = ff_tget_double(gb, le);
335 break;
336 case AV_TIFF_FLOAT:
337 for (size_t i = 0; i < entry->count; i++) {
338 av_alias32 alias = { .u32 = ff_tget_long(gb, le) };
339 entry->value.dbl[i] = alias.f32;
340 }
341 break;
342 case AV_TIFF_RATIONAL:
344 for (size_t i = 0; i < entry->count; i++) {
345 int32_t num = ff_tget_long(gb, le);
346 int32_t den = ff_tget_long(gb, le);
347 entry->value.rat[i] = av_make_q(num, den);
348 }
349 break;
351 case AV_TIFF_BYTE:
352 /* these three fields are aliased to entry->value.ptr via a union */
353 /* and entry->value.ptr will always be nonzero here */
354 av_assert0(entry->value.ubytes);
355 bytestream2_get_buffer(gb, entry->value.ubytes, entry->count);
356 break;
357 case AV_TIFF_SBYTE:
358 av_assert0(entry->value.sbytes);
359 bytestream2_get_buffer(gb, entry->value.sbytes, entry->count);
360 break;
361 case AV_TIFF_STRING:
362 av_assert0(entry->value.str);
363 bytestream2_get_buffer(gb, entry->value.str, entry->count);
364 break;
365 }
366
367 return 0;
368}
369
370static void exif_write_values(PutByteContext *pb, int le, const AVExifEntry *entry)
371{
372 switch (entry->type) {
373 case AV_TIFF_SHORT:
374 for (size_t i = 0; i < entry->count; i++)
375 tput16(pb, le, entry->value.uint[i]);
376 break;
377 case AV_TIFF_LONG:
378 for (size_t i = 0; i < entry->count; i++)
379 tput32(pb, le, entry->value.uint[i]);
380 break;
381 case AV_TIFF_SSHORT:
382 for (size_t i = 0; i < entry->count; i++)
383 tput16(pb, le, entry->value.sint[i]);
384 break;
385 case AV_TIFF_SLONG:
386 for (size_t i = 0; i < entry->count; i++)
387 tput32(pb, le, entry->value.sint[i]);
388 break;
389 case AV_TIFF_DOUBLE:
390 for (size_t i = 0; i < entry->count; i++) {
391 const av_alias64 a = { .f64 = entry->value.dbl[i] };
392 tput64(pb, le, a.u64);
393 }
394 break;
395 case AV_TIFF_FLOAT:
396 for (size_t i = 0; i < entry->count; i++) {
397 const av_alias32 a = { .f32 = entry->value.dbl[i] };
398 tput32(pb, le, a.u32);
399 }
400 break;
401 case AV_TIFF_RATIONAL:
403 for (size_t i = 0; i < entry->count; i++) {
404 tput32(pb, le, entry->value.rat[i].num);
405 tput32(pb, le, entry->value.rat[i].den);
406 }
407 break;
409 case AV_TIFF_BYTE:
410 bytestream2_put_buffer(pb, entry->value.ubytes, entry->count);
411 break;
412 case AV_TIFF_SBYTE:
413 bytestream2_put_buffer(pb, entry->value.sbytes, entry->count);
414 break;
415 case AV_TIFF_STRING:
416 bytestream2_put_buffer(pb, entry->value.str, entry->count);
417 break;
418 }
419}
420
421static const uint8_t aoc_header[] = { 'A', 'O', 'C', 0, };
422static const uint8_t apple_header[] = { 'A', 'p', 'p', 'l', 'e', ' ', 'i', 'O', 'S', 0, 0, 1, 'M', 'M'};
423static const uint8_t casio_header[] = { 'Q', 'V', 'C', 0, 0, 0, };
424static const uint8_t foveon_header[] = { 'F', 'O', 'V', 'E', 'O', 'N', 0, 0, };
425static const uint8_t fuji_header[] = { 'F', 'U', 'J', 'I', };
426static const uint8_t nikon_header[] = { 'N', 'i', 'k', 'o', 'n', 0, };
427static const uint8_t olympus1_header[] = { 'O', 'L', 'Y', 'M', 'P', 0, };
428static const uint8_t olympus2_header[] = { 'O', 'L', 'Y', 'M', 'P', 'U', 'S', 0, 'I', 'I', };
429static const uint8_t panasonic_header[] = { 'P', 'a', 'n', 'a', 's', 'o', 'n', 'i', 'c', 0, 0, 0, };
430static const uint8_t sigma_header[] = { 'S', 'I', 'G', 'M', 'A', 0, 0, 0, };
431static const uint8_t sony_header[] = { 'S', 'O', 'N', 'Y', ' ', 'D', 'S', 'C', ' ', 0, 0, 0, };
432
434 const uint8_t *header;
437};
438
439#define MAKERNOTE_STRUCT(h, r) { \
440 .header = (h), \
441 .header_size = sizeof((h)), \
442 .result = (r), \
443}
444
457
458/*
459 * derived from Exiv2 MakerNote's article
460 * https://exiv2.org/makernote.html or archived at
461 * https://web.archive.org/web/20250311155857/https://exiv2.org/makernote.html
462 */
464{
466 return -1;
467
468 for (int i = 0; i < FF_ARRAY_ELEMS(makernote_data); i++) {
469 if (!memcmp(gb->buffer, makernote_data[i].header, makernote_data[i].header_size))
470 return makernote_data[i].result;
471 }
472
473 if (!memcmp(gb->buffer, nikon_header, sizeof(nikon_header))) {
474 if (bytestream2_get_bytes_left(gb) < 14)
475 return -1;
476 else if (AV_RB32(gb->buffer + 10) == EXIF_MM_LONG || AV_RB32(gb->buffer + 10) == EXIF_II_LONG)
477 return -1;
478 return 8;
479 }
480
481 return 0;
482}
483
484static int exif_parse_ifd_list(void *logctx, GetByteContext *gb, int le,
485 int depth, int *entries_left, size_t *bytes_left,
486 AVExifMetadata *ifd, int guess);
487
488static int exif_decode_tag(void *logctx, GetByteContext *gb, int le,
489 int depth, int *entries_left, size_t *bytes_left,
490 int guess, AVExifEntry *entry)
491{
492 int ret = 0, makernote_offset = -1, tell, is_ifd, count;
493 enum AVTiffDataType type;
494 uint32_t payload;
495
496 /* safety check to prevent infinite recursion on malicious IFDs */
497 if (depth > 3)
498 return AVERROR_INVALIDDATA;
499
501
502 entry->id = ff_tget_short(gb, le);
503 type = ff_tget_short(gb, le);
504 count = ff_tget_long(gb, le);
505 payload = ff_tget_long(gb, le);
506
507 av_log(logctx, AV_LOG_DEBUG, "TIFF Tag: id: 0x%04x, type: %d, count: %u, offset: %d, "
508 "payload: %" PRIu32 "\n", entry->id, type, count, tell, payload);
509
510 if (!type) {
511 av_log(logctx, AV_LOG_DEBUG, "Skipping invalid TIFF tag 0\n");
512 goto end;
513 }
514
515 /* AV_TIFF_IFD is the largest, numerically */
516 if (type > AV_TIFF_IFD || count >= INT_MAX/8U)
517 return AVERROR_INVALIDDATA;
518
519 is_ifd = type == AV_TIFF_IFD || ff_tis_ifd(entry->id) || entry->id == MAKERNOTE_TAG;
520
521 if (is_ifd) {
522 if (!payload)
523 goto end;
524 bytestream2_seek(gb, payload, SEEK_SET);
525 }
526
527 if (entry->id == MAKERNOTE_TAG) {
528 makernote_offset = exif_get_makernote_offset(gb);
529 if (makernote_offset < 0)
530 is_ifd = 0;
531 }
532
533 if (is_ifd) {
534 entry->type = AV_TIFF_IFD;
535 entry->count = 1;
536 entry->ifd_offset = makernote_offset > 0 ? makernote_offset : 0;
537 if (entry->ifd_offset) {
538 entry->ifd_lead = av_malloc(entry->ifd_offset);
539 if (!entry->ifd_lead)
540 return AVERROR(ENOMEM);
541 bytestream2_get_buffer(gb, entry->ifd_lead, entry->ifd_offset);
542 }
543 ret = exif_parse_ifd_list(logctx, gb, le, depth + 1, entries_left, bytes_left,
544 &entry->value.ifd, guess || entry->id == MAKERNOTE_TAG);
546 /*
547 * we guessed that MakerNote was an IFD
548 * but we were probably incorrect at this
549 * point so we try again as a binary blob
550 */
551 av_log(logctx, AV_LOG_DEBUG, "unrecognized MakerNote IFD, retrying as blob\n");
552 is_ifd = 0;
553 }
554 }
555
556 /* inverted condition instead of else so we can fall through from above */
557 if (!is_ifd) {
559 entry->count = count;
560 bytestream2_seek(gb, count * exif_sizes[type] > 4 ? payload : tell + 8, SEEK_SET);
561 ret = exif_read_values(logctx, gb, le, &bytes_left[guess], entry);
562 }
563
564end:
565 bytestream2_seek(gb, tell + BASE_TAG_SIZE, SEEK_SET);
566
567 return ret;
568}
569
570static int exif_parse_ifd_list(void *logctx, GetByteContext *gb, int le,
571 int depth, int *entries_left, size_t *bytes_left,
572 AVExifMetadata *ifd, int guess)
573{
574 uint32_t entries;
575 size_t required_size;
576 void *temp;
577 int ret = 0;
578
579 av_log(logctx, AV_LOG_DEBUG, "parsing IFD list at offset: %d\n", bytestream2_tell(gb));
580
581 if (bytestream2_get_bytes_left(gb) < 2) {
582 av_log(logctx, guess ? AV_LOG_DEBUG : AV_LOG_ERROR,
583 "not enough bytes remaining in EXIF buffer: 2 required\n");
585 goto end;
586 }
587
588 entries = ff_tget_short(gb, le);
589 if (bytestream2_get_bytes_left(gb) < entries * BASE_TAG_SIZE) {
590 av_log(logctx, guess ? AV_LOG_DEBUG : AV_LOG_ERROR,
591 "not enough bytes remaining in EXIF buffer. entries: %" PRIu32 "\n", entries);
593 goto end;
594 }
595 if (entries > 4096) {
596 /* that is a lot of entries, probably an error */
597 av_log(logctx, guess ? AV_LOG_DEBUG : AV_LOG_ERROR,
598 "too many entries: %" PRIu32 "\n", entries);
600 goto end;
601 }
602 if (entries > entries_left[guess]) {
603 av_log(logctx, guess ? AV_LOG_DEBUG : AV_LOG_ERROR,
604 "IFD tree has more entries than the EXIF buffer can hold\n");
606 goto end;
607 }
608 entries_left[guess] -= entries;
609
610 ifd->count = entries;
611 av_log(logctx, AV_LOG_DEBUG, "entry count for IFD: %u\n", ifd->count);
612
613 /* empty IFD is technically legal but equivalent to no metadata present */
614 if (!ifd->count) {
615 ret = 0;
616 goto end;
617 }
618
619 if (av_size_mult(ifd->count, sizeof(*ifd->entries), &required_size) < 0) {
620 ret = AVERROR(ENOMEM);
621 goto end;
622 }
623 temp = av_fast_realloc(ifd->entries, &ifd->size, required_size);
624 if (!temp) {
625 av_freep(&ifd->entries);
626 ret = AVERROR(ENOMEM);
627 goto end;
628 }
629 ifd->entries = temp;
630
631 /* entries have pointers in them which can cause issues if */
632 /* they are freed or realloc'd when garbage */
633 memset(ifd->entries, 0, required_size);
634
635 for (uint32_t i = 0; i < entries; i++) {
636 ret = exif_decode_tag(logctx, gb, le, depth, entries_left, bytes_left,
637 guess, &ifd->entries[i]);
638 if (ret < 0)
639 goto end;
640 }
641
642end:
643 if (ret < 0) {
644 av_exif_free(ifd);
645 return ret;
646 }
647 /*
648 * at the end of an IFD is an pointer to the next IFD
649 * or zero if there are no more IFDs, which is usually the case
650 */
651 ret = ff_tget_long(gb, le);
652
653 /* overflow */
654 if (ret < 0) {
656 av_exif_free(ifd);
657 }
658
659 return ret;
660}
661
662/*
663 * note that this function does not free the entry pointer itself
664 * because it's probably part of a larger array that should be freed
665 * all at once
666 */
668{
669 if (!entry)
670 return;
671 if (entry->type == AV_TIFF_IFD)
672 av_exif_free(&entry->value.ifd);
673 else
674 av_freep(&entry->value.ptr);
675 av_freep(&entry->ifd_lead);
676}
677
679{
680 if (!ifd)
681 return;
682 if (!ifd->entries) {
683 ifd->count = 0;
684 ifd->size = 0;
685 return;
686 }
687 for (size_t i = 0; i < ifd->count; i++) {
688 AVExifEntry *entry = &ifd->entries[i];
690 }
691 av_freep(&ifd->entries);
692 ifd->count = 0;
693 ifd->size = 0;
694}
695
696static size_t exif_get_ifd_size(const AVExifMetadata *ifd)
697{
698 /* 6 == 4 + 2; 2-byte entry-count at the beginning */
699 /* plus 4-byte next-IFD pointer at the end */
700 size_t total_size = IFD_EXTRA_SIZE;
701 for (size_t i = 0; i < ifd->count; i++) {
702 const AVExifEntry *entry = &ifd->entries[i];
703 if (entry->type == AV_TIFF_IFD) {
704 total_size += BASE_TAG_SIZE + exif_get_ifd_size(&entry->value.ifd) + entry->ifd_offset;
705 } else {
706 size_t payload_size = entry->count * exif_sizes[entry->type];
707 total_size += BASE_TAG_SIZE + (payload_size > 4 ? payload_size : 0);
708 }
709 }
710 return total_size;
711}
712
713static int exif_write_ifd(void *logctx, PutByteContext *pb, int le, int depth, const AVExifMetadata *ifd)
714{
715 int offset, ret, tell, tell2;
717 tput16(pb, le, ifd->count);
718 offset = tell + IFD_EXTRA_SIZE + BASE_TAG_SIZE * (uint32_t) ifd->count;
719 av_log(logctx, AV_LOG_DEBUG, "writing IFD with %u entries and initial offset %d\n", ifd->count, offset);
720 for (size_t i = 0; i < ifd->count; i++) {
721 const AVExifEntry *entry = &ifd->entries[i];
722 av_log(logctx, AV_LOG_DEBUG, "writing TIFF entry: id: 0x%04" PRIx16 ", type: %d, count: %"
723 PRIu32 ", offset: %d, offset value: %d\n",
724 entry->id, entry->type, entry->count,
726 tput16(pb, le, entry->id);
727 if (entry->id == MAKERNOTE_TAG && entry->type == AV_TIFF_IFD) {
728 size_t ifd_size = exif_get_ifd_size(&entry->value.ifd);
729 tput16(pb, le, AV_TIFF_UNDEFINED);
730 tput32(pb, le, ifd_size);
731 } else {
732 tput16(pb, le, entry->type);
733 tput32(pb, le, entry->count);
734 }
735 if (entry->type == AV_TIFF_IFD) {
736 tput32(pb, le, offset);
737 tell2 = bytestream2_tell_p(pb);
738 bytestream2_seek_p(pb, offset, SEEK_SET);
739 if (entry->ifd_offset)
740 bytestream2_put_buffer(pb, entry->ifd_lead, entry->ifd_offset);
741 ret = exif_write_ifd(logctx, pb, le, depth + 1, &entry->value.ifd);
742 if (ret < 0)
743 return ret;
744 offset += ret + entry->ifd_offset;
745 bytestream2_seek_p(pb, tell2, SEEK_SET);
746 } else {
747 size_t payload_size = entry->count * exif_sizes[entry->type];
748 if (payload_size > 4) {
749 tput32(pb, le, offset);
750 tell2 = bytestream2_tell_p(pb);
751 bytestream2_seek_p(pb, offset, SEEK_SET);
752 exif_write_values(pb, le, entry);
753 offset += payload_size;
754 bytestream2_seek_p(pb, tell2, SEEK_SET);
755 } else {
756 /* zero uninitialized excess payload values */
757 AV_WN32(pb->buffer, 0);
758 exif_write_values(pb, le, entry);
759 bytestream2_seek_p(pb, 4 - payload_size, SEEK_CUR);
760 }
761 }
762 }
763
764 /*
765 * we write 0 if this is the top-level exif IFD
766 * indicating that there are no more IFD pointers
767 */
768 tput32(pb, le, depth ? offset : 0);
769 return offset - tell;
770}
771
772int av_exif_write(void *logctx, const AVExifMetadata *ifd, AVBufferRef **buffer, enum AVExifHeaderMode header_mode)
773{
774 AVBufferRef *buf = NULL;
775 size_t size, headsize = 8;
777 int ret = 0, off = 0, next;
778 AVExifMetadata *ifd_new = NULL;
779 AVExifMetadata extra_ifds[16] = { 0 };
780
781 int le = 1;
782
783 if (*buffer) {
784 ret = AVERROR(EINVAL);
785 goto end;
786 }
787
788 size = exif_get_ifd_size(ifd);
789 switch (header_mode) {
790 case AV_EXIF_EXIF00:
791 off = 6;
792 break;
793 case AV_EXIF_T_OFF:
794 off = 4;
795 break;
797 le = 0;
798 headsize = 0;
799 break;
801 le = 1;
802 headsize = 0;
803 break;
804 }
805
806 ret = av_buffer_realloc(&buf, size + off + headsize);
807 if (ret < 0)
808 goto end;
809
810 if (header_mode == AV_EXIF_EXIF00) {
811 AV_WL32(buf->data, MKTAG('E','x','i','f'));
812 AV_WN16(buf->data + 4, 0);
813 } else if (header_mode == AV_EXIF_T_OFF) {
814 AV_WN32(buf->data, 0);
815 }
816
817 bytestream2_init_writer(&pb, buf->data + off, buf->size - off);
818
819 if (header_mode != AV_EXIF_ASSUME_BE && header_mode != AV_EXIF_ASSUME_LE) {
820 /* these constants are be32 in both cases */
821 /* le == 1 always in this case */
822 bytestream2_put_be32(&pb, EXIF_II_LONG);
823 tput32(&pb, le, 8);
824 }
825
826 int extras = 0;
827 for (int i = 0; i < FF_ARRAY_ELEMS(extra_ifds); i++) {
828 AVExifEntry *extra_entry = NULL;
829 uint16_t extra_tag = 0xFFFCu - i;
830 ret = av_exif_get_entry(logctx, (AVExifMetadata *) ifd, extra_tag, 0, &extra_entry);
831 if (ret < 0)
832 break;
833 if (!ret)
834 continue;
835 av_log(logctx, AV_LOG_DEBUG, "found extra IFD tag: %04x\n", extra_tag);
836 if (!ifd_new) {
837 ifd_new = av_exif_clone_ifd(ifd);
838 if (!ifd_new)
839 break;
840 ifd = ifd_new;
841 }
842 /* calling remove_entry will call av_exif_free on the original */
843 AVExifMetadata *cloned = av_exif_clone_ifd(&extra_entry->value.ifd);
844 if (!cloned)
845 break;
846 extra_ifds[extras++] = *cloned;
847 /* don't use av_exif_free here, we want to preserve internals */
848 av_free(cloned);
849 ret = av_exif_remove_entry(logctx, ifd_new, extra_tag, 0);
850 if (ret < 0)
851 break;
852 }
853
854 if (ret < 0) {
855 av_log(logctx, AV_LOG_ERROR, "error popping additional IFD: %s\n", av_err2str(ret));
856 goto end;
857 }
858
859 next = bytestream2_tell_p(&pb);
860 ret = exif_write_ifd(logctx, &pb, le, 0, ifd);
861 if (ret < 0) {
862 av_log(logctx, AV_LOG_ERROR, "error writing EXIF data: %s\n", av_err2str(ret));
863 goto end;
864 }
865 next += ret;
866
867 for (int i = 0; i < extras; i++) {
868 av_log(logctx, AV_LOG_DEBUG, "writing additional ifd at: %d\n", next);
869 /* exif_write_ifd always writes 0 i.e. last ifd so we overwrite that here */
870 bytestream2_seek_p(&pb, -4, SEEK_CUR);
871 tput32(&pb, le, next);
872 bytestream2_seek_p(&pb, next, SEEK_SET);
873 ret = exif_write_ifd(logctx, &pb, le, 0, &extra_ifds[i]);
874 if (ret < 0) {
875 av_log(logctx, AV_LOG_ERROR, "error writing additional IFD: %s\n", av_err2str(ret));
876 goto end;
877 }
878 next += ret;
879 }
880
881 /* shrink the buffer to the amount of data we actually used */
882 /* extras don't contribute the initial BASE_TAG_SIZE each */
883 ret = av_buffer_realloc(&buf, buf->size - BASE_TAG_SIZE * extras);
884 if (ret < 0)
885 goto end;
886
887 *buffer = buf;
888 ret = 0;
889
890end:
891 av_exif_free(ifd_new);
892 av_freep(&ifd_new);
893 for (int i = 0; i < FF_ARRAY_ELEMS(extra_ifds); i++)
894 av_exif_free(&extra_ifds[i]);
895 if (ret < 0)
896 av_buffer_unref(&buf);
897
898 return ret;
899}
900
901int av_exif_parse_buffer(void *logctx, const uint8_t *buf, size_t size,
902 AVExifMetadata *ifd, enum AVExifHeaderMode header_mode)
903{
904 int ret, le;
905 GetByteContext gbytes;
906 if (size > INT_MAX)
907 return AVERROR(EINVAL);
908 size_t off = 0;
909 switch (header_mode) {
910 case AV_EXIF_EXIF00:
911 if (size < 6)
912 return AVERROR_INVALIDDATA;
913 off = 6;
915 case AV_EXIF_T_OFF:
916 if (size < 4)
917 return AVERROR_INVALIDDATA;
918 if (!off)
919 off = AV_RB32(buf) + 4;
921 case AV_EXIF_TIFF_HEADER: {
922 int ifd_offset;
923 if (size <= off)
924 return AVERROR_INVALIDDATA;
925 bytestream2_init(&gbytes, buf + off, size - off);
926 // read TIFF header
927 ret = ff_tdecode_header(&gbytes, &le, &ifd_offset);
928 if (ret < 0) {
929 av_log(logctx, AV_LOG_ERROR, "invalid TIFF header in EXIF data: %s\n", av_err2str(ret));
930 return ret;
931 }
932 bytestream2_seek(&gbytes, ifd_offset, SEEK_SET);
933 break;
934 }
936 le = 1;
937 bytestream2_init(&gbytes, buf, size);
938 break;
940 le = 0;
941 bytestream2_init(&gbytes, buf, size);
942 break;
943 default:
944 return AVERROR(EINVAL);
945 }
946
947 /*
948 * parse IFD0 here. If the return value is positive that tells us
949 * there is subimage metadata, but we don't parse that IFD here
950 */
951 int ifd_offsets[17] = { bytestream2_tell(&gbytes) };
952 int nb_ifds = 1;
953 int entries_left[2] = { size / BASE_TAG_SIZE, size / BASE_TAG_SIZE };
954 size_t bytes_left[2] = { size, size };
955 ret = exif_parse_ifd_list(logctx, &gbytes, le, 0, entries_left, bytes_left, ifd, 0);
956 if (ret < 0) {
957 av_log(logctx, AV_LOG_ERROR, "error decoding EXIF data: %s\n", av_err2str(ret));
958 return ret;
959 }
960 if (!ret)
961 goto finish;
962 int next = ret;
963 bytestream2_seek(&gbytes, next, SEEK_SET);
964
965 /* cap at 16 extra IFDs for sanity/parse security */
966 for (int extra_tag = 0xFFFCu; extra_tag > 0xFFECu; extra_tag--) {
967 AVExifMetadata extra_ifd = { 0 };
968 for (int i = 0; i < nb_ifds; i++) {
969 if (ifd_offsets[i] == next) {
970 av_log(logctx, AV_LOG_WARNING, "EXIF IFD chain loops back to offset %d\n", next);
971 goto finish;
972 }
973 }
974 ifd_offsets[nb_ifds++] = next;
975 ret = exif_parse_ifd_list(logctx, &gbytes, le, 0, entries_left, bytes_left, &extra_ifd, 1);
976 if (ret < 0) {
977 av_exif_free(&extra_ifd);
978 break;
979 }
980 next = ret;
981 av_log(logctx, AV_LOG_DEBUG, "found extra IFD: %04x with next=%d\n", extra_tag, ret);
982 bytestream2_seek(&gbytes, next, SEEK_SET);
983 ret = av_exif_set_entry(logctx, ifd, extra_tag, AV_TIFF_IFD, 1, NULL, 0, &extra_ifd);
984 av_exif_free(&extra_ifd);
985 if (ret < 0 || !next || bytestream2_get_bytes_left(&gbytes) <= 0)
986 break;
987 }
988
989finish:
990 return bytestream2_tell(&gbytes) + off;
991}
992
993#define COLUMN_SEP(i, c) ((i) ? ((i) % (c) ? ", " : "\n") : "")
994
995static int exif_ifd_to_dict(void *logctx, const char *prefix, const AVExifMetadata *ifd, AVDictionary **metadata)
996{
997 AVBPrint bp;
998 int ret = 0;
999 char *key = NULL;
1000 char *value = NULL;
1001
1002 if (!prefix)
1003 prefix = "";
1004
1005 for (uint16_t i = 0; i < ifd->count; i++) {
1006 const AVExifEntry *entry = &ifd->entries[i];
1007 const char *name = av_exif_get_tag_name(entry->id);
1009 if (*prefix)
1010 av_bprintf(&bp, "%s/", prefix);
1011 if (name)
1012 av_bprintf(&bp, "%s", name);
1013 else
1014 av_bprintf(&bp, "0x%04X", entry->id);
1015 ret = av_bprint_finalize(&bp, &key);
1016 if (ret < 0)
1017 goto end;
1019 switch (entry->type) {
1020 case AV_TIFF_IFD:
1021 ret = exif_ifd_to_dict(logctx, key, &entry->value.ifd, metadata);
1022 if (ret < 0)
1023 goto end;
1024 break;
1025 case AV_TIFF_SHORT:
1026 case AV_TIFF_LONG:
1027 for (uint32_t j = 0; j < entry->count; j++)
1028 av_bprintf(&bp, "%s%7" PRIu32, COLUMN_SEP(j, 8), (uint32_t)entry->value.uint[j]);
1029 break;
1030 case AV_TIFF_SSHORT:
1031 case AV_TIFF_SLONG:
1032 for (uint32_t j = 0; j < entry->count; j++)
1033 av_bprintf(&bp, "%s%7" PRId32, COLUMN_SEP(j, 8), (int32_t)entry->value.sint[j]);
1034 break;
1035 case AV_TIFF_RATIONAL:
1036 case AV_TIFF_SRATIONAL:
1037 for (uint32_t j = 0; j < entry->count; j++)
1038 av_bprintf(&bp, "%s%7i:%-7i", COLUMN_SEP(j, 4), entry->value.rat[j].num, entry->value.rat[j].den);
1039 break;
1040 case AV_TIFF_DOUBLE:
1041 case AV_TIFF_FLOAT:
1042 for (uint32_t j = 0; j < entry->count; j++)
1043 av_bprintf(&bp, "%s%.15g", COLUMN_SEP(j, 4), entry->value.dbl[j]);
1044 break;
1045 case AV_TIFF_STRING:
1046 av_bprintf(&bp, "%s", entry->value.str);
1047 break;
1048 case AV_TIFF_UNDEFINED:
1049 case AV_TIFF_BYTE:
1050 for (uint32_t j = 0; j < entry->count; j++)
1051 av_bprintf(&bp, "%s%3i", COLUMN_SEP(j, 16), entry->value.ubytes[j]);
1052 break;
1053 case AV_TIFF_SBYTE:
1054 for (uint32_t j = 0; j < entry->count; j++)
1055 av_bprintf(&bp, "%s%3i", COLUMN_SEP(j, 16), entry->value.sbytes[j]);
1056 break;
1057 }
1058 if (entry->type != AV_TIFF_IFD) {
1059 if (!av_bprint_is_complete(&bp)) {
1061 ret = AVERROR(ENOMEM);
1062 goto end;
1063 }
1064 ret = av_bprint_finalize(&bp, &value);
1065 if (ret < 0)
1066 goto end;
1068 key = NULL;
1069 value = NULL;
1070 if (ret < 0)
1071 goto end;
1072 } else {
1073 av_freep(&key);
1074 }
1075 }
1076
1077end:
1078 av_freep(&key);
1079 av_freep(&value);
1080 return ret;
1081}
1082
1084{
1085 return exif_ifd_to_dict(logctx, "", ifd, metadata);
1086}
1087
1088#define EXIF_COPY(fname, srcname) do { \
1089 size_t sz; \
1090 if (av_size_mult(src->count, sizeof(*(fname)), &sz) < 0) { \
1091 ret = AVERROR(ENOMEM); \
1092 goto end; \
1093 } \
1094 (fname) = av_memdup((srcname), sz); \
1095 if (!(fname)) { \
1096 ret = AVERROR(ENOMEM); \
1097 goto end; \
1098 } \
1099} while (0)
1100
1102{
1103 int ret = 0;
1104
1105 memset(dst, 0, sizeof(*dst));
1106
1107 dst->count = src->count;
1108 dst->id = src->id;
1109 dst->type = src->type;
1110
1111 dst->ifd_offset = src->ifd_offset;
1112 if (src->ifd_lead) {
1113 dst->ifd_lead = av_memdup(src->ifd_lead, src->ifd_offset);
1114 if (!dst->ifd_lead) {
1115 ret = AVERROR(ENOMEM);
1116 goto end;
1117 }
1118 } else {
1119 dst->ifd_lead = NULL;
1120 }
1121
1122 switch(src->type) {
1123 case AV_TIFF_IFD: {
1124 AVExifMetadata *cloned = av_exif_clone_ifd(&src->value.ifd);
1125 if (!cloned) {
1126 ret = AVERROR(ENOMEM);
1127 goto end;
1128 }
1129 dst->value.ifd = *cloned;
1130 av_freep(&cloned);
1131 break;
1132 }
1133 case AV_TIFF_SHORT:
1134 case AV_TIFF_LONG:
1135 EXIF_COPY(dst->value.uint, src->value.uint);
1136 break;
1137 case AV_TIFF_SLONG:
1138 case AV_TIFF_SSHORT:
1139 EXIF_COPY(dst->value.sint, src->value.sint);
1140 break;
1141 case AV_TIFF_RATIONAL:
1142 case AV_TIFF_SRATIONAL:
1143 EXIF_COPY(dst->value.rat, src->value.rat);
1144 break;
1145 case AV_TIFF_DOUBLE:
1146 case AV_TIFF_FLOAT:
1147 EXIF_COPY(dst->value.dbl, src->value.dbl);
1148 break;
1149 case AV_TIFF_BYTE:
1150 case AV_TIFF_UNDEFINED:
1151 EXIF_COPY(dst->value.ubytes, src->value.ubytes);
1152 break;
1153 case AV_TIFF_SBYTE:
1154 EXIF_COPY(dst->value.sbytes, src->value.sbytes);
1155 break;
1156 case AV_TIFF_STRING:
1157 dst->value.str = av_memdup(src->value.str, src->count+1);
1158 if (!dst->value.str) {
1159 ret = AVERROR(ENOMEM);
1160 goto end;
1161 }
1162 break;
1163 }
1164
1165 return 0;
1166
1167end:
1168 av_freep(&dst->ifd_lead);
1169 if (src->type == AV_TIFF_IFD)
1170 av_exif_free(&dst->value.ifd);
1171 else
1172 av_freep(&dst->value.ptr);
1173 memset(dst, 0, sizeof(*dst));
1174
1175 return ret;
1176}
1177
1178static int exif_get_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int depth, AVExifEntry **value)
1179{
1180 int offset = 1;
1181
1182 if (!ifd || ifd->count && !ifd->entries || !value)
1183 return AVERROR(EINVAL);
1184
1185 for (size_t i = 0; i < ifd->count; i++) {
1186 if (ifd->entries[i].id == id) {
1187 *value = &ifd->entries[i];
1188 return i + offset;
1189 }
1190 if (ifd->entries[i].type == AV_TIFF_IFD) {
1191 if (depth < 3) {
1192 int ret = exif_get_entry(logctx, &ifd->entries[i].value.ifd, id, depth + 1, value);
1193 if (ret)
1194 return ret < 0 ? ret : ret + offset;
1195 }
1196 offset += ifd->entries[i].value.ifd.count;
1197 }
1198 }
1199
1200 return 0;
1201}
1202
1203int av_exif_get_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int flags, AVExifEntry **value)
1204{
1205 return exif_get_entry(logctx, ifd, id, (flags & AV_EXIF_FLAG_RECURSIVE) ? 0 : INT_MAX, value);
1206}
1207
1208int av_exif_set_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, enum AVTiffDataType type,
1209 uint32_t count, const uint8_t *ifd_lead, uint32_t ifd_offset, const void *value)
1210{
1211 void *temp;
1212 int ret, offset;
1214 AVExifEntry src = { 0 };
1215
1216 if (!ifd || ifd->count && !ifd->entries
1217 || ifd_lead && !ifd_offset || !ifd_lead && ifd_offset
1218 || !value || ifd->count == 0xFFFFu)
1219 return AVERROR(EINVAL);
1220
1221 ret = av_exif_get_entry(logctx, ifd, id, 0, &entry);
1222 if (ret < 0)
1223 return ret;
1224 offset = ret;
1225
1226 if (entry) {
1228 } else {
1229 size_t required_size;
1230 ret = av_size_mult(ifd->count + 1, sizeof(*ifd->entries), &required_size);
1231 if (ret < 0)
1232 return AVERROR(ENOMEM);
1233 temp = av_fast_realloc(ifd->entries, &ifd->size, required_size);
1234 if (!temp)
1235 return AVERROR(ENOMEM);
1236 ifd->entries = temp;
1237 entry = &ifd->entries[ifd->count++];
1238 }
1239
1240 src.count = count;
1241 src.id = id;
1242 src.type = type;
1243 src.ifd_lead = (uint8_t *) ifd_lead;
1244 src.ifd_offset = ifd_offset;
1245 if (type == AV_TIFF_IFD)
1246 src.value.ifd = * (const AVExifMetadata *) value;
1247 else
1248 src.value.ptr = (void *) value;
1249
1251
1252 if (ret < 0) {
1253 /* offset is the actual offset + 1 */
1254 if (offset) {
1255 size_t remaining = ifd->count - offset;
1256 /* pop the entry off the IFD by shifting everything to the left */
1257 memmove(&ifd->entries[offset - 1], &ifd->entries[offset], sizeof(*ifd->entries) * remaining);
1258 }
1259 ifd->count--;
1260 }
1261
1262 return ret;
1263}
1264
1265static int exif_remove_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int depth)
1266{
1267 int32_t index = -1;
1268 int ret = 0;
1269
1270 if (!ifd || ifd->count && !ifd->entries)
1271 return AVERROR(EINVAL);
1272
1273 for (size_t i = 0; i < ifd->count; i++) {
1274 if (ifd->entries[i].id == id) {
1275 index = i;
1276 break;
1277 }
1278 if (ifd->entries[i].type == AV_TIFF_IFD && depth < 3) {
1279 ret = exif_remove_entry(logctx, &ifd->entries[i].value.ifd, id, depth + 1);
1280 if (ret)
1281 return ret;
1282 }
1283 }
1284
1285 if (index < 0)
1286 return 0;
1288
1289 if (index == --ifd->count) {
1290 if (!index) {
1291 av_freep(&ifd->entries);
1292 ifd->size = 0;
1293 }
1294 return 1;
1295 }
1296
1297 memmove(&ifd->entries[index], &ifd->entries[index + 1], (ifd->count - index) * sizeof(*ifd->entries));
1298
1299 return 1 + (ifd->count - index);
1300}
1301
1302int av_exif_remove_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int flags)
1303{
1304 return exif_remove_entry(logctx, ifd, id, (flags & AV_EXIF_FLAG_RECURSIVE) ? 0 : INT_MAX);
1305}
1306
1308{
1309 AVExifMetadata *ret = av_mallocz(sizeof(*ret));
1310 if (!ret)
1311 return NULL;
1312
1313 ret->count = ifd->count;
1314 if (ret->count) {
1315 size_t required_size;
1316 if (av_size_mult(ret->count, sizeof(*ret->entries), &required_size) < 0)
1317 goto fail;
1318 av_fast_mallocz(&ret->entries, &ret->size, required_size);
1319 if (!ret->entries)
1320 goto fail;
1321 }
1322
1323 for (size_t i = 0; i < ret->count; i++) {
1324 const AVExifEntry *entry = &ifd->entries[i];
1325 AVExifEntry *ret_entry = &ret->entries[i];
1326 int status = exif_clone_entry(ret_entry, entry);
1327 if (status < 0)
1328 goto fail;
1329 }
1330
1331 return ret;
1332
1333fail:
1335 av_free(ret);
1336 return NULL;
1337}
1338
1339static const int rotation_lut[2][4] = {
1340 {1, 8, 3, 6}, {4, 7, 2, 5},
1341};
1342
1344{
1345 double rotation = av_display_rotation_get(matrix);
1346 // determinant
1347 int vflip = ((int64_t)matrix[0] * (int64_t)matrix[4]
1348 - (int64_t)matrix[1] * (int64_t)matrix[3]) < 0;
1349 if (!isfinite(rotation))
1350 return 0;
1351 int rot = (int)(rotation + 0.5);
1352 rot = (((rot % 360) + 360) % 360) / 90;
1353 return rotation_lut[vflip][rot];
1354}
1355
1357{
1358 switch (orientation) {
1359 case 1:
1361 break;
1362 case 2:
1365 break;
1366 case 3:
1368 break;
1369 case 4:
1372 break;
1373 case 5:
1376 break;
1377 case 6:
1379 break;
1380 case 7:
1383 break;
1384 case 8:
1386 break;
1387 default:
1388 return AVERROR(EINVAL);
1389 }
1390
1391 return 0;
1392}
1393
1394int ff_exif_sanitize_ifd(void *logctx, const AVFrame *frame, AVExifMetadata *ifd)
1395{
1396 int ret = 0;
1397 AVFrameSideData *sd_orient = NULL;
1398 AVExifEntry *or = NULL;
1399 AVExifEntry *iw = NULL;
1400 AVExifEntry *ih = NULL;
1401 AVExifEntry *pw = NULL;
1402 AVExifEntry *ph = NULL;
1403 uint64_t orientation = 1;
1404 uint64_t w = frame->width;
1405 uint64_t h = frame->height;
1406 int rewrite = 0;
1407
1409
1410 if (sd_orient)
1411 orientation = av_exif_matrix_to_orientation((int32_t *) sd_orient->data);
1412 if (!orientation) {
1413 av_log(logctx, AV_LOG_WARNING, "display matrix is singular\n");
1414 orientation = 1;
1415 }
1416 if (orientation != 1)
1417 av_log(logctx, AV_LOG_DEBUG, "matrix contains nontrivial EXIF orientation: %" PRIu64 "\n", orientation);
1418
1419 for (size_t i = 0; i < ifd->count; i++) {
1420 AVExifEntry *entry = &ifd->entries[i];
1421 if (entry->id == ORIENTATION_TAG && entry->count > 0 && entry->type == AV_TIFF_SHORT) {
1422 or = entry;
1423 continue;
1424 }
1425 if (entry->id == IMAGE_WIDTH_TAG && entry->count > 0 && entry->type == AV_TIFF_LONG) {
1426 iw = entry;
1427 continue;
1428 }
1429 if (entry->id == IMAGE_LENGTH_TAG && entry->count > 0 && entry->type == AV_TIFF_LONG) {
1430 ih = entry;
1431 continue;
1432 }
1433 if (entry->id == EXIFIFD_TAG && entry->type == AV_TIFF_IFD) {
1434 AVExifMetadata *exif = &entry->value.ifd;
1435 for (size_t j = 0; j < exif->count; j++) {
1436 AVExifEntry *exifentry = &exif->entries[j];
1437 if (exifentry->id == PIXEL_X_TAG && exifentry->count > 0 && exifentry->type == AV_TIFF_SHORT) {
1438 pw = exifentry;
1439 continue;
1440 }
1441 if (exifentry->id == PIXEL_Y_TAG && exifentry->count > 0 && exifentry->type == AV_TIFF_SHORT) {
1442 ph = exifentry;
1443 continue;
1444 }
1445 }
1446 }
1447 }
1448
1449 if (or && or->value.uint[0] != orientation) {
1450 rewrite = 1;
1451 or->value.uint[0] = orientation;
1452 }
1453 if (iw && iw->value.uint[0] != w) {
1454 rewrite = 1;
1455 iw->value.uint[0] = w;
1456 }
1457 if (ih && ih->value.uint[0] != h) {
1458 rewrite = 1;
1459 ih->value.uint[0] = h;
1460 }
1461 if (pw && pw->value.uint[0] != w) {
1462 rewrite = 1;
1463 pw->value.uint[0] = w;
1464 }
1465 if (ph && ph->value.uint[0] != h) {
1466 rewrite = 1;
1467 ph->value.uint[0] = h;
1468 }
1469 if (!or && orientation != 1) {
1470 rewrite = 1;
1471 ret = av_exif_set_entry(logctx, ifd, ORIENTATION_TAG, AV_TIFF_SHORT, 1, NULL, 0, &orientation);
1472 if (ret < 0)
1473 goto end;
1474 }
1475 if (!iw && w) {
1476 rewrite = 1;
1477 ret = av_exif_set_entry(logctx, ifd, IMAGE_WIDTH_TAG, AV_TIFF_LONG, 1, NULL, 0, &w);
1478 if (ret < 0)
1479 goto end;
1480 }
1481 if (!ih && h) {
1482 rewrite = 1;
1483 ret = av_exif_set_entry(logctx, ifd, IMAGE_LENGTH_TAG, AV_TIFF_LONG, 1, NULL, 0, &h);
1484 if (ret < 0)
1485 goto end;
1486 }
1487 if (!pw && w && w <= 0xFFFFu || !ph && h && h <= 0xFFFFu) {
1488 AVExifMetadata *exif;
1489 AVExifEntry *exif_entry;
1490 int exif_found = av_exif_get_entry(logctx, ifd, EXIFIFD_TAG, 0, &exif_entry);
1491 rewrite = 1;
1492 if (exif_found < 0)
1493 goto end;
1494 if (exif_found > 0) {
1495 exif = &exif_entry->value.ifd;
1496 } else {
1497 AVExifMetadata exif_new = { 0 };
1498 ret = av_exif_set_entry(logctx, ifd, EXIFIFD_TAG, AV_TIFF_IFD, 1, NULL, 0, &exif_new);
1499 if (ret < 0) {
1500 av_exif_free(&exif_new);
1501 goto end;
1502 }
1503 exif = &ifd->entries[ifd->count - 1].value.ifd;
1504 }
1505 if (!pw && w && w <= 0xFFFFu) {
1506 ret = av_exif_set_entry(logctx, exif, PIXEL_X_TAG, AV_TIFF_SHORT, 1, NULL, 0, &w);
1507 if (ret < 0)
1508 goto end;
1509 }
1510 if (!ph && h && h <= 0xFFFFu) {
1511 ret = av_exif_set_entry(logctx, exif, PIXEL_Y_TAG, AV_TIFF_SHORT, 1, NULL, 0, &h);
1512 if (ret < 0)
1513 goto end;
1514 }
1515 }
1516
1517 return rewrite;
1518
1519end:
1520 return ret;
1521}
1522
1523int ff_exif_get_buffer(void *logctx, const AVFrame *frame, AVBufferRef **buffer_ptr, enum AVExifHeaderMode header_mode)
1524{
1525 AVFrameSideData *sd_exif = NULL;
1527 AVExifMetadata ifd = { 0 };
1528 int ret = 0;
1529 int rewrite = 0;
1530
1531 if (!buffer_ptr || *buffer_ptr)
1532 return AVERROR(EINVAL);
1533
1536 return 0;
1537
1538 if (sd_exif) {
1539 ret = av_exif_parse_buffer(logctx, sd_exif->data, sd_exif->size, &ifd, AV_EXIF_TIFF_HEADER);
1540 if (ret < 0)
1541 goto end;
1542 }
1543
1544 rewrite = ff_exif_sanitize_ifd(logctx, frame, &ifd);
1545 if (rewrite < 0) {
1546 ret = rewrite;
1547 goto end;
1548 }
1549
1550 /*
1551 * we always have to rewrite if the requested header mode
1552 * does not match the internal header mode, which is always
1553 * AV_EXIF_TIFF_HEADER inside FFmpeg.
1554 *
1555 * If ifd.count == 0 then there's no data to write at all.
1556 * This is possible if the frame width and height are zero and the orientation is 1.
1557 */
1558 rewrite = (rewrite || header_mode != AV_EXIF_TIFF_HEADER) && ifd.count;
1559
1560 if (rewrite) {
1561 ret = av_exif_write(logctx, &ifd, &buffer, header_mode);
1562 if (ret < 0)
1563 goto end;
1564
1565 *buffer_ptr = buffer;
1566 } else if (sd_exif) {
1567 *buffer_ptr = av_buffer_ref(sd_exif->buf);
1568 if (!*buffer_ptr) {
1569 ret = AVERROR(ENOMEM);
1570 goto end;
1571 }
1572 }
1573
1574 av_exif_free(&ifd);
1575
1576 return !!(rewrite || sd_exif);
1577
1578end:
1579 av_exif_free(&ifd);
1580 return ret;
1581}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
#define entry
static void finish(void)
int32_t
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
static int BS_FUNC tell(const BSCTX *bc)
Return number of bits already read.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition bprint.c:121
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:68
AVBPrint public header.
#define AV_BPRINT_SIZE_UNLIMITED
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
Definition bytestream.h:197
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition bytestream.h:267
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition bytestream.h:147
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
Definition bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition bytestream.h:137
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
Definition bytestream.h:212
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
Definition bytestream.h:236
static av_always_inline int bytestream2_tell(const GetByteContext *g)
Definition bytestream.h:192
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition bytestream.h:286
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static int FUNC ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVFrame * frame
Display matrix.
enum AVCodecID id
Definition dts2pts.c:612
double value
Definition eval.c:102
#define ORIENTATION_TAG
Definition exif.c:51
static const uint8_t sigma_header[]
Definition exif.c:430
int av_exif_get_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int flags, AVExifEntry **value)
Get an entry with the tagged ID from the EXIF metadata struct.
Definition exif.c:1203
#define EXIFIFD_TAG
Definition exif.c:52
#define PIXEL_Y_TAG
Definition exif.c:56
#define IMAGE_LENGTH_TAG
Definition exif.c:54
static void exif_write_values(PutByteContext *pb, int le, const AVExifEntry *entry)
Definition exif.c:370
static const struct exif_makernote_data makernote_data[]
Definition exif.c:445
static const uint8_t panasonic_header[]
Definition exif.c:429
static void tput16(PutByteContext *pb, const int le, const uint16_t value)
Definition exif.c:258
static void tput64(PutByteContext *pb, const int le, const uint64_t value)
Definition exif.c:268
static int exif_decode_tag(void *logctx, GetByteContext *gb, int le, int depth, int *entries_left, size_t *bytes_left, int guess, AVExifEntry *entry)
Definition exif.c:488
static const uint8_t olympus2_header[]
Definition exif.c:428
static int exif_get_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int depth, AVExifEntry **value)
Definition exif.c:1178
static int exif_remove_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int depth)
Definition exif.c:1265
static int exif_clone_entry(AVExifEntry *dst, const AVExifEntry *src)
Definition exif.c:1101
static const struct exif_tag tag_list[]
Definition exif.c:63
static void exif_free_entry(AVExifEntry *entry)
Definition exif.c:667
static const uint8_t foveon_header[]
Definition exif.c:424
int av_exif_set_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, enum AVTiffDataType type, uint32_t count, const uint8_t *ifd_lead, uint32_t ifd_offset, const void *value)
Add an entry to the provided EXIF metadata struct.
Definition exif.c:1208
#define BASE_TAG_SIZE
Definition exif.c:46
int av_exif_parse_buffer(void *logctx, const uint8_t *buf, size_t size, AVExifMetadata *ifd, enum AVExifHeaderMode header_mode)
Decodes the EXIF data provided in the buffer and writes it into the struct *ifd.
Definition exif.c:901
static size_t exif_get_ifd_size(const AVExifMetadata *ifd)
Definition exif.c:696
int av_exif_ifd_to_dict(void *logctx, const AVExifMetadata *ifd, AVDictionary **metadata)
Recursively reads all tags from the IFD and stores them in the provided metadata dictionary.
Definition exif.c:1083
void av_exif_free(AVExifMetadata *ifd)
Frees all resources associated with the given EXIF metadata struct.
Definition exif.c:678
static const uint8_t aoc_header[]
Definition exif.c:421
int av_exif_matrix_to_orientation(const int32_t *matrix)
Convert a display matrix used by AV_FRAME_DATA_DISPLAYMATRIX into an orientation constant used by EXI...
Definition exif.c:1343
static const uint8_t casio_header[]
Definition exif.c:423
#define PIXEL_X_TAG
Definition exif.c:55
static const uint8_t fuji_header[]
Definition exif.c:425
const char * av_exif_get_tag_name(uint16_t id)
Retrieves the tag name associated with the provided tag ID.
Definition exif.c:235
#define MAKERNOTE_STRUCT(h, r)
Definition exif.c:439
int av_exif_orientation_to_matrix(int32_t *matrix, int orientation)
Convert an orientation constant used by EXIF's orientation tag into a display matrix used by AV_FRAME...
Definition exif.c:1356
static const uint8_t olympus1_header[]
Definition exif.c:427
int ff_exif_get_buffer(void *logctx, const AVFrame *frame, AVBufferRef **buffer_ptr, enum AVExifHeaderMode header_mode)
Gets all relevant side data, collects it into an IFD, and writes it into the corresponding buffer poi...
Definition exif.c:1523
#define EXIF_II_LONG
Definition exif.c:43
AVExifMetadata * av_exif_clone_ifd(const AVExifMetadata *ifd)
Allocates a duplicate of the provided EXIF metadata struct.
Definition exif.c:1307
static const int rotation_lut[2][4]
Definition exif.c:1339
#define IMAGE_WIDTH_TAG
Definition exif.c:53
static int exif_parse_ifd_list(void *logctx, GetByteContext *gb, int le, int depth, int *entries_left, size_t *bytes_left, AVExifMetadata *ifd, int guess)
Definition exif.c:570
static int exif_read_values(void *logctx, GetByteContext *gb, int le, size_t *bytes_left, AVExifEntry *entry)
Definition exif.c:273
static int exif_ifd_to_dict(void *logctx, const char *prefix, const AVExifMetadata *ifd, AVDictionary **metadata)
Definition exif.c:995
#define EXIF_COPY(fname, srcname)
Definition exif.c:1088
#define MAKERNOTE_TAG
Definition exif.c:50
int ff_exif_sanitize_ifd(void *logctx, const AVFrame *frame, AVExifMetadata *ifd)
Compares values in the IFD with data in the provided AVFrame and sets the values in that IFD to match...
Definition exif.c:1394
int av_exif_write(void *logctx, const AVExifMetadata *ifd, AVBufferRef **buffer, enum AVExifHeaderMode header_mode)
Allocates a buffer using av_malloc of an appropriate size and writes the EXIF data represented by ifd...
Definition exif.c:772
#define COLUMN_SEP(i, c)
Definition exif.c:993
#define IFD_EXTRA_SIZE
Definition exif.c:47
#define EXIF_TAG_NAME_LENGTH
Definition exif.c:49
static int exif_write_ifd(void *logctx, PutByteContext *pb, int le, int depth, const AVExifMetadata *ifd)
Definition exif.c:713
int32_t av_exif_get_tag_id(const char *name)
Retrieves the tag ID associated with the provided tag string name.
Definition exif.c:245
static void tput32(PutByteContext *pb, const int le, const uint32_t value)
Definition exif.c:263
static const uint8_t apple_header[]
Definition exif.c:422
int av_exif_remove_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int flags)
Remove an entry from the provided EXIF metadata struct.
Definition exif.c:1302
#define EXIF_MM_LONG
Definition exif.c:44
static const uint8_t sony_header[]
Definition exif.c:431
static const size_t exif_sizes[]
Definition exif.c:218
static const uint8_t nikon_header[]
Definition exif.c:426
static int exif_get_makernote_offset(GetByteContext *gb)
Definition exif.c:463
AVTiffDataType
Data type identifiers for TIFF tags.
Definition exif.h:41
@ AV_TIFF_SLONG
Definition exif.h:50
@ AV_TIFF_STRING
Definition exif.h:43
@ AV_TIFF_FLOAT
Definition exif.h:52
@ AV_TIFF_SBYTE
Definition exif.h:47
@ AV_TIFF_SHORT
Definition exif.h:44
@ AV_TIFF_SRATIONAL
Definition exif.h:51
@ AV_TIFF_SSHORT
Definition exif.h:49
@ AV_TIFF_RATIONAL
Definition exif.h:46
@ AV_TIFF_LONG
Definition exif.h:45
@ AV_TIFF_IFD
Definition exif.h:54
@ AV_TIFF_DOUBLE
Definition exif.h:53
@ AV_TIFF_BYTE
Definition exif.h:42
@ AV_TIFF_UNDEFINED
Definition exif.h:48
#define AV_EXIF_FLAG_RECURSIVE
Also check subdirectories.
Definition exif.h:149
AVExifHeaderMode
Definition exif.h:57
@ AV_EXIF_EXIF00
The first six bytes contain "Exif\0\0", then it's AV_EXIF_TIFF_HEADER.
Definition exif.h:70
@ AV_EXIF_TIFF_HEADER
The TIFF header starts with 0x49492a00, or 0x4d4d002a.
Definition exif.h:62
@ AV_EXIF_ASSUME_BE
skip the TIFF header, assume big endian
Definition exif.h:66
@ AV_EXIF_ASSUME_LE
skip the TIFF header, assume little endian
Definition exif.h:64
@ AV_EXIF_T_OFF
The first four bytes point to the actual start, then it's AV_EXIF_TIFF_HEADER.
Definition exif.h:68
EXIF metadata parser - internal functions.
const char * key
int ret
Definition ffplay.c:391
#define fail
Definition test.h:479
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition bprint.h:218
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition bprint.c:234
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:140
int av_buffer_realloc(AVBufferRef **pbuf, size_t size)
Reallocate a given buffer.
Definition buffer.c:184
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:104
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
Definition dict.h:79
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:87
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that's been allocated with av_malloc() or another memory allocation function.
Definition dict.h:77
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:662
@ AV_FRAME_DATA_EXIF
Exchangeable image file format metadata.
Definition frame.h:263
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition frame.h:85
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
Allocate and clear a buffer, reusing the given one if large enough.
Definition mem.c:666
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition mem.c:601
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition mem.c:408
int av_size_mult(size_t a, size_t b, size_t *r)
Multiply two size_t values checking for overflow.
Definition mem.c:671
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure clockwise rotation by the specified angle (in de...
Definition display.c:50
double av_display_rotation_get(const int32_t matrix[9])
Extract the rotation component of the transformation matrix.
Definition display.c:34
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
Definition display.c:65
int index
Definition gxfenc.c:90
int a
#define AV_WN32(p, v)
#define AV_WL32(p, v)
#define AV_RB32(p)
#define AV_WN16(p, v)
enum MPFType type
Definition jpegmpfenc.c:55
unsigned offset
Definition libaomenc.c:763
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
uint8_t w
Definition llvidencdsp.c:39
#define MKTAG(a, b, c, d)
Definition macros.h:55
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:370
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
const char * name
Definition qsvenc.c:142
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
size_t size
Size of data in bytes.
Definition buffer.h:94
AVExifMetadata ifd
Definition exif.h:114
enum AVTiffDataType type
Definition exif.h:86
uint16_t id
Definition exif.h:85
uint32_t count
Definition exif.h:87
union AVExifEntry::@325220332140161067313112036135003363017341144014 value
uint64_t * uint
Definition exif.h:108
unsigned int count
Definition exif.h:79
AVExifEntry * entries
Definition exif.h:77
unsigned int size
Definition exif.h:81
Structure to hold side data for an AVFrame.
Definition frame.h:334
size_t size
Definition frame.h:337
uint8_t * data
Definition frame.h:336
AVBufferRef * buf
Definition frame.h:339
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
const uint8_t * buffer
Definition bytestream.h:34
uint8_t * buffer
Definition bytestream.h:38
Definition mccdec.c:79
size_t header_size
Definition exif.c:435
const uint8_t * header
Definition exif.c:434
const char name[EXIF_TAG_NAME_LENGTH]
Definition exif.c:59
uint16_t id
Definition exif.c:60
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
int num
Definition error.c:23
static void vflip(AVFrame *frame, const AVPixFmtDescriptor *desc)
static char buffer[20]
Definition seek.c:33
int ff_tis_ifd(unsigned tag)
Returns a value > 0 if the tag is a known IFD-tag.
Definition tiff_common.c:33
int ff_tdecode_header(GetByteContext *gb, int *le, int *ifd_offset)
Decodes a TIFF header from the input bytestream and sets the endianness in *le and the offset to the ...
unsigned ff_tget_short(GetByteContext *gb, int le)
Reads a short from the bytestream using given endianness.
Definition tiff_common.c:45
double ff_tget_double(GetByteContext *gb, int le)
Reads a double from the bytestream using given endianness.
Definition tiff_common.c:57
unsigned ff_tget_long(GetByteContext *gb, int le)
Reads a long from the bytestream using given endianness.
Definition tiff_common.c:51
TIFF Common Routines.
int size
char prefix[8]
else temp
Definition vf_mcdeint.c:275