EXIF library (libexif) Internals 0.6.26
test-parse.c
Go to the documentation of this file.
1
24#include "libexif/exif-data.h"
25#include "libexif/exif-system.h"
26
27#include <string.h>
28#include <stdio.h>
29#include <stdlib.h>
30
31static unsigned entry_count;
32
34static void content_foreach_func(ExifEntry *entry, void *UNUSED(callback_data))
35{
36 char buf[2000];
37 exif_entry_get_value(entry, buf, sizeof(buf));
38 printf(" Entry %u: %s (%s)\n"
39 " Size, Comps: %d, %d\n"
40 " Value: %s\n",
42 exif_tag_get_name(entry->tag),
44 entry->size,
45 (int)(entry->components),
46 exif_entry_get_value(entry, buf, sizeof(buf)));
48}
49
50
52static void data_foreach_func(ExifContent *content, void *callback_data)
53{
54 static unsigned content_count;
55 entry_count = 0;
56 printf(" Content %u: ifd=%d\n", content_count, exif_content_get_ifd(content));
57 exif_content_foreach_entry(content, content_foreach_func, callback_data);
58 ++content_count;
59}
60
61static void dump_makernote(ExifData *d) {
63 if (mn) {
64 char buf[2000];
65 int i;
66 int num = exif_mnote_data_count(mn);
67 printf(" MakerNote\n");
68 for (i=0; i < num; ++i) {
69 if (exif_mnote_data_get_value(mn, i, buf, sizeof(buf))) {
70 const char *name = exif_mnote_data_get_name(mn, i);
71 unsigned int id = exif_mnote_data_get_id(mn, i);
72 if (!name)
73 name = "(unknown)";
74 printf(" Entry %u: %u, %s\n"
75 " Size: %u\n"
76 " Value: %s\n", i, id, name, (unsigned)strlen(buf), buf);
77 }
78 }
79 }
80}
81
83static void test_parse(const char *filename, void *callback_data, int swap)
84{
85 ExifData *d;
86
87 /* Skip over path to display only the file name */
88 const char *fn = strrchr(filename, '/');
89 if (fn)
90 ++fn;
91 else
92 fn = filename;
93 printf("File %s\n", fn);
94
95 d = exif_data_new_from_file(filename);
96 if (!d) {
97 fprintf (stderr, "Could not load data from '%s'!\n", filename);
98 return;
99 }
100 printf("Byte order: %s\n",
102
103 if (swap) {
105 if (exif_data_get_byte_order(d) == order) {
107 }
108 /* This switches the byte order of the entire EXIF data structure,
109 * including the MakerNote */
110 exif_data_set_byte_order(d, order);
111 printf("New byte order: %s\n",
113 }
114
116
118
120}
121
122
124typedef void (*test_parse_func) (const char *filename, void *callback_data, int swap);
125
126
128static void split_ws_string(const char *string, test_parse_func func, void *callback_data)
129{
130 const char *start = string;
131 const char *p = start;
132 for (;;) {
133 if (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || *p == '\0' ) {
134 size_t len = p-start;
135 if (len > 0) {
136 /* emulate strndup */
137 char *str = malloc(1+len);
138 if (str) {
139 memcpy(str, start, len);
140 str[len] = '\0';
141 func(str, callback_data, 0);
142 free(str);
143 start = p+1;
144 }
145 } else {
146 start = p+1;
147 }
148 }
149 if (*p == '\0') {
150 break;
151 }
152 p++;
153 }
154}
155
156
158int main(const int argc, const char *argv[])
159{
160 int i;
161 void *callback_data = NULL;
162 int swap = 0;
163 int first = 1;
164
165 if (argc > 1 && !strcmp(argv[1], "--swap-byte-order")) {
166 swap = 1;
167 ++first;
168 }
169
170 if (argc > first) {
171 for (i=first; i<argc; i++) {
172 test_parse(argv[i], callback_data, swap);
173 }
174 } else {
175 /* If no command-line argument is found, get the file names from
176 the environment. */
177 const char *envar = getenv("TEST_IMAGES");
178 if (envar) {
179 split_ws_string(envar, test_parse, callback_data);
180 }
181 }
182
183 return 0;
184}
const char * exif_byte_order_get_name(ExifByteOrder order)
Return a short, localized, textual name for the given byte order.
ExifByteOrder
Which byte order to use.
@ EXIF_BYTE_ORDER_INTEL
Little-endian byte order.
@ EXIF_BYTE_ORDER_MOTOROLA
Big-endian byte order.
ExifIfd exif_content_get_ifd(ExifContent *c)
Return the IFD number in which the given ExifContent is found.
void exif_content_foreach_entry(ExifContent *content, ExifContentForeachEntryFunc func, void *data)
Executes function on each EXIF tag in this IFD in turn.
void exif_data_set_byte_order(ExifData *data, ExifByteOrder order)
Set the byte order to use for this EXIF data.
Definition exif-data.c:1229
void exif_data_unref(ExifData *data)
Definition exif-data.c:1110
ExifByteOrder exif_data_get_byte_order(ExifData *data)
Return the byte order in use by this EXIF structure.
Definition exif-data.c:1185
ExifMnoteData * exif_data_get_mnote_data(ExifData *d)
Return the MakerNote data out of the EXIF data.
Definition exif-data.c:92
ExifData * exif_data_new_from_file(const char *path)
Allocate a new ExifData and load EXIF data from a JPEG file.
Definition exif-data.c:1087
void exif_data_foreach_content(ExifData *data, ExifDataForeachContentFunc func, void *user_data)
Execute a function on each IFD in turn.
Definition exif-data.c:1194
Defines the ExifData type and the associated functions.
const char * exif_entry_get_value(ExifEntry *e, char *val, unsigned int maxlen)
Return a localized textual representation of the value of the EXIF entry.
Definition exif-entry.c:854
const char * exif_format_get_name(ExifFormat format)
Return a textual representation of the given EXIF data type.
Definition exif-format.c:55
char * exif_mnote_data_get_value(ExifMnoteData *d, unsigned int n, char *val, unsigned int maxlen)
Return a textual representation of the value of the MakerNote entry.
unsigned int exif_mnote_data_get_id(ExifMnoteData *d, unsigned int n)
Return the MakerNote tag number for the tag at the specified index within the MakerNote.
const char * exif_mnote_data_get_name(ExifMnoteData *d, unsigned int n)
Returns textual name of the given MakerNote tag.
unsigned int exif_mnote_data_count(ExifMnoteData *d)
Return the number of tags in the MakerNote.
System specific definitions, not for installation!
#define UNUSED(param)
Definition exif-system.h:31
const char * exif_tag_get_name(ExifTag tag)
Definition exif-tag.c:1151
const char * name
const char * string
int main(void)
Represents the entire EXIF data found in an image.
Definition exif-data.h:48
Data found in one EXIF tag.
Definition exif-entry.h:45
unsigned long components
Number of elements in the array, if this is an array entry.
Definition exif-entry.h:54
ExifFormat format
Type of data in this entry.
Definition exif-entry.h:50
ExifTag tag
EXIF tag for this entry.
Definition exif-entry.h:47
unsigned int size
Number of bytes in the buffer at data.
Definition exif-entry.h:63
void(* test_parse_func)(const char *filename, void *callback_data, int swap)
Definition test-parse.c:124
static unsigned entry_count
Definition test-parse.c:31
static void data_foreach_func(ExifContent *content, void *callback_data)
Definition test-parse.c:52
static void test_parse(const char *filename, void *callback_data, int swap)
Definition test-parse.c:83
static void content_foreach_func(ExifEntry *entry, void *UNUSED(callback_data))
Definition test-parse.c:34
static void dump_makernote(ExifData *d)
Definition test-parse.c:61
static void split_ws_string(const char *string, test_parse_func func, void *callback_data)
Definition test-parse.c:128

libexif Generated by doxygen