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