/* get exif data in readable form */ void exif_get_info(ExifData * ed, char *buffer, unsigned int maxsize) { ExifEntry *entry = NULL; char buf[64]; if ( (buffer == NULL) || (maxsize == 0) ) { return; } else if (ed == NULL) { snprintf(buffer, (size_t)maxsize, "%s\n", "No Exif data in file."); return; } else if ( ed != NULL ) { /* normal exif tags */ exif_get_tag(ed, EXIF_IFD_0, EXIF_TAG_MAKE, buffer, maxsize); exif_get_tag(ed, EXIF_IFD_0, EXIF_TAG_MODEL, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_0, EXIF_TAG_IMAGE_DESCRIPTION, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_ORIGINAL, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_DATE_TIME_DIGITIZED, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_EXPOSURE_TIME, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_SHUTTER_SPEED_VALUE, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_FNUMBER, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_APERTURE_VALUE, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_EXPOSURE_BIAS_VALUE, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_ISO_SPEED_RATINGS, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_FOCAL_LENGTH, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_FOCAL_LENGTH_IN_35MM_FILM, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_EXPOSURE_MODE, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_EXPOSURE_PROGRAM, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_SCENE_CAPTURE_TYPE, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_FLASH, buffer + strlen(buffer), maxsize - strlen(buffer)); exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_FLASH_ENERGY, buffer + strlen(buffer), maxsize - strlen(buffer)); /* vendor specific makernote tags */ entry = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_MAKE); if (entry != NULL) { if (exif_entry_get_value(entry, buf, sizeof(buf))) { exif_trim_spaces(buf); /* Nikon */ if ( strcmp(buf, "Nikon") != 0 ) { /* Digital Vari-Program */ exif_get_mnote_tag(ed, 171, buffer + strlen(buffer), maxsize - strlen(buffer)); /* Lens */ exif_get_mnote_tag(ed, 132, buffer + strlen(buffer), maxsize - strlen(buffer)); } } } } }
/* Show the given MakerNote tag if it exists */ void exif_get_mnote_tag(ExifData *d, unsigned int tag, char* buffer, unsigned int maxsize) { ExifMnoteData *mn = NULL; int i, num; char buf[1024]; if ( (d!=NULL) && (buffer!=NULL) && (maxsize > 0) ) { mn = exif_data_get_mnote_data(d); } else { return; } if ( mn != NULL ) { num = exif_mnote_data_count(mn); /* Loop through all MakerNote tags, searching for the desired one */ for (i=0; i < num; ++i) { D(("%d/%d %d 0x%2x %s; %s\n", i, num, exif_mnote_data_get_id(mn, i), exif_mnote_data_get_id(mn, i), exif_mnote_data_get_name(mn,i), exif_mnote_data_get_title(mn, i) )); if (exif_mnote_data_get_id(mn, i) == tag) { if (exif_mnote_data_get_value(mn, i, buf, sizeof(buf))) { /* Don't bother printing it if it's entirely blank */ exif_trim_spaces(buf); if (*buf != '\0') { D(("%s\n", buf)); snprintf(buffer, (size_t)maxsize, "%s: %s\n", exif_mnote_data_get_title(mn, i), buf); } } } } } }
/* show given exif tag content */ static void exif_get_tag(ExifData *d, ExifIfd ifd, ExifTag tag, char* buffer, unsigned int maxsize) { char s[MAX_EXIF_DATA]; if ( (d != NULL) && (buffer != NULL) && (maxsize>0) ) { ExifEntry *entry = exif_content_get_entry(d->ifd[ifd], tag); if (entry != NULL) { /* Get the contents of the tag in human-readable form */ exif_entry_get_value(entry, s, maxsize); /* Don't bother printing it if it's entirely blank */ exif_trim_spaces(s); if (*s != '\0') { D(("%s: %s\n", exif_tag_get_name_in_ifd(tag,ifd), s)); snprintf(buffer, (size_t)maxsize, "%s: %s\n", exif_tag_get_name_in_ifd(tag,ifd), s); } } } }
/* get all exif data in readable form */ void exif_get_info(ExifData * ed, char *buffer, unsigned int maxsize) { ExifEntry *entry = NULL; char buf[EXIF_STD_BUF_LEN]; unsigned short int i = 0; if ( (buffer == NULL) || (maxsize == 0) ) { return; } else if (ed == NULL) { snprintf(buffer, (size_t)maxsize, "%s\n", "No Exif data in file."); return; } else { /* show normal exif tags. list must be defined in exif_cfg.h */ while ( (Exif_tag_list[i].ifd != EXIF_IFD_COUNT) && (i < USHRT_MAX) ) { exif_get_tag(ed, Exif_tag_list[i].ifd, Exif_tag_list[i].tag, buffer + strlen(buffer), maxsize - strlen(buffer)); i++; } /* show vendor specific makernote tags */ entry = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_MAKE); if (entry != NULL) { if (exif_entry_get_value(entry, buf, sizeof(buf))) { exif_trim_spaces(buf); if ( (strcmp(buf, "NIKON CORPORATION") == 0) || (strcmp(buf, "Nikon") == 0) || (strcmp(buf, "NIKON") == 0) ) { /* show nikon makernote exif tags. list must be defined in exif_cfg.h */ i=0; while ( (Exif_makernote_nikon_tag_list[i] != EXIF_NIKON_MAKERNOTE_END) && (i < USHRT_MAX) ) { exn_get_mnote_nikon_tags(ed, Exif_makernote_nikon_tag_list[i], buffer + strlen(buffer), maxsize - strlen(buffer)); i++; } } else if ( (strcmp(buf, "Canon") == 0) ) { /* show canon makernote exif tags. list must be defined in exif_cfg.h */ i=0; while ( (Exif_makernote_canon_tag_list[i] != EXIF_CANON_MAKERNOTE_END) && (i < USHRT_MAX) ) { exc_get_mnote_canon_tags(ed, Exif_makernote_canon_tag_list[i], buffer + strlen(buffer), maxsize - strlen(buffer)); i++; } } else { } } } /* show gps coordinates */ exif_get_gps_coords(ed, buffer + strlen(buffer), maxsize - strlen(buffer)); } }