Ejemplo n.º 1
0
/**
 * a_geotag_get_exif_date_from_file:
 * @filename: The image file to process
 * @has_GPS_info: Returns whether the file has existing GPS information
 *
 * Returns: An allocated string with the date and time in EXIF_DATE_FORMAT, otherwise NULL if some kind of failure
 *
 *  Here EXIF processing is used to get time information
 *
 */
gchar* a_geotag_get_exif_date_from_file ( const gchar *filename, gboolean *has_GPS_info )
{
	gchar* datetime = NULL;

	ExifData *ed = exif_data_new_from_file ( filename );

	// Detect EXIF load failure
	if ( !ed )
		return datetime;

	gchar str[128];
	ExifEntry *ee;

	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_EXIF], EXIF_TAG_DATE_TIME_ORIGINAL);
	if ( ee ) {
		exif_entry_get_value ( ee, str, 128 );
		datetime = g_strdup ( str );
	}

	// Check GPS Info
	*has_GPS_info = FALSE;
	
	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_GPS], EXIF_TAG_GPS_VERSION_ID);
	// Confirm this has a GPS Id - normally "2.0.0.0" or "2.2.0.0"
	if ( ee && ee->components == 4 )
		*has_GPS_info = TRUE;

	exif_data_free ( ed );

	return datetime;
}
Ejemplo n.º 2
0
static bool readExif(const char* path, float& shutter)
{
  ExifData* data = exif_data_new_from_file(path);
  if (data == nullptr)
    return false;
  
  ExifEntry *shutterEnt;
  shutterEnt = exif_content_get_entry(data->ifd[EXIF_IFD_EXIF],
                                      EXIF_TAG_EXPOSURE_TIME);
  if(!shutterEnt)
    shutterEnt = exif_content_get_entry(data->ifd[EXIF_IFD_0],
                                        EXIF_TAG_EXPOSURE_TIME);
  if(!shutterEnt)
    shutterEnt = exif_content_get_entry(data->ifd[EXIF_IFD_1],
                                        EXIF_TAG_EXPOSURE_TIME);
  
  if(shutterEnt == NULL){
    fprintf(stderr, "Error: Cannot read photography info.\n");
    exif_data_unref(data);
    return false;
  }
  
  char buf[1024];
  exif_entry_get_value(shutterEnt, buf, sizeof(buf));
  printf("shutter = %s\n", buf);
  
  ExifSRational r;
  r = exif_get_srational(shutterEnt->data, exif_data_get_byte_order(data));
  shutter = (float)r.numerator / (float)r.denominator;
  
  // Close
  exif_data_unref(data);
  return true;
}
Ejemplo n.º 3
0
// Implementation using libexif
void ImageResolution::readexif(char const *fn) {
  ExifData *ed;
  ed = exif_data_new_from_file(fn);
  if (!ed)
    return;
  ExifByteOrder byte_order = exif_data_get_byte_order(ed);
  
  ExifEntry *xres = exif_content_get_entry(ed->ifd[EXIF_IFD_0],
					   EXIF_TAG_X_RESOLUTION);
  ExifEntry *yres = exif_content_get_entry(ed->ifd[EXIF_IFD_0],
					   EXIF_TAG_Y_RESOLUTION);
  ExifEntry *unit = exif_content_get_entry(ed->ifd[EXIF_IFD_0],
					   EXIF_TAG_RESOLUTION_UNIT);
  if (xres && yres) {
    x_ = exifDouble(xres, byte_order);
    y_ = exifDouble(yres, byte_order);
    if (unit) {
      double u = exifDouble(unit, byte_order);
      if (u==3) {
	x_ *= 2.54;
	y_ *= 2.54;
      }
    }
    ok_ = true;
  }
  exif_data_free(ed);
}
Ejemplo n.º 4
0
/**
 * a_geotag_get_exif_date_from_file:
 * @filename: The image file to process
 * @has_GPS_info: Returns whether the file has existing GPS information
 *
 * Returns: An allocated string with the date and time in EXIF_DATE_FORMAT, otherwise NULL if some kind of failure
 *
 *  Here EXIF processing is used to get time information
 *
 */
gchar* a_geotag_get_exif_date_from_file ( const gchar *filename, gboolean *has_GPS_info )
{
	gchar* datetime = NULL;
	*has_GPS_info = FALSE;

#ifdef HAVE_LIBGEXIV2
	GExiv2Metadata *gemd = gexiv2_metadata_new ();
	if ( gexiv2_metadata_open_path ( gemd, filename, NULL ) ) {
		gdouble lat, lon;
		*has_GPS_info = ( gexiv2_metadata_get_gps_longitude(gemd,&lon) && gexiv2_metadata_get_gps_latitude(gemd,&lat) );

		// Prefer 'Photo' version over 'Image'
		if ( gexiv2_metadata_has_tag ( gemd, "Exif.Photo.DateTimeOriginal" ) )
			datetime = g_strdup ( gexiv2_metadata_get_tag_interpreted_string ( gemd, "Exif.Photo.DateTimeOriginal" ) );
		else
			datetime = g_strdup ( gexiv2_metadata_get_tag_interpreted_string ( gemd, "Exif.Image.DateTimeOriginal" ) );
	}
	metadata_free ( gemd );
#else
#ifdef HAVE_LIBEXIF
	ExifData *ed = exif_data_new_from_file ( filename );

	// Detect EXIF load failure
	if ( !ed )
		return datetime;

	gchar str[128];
	ExifEntry *ee;

	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_EXIF], EXIF_TAG_DATE_TIME_ORIGINAL);
	if ( ee ) {
		exif_entry_get_value ( ee, str, 128 );
		datetime = g_strdup ( str );
	}

	// Check GPS Info

	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_GPS], EXIF_TAG_GPS_VERSION_ID);
	// Confirm this has a GPS Id - normally "2.0.0.0" or "2.2.0.0"
	if ( ee && ee->components == 4 )
		*has_GPS_info = TRUE;

	// Check other basic GPS fields exist too
	// I have encountered some images which have just the EXIF_TAG_GPS_VERSION_ID but nothing else
	// So to confirm check more EXIF GPS TAGS:
	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_GPS], EXIF_TAG_GPS_LATITUDE);
	if ( !ee )
		*has_GPS_info = FALSE;
	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_GPS], EXIF_TAG_GPS_LONGITUDE);
	if ( !ee )
		*has_GPS_info = FALSE;

	exif_data_free ( ed );
#endif
#endif
	return datetime;
}
Ejemplo n.º 5
0
MapTags *read_sgeo_tags_map(ExifData **exif_array, ExifIfd ifd, ExifShort map_count)
{
	int i;
	MapTags *map_data = NULL;
	ExifData *exif = NULL;
	ExifEntry *entry;
	ExifByteOrder order;
	SGeoTag stag;
	ExifSRational *srational = NULL;
	ExifLong *elong = NULL;
	
	order = exif_data_get_byte_order(exif);
	map_data = (MapTags* )calloc(map_count, sizeof(*map_data));
	for (i = 0; i < map_count; i++)
	{
		exif = exif_array[i];

		entry = exif_content_get_entry (exif->ifd[ifd], (ExifTag)(SGEO_TAG_MAP_VERSION));
		if (entry)
			memcpy(map_data[i].VersionID, entry->data, sizeof(map_data[i].VersionID));

		entry = exif_content_get_entry (exif->ifd[ifd], (ExifTag)(SGEO_TAG_MAP_ID));
		if (entry)
			map_data[i].ID = exif_get_long(entry->data, order);

		srational = &map_data[i].TopLeftLongitude;
		for (stag = SGEO_TAG_MAP_TOP_LEFT_LONGITUDE; stag <= SGEO_TAG_MAP_BOTTOM_RIGHT_LATITUDE; stag++)
		{
			entry = exif_content_get_entry (exif->ifd[ifd], (ExifTag)(stag));
			if (entry)
				*srational = exif_get_srational(entry->data, order);
			srational++;
		}
		elong = &map_data[i].CoordinateSystem;
		for (stag = SGEO_TAG_MAP_COORDINATE_SYSTEM; stag <= SGEO_TAG_MAP_THUMBNAIL_FORMAT; stag++)
		{
			entry = exif_content_get_entry (exif->ifd[ifd], (ExifTag)(stag));
			if (entry)
				*elong = exif_get_long(entry->data, order);
			elong++;
		}
		entry = exif_content_get_entry (exif->ifd[ifd], (ExifTag)(SGEO_TAG_MAP_THUMBNAIL));
		if (entry)
		{
			map_data[i].Data = (void *)malloc(entry->size);
			map_data[i].DataSize = entry->size;
			memcpy(map_data[i].Data, entry->data, entry->size);
		}
	}
	return map_data;
}
Ejemplo n.º 6
0
/* Write a tag. Update what's there, or make a new one.
 */
static void
vips_exif_set_tag( ExifData *ed, int ifd, ExifTag tag, write_fn fn, void *data )
{
	ExifEntry *entry;

	if( (entry = exif_content_get_entry( ed->ifd[ifd], tag )) ) {
		fn( ed, entry, 0, data );
	}
	else {
		entry = exif_entry_new();

		/* tag must be set before calling exif_content_add_entry.
		 */
		entry->tag = tag; 
		exif_content_add_entry( ed->ifd[ifd], entry );
		exif_entry_unref( entry );

		/* libexif makes us have a special path for string-valued
		 * fields :(
		 */
		if( tag_is_encoding( tag ) ) 
			vips_exif_set_string_encoding( ed, entry, 0, data );
		else if( tag_is_ascii( tag ) ) 
			vips_exif_set_string_ascii( ed, entry, 0, data );
		else if( tag_is_utf16( tag ) )
			vips_exif_set_string_utf16( ed, entry, 0, data );
		else {
			exif_entry_initialize( entry, tag );
			fn( ed, entry, 0, data );
		}
	}
}
Ejemplo n.º 7
0
/* Print exif for debugging ... hacked from exif-0.6.9/actions.c
 */
static void
show_tags( ExifData *data )
{
	int i;
	unsigned int tag;
	const char *name;

	printf( "show EXIF tags:\n" );

        for( i = 0; i < EXIF_IFD_COUNT; i++ )
                printf( "%-7.7s", exif_ifd_get_name( i ) );
	printf( "\n" );

        for( tag = 0; tag < 0xffff; tag++ ) {
                name = exif_tag_get_title( tag );
                if( !name )      
                        continue;   
                printf( "  0x%04x %-29.29s", tag, name );
                for( i = 0; i < EXIF_IFD_COUNT; i++ )
                        if( exif_content_get_entry( data->ifd[i], tag ) )
                                printf( "   *   " );
                        else
                                printf( "   -   " );
		printf( "\n" );
        }
}
Ejemplo n.º 8
0
// Remove an existing EXIF entry from |exifData| if it exists. This is useful
// when replacing existing data, it's easier to just remove the data and
// re-allocate it than to adjust the amount of allocated data.
static void removeExistingEntry(ExifData* exifData, ExifIfd ifd, int tag) {
    ExifEntry* entry = exif_content_get_entry(exifData->ifd[ifd],
                                              static_cast<ExifTag>(tag));
    if (entry) {
        exif_content_remove_entry(exifData->ifd[ifd], entry);
    }
}
Ejemplo n.º 9
0
/**
 * a_geotag_create_waypoint_positioned:
 * @filename: The image file to process
 * @coord:    The location for positioning the Waypoint
 * @name:     Returns a name for the Waypoint (can be NULL)
 *
 * Returns: An allocated Waypoint or NULL if Waypoint could not be generated
 *
 *  Here EXIF processing is used to get non position related information (i.e. just the comment)
 *
 */
VikWaypoint* a_geotag_create_waypoint_positioned ( const gchar *filename, VikCoord coord, gdouble alt, gchar **name )
{
	*name = NULL;
	VikWaypoint *wp = vik_waypoint_new();
	wp->visible = TRUE;
	wp->coord = coord;
	wp->altitude = alt;

	ExifData *ed = exif_data_new_from_file ( filename );

	// Set info from exif values
	if ( ed ) {
		wp->comment = geotag_get_exif_comment ( ed );

		gchar str[128];
		ExifEntry *ee;
		// Name
		ee = exif_content_get_entry (ed->ifd[EXIF_IFD_0], EXIF_TAG_XP_TITLE);
		if ( ee ) {
			exif_entry_get_value ( ee, str, 128 );
			*name = g_strdup ( str );
		}

		// Finished with EXIF
		exif_data_free ( ed );
	}

	vik_waypoint_set_image ( wp, filename );


	return wp;
}
Ejemplo n.º 10
0
// get the tag
void get_tag(ExifData* d, ExifIfd ifd, ExifTag tag, char* buf, int len)
{
  ExifEntry *entry = exif_content_get_entry(d->ifd[ifd],tag);
  if (entry) {
    exif_entry_get_value(entry, buf, len);
    right_trim(buf,' ');
  }
}
Ejemplo n.º 11
0
void
exif_content_fix (ExifContent *c)
{
	ExifIfd ifd = exif_content_get_ifd (c);
	ExifDataType dt;
	ExifTag t;
	ExifEntry *e;

	if (!c) return;

	dt = exif_data_get_data_type (c->parent);

	/* First of all, fix all existing entries. */
	exif_content_foreach_entry (c, fix_func, NULL);

	/*
	 * Then check for existing tags that are not allowed and for
	 * non-existing mandatory tags.
	 */
	for (t = 0; t <= 0xffff; t++) {
		switch (exif_tag_get_support_level_in_ifd (t, ifd, dt)) {
		case EXIF_SUPPORT_LEVEL_MANDATORY:
			if (exif_content_get_entry (c, t)) break;
			exif_log (c->priv->log, EXIF_LOG_CODE_DEBUG, "exif-content",
					"Tag '%s' is mandatory in IFD '%s' and has therefore been added.",
					exif_tag_get_name_in_ifd (t, ifd), exif_ifd_get_name (ifd));
			e = exif_entry_new ();
			exif_content_add_entry (c, e);
			exif_entry_initialize (e, t);
			exif_entry_unref (e);
			break;
		case EXIF_SUPPORT_LEVEL_NOT_RECORDED:
			e = exif_content_get_entry (c, t);
			if (!e) break;
			exif_log (c->priv->log, EXIF_LOG_CODE_DEBUG, "exif-content",
					"Tag '%s' is not recoreded in IFD '%s' and has therefore been "
					"removed.", exif_tag_get_name_in_ifd (t, ifd),
					exif_ifd_get_name (ifd));
			exif_content_remove_entry (c, e);
			break;
		case EXIF_SUPPORT_LEVEL_OPTIONAL:
		default:
			break;
		}
	}
}
Ejemplo n.º 12
0
Archivo: exif.c Proyecto: radhermit/feh
/* 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));
        }

      }
    }
  }
}
Ejemplo n.º 13
0
static void update_orientation(ExifData *ed, int ifd, int orientation)
{
    ExifEntry *ee;

    ee = exif_content_get_entry(ed->ifd[ifd], 0x0112);
    if (NULL == ee)
	return;
    set_int(ed,ee,orientation);
}
Ejemplo n.º 14
0
/**! If the entry doesn't exist, create it.
 * Based on exif command line action_create_value function in exif 0.6.20
 */
static ExifEntry* my_exif_create_value (ExifData *ed, ExifTag tag, ExifIfd ifd)
{
	ExifEntry *e = exif_content_get_entry (ed->ifd[ifd], tag);
	if ( !e ) {
	    e = exif_entry_new ();
	    exif_content_add_entry (ed->ifd[ifd], e);

		exif_entry_initialize (e, tag);

		// exif_entry_initialize doesn't seem to do much, especially for the GPS tags
		//   so have to setup fields ourselves:
		e->tag = tag;

		if ( tag == EXIF_TAG_GPS_VERSION_ID ) {
			e->format = EXIF_FORMAT_BYTE;
			e->components = 4;
			e->size = sizeof (char) * e->components;
			if ( e->data )
				g_free (e->data);
			e->data = g_malloc (e->size);
		}
		if ( tag == EXIF_TAG_GPS_MAP_DATUM ||
			 tag == EXIF_TAG_GPS_LATITUDE_REF || tag == EXIF_TAG_GPS_LONGITUDE_REF ||
			 tag == EXIF_TAG_GPS_PROCESSING_METHOD ) {
			e->format = EXIF_FORMAT_ASCII;
			// NB Allocation is handled later on when the actual string used is known
		}
		if ( tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE ) {
			e->format = EXIF_FORMAT_RATIONAL;
			e->components = 3;
			e->size = sizeof (ExifRational) * e->components;
			if ( e->data )
				g_free (e->data);
			e->data = g_malloc (e->size);
		}
		if ( tag == EXIF_TAG_GPS_ALTITUDE ) {
			e->format = EXIF_FORMAT_RATIONAL;
			e->components = 1;
			e->size = sizeof (ExifRational) * e->components;
			if ( e->data )
				g_free (e->data);
			e->data = g_malloc (e->size);
		}
		if ( tag == EXIF_TAG_GPS_ALTITUDE_REF ) {
			e->components = 1;
			e->size = sizeof (char) * e->components;
			if ( e->data )
				g_free (e->data);
			e->data = g_malloc (e->size);
		}
	    /* The entry has been added to the IFD, so we can unref it */
	    //exif_entry_unref(e);
		// Crashes later on, when saving to jpeg if the above unref is enabled!!
		// ?Some other malloc problem somewhere?
	}
	return e;
}
Ejemplo n.º 15
0
static QImage* reorient_with_exif( producer_qimage self, int image_idx, QImage *qimage )
{
#ifdef USE_EXIF
	mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( &self->parent );
	ExifData *d = exif_data_new_from_file( mlt_properties_get_value( self->filenames, image_idx ) );
	ExifEntry *entry;
	int exif_orientation = 0;
	/* get orientation and rotate image accordingly if necessary */
	if (d) {
		if ( ( entry = exif_content_get_entry ( d->ifd[EXIF_IFD_0], EXIF_TAG_ORIENTATION ) ) )
			exif_orientation = exif_get_short (entry->data, exif_data_get_byte_order (d));

		/* Free the EXIF data */
		exif_data_unref(d);
	}

	// Remember EXIF value, might be useful for someone
	mlt_properties_set_int( producer_props, "_exif_orientation" , exif_orientation );

	if ( exif_orientation > 1 )
	{
		  // Rotate image according to exif data
		  QImage processed;
		  QMatrix matrix;

		  switch ( exif_orientation ) {
		  case 2:
			  matrix.scale( -1, 1 );
			  break;
		  case 3:
			  matrix.rotate( 180 );
			  break;
		  case 4:
			  matrix.scale( 1, -1 );
			  break;
		  case 5:
			  matrix.rotate( 270 );
			  matrix.scale( -1, 1 );
			  break;
		  case 6:
			  matrix.rotate( 90 );
			  break;
		  case 7:
			  matrix.rotate( 90 );
			  matrix.scale( -1, 1 );
			  break;
		  case 8:
			  matrix.rotate( 270 );
			  break;
		  }
		  processed = qimage->transformed( matrix );
		  delete qimage;
		  qimage = new QImage( processed );
	}
#endif
	return qimage;
}
Ejemplo n.º 16
0
static struct LatLon get_latlon ( ExifData *ed )
{
	struct LatLon ll = { 0.0, 0.0 };
	const struct LatLon ll0 = { 0.0, 0.0 };

	gchar str[128];
	ExifEntry *ee;
	//
	// Lat & Long is necessary to form a waypoint.
	//
	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_GPS], EXIF_TAG_GPS_LATITUDE);
	if ( ! ( ee && ee->components == 3 && ee->format == EXIF_FORMAT_RATIONAL ) )
		return ll0;

	ll.lat = Rational2Double ( ee->data,
							   exif_format_get_size(ee->format),
							   exif_data_get_byte_order(ed) );

	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_GPS], EXIF_TAG_GPS_LATITUDE_REF);
	if ( ee ) {
		exif_entry_get_value ( ee, str, 128 );
		if ( str[0] == 'S' )
			ll.lat = -ll.lat;
	}

	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_GPS], EXIF_TAG_GPS_LONGITUDE);
	if ( ! ( ee && ee->components == 3 && ee->format == EXIF_FORMAT_RATIONAL ) )
		return ll0;

	ll.lon = Rational2Double ( ee->data,
							   exif_format_get_size(ee->format),
							   exif_data_get_byte_order(ed) );

	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_GPS], EXIF_TAG_GPS_LONGITUDE_REF);
	if ( ee ) {
		exif_entry_get_value ( ee, str, 128 );
		if ( str[0] == 'W' )
			ll.lon = -ll.lon;
	}

	return ll;
}
Ejemplo n.º 17
0
static int
vips_exif_entry_get_int( ExifData *ed, int ifd, ExifTag tag, int *out )
{
	ExifEntry *entry;

	if( !(entry = exif_content_get_entry( ed->ifd[ifd], tag )) ||
		entry->components != 1 )
		return( -1 );

	return( vips_exif_get_int( ed, entry, 0, out ) );
}
Ejemplo n.º 18
0
long GalleryUtil::GetNaturalRotation(void *exifData)
{
    long rotateAngle = 0;

#ifdef EXIF_SUPPORT
    // Qt 5.4.1 automatically orientates images according to their EXIF data
    if (strcmp(qVersion(), "5.4.1") == 0)
        return 0;

    ExifData *data = (ExifData *)exifData;

    if (!data)
        return 0;

    for (int i = 0; i < EXIF_IFD_COUNT; i++)
    {
        ExifEntry *entry = exif_content_get_entry(data->ifd[i],
                                                  EXIF_TAG_ORIENTATION);
        ExifByteOrder byteorder = exif_data_get_byte_order(data);

        if (entry)
        {
            ExifShort v_short = exif_get_short(entry->data, byteorder);
            LOG(VB_GENERAL, LOG_DEBUG,
                QString("Exif entry=%1").arg(v_short));

            /* See http://sylvana.net/jpegcrop/exif_orientation.html*/
            switch (v_short)
            {
                case 3:
                    rotateAngle = 180;
                    break;
                case 6:
                    rotateAngle = 90;
                    break;
                case 8:
                    rotateAngle = -90;
                    break;
                default:
                    rotateAngle = 0;
                    break;
            }
            break;
        }
    }
#else
    // Shut the compiler up about the unused argument
    (void)exifData;
#endif // EXIF_SUPPORT

    return rotateAngle;
}
Ejemplo n.º 19
0
void
exif_content_fix (ExifContent *c)
{
	ExifIfd ifd = exif_content_get_ifd (c);
	ExifDataType dt;
	ExifEntry *e;
	unsigned int i, num;

	if (!c)
		return;

	dt = exif_data_get_data_type (c->parent);

	/*
	 * First of all, fix all existing entries.
	 */
	exif_content_foreach_entry (c, fix_func, NULL);

	/*
	 * Go through each tag and if it's not recorded, remove it. If one
	 * is removed, exif_content_foreach_entry() will skip the next entry,
	 * so if this happens do the loop again from the beginning to ensure
	 * they're all checked. This could be avoided if we stop relying on
	 * exif_content_foreach_entry but loop intelligently here.
	 */
	do {
		num = c->count;
		exif_content_foreach_entry (c, remove_not_recorded, NULL);
	} while (num != c->count);

	/*
	 * Then check for non-existing mandatory tags and create them if needed
	 */
	num = exif_tag_table_count();
	for (i = 0; i < num; ++i) {
		const ExifTag t = exif_tag_table_get_tag (i);
		if (exif_tag_get_support_level_in_ifd (t, ifd, dt) ==
			EXIF_SUPPORT_LEVEL_MANDATORY) {
			if (exif_content_get_entry (c, t))
				/* This tag already exists */
				continue;
			exif_log (c->priv->log, EXIF_LOG_CODE_DEBUG, "exif-content",
					"Tag '%s' is mandatory in IFD '%s' and has therefore been added.",
					exif_tag_get_name_in_ifd (t, ifd), exif_ifd_get_name (ifd));
			e = exif_entry_new ();
			exif_content_add_entry (c, e);
			exif_entry_initialize (e, t);
			exif_entry_unref (e);
		}
	}
}
Ejemplo n.º 20
0
/* Just find the first occurence of the tag (is this correct?)
 */
static ExifEntry *
find_entry( ExifData *ed, ExifTag tag )
{
	int i;

	for( i = 0; i < EXIF_IFD_COUNT; i++ ) {
		ExifEntry *entry;

		if( (entry = exif_content_get_entry( ed->ifd[i], tag )) )
			return( entry );
	}

	return( NULL );
}
Ejemplo n.º 21
0
QDateTime Exif2GPX::getTimeFromEXIF(const QString& filename) {
  
  // load the exif data
  ExifData* exifData;
  if (!(exifData = exif_data_new_from_file((const char*)filename))) {
    std::cerr<<"Could not load EXIF data from "<<filename<<std::endl;
    return QDateTime();
  }
  
  // find the timestamp
  ExifEntry* entry;
  entry = exif_content_get_entry(exifData->ifd[EXIF_IFD_0], 
				 EXIF_TAG_DATE_TIME);
  if (!entry)
    entry = exif_content_get_entry(exifData->ifd[EXIF_IFD_EXIF],
				   EXIF_TAG_DATE_TIME_ORIGINAL);
  if (!entry)
    entry = exif_content_get_entry(exifData->ifd[EXIF_IFD_EXIF],
				   EXIF_TAG_DATE_TIME_DIGITIZED);
  if (!entry) {
    std::cerr<<"Could not find a valid timestamp in "<<filename<<std::endl;
    return QDateTime();
  }
  
  // parse it
  int year, month, day, hour, minute, second;
  if (std::sscanf((char*)entry->data, "%d:%d:%d %d:%d:%d", &year, &month, &day,
		  &hour, &minute, &second) != 6) {
    std::cerr<<"Could not find a valid timestamp in "<<filename<<std::endl;
    return QDateTime();
  }
  QDateTime timestamp(QDate(year, month, day), QTime(hour, minute, second));
  
  std::cerr<<filename<<": "<<timestamp.toString()<<std::endl;

  return timestamp;
}
Ejemplo n.º 22
0
/**
 * Attempt to get a single comment from the various exif fields
 */
static gchar* geotag_get_exif_comment ( ExifData *ed )
{
	gchar str[128];
	ExifEntry *ee;
	//
	// Try various options to create a comment
	//
	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_0], EXIF_TAG_IMAGE_DESCRIPTION);
	if ( ee ) {
		exif_entry_get_value ( ee, str, 128 );
		return g_strdup ( str );
	}

	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_0], EXIF_TAG_XP_COMMENT);
	if ( ee ) {
		exif_entry_get_value ( ee, str, 128 );
		return g_strdup ( str );
	}

	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_0], EXIF_TAG_XP_SUBJECT);
	if ( ee ) {
		exif_entry_get_value ( ee, str, 128 );
		return g_strdup ( str );
	}

	// Consider using these for existing GPS info??
	//#define EXIF_TAG_GPS_TIME_STAMP        0x0007
	//#define EXIF_TAG_GPS_DATE_STAMP         0x001d
	ee = exif_content_get_entry (ed->ifd[EXIF_IFD_EXIF], EXIF_TAG_DATE_TIME_ORIGINAL);
	if ( ee ) {
		exif_entry_get_value ( ee, str, 128 );
		return g_strdup ( str );
	}
	
	// Otherwise nothing found
	return NULL;
}
///@todo create a dedicated EXIF class
QString ImageImporter::getEntry(ExifContent* c, ExifTag tag)
{

    QString retval;
    ExifEntry* entry = exif_content_get_entry(c, tag);

    if (entry) {
        const int len = 256;
        char charData[len];
        exif_entry_get_value(entry, charData, len);
        retval = QString(charData);
    }

    return retval;
}
Ejemplo n.º 24
0
gint
jpeg_exif_get_orientation (ExifData *exif_data)
{
  ExifEntry *entry;
  gint       byte_order = exif_data_get_byte_order (exif_data);

  /* get orientation and rotate image accordingly if necessary */
  if ((entry = exif_content_get_entry (exif_data->ifd[EXIF_IFD_0],
                                       EXIF_TAG_ORIENTATION)))
    {
      return exif_get_short (entry->data, byte_order);
    }

  return 0;
}
Ejemplo n.º 25
0
Archivo: image.c Proyecto: pts/pts-qiv
//#include "libexif/exif-tag.h"   //EXIF_TAG_ORIENTATION
enum Orientation orient( const char * path) {
    enum Orientation orientation = NOT_AVAILABLE;

    ExifData * mExifData = exif_data_new_from_file( path);
    if (mExifData) {
        ExifEntry * mOrientationEntry = exif_content_get_entry( mExifData->ifd[ EXIF_IFD_0], EXIF_TAG_ORIENTATION);
        if (mOrientationEntry) {
            ExifByteOrder mByteOrder = exif_data_get_byte_order( mExifData);
            short value=exif_get_short( mOrientationEntry->data, mByteOrder);
            if (value>=NORMAL && value<=ROT_270)
                orientation = value;    //Orientation( value);
        }
        exif_data_unref( mExifData );
    }
    return orientation;
}
Ejemplo n.º 26
0
/**
 * a_geotag_waypoint_positioned:
 * @filename: The image file to process
 * @coord:    The location for positioning the Waypoint
 * @name:     Returns a name for the Waypoint (can be NULL)
 * @waypoint: An existing waypoint to update (can be NULL to generate a new waypoint)
 *
 * Returns: An allocated waypoint if the input waypoint is NULL,
 *  otherwise the passed in waypoint is updated
 *
 *  Here EXIF processing is used to get non position related information (i.e. just the comment)
 *
 */
VikWaypoint* a_geotag_waypoint_positioned ( const gchar *filename, VikCoord coord, gdouble alt, gchar **name, VikWaypoint *wp )
{
	*name = NULL;
	if ( wp == NULL ) {
		// Need to create waypoint
		wp = vik_waypoint_new();
		wp->visible = TRUE;
	}
	wp->coord = coord;
	wp->altitude = alt;

#ifdef HAVE_LIBGEXIV2
	GExiv2Metadata *gemd = gexiv2_metadata_new ();
	if ( gexiv2_metadata_open_path ( gemd, filename, NULL ) ) {
			wp->comment = geotag_get_exif_comment ( gemd );
			if ( gexiv2_metadata_has_tag ( gemd, "Exif.Image.XPTitle" ) )
				*name = g_strdup ( gexiv2_metadata_get_tag_interpreted_string ( gemd, "Exif.Image.XPTitle" ) );
	}
	metadata_free ( gemd );
#else
#ifdef HAVE_LIBEXIF
	ExifData *ed = exif_data_new_from_file ( filename );

	// Set info from exif values
	if ( ed ) {
		wp->comment = geotag_get_exif_comment ( ed );

		gchar str[128];
		ExifEntry *ee;
		// Name
		ee = exif_content_get_entry (ed->ifd[EXIF_IFD_0], EXIF_TAG_XP_TITLE);
		if ( ee ) {
			exif_entry_get_value ( ee, str, 128 );
			*name = g_strdup ( str );
		}

		// Finished with EXIF
		exif_data_free ( ed );
	}
#endif
#endif

	vik_waypoint_set_image ( wp, filename );

	return wp;
}
Ejemplo n.º 27
0
void exif_auto_orientate(const fileinfo_t *file) {
	ExifData *ed;
	ExifEntry *entry;
	int byte_order, orientation;

	if ((ed = exif_data_new_from_file(file->path)) == NULL)
		return;
	entry = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_ORIENTATION);
	if (entry != NULL) {
		byte_order = exif_data_get_byte_order(ed);
		orientation = exif_get_short(entry->data, byte_order);
	}
	exif_data_unref(ed);
	if (entry == NULL)
		return;

	switch (orientation) {
		case 5:
			imlib_image_orientate(1);
		case 2:
			imlib_image_flip_vertical();
			break;

		case 3:
			imlib_image_orientate(2);
			break;

		case 7:
			imlib_image_orientate(1);
		case 4:
			imlib_image_flip_horizontal();
			break;

		case 6:
			imlib_image_orientate(1);
			break;

		case 8:
			imlib_image_orientate(3);
			break;
	}
}
Ejemplo n.º 28
0
/**
 * a_geotag_get_position:
 *
 * @filename: The (JPG) file with EXIF information in it
 *
 * Returns: The position in LatLon format.
 *  It will be 0,0 if some kind of failure occurs.
 */
struct LatLon a_geotag_get_position ( const gchar *filename )
{
	struct LatLon ll = { 0.0, 0.0 };

#ifdef HAVE_LIBGEXIV2
	GExiv2Metadata *gemd = gexiv2_metadata_new ();
	if ( gexiv2_metadata_open_path ( gemd, filename, NULL ) ) {
		gdouble lat;
		gdouble lon;
		gdouble alt;
		if ( gexiv2_metadata_get_gps_info ( gemd, &lon, &lat, &alt ) ) {
			ll.lat = lat;
			ll.lon = lon;
		}
	}
	metadata_free  ( gemd );
#else
#ifdef HAVE_LIBEXIF
	// open image with libexif
	ExifData *ed = exif_data_new_from_file ( filename );

	// Detect EXIF load failure
	if ( !ed )
		return ll;

	ExifEntry *ee = exif_content_get_entry (ed->ifd[EXIF_IFD_GPS], EXIF_TAG_GPS_VERSION_ID);
	// Confirm this has a GPS Id - normally "2.0.0.0" or "2.2.0.0"
	if ( ! ( ee && ee->components == 4 ) )
		goto MyReturn0;

	ll = get_latlon ( ed );

MyReturn0:
	// Finished with EXIF
	exif_data_free ( ed );
#endif
#endif

	return ll;
}
Ejemplo n.º 29
0
Archivo: exif.c Proyecto: radhermit/feh
/* 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);
      }
    }
  }
}
Ejemplo n.º 30
0
/* Write a tag. Update what's there, or make a new one.
 */
static void
write_tag( ExifData *ed, int ifd, ExifTag tag, write_fn fn, void *data )
{
	ExifEntry *entry;

	if( (entry = exif_content_get_entry( ed->ifd[ifd], tag )) ) {
		fn( ed, entry, 0, data );
	}
	else {
		entry = exif_entry_new();

		/* tag must be set before calling exif_content_add_entry.
		 */
		entry->tag = tag; 

		exif_content_add_entry( ed->ifd[ifd], entry );
		exif_entry_initialize( entry, tag );
		exif_entry_unref( entry );

		fn( ed, entry, 0, data );
	}
}