From: <lu...@us...> - 2003-03-18 07:13:27
|
Update of /cvsroot/libexif/libexif/libexif In directory sc8-pr-cvs1:/tmp/cvs-serv14374/libexif Modified Files: exif-data.c exif-loader.c Log Message: 2003-03-18 Lutz Mueller <lu...@us...> * libexif/exif-data.c (exif_data_new_from_file): Use the new ExifLoader. It seems to work. Index: exif-data.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-data.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- exif-data.c 15 Dec 2002 11:41:11 -0000 1.23 +++ exif-data.c 18 Mar 2003 07:13:24 -0000 1.24 @@ -22,6 +22,7 @@ #include "exif-data.h" #include "exif-ifd.h" #include "exif-utils.h" +#include "exif-loader.h" #include "jpeg-marker.h" #include <stdlib.h> @@ -647,56 +648,25 @@ exif_data_new_from_file (const char *path) { FILE *f; - unsigned int size; - unsigned char *data; + int size; ExifData *edata; - int marker, ll, lh; + ExifLoader *loader; + unsigned char data[1024]; f = fopen (path, "rb"); if (!f) return (NULL); + loader = exif_loader_new (); while (1) { - while ((marker = fgetc (f)) == 0xff); - - /* JPEG_MARKER_SOI */ - if (marker == JPEG_MARKER_SOI) - continue; - - /* JPEG_MARKER_APP0 */ - if (marker == JPEG_MARKER_APP0) { - lh = fgetc (f); - ll = fgetc (f); - size = (lh << 8) | ll; - if (fseek (f, size - 2, SEEK_CUR) < 0) - return (NULL); - continue; - } - - /* JPEG_MARKER_APP1 */ - if (marker == JPEG_MARKER_APP1) - break; - - /* Unknown marker or data. Give up. */ - return (NULL); - } - - /* EXIF data found. Allocate the necessary memory and read the data. */ - lh = fgetc (f); - ll = fgetc (f); - size = (lh << 8) | ll; - data = malloc (sizeof (char) * size); - if (!data) - return (NULL); - if (fread (data, 1, size, f) != size) { - free (data); - return (NULL); + size = fread (data, 1, 1024, f); + if (size < 0) break; + if (!exif_loader_write (loader, data, size)) break; } - - edata = exif_data_new_from_data (data, size); - free (data); - fclose (f); + + edata = exif_loader_get_data (loader); + exif_loader_unref (loader); return (edata); } Index: exif-loader.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-loader.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- exif-loader.c 17 Mar 2003 20:39:19 -0000 1.1 +++ exif-loader.c 18 Mar 2003 07:13:24 -0000 1.2 @@ -166,6 +166,10 @@ { if (!loader) return; free (loader->buf); loader->buf = NULL; + loader->size = 0; + loader->bytes_read = 0; + loader->last_marker = 0; + loader->state = 0; } ExifData * |