EXIF library (libexif) Internals  0.6.24
test-mem.c
Go to the documentation of this file.
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 
21 #include <config.h>
22 
23 #include <libexif/exif-data.h>
24 #include <libexif/exif-ifd.h>
25 #include <libexif/exif-loader.h>
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 
30 int
31 main ()
32 {
33  ExifData *ed;
34  /* ExifEntry *e; */
35  unsigned char *eb, size[2];
36  unsigned int ebs;
37  ExifLoader *loader;
38  unsigned int i;
39 
40  printf ("Creating EXIF data...\n");
41  ed = exif_data_new ();
42  if (!ed) {
43  fprintf(stderr, "Out of memory\n");
44  exit(13);
45  }
46 
48 
49  printf ("Fill EXIF data with all necessary entries to follow specs...\n");
50  exif_data_fix (ed);
51 
52  /* Add a dummy thumbnail */
53  ed->size = 4;
54  ed->data = calloc(1, ed->size);
55  if (!ed->data) {
56  fprintf(stderr, "Out of memory\n");
57  exif_data_unref (ed);
58  exit(13);
59  }
60 
61  exif_data_dump (ed);
62 
63  printf ("Saving EXIF data to memory...\n");
64  exif_data_save_data (ed, &eb, &ebs);
65  exif_data_unref (ed);
66 
67  printf ("Writing %i byte(s) EXIF data to loader...\n", ebs);
68  loader = exif_loader_new ();
69  if (!loader) {
70  fprintf(stderr, "Out of memory\n");
71  free (eb);
72  exit(13);
73  }
74  size[0] = (unsigned char) ebs;
75  size[1] = (unsigned char) (ebs >> 8);
76  exif_loader_write (loader, size, 2);
77  for (i = 0; i < ebs && exif_loader_write (loader, eb + i, 1); i++);
78  printf ("Wrote %i byte(s).\n", i);
79  free (eb);
80  ed = exif_loader_get_data (loader);
81  if (!ed) {
82  fprintf(stderr, "Out of memory\n");
83  exit(13);
84  }
85  exif_loader_unref (loader);
86  exif_data_dump (ed);
87  exif_data_unref (ed);
88 
89  return 0;
90 }
@ EXIF_DATA_TYPE_UNCOMPRESSED_CHUNKY
ExifData * exif_data_new(void)
Allocate a new ExifData.
Definition: exif-data.c:96
void exif_data_unref(ExifData *data)
Definition: exif-data.c:1098
void exif_data_fix(ExifData *d)
Fix the EXIF data to bring it into specification.
Definition: exif-data.c:1342
void exif_data_dump(ExifData *data)
Dump all EXIF data to stdout.
Definition: exif-data.c:1146
void exif_data_set_data_type(ExifData *d, ExifDataType dt)
Set the data type for the given ExifData.
Definition: exif-data.c:1348
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.
Definition: exif-data.c:1030
Defines the ExifData type and the associated functions.
unsigned char size
Definition: exif-format.c:35
ExifLoader * exif_loader_new(void)
Allocate a new ExifLoader.
Definition: exif-loader.c:352
void exif_loader_unref(ExifLoader *loader)
Decrease the refcount of the ExifLoader.
Definition: exif-loader.c:404
ExifData * exif_loader_get_data(ExifLoader *loader)
Create an ExifData from the data in the loader.
Definition: exif-loader.c:426
unsigned char exif_loader_write(ExifLoader *eld, unsigned char *buf, unsigned int len)
Load a buffer into the ExifLoader from a memory buffer.
Definition: exif-loader.c:163
Defines the ExifLoader type.
Represents the entire EXIF data found in an image.
Definition: exif-data.h:47
unsigned char * data
Pointer to thumbnail image, or NULL if not available.
Definition: exif-data.h:52
unsigned int size
Number of bytes in thumbnail image at data.
Definition: exif-data.h:55
int main()
Definition: test-mem.c:31

libexif Generated by doxygen