• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* test-mem.c
2  *
3  * Copyright (c) 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 <libexif/exif-data.h>
26 #include <libexif/exif-ifd.h>
27 #include <libexif/exif-loader.h>
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 
32 int
main(void)33 main (void)
34 {
35 	ExifData *ed;
36 	/* ExifEntry *e; */
37 	unsigned char *eb, size[2];
38 	unsigned int ebs;
39 	ExifLoader *loader;
40 	unsigned int i;
41 
42 	printf ("Creating EXIF data...\n");
43 	ed = exif_data_new ();
44 	if (!ed) {
45 		fprintf(stderr, "Out of memory\n");
46 		exit(13);
47 	}
48 
49 	exif_data_set_data_type (ed, EXIF_DATA_TYPE_UNCOMPRESSED_CHUNKY);
50 
51 	printf ("Fill EXIF data with all necessary entries to follow specs...\n");
52 	exif_data_fix (ed);
53 
54 	/* Add a dummy thumbnail */
55 	ed->size = 4;
56 	ed->data = calloc(1, ed->size);
57 	if (!ed->data) {
58 		fprintf(stderr, "Out of memory\n");
59 		exif_data_unref (ed);
60 		exit(13);
61 	}
62 
63 	exif_data_dump (ed);
64 
65 	printf ("Saving EXIF data to memory...\n");
66 	exif_data_save_data (ed, &eb, &ebs);
67 	exif_data_unref (ed);
68 
69 	printf ("Writing %i byte(s) EXIF data to loader...\n", ebs);
70 	loader = exif_loader_new ();
71 	if (!loader) {
72 		fprintf(stderr, "Out of memory\n");
73 		free (eb);
74 		exit(13);
75 	}
76 	size[0] = (unsigned char) ebs;
77 	size[1] = (unsigned char) (ebs >> 8);
78 	exif_loader_write (loader, size, 2);
79 	for (i = 0; i < ebs && exif_loader_write (loader, eb + i, 1); i++);
80 	printf ("Wrote %i byte(s).\n", i);
81 	free (eb);
82 	ed = exif_loader_get_data (loader);
83 	if (!ed) {
84 		fprintf(stderr, "Out of memory\n");
85 		exit(13);
86 	}
87 	exif_loader_unref (loader);
88 	exif_data_dump (ed);
89 	exif_data_unref (ed);
90 
91 	return 0;
92 }
93