exif-data.c File Reference

#include <config.h>
#include <libexif/exif-mnote-data.h>
#include <libexif/exif-data.h>
#include <libexif/exif-ifd.h>
#include <libexif/exif-mnote-data-priv.h>
#include <libexif/exif-utils.h>
#include <libexif/exif-loader.h>
#include <libexif/exif-log.h>
#include <libexif/i18n.h>
#include <libexif/exif-system.h>
#include <libexif/canon/exif-mnote-data-canon.h>
#include <libexif/fuji/exif-mnote-data-fuji.h>
#include <libexif/olympus/exif-mnote-data-olympus.h>
#include <libexif/pentax/exif-mnote-data-pentax.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  _ExifDataPrivate
struct  _ByteOrderChangeData

Defines

#define JPEG_MARKER_SOI   0xd8
#define JPEG_MARKER_APP0   0xe0
#define JPEG_MARKER_APP1   0xe1
#define CHECK_REC(i)
#define LOG_TOO_SMALL

Typedefs

typedef struct
_ByteOrderChangeData 
ByteOrderChangeData

Enumerations

enum  ExifDataTypeMakerNote {
  EXIF_DATA_TYPE_MAKER_NOTE_NONE = 0, EXIF_DATA_TYPE_MAKER_NOTE_CANON = 1, EXIF_DATA_TYPE_MAKER_NOTE_OLYMPUS = 2, EXIF_DATA_TYPE_MAKER_NOTE_PENTAX = 3,
  EXIF_DATA_TYPE_MAKER_NOTE_NIKON = 4, EXIF_DATA_TYPE_MAKER_NOTE_CASIO = 5, EXIF_DATA_TYPE_MAKER_NOTE_FUJI = 6
}

Functions

static void * exif_data_alloc (ExifData *data, unsigned int i)
ExifMnoteDataexif_data_get_mnote_data (ExifData *d)
 Return the MakerNote data out of the EXIF data.
ExifDataexif_data_new (void)
 Allocate a new ExifData.
ExifDataexif_data_new_mem (ExifMem *mem)
 Allocate a new ExifData using the given memory allocator.
ExifDataexif_data_new_from_data (const unsigned char *data, unsigned int size)
 Allocate a new ExifData and load EXIF data from a memory buffer.
static int exif_data_load_data_entry (ExifData *data, ExifEntry *entry, const unsigned char *d, unsigned int size, unsigned int offset)
static void exif_data_save_data_entry (ExifData *data, ExifEntry *e, unsigned char **d, unsigned int *ds, unsigned int offset)
static void exif_data_load_data_thumbnail (ExifData *data, const unsigned char *d, unsigned int ds, ExifLong o, ExifLong s)
static void exif_data_load_data_content (ExifData *data, ExifIfd ifd, const unsigned char *d, unsigned int ds, unsigned int offset, unsigned int recursion_depth)
 Load data for an IFD.
static int cmp_func (const unsigned char *p1, const unsigned char *p2, ExifByteOrder o)
static int cmp_func_intel (const void *elem1, const void *elem2)
static int cmp_func_motorola (const void *elem1, const void *elem2)
static void exif_data_save_data_content (ExifData *data, ExifContent *ifd, unsigned char **d, unsigned int *ds, unsigned int offset)
static void interpret_maker_note (ExifData *data, const unsigned char *d, unsigned int ds)
 If MakerNote is recognized, load it.
void exif_data_load_data (ExifData *data, const unsigned char *d_orig, unsigned int ds)
 Load the ExifData structure from the raw JPEG or EXIF data in the given memory buffer.
void exif_data_save_data (ExifData *data, unsigned char **d, unsigned int *ds)
 Store raw EXIF data representing the ExifData structure into a memory buffer.
ExifDataexif_data_new_from_file (const char *path)
 Allocate a new ExifData and load EXIF data from a JPEG file.
void exif_data_ref (ExifData *data)
void exif_data_unref (ExifData *data)
void exif_data_free (ExifData *data)
void exif_data_dump (ExifData *data)
 Dump all EXIF data to stdout.
ExifByteOrder exif_data_get_byte_order (ExifData *data)
 Return the byte order in use by this EXIF structure.
void exif_data_foreach_content (ExifData *data, ExifDataForeachContentFunc func, void *user_data)
 Execute a function on each IFD in turn.
static void entry_set_byte_order (ExifEntry *e, void *data)
static void content_set_byte_order (ExifContent *content, void *data)
void exif_data_set_byte_order (ExifData *data, ExifByteOrder order)
 Set the byte order to use for this EXIF data.
void exif_data_log (ExifData *data, ExifLog *log)
 Set the log message object for all IFDs.
ExifLogexif_data_get_log (ExifData *)
const char * exif_data_option_get_name (ExifDataOption o)
 Return a short textual description of the given ExifDataOption.
const char * exif_data_option_get_description (ExifDataOption o)
 Return a verbose textual description of the given ExifDataOption.
void exif_data_set_option (ExifData *d, ExifDataOption o)
 Set the given option on the given ExifData.
void exif_data_unset_option (ExifData *d, ExifDataOption o)
 Clear the given option on the given ExifData.
static void fix_func (ExifContent *c, void *UNUSED(data))
void exif_data_fix (ExifData *d)
 Fix the EXIF data to bring it into specification.
void exif_data_set_data_type (ExifData *d, ExifDataType dt)
 Set the data type for the given ExifData.
ExifDataType exif_data_get_data_type (ExifData *d)
 Return the data type for the given ExifData.

Variables

static const
unsigned char 
ExifHeader [] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00}
struct {
   ExifDataOption   option
   const char *   name
   const char *   description
exif_data_option []


Define Documentation

#define CHECK_REC (  ) 

Value:

if ((i) == ifd) {                               \
        exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, \
                "ExifData", "Recursive entry in IFD "   \
                "'%s' detected. Skipping...",           \
                exif_ifd_get_name (i));                 \
        break;                                          \
}                                                       \
if (data->ifd[(i)]->count) {                            \
        exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, \
                "ExifData", "Attempt to load IFD "      \
                "'%s' multiple times detected. "        \
                "Skipping...",                          \
                exif_ifd_get_name (i));                 \
        break;                                          \
}

Definition at line 330 of file exif-data.c.

Referenced by exif_data_load_data_content().

#define JPEG_MARKER_APP0   0xe0

Definition at line 45 of file exif-data.c.

Referenced by exif_data_load_data(), and exif_loader_write().

#define JPEG_MARKER_APP1   0xe1

Definition at line 47 of file exif-data.c.

Referenced by exif_data_load_data(), and exif_loader_write().

#define JPEG_MARKER_SOI   0xd8

Definition at line 43 of file exif-data.c.

Referenced by exif_data_load_data(), and exif_loader_write().

#define LOG_TOO_SMALL

Value:

exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifData", \
                _("Size of data too small to allow for EXIF data."));

Definition at line 778 of file exif-data.c.

Referenced by exif_data_load_data().


Typedef Documentation

typedef struct _ByteOrderChangeData ByteOrderChangeData

Definition at line 1110 of file exif-data.c.


Enumeration Type Documentation

enum ExifDataTypeMakerNote

Enumerator:
EXIF_DATA_TYPE_MAKER_NOTE_NONE 
EXIF_DATA_TYPE_MAKER_NOTE_CANON 
EXIF_DATA_TYPE_MAKER_NOTE_OLYMPUS 
EXIF_DATA_TYPE_MAKER_NOTE_PENTAX 
EXIF_DATA_TYPE_MAKER_NOTE_NIKON 
EXIF_DATA_TYPE_MAKER_NOTE_CASIO 
EXIF_DATA_TYPE_MAKER_NOTE_FUJI 

Definition at line 718 of file exif-data.c.


Function Documentation

static int cmp_func ( const unsigned char *  p1,
const unsigned char *  p2,
ExifByteOrder  o 
) [static]

Definition at line 484 of file exif-data.c.

References exif_get_short().

Referenced by cmp_func_intel(), and cmp_func_motorola().

static int cmp_func_intel ( const void *  elem1,
const void *  elem2 
) [static]

Definition at line 493 of file exif-data.c.

References cmp_func(), and EXIF_BYTE_ORDER_INTEL.

Referenced by exif_data_save_data_content().

static int cmp_func_motorola ( const void *  elem1,
const void *  elem2 
) [static]

Definition at line 500 of file exif-data.c.

References cmp_func(), and EXIF_BYTE_ORDER_MOTOROLA.

Referenced by exif_data_save_data_content().

static void content_set_byte_order ( ExifContent content,
void *  data 
) [static]

Definition at line 1127 of file exif-data.c.

References entry_set_byte_order(), and exif_content_foreach_entry().

Referenced by exif_data_set_byte_order().

static void entry_set_byte_order ( ExifEntry e,
void *  data 
) [static]

Definition at line 1116 of file exif-data.c.

References _ExifEntry::components, _ExifEntry::data, exif_array_set_byte_order(), _ExifEntry::format, _ByteOrderChangeData::new, and _ByteOrderChangeData::old.

Referenced by content_set_byte_order().

static void* exif_data_alloc ( ExifData data,
unsigned int  i 
) [static]

Definition at line 70 of file exif-data.c.

References EXIF_LOG_NO_MEMORY, exif_mem_alloc(), _ExifDataPrivate::log, _ExifDataPrivate::mem, and _ExifData::priv.

Referenced by exif_data_load_data_entry(), exif_data_load_data_thumbnail(), and exif_data_save_data().

void exif_data_dump ( ExifData data  ) 

Dump all EXIF data to stdout.

This is intended for diagnostic purposes only.

Parameters:
[in] data EXIF data

Definition at line 1062 of file exif-data.c.

Referenced by main().

void exif_data_fix ( ExifData d  ) 

Fix the EXIF data to bring it into specification.

Call exif_content_fix on each IFD to fix existing entries, create any new entries that are mandatory but do not yet exist, and remove any entries that are not allowed.

Parameters:
[in,out] d EXIF data

Definition at line 1258 of file exif-data.c.

Referenced by exif_data_load_data(), and main().

void exif_data_foreach_content ( ExifData data,
ExifDataForeachContentFunc  func,
void *  user_data 
)

Execute a function on each IFD in turn.

Parameters:
[in] data EXIF data over which to iterate
[in] func function to call for each entry
[in] user_data data to pass into func on each call

Definition at line 1098 of file exif-data.c.

Referenced by exif_data_fix(), exif_data_set_byte_order(), and test_parse().

void exif_data_free ( ExifData data  ) 

Definition at line 1025 of file exif-data.c.

Referenced by exif_data_new_mem(), and exif_data_unref().

ExifByteOrder exif_data_get_byte_order ( ExifData data  ) 

Return the byte order in use by this EXIF structure.

Parameters:
[in] data EXIF data
Returns:
byte order

Definition at line 1089 of file exif-data.c.

Referenced by exif_entry_fix(), exif_entry_format_value(), exif_entry_get_value(), exif_entry_initialize(), main(), and test_exif_data().

ExifDataType exif_data_get_data_type ( ExifData d  ) 

Return the data type for the given ExifData.

Parameters:
[in] d EXIF data
Returns:
data type, or EXIF_DATA_TYPE_UNKNOWN on error

Definition at line 1273 of file exif-data.c.

Referenced by exif_content_fix(), and remove_not_recorded().

ExifLog * exif_data_get_log ( ExifData data  ) 

Definition at line 1166 of file exif-data.c.

References _ExifDataPrivate::log, and _ExifData::priv.

Referenced by exif_entry_alloc(), exif_entry_log(), and exif_entry_realloc().

ExifMnoteData* exif_data_get_mnote_data ( ExifData d  ) 

Return the MakerNote data out of the EXIF data.

Only certain MakerNote formats that are recognized by libexif are supported. The pointer references a member of the ExifData structure and must NOT be freed by the caller.

Parameters:
[in] d EXIF data
Returns:
MakerNote data, or NULL if not found or not supported

Definition at line 86 of file exif-data.c.

Referenced by test_exif_data().

void exif_data_load_data ( ExifData data,
const unsigned char *  d,
unsigned int  size 
)

Load the ExifData structure from the raw JPEG or EXIF data in the given memory buffer.

If the EXIF data contains a recognized MakerNote, it is loaded and stored as well for later retrieval by exif_data_get_mnote_data. If the EXIF_DATA_OPTION_FOLLOW_SPECIFICATION option has been set on this ExifData, then the tags are automatically fixed after loading (by calling exif_data_fix).

Parameters:
[in,out] data EXIF data
[in] d pointer to raw JPEG or EXIF data
[in] size number of bytes of data at d

Definition at line 783 of file exif-data.c.

Referenced by exif_data_new_from_data(), and exif_loader_get_data().

static void exif_data_load_data_content ( ExifData data,
ExifIfd  ifd,
const unsigned char *  d,
unsigned int  ds,
unsigned int  offset,
unsigned int  recursion_depth 
) [static]

Load data for an IFD.

Parameters:
[in,out] data ExifData
[in] ifd IFD to load
[in] d pointer to buffer containing raw IFD data
[in] ds size of raw data in buffer at d
[in] offset offset into buffer at d at which IFD starts
[in] recursion_depth number of times this function has been recursively called without returning

Definition at line 358 of file exif-data.c.

References CHECK_REC, exif_content_add_entry(), exif_data_load_data_entry(), exif_data_load_data_thumbnail(), EXIF_DATA_OPTION_IGNORE_UNKNOWN_TAGS, exif_entry_new_mem(), exif_entry_unref(), exif_get_long(), exif_get_short(), EXIF_IFD_COUNT, EXIF_IFD_EXIF, exif_ifd_get_name(), EXIF_IFD_GPS, EXIF_IFD_INTEROPERABILITY, exif_log(), EXIF_LOG_CODE_CORRUPT_DATA, EXIF_LOG_CODE_DEBUG, EXIF_TAG_EXIF_IFD_POINTER, exif_tag_get_name(), exif_tag_get_name_in_ifd(), EXIF_TAG_GPS_INFO_IFD_POINTER, EXIF_TAG_INTEROPERABILITY_IFD_POINTER, EXIF_TAG_JPEG_INTERCHANGE_FORMAT, EXIF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH, _ExifData::ifd, _ExifDataPrivate::log, _ExifDataPrivate::mem, _ExifDataPrivate::options, _ExifDataPrivate::order, _ExifData::priv, and tag.

Referenced by exif_data_load_data().

static int exif_data_load_data_entry ( ExifData data,
ExifEntry entry,
const unsigned char *  d,
unsigned int  size,
unsigned int  offset 
) [static]

Definition at line 160 of file exif-data.c.

References _ExifEntry::components, _ExifEntry::data, exif_data_alloc(), exif_format_get_size(), exif_get_long(), exif_get_short(), exif_log(), EXIF_LOG_CODE_DEBUG, EXIF_LOG_NO_MEMORY, exif_tag_get_name(), EXIF_TAG_MAKER_NOTE, _ExifEntry::format, _ExifDataPrivate::log, _ExifDataPrivate::offset_mnote, _ExifDataPrivate::order, _ExifData::priv, _ExifEntry::size, and _ExifEntry::tag.

Referenced by exif_data_load_data_content().

static void exif_data_load_data_thumbnail ( ExifData data,
const unsigned char *  d,
unsigned int  ds,
ExifLong  o,
ExifLong  s 
) [static]

Definition at line 307 of file exif-data.c.

References _ExifData::data, exif_data_alloc(), exif_log(), EXIF_LOG_CODE_DEBUG, EXIF_LOG_NO_MEMORY, exif_mem_free(), _ExifDataPrivate::log, _ExifDataPrivate::mem, _ExifData::priv, and _ExifData::size.

Referenced by exif_data_load_data_content().

void exif_data_log ( ExifData data,
ExifLog log 
)

Set the log message object for all IFDs.

Parameters:
[in] data EXIF data
[in] log ExifLog

Definition at line 1149 of file exif-data.c.

Referenced by exif_loader_get_data().

ExifData* exif_data_new ( void   ) 

Allocate a new ExifData.

The ExifData contains an empty ExifContent for each IFD and the default set of options, which has EXIF_DATA_OPTION_IGNORE_UNKNOWN_TAGS and EXIF_DATA_OPTION_FOLLOW_SPECIFICATION set.

Returns:
allocated ExifData, or NULL on error

Definition at line 92 of file exif-data.c.

Referenced by exif_data_new_from_data(), and main().

ExifData* exif_data_new_from_data ( const unsigned char *  data,
unsigned int  size 
)

Allocate a new ExifData and load EXIF data from a memory buffer.

Parameters:
[in] data pointer to raw JPEG or EXIF data
[in] size number of bytes of data at data
Returns:
allocated ExifData, or NULL on error

Definition at line 150 of file exif-data.c.

Referenced by main().

ExifData* exif_data_new_from_file ( const char *  path  ) 

Allocate a new ExifData and load EXIF data from a JPEG file.

Uses an ExifLoader internally to do the loading.

Parameters:
[in] path filename including path
Returns:
allocated ExifData, or NULL on error

Definition at line 991 of file exif-data.c.

Referenced by main(), and test_parse().

ExifData* exif_data_new_mem ( ExifMem  ) 

Allocate a new ExifData using the given memory allocator.

The ExifData contains an empty ExifContent for each IFD and the default set of options, which has EXIF_DATA_OPTION_IGNORE_UNKNOWN_TAGS and EXIF_DATA_OPTION_FOLLOW_SPECIFICATION set.

Returns:
allocated ExifData, or NULL on error

Definition at line 103 of file exif-data.c.

Referenced by exif_data_new(), and exif_loader_get_data().

const char* exif_data_option_get_description ( ExifDataOption  o  ) 

Return a verbose textual description of the given ExifDataOption.

Parameters:
[in] o option
Returns:
verbose localized textual description of the option

Definition at line 1201 of file exif-data.c.

const char* exif_data_option_get_name ( ExifDataOption  o  ) 

Return a short textual description of the given ExifDataOption.

Parameters:
[in] o option
Returns:
localized textual description of the option

Definition at line 1190 of file exif-data.c.

void exif_data_ref ( ExifData data  ) 

Definition at line 1005 of file exif-data.c.

void exif_data_save_data ( ExifData data,
unsigned char **  d,
unsigned int *  ds 
)

Store raw EXIF data representing the ExifData structure into a memory buffer.

The buffer is allocated by this function and must subsequently be freed by the caller using the matching free function as used by the ExifMem in use by this ExifData.

Parameters:
[in] data EXIF data
[out] d pointer to buffer pointer containing raw EXIF data on return
[out] ds pointer to variable to hold the number of bytes of data at d, or set to 0 on error

Definition at line 946 of file exif-data.c.

Referenced by main().

static void exif_data_save_data_content ( ExifData data,
ExifContent ifd,
unsigned char **  d,
unsigned int *  ds,
unsigned int  offset 
) [static]

Definition at line 507 of file exif-data.c.

References cmp_func_intel(), cmp_func_motorola(), _ExifContent::count, _ExifData::data, _ExifContent::entries, EXIF_BYTE_ORDER_INTEL, exif_data_save_data_entry(), EXIF_FORMAT_LONG, EXIF_IFD_0, EXIF_IFD_1, EXIF_IFD_COUNT, EXIF_IFD_EXIF, exif_ifd_get_name(), EXIF_IFD_GPS, EXIF_IFD_INTEROPERABILITY, exif_log(), EXIF_LOG_CODE_DEBUG, EXIF_LOG_NO_MEMORY, exif_mem_realloc(), exif_set_long(), exif_set_short(), EXIF_TAG_EXIF_IFD_POINTER, EXIF_TAG_GPS_INFO_IFD_POINTER, EXIF_TAG_INTEROPERABILITY_IFD_POINTER, EXIF_TAG_JPEG_INTERCHANGE_FORMAT, EXIF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH, _ExifData::ifd, _ExifDataPrivate::log, _ExifDataPrivate::mem, _ExifDataPrivate::order, _ExifData::priv, and _ExifData::size.

Referenced by exif_data_save_data().

static void exif_data_save_data_entry ( ExifData data,
ExifEntry e,
unsigned char **  d,
unsigned int *  ds,
unsigned int  offset 
) [static]

Definition at line 229 of file exif-data.c.

References _ExifEntry::components, _ExifEntry::data, EXIF_DATA_OPTION_DONT_CHANGE_MAKER_NOTE, exif_format_get_size(), EXIF_LOG_NO_MEMORY, exif_mem_free(), exif_mem_realloc(), exif_mnote_data_save(), exif_mnote_data_set_offset(), exif_set_long(), exif_set_short(), EXIF_TAG_MAKER_NOTE, _ExifEntry::format, _ExifDataPrivate::log, _ExifDataPrivate::md, _ExifDataPrivate::mem, _ExifDataPrivate::options, _ExifDataPrivate::order, _ExifData::priv, _ExifEntry::size, and _ExifEntry::tag.

Referenced by exif_data_save_data_content().

void exif_data_set_byte_order ( ExifData data,
ExifByteOrder  order 
)

Set the byte order to use for this EXIF data.

If any tags already exist (including MakerNote tags) they are are converted to the specified byte order.

Parameters:
[in,out] data EXIF data
[in] order byte order

Definition at line 1133 of file exif-data.c.

void exif_data_set_data_type ( ExifData d,
ExifDataType  dt 
)

Set the data type for the given ExifData.

Parameters:
[in] d EXIF data
[in] dt data type

Definition at line 1264 of file exif-data.c.

Referenced by exif_data_new_mem(), and main().

void exif_data_set_option ( ExifData d,
ExifDataOption  o 
)

Set the given option on the given ExifData.

Parameters:
[in] d EXIF data
[in] o option

Definition at line 1212 of file exif-data.c.

Referenced by exif_data_new_mem().

void exif_data_unref ( ExifData data  ) 

Definition at line 1014 of file exif-data.c.

Referenced by main(), test_exif_data(), and test_parse().

void exif_data_unset_option ( ExifData d,
ExifDataOption  o 
)

Clear the given option on the given ExifData.

Parameters:
[in] d EXIF data
[in] o option

Definition at line 1221 of file exif-data.c.

static void fix_func ( ExifContent c,
void *  UNUSED(data) 
) [static]

Definition at line 1230 of file exif-data.c.

References _ExifContent::count, _ExifData::data, _ExifContent::entries, exif_content_fix(), exif_content_get_ifd(), exif_content_remove_entry(), EXIF_IFD_1, exif_log(), EXIF_LOG_CODE_DEBUG, _ExifDataPrivate::log, _ExifContent::parent, and _ExifData::priv.

static void interpret_maker_note ( ExifData data,
const unsigned char *  d,
unsigned int  ds 
) [static]

If MakerNote is recognized, load it.

Parameters:
[in,out] data ExifData
[in] d pointer to raw EXIF data
[in] ds length of data at d

Definition at line 735 of file exif-data.c.

References exif_data_get_entry, exif_log(), EXIF_LOG_CODE_DEBUG, exif_mnote_data_canon_identify(), exif_mnote_data_canon_new(), exif_mnote_data_fuji_identify(), exif_mnote_data_fuji_new(), exif_mnote_data_load(), exif_mnote_data_log(), exif_mnote_data_olympus_identify(), exif_mnote_data_olympus_new(), exif_mnote_data_pentax_identify(), exif_mnote_data_pentax_new(), exif_mnote_data_set_byte_order(), exif_mnote_data_set_offset(), EXIF_TAG_MAKER_NOTE, _ExifDataPrivate::log, _ExifDataPrivate::md, _ExifDataPrivate::mem, _ExifDataPrivate::offset_mnote, _ExifDataPrivate::options, _ExifDataPrivate::order, and _ExifData::priv.

Referenced by exif_data_load_data().


Variable Documentation

const char* description

Definition at line 1176 of file exif-data.c.

struct { ... } exif_data_option[] [static]

Referenced by exif_data_option_get_description(), and exif_data_option_get_name().

const unsigned char ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00} [static]

Definition at line 49 of file exif-data.c.

Referenced by exif_data_load_data(), exif_data_save_data(), and exif_loader_write().

const char* name

Definition at line 1175 of file exif-data.c.

ExifDataOption option

Definition at line 1174 of file exif-data.c.

Referenced by exif_data_option_get_description(), and exif_data_option_get_name().


SourceForge.net Logo Generated by doxygen