• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* exif-mnote.c
2  *
3  * Copyright 2002 Lutz Mueller <lutz@users.sourceforge.net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA  02110-1301  USA.
19  *
20  * SPDX-License-Identifier: LGPL-2.0-or-later
21  */
22 
23 #include <config.h>
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 
28 #include <libexif/exif-data.h>
29 
strornull(const char * ptr)30 static const char *strornull(const char *ptr) {
31 	if (!ptr)
32 		return "(none)";
33 	return ptr;
34 }
35 
36 static int
test_exif_data(ExifData * d)37 test_exif_data (ExifData *d)
38 {
39 	unsigned int i, c;
40 	char v[1024], *p;
41 	ExifMnoteData *md;
42 
43 	printf("Byte order: %s\n",
44 		exif_byte_order_get_name (exif_data_get_byte_order (d)));
45 
46 	printf("Parsing maker note...\n");
47 	md = exif_data_get_mnote_data (d);
48 	if (!md) {
49 		fprintf (stderr, "Could not parse maker note!\n");
50 		exif_data_unref (d);
51 		return 1;
52 	}
53 
54 	printf("Increasing ref-count...\n");
55 	exif_mnote_data_ref (md);
56 
57 	printf("Decreasing ref-count...\n");
58 	exif_mnote_data_unref (md);
59 
60 	printf("Counting entries...\n");
61 	c = exif_mnote_data_count (md);
62 	printf("Found %i entries.\n", c);
63 	for (i = 0; i < c; i++) {
64 		printf("Dumping entry number %i...\n", i);
65 		printf("  Name: '%s'\n",
66 				strornull(exif_mnote_data_get_name (md, i)));
67 		printf("  Title: '%s'\n",
68 				strornull(exif_mnote_data_get_title (md, i)));
69 		printf("  Description: '%s'\n",
70 				strornull(exif_mnote_data_get_description (md, i)));
71 		p = exif_mnote_data_get_value (md, i, v, sizeof (v));
72 		if (p) { printf("  Value: '%s'\n", v); }
73 	}
74 
75 	return 0;
76 }
77 
78 int
main(int argc,char ** argv)79 main (int argc, char **argv)
80 {
81 	ExifData *d;
82 	unsigned int buf_size;
83 	unsigned char *buf;
84 	int r;
85 
86 	if (argc <= 1) {
87 		fprintf (stderr, "You need to supply a filename!\n");
88 		return 1;
89 	}
90 
91 	printf("Loading '%s'...\n", argv[1]);
92 	d = exif_data_new_from_file (argv[1]);
93 	if (!d) {
94 		fprintf (stderr, "Could not load data from '%s'!\n", argv[1]);
95 		return 1;
96 	}
97 	printf("Loaded '%s'.\n", argv[1]);
98 
99 	printf("######### Test 1 #########\n");
100 	r = test_exif_data (d);
101 	if (r) return r;
102 
103 	exif_data_save_data (d, &buf, &buf_size);
104 	exif_data_unref (d);
105 	d = exif_data_new_from_data (buf, buf_size);
106 	free (buf);
107 	if (!d) {
108 		fprintf (stderr, "Could not load data from buf!\n");
109 		return 1;
110 	}
111 
112 	printf ("######### Test 2 #########\n");
113 	r = test_exif_data (d);
114 	exif_data_unref (d);
115 	if (r) return r;
116 
117 	printf ("Test successful!\n");
118 
119 	return 0;
120 }
121