ifd_enumerate.go: Add date normalization. Skip altitude if zero denominator.

Fixes 
dustin/add_float_and_double
Dustin Oprea 2020-07-17 02:39:59 -04:00
parent 08f1b67089
commit 46b1a0cd17
4 changed files with 68 additions and 14 deletions

View File

@ -1055,23 +1055,35 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) {
altitudeRefTags, foundAltitudeRef := ifd.EntriesByTagId[TagAltitudeRefId]
if foundAltitude == true && foundAltitudeRef == true {
altitudePhrase, err := altitudeTags[0].Format()
log.PanicIf(err)
ifdEnumerateLogger.Debugf(nil, "Altitude is [%s].", altitudePhrase)
altitudeValue, err := altitudeTags[0].Value()
log.PanicIf(err)
altitudeRefPhrase, err := altitudeRefTags[0].Format()
log.PanicIf(err)
ifdEnumerateLogger.Debugf(nil, "Altitude-reference is [%s].", altitudeRefPhrase)
altitudeRefValue, err := altitudeRefTags[0].Value()
log.PanicIf(err)
altitudeRaw := altitudeValue.([]exifcommon.Rational)
altitude := int(altitudeRaw[0].Numerator / altitudeRaw[0].Denominator)
if altitudeRaw[0].Denominator > 0 {
altitude := int(altitudeRaw[0].Numerator / altitudeRaw[0].Denominator)
if altitudeRefValue.([]byte)[0] == 1 {
altitude *= -1
if altitudeRefValue.([]byte)[0] == 1 {
altitude *= -1
}
gi.Altitude = altitude
}
gi.Altitude = altitude
}
// Parse time.
// Parse timestamp from separate date and time tags.
timestampTags, foundTimestamp := ifd.EntriesByTagId[TagTimestampId]
datestampTags, foundDatestamp := ifd.EntriesByTagId[TagDatestampId]
@ -1080,7 +1092,13 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) {
datestampValue, err := datestampTags[0].Value()
log.PanicIf(err)
dateParts := strings.Split(datestampValue.(string), ":")
datePhrase := datestampValue.(string)
ifdEnumerateLogger.Debugf(nil, "Date tag value is [%s].", datePhrase)
// Normalize the separators.
datePhrase = strings.ReplaceAll(datePhrase, "-", ":")
dateParts := strings.Split(datePhrase, ":")
year, err1 := strconv.ParseUint(dateParts[0], 10, 16)
month, err2 := strconv.ParseUint(dateParts[1], 10, 8)
@ -1090,6 +1108,11 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) {
timestampValue, err := timestampTags[0].Value()
log.PanicIf(err)
timePhrase, err := timestampTags[0].Format()
log.PanicIf(err)
ifdEnumerateLogger.Debugf(nil, "Time tag value is [%s].", timePhrase)
timestampRaw := timestampValue.([]exifcommon.Rational)
hour := int(timestampRaw[0].Numerator / timestampRaw[0].Denominator)

View File

@ -34,6 +34,10 @@ func ParseExifFullTimestamp(fullTimestampPhrase string) (timestamp time.Time, er
parts := strings.Split(fullTimestampPhrase, " ")
datestampValue, timestampValue := parts[0], parts[1]
// Normalize the separators.
datestampValue = strings.ReplaceAll(datestampValue, "-", ":")
timestampValue = strings.ReplaceAll(timestampValue, "-", ":")
dateParts := strings.Split(datestampValue, ":")
year, err := strconv.ParseUint(dateParts[0], 10, 16)

View File

@ -97,6 +97,10 @@ func ParseExifFullTimestamp(fullTimestampPhrase string) (timestamp time.Time, er
parts := strings.Split(fullTimestampPhrase, " ")
datestampValue, timestampValue := parts[0], parts[1]
// Normalize the separators.
datestampValue = strings.ReplaceAll(datestampValue, "-", ":")
timestampValue = strings.ReplaceAll(timestampValue, "-", ":")
dateParts := strings.Split(datestampValue, ":")
year, err := strconv.ParseUint(dateParts[0], 10, 16)

View File

@ -1127,23 +1127,35 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) {
altitudeRefTags, foundAltitudeRef := ifd.entriesByTagId[TagAltitudeRefId]
if foundAltitude == true && foundAltitudeRef == true {
altitudePhrase, err := altitudeTags[0].Format()
log.PanicIf(err)
ifdEnumerateLogger.Debugf(nil, "Altitude is [%s].", altitudePhrase)
altitudeValue, err := altitudeTags[0].Value()
log.PanicIf(err)
altitudeRefPhrase, err := altitudeRefTags[0].Format()
log.PanicIf(err)
ifdEnumerateLogger.Debugf(nil, "Altitude-reference is [%s].", altitudeRefPhrase)
altitudeRefValue, err := altitudeRefTags[0].Value()
log.PanicIf(err)
altitudeRaw := altitudeValue.([]exifcommon.Rational)
altitude := int(altitudeRaw[0].Numerator / altitudeRaw[0].Denominator)
if altitudeRaw[0].Denominator > 0 {
altitude := int(altitudeRaw[0].Numerator / altitudeRaw[0].Denominator)
if altitudeRefValue.([]byte)[0] == 1 {
altitude *= -1
if altitudeRefValue.([]byte)[0] == 1 {
altitude *= -1
}
gi.Altitude = altitude
}
gi.Altitude = altitude
}
// Parse time.
// Parse timestamp from separate date and time tags.
timestampTags, foundTimestamp := ifd.entriesByTagId[TagTimestampId]
datestampTags, foundDatestamp := ifd.entriesByTagId[TagDatestampId]
@ -1152,7 +1164,13 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) {
datestampValue, err := datestampTags[0].Value()
log.PanicIf(err)
dateParts := strings.Split(datestampValue.(string), ":")
datePhrase := datestampValue.(string)
ifdEnumerateLogger.Debugf(nil, "Date tag value is [%s].", datePhrase)
// Normalize the separators.
datePhrase = strings.ReplaceAll(datePhrase, "-", ":")
dateParts := strings.Split(datePhrase, ":")
year, err1 := strconv.ParseUint(dateParts[0], 10, 16)
month, err2 := strconv.ParseUint(dateParts[1], 10, 8)
@ -1162,6 +1180,11 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) {
timestampValue, err := timestampTags[0].Value()
log.PanicIf(err)
timePhrase, err := timestampTags[0].Format()
log.PanicIf(err)
ifdEnumerateLogger.Debugf(nil, "Time tag value is [%s].", timePhrase)
timestampRaw := timestampValue.([]exifcommon.Rational)
hour := int(timestampRaw[0].Numerator / timestampRaw[0].Denominator)