FFmpeg
|
#include <inttypes.h>
#include "libavutil/avconfig.h"
#include "libavutil/bprint.h"
#include "libavutil/display.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "bytestream.h"
#include "exif_internal.h"
#include "tiff_common.h"
Go to the source code of this file.
Data Structures | |
struct | exif_tag |
struct | exif_makernote_data |
Macros | |
#define | EXIF_II_LONG 0x49492a00 |
#define | EXIF_MM_LONG 0x4d4d002a |
#define | BASE_TAG_SIZE 12 |
#define | IFD_EXTRA_SIZE 6 |
#define | EXIF_TAG_NAME_LENGTH 32 |
#define | MAKERNOTE_TAG 0x927c |
#define | ORIENTATION_TAG 0x112 |
#define | EXIFIFD_TAG 0x8769 |
#define | IMAGE_WIDTH_TAG 0x100 |
#define | IMAGE_LENGTH_TAG 0x101 |
#define | PIXEL_X_TAG 0xa002 |
#define | PIXEL_Y_TAG 0xa003 |
#define | MAKERNOTE_STRUCT(h, r) |
#define | COLUMN_SEP(i, c) ((i) ? ((i) % (c) ? ", " : "\n") : "") |
#define | EXIF_COPY(fname, srcname) |
Functions | |
const char * | av_exif_get_tag_name (uint16_t id) |
Retrieves the tag name associated with the provided tag ID. More... | |
int32_t | av_exif_get_tag_id (const char *name) |
Retrieves the tag ID associated with the provided tag string name. More... | |
static void | tput16 (PutByteContext *pb, const int le, const uint16_t value) |
static void | tput32 (PutByteContext *pb, const int le, const uint32_t value) |
static void | tput64 (PutByteContext *pb, const int le, const uint64_t value) |
static int | exif_read_values (void *logctx, GetByteContext *gb, int le, AVExifEntry *entry) |
static void | exif_write_values (PutByteContext *pb, int le, const AVExifEntry *entry) |
static int | exif_get_makernote_offset (GetByteContext *gb) |
static int | exif_parse_ifd_list (void *logctx, GetByteContext *gb, int le, int depth, AVExifMetadata *ifd) |
static int | exif_decode_tag (void *logctx, GetByteContext *gb, int le, int depth, AVExifEntry *entry) |
static void | exif_free_entry (AVExifEntry *entry) |
void | av_exif_free (AVExifMetadata *ifd) |
Frees all resources associated with the given EXIF metadata struct. More... | |
static size_t | exif_get_ifd_size (const AVExifMetadata *ifd) |
static int | exif_write_ifd (void *logctx, PutByteContext *pb, int le, int depth, const AVExifMetadata *ifd) |
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 into that buffer. More... | |
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. More... | |
static int | exif_ifd_to_dict (void *logctx, const char *prefix, const AVExifMetadata *ifd, AVDictionary **metadata) |
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. More... | |
int | avpriv_exif_decode_ifd (void *logctx, const uint8_t *buf, int size, int le, int depth, AVDictionary **metadata) |
static int | exif_clone_entry (AVExifEntry *dst, const AVExifEntry *src) |
static int | exif_get_entry (void *logctx, AVExifMetadata *ifd, uint16_t id, int depth, AVExifEntry **value) |
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. More... | |
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. More... | |
static int | exif_remove_entry (void *logctx, AVExifMetadata *ifd, uint16_t id, int depth) |
int | av_exif_remove_entry (void *logctx, AVExifMetadata *ifd, uint16_t id, int flags) |
Remove an entry from the provided EXIF metadata struct. More... | |
AVExifMetadata * | av_exif_clone_ifd (const AVExifMetadata *ifd) |
Allocates a duplicate of the provided EXIF metadata struct. More... | |
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 EXIF's orientation tag. More... | |
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_DATA_DISPLAYMATRIX. More... | |
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 the ones in that AVFrame. More... | |
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 pointer. More... | |
Variables | |
static const struct exif_tag | tag_list [] |
static const size_t | exif_sizes [] |
static const uint8_t | aoc_header [] = { 'A', 'O', 'C', 0, } |
static const uint8_t | casio_header [] = { 'Q', 'V', 'C', 0, 0, 0, } |
static const uint8_t | foveon_header [] = { 'F', 'O', 'V', 'E', 'O', 'N', 0, 0, } |
static const uint8_t | fuji_header [] = { 'F', 'U', 'J', 'I', } |
static const uint8_t | nikon_header [] = { 'N', 'i', 'k', 'o', 'n', 0, } |
static const uint8_t | olympus1_header [] = { 'O', 'L', 'Y', 'M', 'P', 0, } |
static const uint8_t | olympus2_header [] = { 'O', 'L', 'Y', 'M', 'P', 'U', 'S', 0, 'I', 'I', } |
static const uint8_t | panasonic_header [] = { 'P', 'a', 'n', 'a', 's', 'o', 'n', 'i', 'c', 0, 0, 0, } |
static const uint8_t | sigma_header [] = { 'S', 'I', 'G', 'M', 'A', 0, 0, 0, } |
static const uint8_t | sony_header [] = { 'S', 'O', 'N', 'Y', ' ', 'D', 'S', 'C', ' ', 0, 0, 0, } |
static const struct exif_makernote_data | makernote_data [] |
static const int | rotation_lut [2][4] |
EXIF metadata parser
Definition in file exif.c.
#define EXIF_COPY | ( | fname, | |
srcname | |||
) |
const char* av_exif_get_tag_name | ( | uint16_t | id | ) |
Retrieves the tag name associated with the provided tag ID.
If the tag ID is unknown, NULL is returned.
For example, av_exif_get_tag_name(0x112) returns "Orientation".
Definition at line 215 of file exif.c.
Referenced by exif_ifd_to_dict().
int32_t av_exif_get_tag_id | ( | const char * | name | ) |
Retrieves the tag ID associated with the provided tag string name.
If the tag name is unknown, a negative number is returned. Otherwise it always fits inside a uint16_t integer.
For example, av_exif_get_tag_id("Orientation") returns 274 (0x0112).
Definition at line 225 of file exif.c.
Referenced by exif_attach_ifd(), libjxl_preprocess_stream(), libjxl_receive_frame(), mov_parse_exif_item(), and side_data_exif_parse().
|
inlinestatic |
Definition at line 238 of file exif.c.
Referenced by exif_write_ifd(), and exif_write_values().
|
inlinestatic |
Definition at line 243 of file exif.c.
Referenced by av_exif_write(), exif_write_ifd(), and exif_write_values().
|
inlinestatic |
Definition at line 248 of file exif.c.
Referenced by exif_write_values().
|
static |
Definition at line 253 of file exif.c.
Referenced by exif_decode_tag().
|
static |
Definition at line 343 of file exif.c.
Referenced by exif_write_ifd().
|
static |
Definition at line 434 of file exif.c.
Referenced by exif_decode_tag().
|
static |
Definition at line 534 of file exif.c.
Referenced by av_exif_parse_buffer(), avpriv_exif_decode_ifd(), and exif_decode_tag().
|
static |
Definition at line 458 of file exif.c.
Referenced by exif_parse_ifd_list().
|
static |
Definition at line 598 of file exif.c.
Referenced by av_exif_free(), av_exif_set_entry(), and exif_remove_entry().
void av_exif_free | ( | AVExifMetadata * | ifd | ) |
Frees all resources associated with the given EXIF metadata struct.
Does not free the pointer passed itself, in case it is stack-allocated. The pointer passed to this function must be freed by the caller, if it is heap-allocated. Passing NULL is permitted.
Definition at line 609 of file exif.c.
Referenced by av_exif_clone_ifd(), av_exif_parse_buffer(), avi_extract_stream_metadata(), avpriv_exif_decode_ifd(), decode_frame(), exif_attach_ifd(), exif_clone_entry(), exif_decode_tag(), exif_free_entry(), ff_decode_exif_attach_buffer(), ff_exif_get_buffer(), ff_exif_sanitize_ifd(), ff_mjpeg_decode_end(), ff_mjpeg_decode_frame_from_buf(), libjxl_preprocess_stream(), libjxl_receive_frame(), mov_parse_exif_item(), side_data_exif_parse(), and tiff_end().
|
static |
Definition at line 627 of file exif.c.
Referenced by av_exif_write(), and exif_write_ifd().
|
static |
Definition at line 644 of file exif.c.
Referenced by av_exif_write().
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 into that buffer.
Upon error, *buffer will be NULL. The buffer becomes owned by the caller upon success. The *buffer argument must be NULL before calling.
Definition at line 703 of file exif.c.
Referenced by exif_attach_ifd(), ff_exif_get_buffer(), libjxl_preprocess_stream(), mov_parse_exif_item(), and side_data_exif_parse().
int av_exif_parse_buffer | ( | void * | logctx, |
const uint8_t * | data, | ||
size_t | size, | ||
AVExifMetadata * | ifd, | ||
enum AVExifHeaderMode | header_mode | ||
) |
Decodes the EXIF data provided in the buffer and writes it into the struct *ifd.
If this function succeeds, the IFD is owned by the caller and must be cleared after use by calling av_exif_free(); If this function fails and returns a negative value, it will call av_exif_free(ifd) before returning.
Definition at line 764 of file exif.c.
Referenced by avi_extract_stream_metadata(), decode_frame(), ff_decode_exif_attach_buffer(), ff_exif_get_buffer(), libjxl_preprocess_stream(), libjxl_receive_frame(), mjpeg_decode_app(), mov_parse_exif_item(), and side_data_exif_parse().
|
static |
Definition at line 826 of file exif.c.
Referenced by av_exif_ifd_to_dict().
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 at line 914 of file exif.c.
Referenced by avi_extract_stream_metadata(), avpriv_exif_decode_ifd(), exif_attach_ifd(), and side_data_exif_parse().
int avpriv_exif_decode_ifd | ( | void * | logctx, |
const uint8_t * | buf, | ||
int | size, | ||
int | le, | ||
int | depth, | ||
AVDictionary ** | metadata | ||
) |
|
static |
Definition at line 949 of file exif.c.
Referenced by av_exif_clone_ifd(), and av_exif_set_entry().
|
static |
Definition at line 1024 of file exif.c.
Referenced by av_exif_get_entry().
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.
A pointer to the entry will be written into *value.
If the entry was present and returned successfully, a positive number is returned. If the entry was not found, *value is left untouched and zero is returned. If an error occurred, a negative number is returned.
Definition at line 1049 of file exif.c.
Referenced by av_exif_set_entry(), ff_exif_sanitize_ifd(), libjxl_preprocess_stream(), and side_data_exif_parse().
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.
If one already exists with the provided ID, it will set the existing one to have the other information provided. Otherwise, it will allocate a new entry.
This function reallocates ifd->entries using av_realloc and allocates (using av_malloc) a new value member of the entry, then copies the contents of value into that buffer.
Definition at line 1054 of file exif.c.
Referenced by ff_exif_sanitize_ifd().
|
static |
Definition at line 1103 of file exif.c.
Referenced by av_exif_remove_entry().
int av_exif_remove_entry | ( | void * | logctx, |
AVExifMetadata * | ifd, | ||
uint16_t | id, | ||
int | flags | ||
) |
Remove an entry from the provided EXIF metadata struct.
If the entry was present and removed successfully, a positive number is returned. If the entry was not found, zero is returned. If an error occurred, a negative number is returned.
Definition at line 1138 of file exif.c.
Referenced by exif_attach_ifd(), libjxl_preprocess_stream(), libjxl_receive_frame(), mov_parse_exif_item(), and side_data_exif_parse().
AVExifMetadata* av_exif_clone_ifd | ( | const AVExifMetadata * | ifd | ) |
Allocates a duplicate of the provided EXIF metadata struct.
The caller owns the duplicate and must free it with av_exif_free. Returns NULL if the duplication process failed.
Definition at line 1143 of file exif.c.
Referenced by exif_attach_ifd(), and exif_clone_entry().
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 EXIF's orientation tag.
Returns an EXIF orientation between 1 and 8 (inclusive) depending on the rotation and flip factors. Returns 0 if the matrix is singular.
Definition at line 1179 of file exif.c.
Referenced by ff_exif_sanitize_ifd(), and libjxl_preprocess_stream().
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_DATA_DISPLAYMATRIX.
Returns 0 on success and negative if the orientation is invalid, i.e. not between 1 and 8 (inclusive).
Definition at line 1192 of file exif.c.
Referenced by attach_displaymatrix(), libjxl_preprocess_stream(), and side_data_exif_parse().
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 the ones in that AVFrame.
This is mostly useful for an encoder that wishes to use ff_exif_get_buffer, but would prefer to modify the IFD after it is sanitized and call av_exif_write afterward.
Definition at line 1230 of file exif.c.
Referenced by ff_exif_get_buffer(), and libjxl_preprocess_stream().
int ff_exif_get_buffer | ( | void * | logctx, |
const AVFrame * | frame, | ||
AVBufferRef ** | buffer, | ||
enum AVExifHeaderMode | header_mode | ||
) |
Gets all relevant side data, collects it into an IFD, and writes it into the corresponding buffer pointer.
This includes both AV_FRAME_DATA_EXIF and other side data types that are included in the frame data, such as possibly an instance of AV_FRAME_DATA_DISPLAYMATRIX. It also sets width and height tags to match those of the AVFrame if they are different.
Upon error, *buffer will be NULL. The buffer becomes owned by the caller upon success. The *buffer argument must be NULL before calling. If *buffer is NULL upon return then a negative return value indicates an error, and a zero return value indicates that there was no EXIF data to write.
Definition at line 1355 of file exif.c.
Referenced by encode_headers().
|
static |
Definition at line 62 of file exif.c.
Referenced by amv_write_alist(), amv_write_vlist(), av_exif_get_tag_id(), and av_exif_get_tag_name().
|
static |
Definition at line 198 of file exif.c.
Referenced by exif_decode_tag(), exif_get_ifd_size(), and exif_write_ifd().
Definition at line 398 of file exif.c.
Referenced by exif_get_makernote_offset().
|
static |
Definition at line 417 of file exif.c.
Referenced by exif_get_makernote_offset().
|
static |
Definition at line 1175 of file exif.c.
Referenced by av_exif_matrix_to_orientation().