commit
e6ee72f6b3
@ -0,0 +1,646 @@
|
|||||||
|

|
||||||
|
|
||||||
|
# Exiv2 Sample Applications
|
||||||
|
|
||||||
|
Exiv2 is a C++ library and a command line utility to read, write, delete and modify Exif, IPTC, XMP and ICC image metadata. Exiv2 also features a collection of sample and test command-line programs. Please be aware that while the program _**exiv2**_ enjoys full support from Team Exiv2, the other programs have been written for test, documentation or development purposes. You are expected to read the code to discover the specification of programs other than _**exiv2**_.
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="TOC1">
|
||||||
|
|
||||||
|
### Sample Programs
|
||||||
|
|
||||||
|
| Name | Purpose | More information | Code |
|
||||||
|
|:--- |:--- |:--- |:-- |
|
||||||
|
| _**addmoddel**_ | Demonstrates Exiv2 library APIs to add, modify or delete metadata | [addmoddel](#addmoddel) | [addmoddel.cpp](samples/addmoddel.cpp) |
|
||||||
|
| _**exifcomment**_ | Set Exif.Photo.UserComment in an image | [exifcomment](#exifcomment) | [exifcomment.cpp](samples/exifcomment.cpp) |
|
||||||
|
| _**exifdata**_ | Prints _**Exif**_ metadata in different formats in an image | [exifdata](#exifdata) | [exifdata.cpp](samples/exifdata.cpp) |
|
||||||
|
| _**exifprint**_ | Print _**Exif**_ metadata in images<br>Miscelleous other features | [exifprint](#exifprint)| [exifprint.cpp](samples/exifprint.cpp) |
|
||||||
|
| _**exifvalue**_ | Prints the value of a single _**Exif**_ tag in a file | [exifvalue](#exifvalue) | [exifvalue.cpp](samples/exifvalue.cpp) |
|
||||||
|
| _**exiv2**_ | Command line utility to read, write, delete and modify Exif, IPTC, XMP and ICC image metadata.<br>This is the primary test tool used by Team Exiv2 and can exercise almost all code in the library. Due to the extensive capability of this utility, the APIs used are usually less obvious for casual code inspection. | [https://exiv2.org/manpage.html](https://exiv2.org/manpage.html)<br>[https://exiv2.org/sample.html](https://exiv2.org/sample.html) | |
|
||||||
|
| _**exiv2json**_ | Extracts data from image in JSON format.<br>This program also contains a parser to recursively parse Xmp metadata into vectors and objects. | [exiv2json](#exiv2json) | [exiv2json.cpp](samples/exiv2json.cpp) |
|
||||||
|
| _**geotag**_ | Reads GPX data and updates images with GPS Tags | [geotag](#geotag) | [geotag.cpp](samples/geotag.cpp) |
|
||||||
|
| _**iptceasy**_ | Demonstrates read, set or modify IPTC metadata | [iptceasy](#iptceasy) | [iptceasy.cpp](samples/iptceasy.cpp) |
|
||||||
|
| _**iptcprint**_ | Demonstrates Exiv2 library APIs to print Iptc data | [iptceasy](#iptceasy) | [iptcprint.cpp](samples/iptcprint.cpp) |
|
||||||
|
| _**metacopy**_ | Demonstrates copying metadata from one image to another | [metacopy](#metacopy) | [metacopy.cpp](samples/metacopy.cpp) |
|
||||||
|
| _**mrwthumb**_ | Sample program to extract a Minolta thumbnail from the makernote | [mrwthumb](#mrwthumb) | [mrwthumb.cpp](samples/mrwthumb.cpp) |
|
||||||
|
| _**xmpparse**_ | Read an XMP packet from a file, parse it and print all (known) properties. | [xmpparse](#xmpparse) | [xmpparse.cpp](samples/xmpparse.cpp) |
|
||||||
|
| _**xmpprint**_ | Read an XMP from a file, parse it and print all (known) properties.. | [xmpprint](#xmpprint) | [xmpprint.cpp](samples/xmpprint.cpp) |
|
||||||
|
| _**xmpsample**_ | Demonstrates Exiv2 library high level XMP classes | [xmpsample](#xmpsample) | [xmpsample.cpp](samples/exmpsample.cpp) |
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="TOC2">
|
||||||
|
|
||||||
|
### Test Programs
|
||||||
|
|
||||||
|
As Exiv2 is open source, we publish all our materials. Some of the following programs are actively used in our test harness. Some of the following programs were written during the development of features and their on-going use may be limited, or even obsolete. In general these programs are published as source and Team Exiv2 will not provide support to users.
|
||||||
|
|
||||||
|
| Name | Kind | More information |
|
||||||
|
|:--- |:--- |:--- |
|
||||||
|
| _**conntest**_ | Test http/https/ftp/ssh/sftp connection | [conntest](#conntest) |
|
||||||
|
| _**convert-test**_ | Conversion test driver | [convert-test](#convert-test) |
|
||||||
|
| _**easyaccess-test**_ | Sample program using high-level metadata access functions | [easyaccess-test](#easyaccess-test) |
|
||||||
|
| _**getopt-test**_ | Sample program to test getopt() | [getopt-test](#getopt-test) |
|
||||||
|
| _**ini-test**_ | Shows simple usage of the INIReader class | [ini-test](#ini-test) |
|
||||||
|
| _**iotest**_ | Test programs for BasicIo functions. | [iotest](#iotest) |
|
||||||
|
| _**iptctest**_ | Sample program test Iptc reading and writing. | [iptctest](#iptctest) |
|
||||||
|
| _**key-test**_ | Key unit tests | [key-test](#key-test) |
|
||||||
|
| _**largeiptc-test**_ | Test for large (>65535 bytes) IPTC buffer | [largeiptc-test](#largeiptc-test) |
|
||||||
|
| _**mmap-test**_ | Simple mmap tests | [mmap-test](#mmap-test) |
|
||||||
|
| _**path-test**_ | Test path IO | [path-test](#path-test) |
|
||||||
|
| _**prevtest**_ | Test access to preview images | [prevtest](#prevtest) |
|
||||||
|
| _**remotetest**_ | Tester application for testing remote i/o. | [remotetest](#remotetest) |
|
||||||
|
| _**stringto-test**_ | Test conversions from string to long, float and Rational types. | [stringto-test](#stringto-test) |
|
||||||
|
| _**taglist**_ | Print a simple comma separated list of tags defined in Exiv2 | [taglist](#taglist) |
|
||||||
|
| _**tiff-test**_ | Simple TIFF write test | [tiff-test](#tiff-test) |
|
||||||
|
| _**werror-test**_ | Simple tests for the wide-string error class WError | [werror-test](#werror-test) |
|
||||||
|
| _**write-test**_ | ExifData write unit tests | [write-test](#write-test) |
|
||||||
|
| _**write2-test**_ | ExifData write unit tests for Exif data created from scratch | [write2-test](#write2-test) |
|
||||||
|
| _**xmpdump**_ | Sample program to dump the XMP packet of an image | [xmpdump](#xmpdump) |
|
||||||
|
| _**xmpparser-test**_ | Read an XMP packet from a file, parse and re-serialize it. | [xmpparser-test](#xmpparser-test) |
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
## 2 Sample Program Descriptions
|
||||||
|
|
||||||
|
<div id="addmoddel">
|
||||||
|
|
||||||
|
#### addmoddel
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: addmoddel file
|
||||||
|
```
|
||||||
|
|
||||||
|
Demonstrates Exiv2 library APIs to add, modify or delete metadata. _Code: [addmoddel.cpp](samples/addmoddel.cpp)_
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="exifcomment">
|
||||||
|
|
||||||
|
#### exifcomment
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: exifcomment file
|
||||||
|
```
|
||||||
|
|
||||||
|
This is a simple program that demonstrates how to set _**Exif.Photo.UserComment**_ in an image. _Code: [exifcomment.cpp](samples/exifcomment.cpp)_
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="exifdata">
|
||||||
|
|
||||||
|
### exifdata
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: exifdata file format
|
||||||
|
formats: csv | json | wolf | xml
|
||||||
|
```
|
||||||
|
|
||||||
|
This is a simple program to demonstrate dumping _**Exif**_ metadata in common formats. _Code: [exifdata.cpp](samples/exifdata.cpp)_
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="exifprint">
|
||||||
|
|
||||||
|
#### exifprint
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: exifprint [ file | --version | --version-test ]
|
||||||
|
```
|
||||||
|
|
||||||
|
| Arguments | Description |
|
||||||
|
|:-- |:--- |
|
||||||
|
| file | Path to image |
|
||||||
|
| --version | Print version information from build |
|
||||||
|
| --version-test | Tests Exiv2 VERSION API |
|
||||||
|
|
||||||
|
This program demonstrates how to print _**Exif**_ metadata in an image. This program is also discussed in the platform ReadMe.txt file included in a build bundle. The option **--version** was added enable the user to build a test application which dumps the build information. The option **--version-test** was added to test the macro EXIV2\_TEST\_VERSION() in **include/exiv2/version.hpp**.
|
||||||
|
|
||||||
|
There is one other unique feature of this program. It is the only test/sample program which can use the EXV\_UNICODE\_PATH build feature of Exiv2 on Windows.
|
||||||
|
|
||||||
|
_Code: [exifprint.cpp](samples/exifprint.cpp)_
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="exifvalue">
|
||||||
|
|
||||||
|
#### exifvalue
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: exifvalue file tag
|
||||||
|
```
|
||||||
|
Prints the value of a single _**Exif**_ tag in a file. _Code: [exifvalue.cpp](samples/exifvalue.cpp)_
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="exiv2json">
|
||||||
|
|
||||||
|
#### exiv2json
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: exiv2json [-option] file
|
||||||
|
Option: all | exif | iptc | xmp | filesystem
|
||||||
|
```
|
||||||
|
| Arguments | Description |
|
||||||
|
|:-- |:--- |
|
||||||
|
| all | All metadata |
|
||||||
|
| filesystem | Filesystem metadata |
|
||||||
|
| exif | Exif metadata |
|
||||||
|
| iptc | Iptc metadata |
|
||||||
|
| xmp | Xmp metadata |
|
||||||
|
| file | path to image |
|
||||||
|
|
||||||
|
This program dumps metadata from an image in JSON format. _Code: [exiv2json.cpp](samples/exiv2json.cpp)_
|
||||||
|
|
||||||
|
exiv2json has a recursive parser to encode XMP into Vectors and Objects. XMP data is XMP and can contain XMP `Bag` and `Seq` which are converted to JSON Objects and Arrays. Exiv2 presents data in the format: Family.Group.Tag. For XMP, results in "flat" output such such as:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ exiv2 -px ~/Stonehenge.jpg
|
||||||
|
Xmp.xmp.Rating XmpText 1 0
|
||||||
|
Xmp.xmp.ModifyDate XmpText 25 2015-07-16T20:25:28+01:00
|
||||||
|
Xmp.dc.description LangAlt 1 lang="x-default" Classic View
|
||||||
|
```
|
||||||
|
|
||||||
|
exiv2json parses the Exiv2 'Family.Group.Tag' data and restores the structure of the original data in JSON. _Code: [exiv2json.cpp](samples/exiv2json.cpp)_
|
||||||
|
|
||||||
|
```
|
||||||
|
$ exiv2json -xmp http://clanmills.com/Stonehenge.jpg
|
||||||
|
{
|
||||||
|
"Xmp": {
|
||||||
|
"xmp": {
|
||||||
|
"Rating": "0",
|
||||||
|
"ModifyDate": "2015-07-16T20:25:28+01:00"
|
||||||
|
},
|
||||||
|
"dc": {
|
||||||
|
"description": {
|
||||||
|
"lang": {
|
||||||
|
"x-default": "Classic View"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"xmlns": {
|
||||||
|
"dc": "http:\/\/purl.org\/dc\/elements\/1.1\/",
|
||||||
|
"xmp": "http:\/\/ns.adobe.com\/xap\/1.0\/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$
|
||||||
|
```
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="geotag">
|
||||||
|
|
||||||
|
#### geotag
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: geotag {-help|-version|-dst|-dryrun|-ascii|-verbose|-adjust value|-tz value|-delta value}+ path+
|
||||||
|
```
|
||||||
|
|
||||||
|
Geotag reads one or more GPX files and adds GPS Tages to images. _Code: [geotag.cpp](samples/geotag.cpp)_
|
||||||
|
|
||||||
|
If the path is a directory, geotag will read all the files in the directory. It constructs a time dictionary of position data, then updates every image with GPS Tags.
|
||||||
|
|
||||||
|
| Arguments | Description |
|
||||||
|
|:-- |:--- |
|
||||||
|
| -ascii | Output in ascii (not UTF8). Prints `deg` instead of °. |
|
||||||
|
| -dst | Apply 1 hour adjustment for daylight saving time. |
|
||||||
|
| -dryrun | Read arguments and print report. Does not modify images. |
|
||||||
|
| -verbose | Report progress. |
|
||||||
|
| -adjust value | Add/subtract time from image data. |
|
||||||
|
| -tz value | Specify time zone. For example PST = -8:00 |
|
||||||
|
| -delta value | Correction between Image DataTime and GPS time. |
|
||||||
|
|
||||||
|
I use this program frequently. I have a little Canon camera which I take when I run. My Samsung Galaxy Watch uploads my runs to Strava and I download the GPX. If I'm in another time-zone and have forgotten to change the time setting in the camera, I use `-adjust` to alter the images. The GPX time is always correct, however the camera is normally off by seconds or minutes. This option enables you to correct for inaccuracy in the setting of the camera time.
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="iptceasy">
|
||||||
|
|
||||||
|
#### iptceasy
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: iptceasy file
|
||||||
|
Reads and writes raw metadata. Use -h option for help.
|
||||||
|
```
|
||||||
|
|
||||||
|
Demonstrates read, set or modify IPTC metadata. _Code: [iptceasy.cpp](samples/iptceasy.cpp)_
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="iptcprint">
|
||||||
|
|
||||||
|
#### iptcprint
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: iptcprint file
|
||||||
|
Reads and writes raw metadata. Use -h option for help.
|
||||||
|
```
|
||||||
|
|
||||||
|
Demonstrates Exiv2 library APIs to print Iptc data. _Code: [iptcprint.cpp](samples/iptcprint.cpp)_
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="metacopy">
|
||||||
|
|
||||||
|
#### metacopy
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: metacopy [-iecaph] readfile writefile
|
||||||
|
Reads and writes raw metadata. Use -h option for help.
|
||||||
|
```
|
||||||
|
|
||||||
|
Metacopy is used to copy a complete metadata block from one file to another. _Code: [metacopy.cpp](samples/metacopy.cpp)_
|
||||||
|
|
||||||
|
Please note that some metadata such as Exif.Photo.PixelXDimension is considered to be part of the image and will not be copied.
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="mrwthumb">
|
||||||
|
|
||||||
|
#### mrwthumb
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: mrwthumb file
|
||||||
|
```
|
||||||
|
|
||||||
|
Sample program to extract a Minolta thumbnail from the makernote. _Code: [mrwthumb.cpp](samples/mrwthumb.cpp)_
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="xmpparse">
|
||||||
|
|
||||||
|
#### xmpparse
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: xmpparse file
|
||||||
|
```
|
||||||
|
|
||||||
|
Read an XMP packet from a file, parse it and print all (known) properties. _Code: [xmpparse.cpp](samples/xmpparse.cpp)_
|
||||||
|
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="xmpprint">
|
||||||
|
|
||||||
|
#### xmpprint
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: xmpprint file
|
||||||
|
```
|
||||||
|
|
||||||
|
Read an XMP from a file, parse it and print all (known) properties. _Code: [xmpprint.cpp](samples/xmpprint.cpp)_
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="xmpsample">
|
||||||
|
|
||||||
|
#### xmpsample
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: xmpsample file
|
||||||
|
```
|
||||||
|
|
||||||
|
Demonstrates Exiv2 library high level XMP classes. _Code: [xmpsample.cpp](samples/xmpsample.cpp)_
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
## 3 Test Program Descriptions
|
||||||
|
|
||||||
|
<div id="conntest">
|
||||||
|
|
||||||
|
#### conntest
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: conntest url {-http1_0}
|
||||||
|
```
|
||||||
|
|
||||||
|
Test http/https/ftp/ssh/sftp connection
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="convert-test">
|
||||||
|
|
||||||
|
#### convert-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: convert-test file
|
||||||
|
```
|
||||||
|
|
||||||
|
Conversion test driver
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="easyaccess-test">
|
||||||
|
|
||||||
|
#### easyaccess-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: easyaccess-test file
|
||||||
|
```
|
||||||
|
|
||||||
|
Sample program using high-level metadata access functions
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="getopt-test">
|
||||||
|
|
||||||
|
#### getopt-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: getopt-test
|
||||||
|
```
|
||||||
|
This program is used to test the function **getopt()**. Prior to Exiv2 v0.27, the sample programs used the platform's C Runtime Library function **getopt()**. Visual Studio builds used code in src/getopt.cpp. Due to differences in the platform **getopt()**, the code in src/getopt.cpp was modified and adopted on every platforms. This test program was added for test and debug purpose. Please note that src/getopt.cpp is compiled and linked into the sample application and is not part of the Exiv2 library.
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="ini-test">
|
||||||
|
|
||||||
|
#### ini-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: ini-test
|
||||||
|
```
|
||||||
|
|
||||||
|
This program is used to test reading the file ini-test. This program was added in Exiv2 v0.26 when the ~/.exiv2 file was added to the Exiv2 architecture.
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="iotest">
|
||||||
|
|
||||||
|
#### iotest
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: iotest filein fileout1 fileout2
|
||||||
|
fileouts are overwritten and should match filein exactly
|
||||||
|
```
|
||||||
|
|
||||||
|
Test programs for BasicIo functions.
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="iptctest">
|
||||||
|
|
||||||
|
#### iptctest
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: iptctest image
|
||||||
|
Commands read from stdin.
|
||||||
|
```
|
||||||
|
|
||||||
|
Sample program test Iptc reading and writing.
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="key-test">
|
||||||
|
|
||||||
|
#### key-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: key-test
|
||||||
|
```
|
||||||
|
|
||||||
|
Key unit tests
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="largeiptc-test">
|
||||||
|
|
||||||
|
#### largeiptc-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: largeiptc-test image datafile
|
||||||
|
```
|
||||||
|
|
||||||
|
Test for large (>65535 bytes) IPTC buffer
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="mmap-test">
|
||||||
|
|
||||||
|
#### mmap-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: mmap-test file
|
||||||
|
```
|
||||||
|
|
||||||
|
Simple mmap tests
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="path-test">
|
||||||
|
|
||||||
|
#### path-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: path-test file
|
||||||
|
```
|
||||||
|
|
||||||
|
Test path IO
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="prevtest">
|
||||||
|
|
||||||
|
#### prevtest
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: prevtest file
|
||||||
|
```
|
||||||
|
|
||||||
|
Test access to preview images
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="remotetest">
|
||||||
|
|
||||||
|
#### remotetest
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: remotetest remotetest file {--nocurl | --curl}
|
||||||
|
```
|
||||||
|
|
||||||
|
Tester application for testing remote i/o.
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="stringto-test">
|
||||||
|
|
||||||
|
#### stringto-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: stringto-test
|
||||||
|
```
|
||||||
|
|
||||||
|
Test conversions from string to long, float and Rational types.
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="taglist">
|
||||||
|
|
||||||
|
#### taglist
|
||||||
|
|
||||||
|
```
|
||||||
|
$ taglist --help
|
||||||
|
Usage: taglist [--help]
|
||||||
|
[--group name|
|
||||||
|
Groups|Exif|Canon|CanonCs|CanonSi|CanonCf|Fujifilm|Minolta|Nikon1|Nikon2|Nikon3|Olympus|
|
||||||
|
Panasonic|Pentax|Sigma|Sony|Iptc|
|
||||||
|
dc|xmp|xmpRights|xmpMM|xmpBJ|xmpTPg|xmpDM|pdf|photoshop|crs|tiff|exif|aux|iptc|all|ALL
|
||||||
|
]
|
||||||
|
Print Exif tags, MakerNote tags, or Iptc datasets
|
||||||
|
```
|
||||||
|
|
||||||
|
Print a simple comma separated list of tags defined in Exiv2
|
||||||
|
|
||||||
|
This program encodes the library's tag definitions in ascii.
|
||||||
|
The data from this program is formatted as HTML on the web-site. https://exiv2.org/metadata.html
|
||||||
|
|
||||||
|
For example, to show the binary definition of Group `Nikon3`:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ taglist Nikon3
|
||||||
|
Version, 1, 0x0001, Nikon3, Exif.Nikon3.Version, Undefined, Nikon Makernote version
|
||||||
|
ISOSpeed, 2, 0x0002, Nikon3, Exif.Nikon3.ISOSpeed, Short, ISO speed setting
|
||||||
|
ColorMode, 3, 0x0003, Nikon3, Exif.Nikon3.ColorMode, Ascii, Color mode
|
||||||
|
Quality, 4, 0x0004, Nikon3, Exif.Nikon3.Quality, Ascii, Image quality setting
|
||||||
|
WhiteBalance, 5, 0x0005, Nikon3, Exif.Nikon3.WhiteBalance, Ascii, White balance
|
||||||
|
Sharpening, 6, 0x0006, Nikon3, Exif.Nikon3.Sharpening, Ascii, Image sharpening setting
|
||||||
|
Focus, 7, 0x0007, Nikon3, Exif.Nikon3.Focus, Ascii, Focus mode
|
||||||
|
FlashSetting, 8, 0x0008, Nikon3, Exif.Nikon3.FlashSetting, Ascii, Flash setting
|
||||||
|
FlashDevice, 9, 0x0009, Nikon3, Exif.Nikon3.FlashDevice, Ascii, Flash device
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
We can see those tags being used:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ exiv2 -pa --grep Nikon3 http://clanmills.com/Stonehenge.jpg
|
||||||
|
Exif.Nikon3.Version Undefined 4 2.11
|
||||||
|
Exif.Nikon3.ISOSpeed Short 2 200
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
This information is formatted (search Nikon (format 3) MakerNote Tags): [https://exiv2.org/tags-nikon.html](https://exiv2.org/tags-nikon.html)
|
||||||
|
|
||||||
|
#### taglist all
|
||||||
|
|
||||||
|
These options are provided to list every Exif tag known to Exiv2. The option `all` prints Group.Name for every tag. The option `ALL` print Group.Name followed by the TagInfo for that tag. For example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ taglist all | grep ISOSpeed$
|
||||||
|
Photo.ISOSpeed
|
||||||
|
PanasonicRaw.ISOSpeed
|
||||||
|
CanonCs.ISOSpeed
|
||||||
|
CanonSi.ISOSpeed
|
||||||
|
Casio2.ISOSpeed
|
||||||
|
MinoltaCs5D.ISOSpeed
|
||||||
|
MinoltaCs7D.ISOSpeed
|
||||||
|
Nikon1.ISOSpeed
|
||||||
|
Nikon2.ISOSpeed
|
||||||
|
Nikon3.ISOSpeed
|
||||||
|
Olympus.ISOSpeed
|
||||||
|
Olympus2.ISOSpeed
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ taglist ALL | grep ISOSpeed,
|
||||||
|
Photo.ISOSpeed, 34867, 0x8833, Photo, Exif.Photo.ISOSpeed, Long, This tag indicates the ISO speed value of a camera or input device that is defined in ISO 12232. When recording this tag, the PhotographicSensitivity and SensitivityType tags shall also be recorded.
|
||||||
|
PanasonicRaw.ISOSpeed, 23, 0x0017, PanasonicRaw, Exif.PanasonicRaw.ISOSpeed, Short, ISO speed setting
|
||||||
|
CanonCs.ISOSpeed, 16, 0x0010, CanonCs, Exif.CanonCs.ISOSpeed, SShort, ISO speed setting
|
||||||
|
CanonSi.ISOSpeed, 2, 0x0002, CanonSi, Exif.CanonSi.ISOSpeed, Short, ISO speed used
|
||||||
|
Casio2.ISOSpeed, 20, 0x0014, Casio2, Exif.Casio2.ISOSpeed, Short, ISO Speed
|
||||||
|
MinoltaCs5D.ISOSpeed, 38, 0x0026, MinoltaCs5D, Exif.MinoltaCs5D.ISOSpeed, Short, ISO speed setting
|
||||||
|
MinoltaCs7D.ISOSpeed, 28, 0x001c, MinoltaCs7D, Exif.MinoltaCs7D.ISOSpeed, Short, ISO speed setting
|
||||||
|
Nikon1.ISOSpeed, 2, 0x0002, Nikon1, Exif.Nikon1.ISOSpeed, Short, ISO speed setting
|
||||||
|
Nikon2.ISOSpeed, 6, 0x0006, Nikon2, Exif.Nikon2.ISOSpeed, Short, ISO speed setting
|
||||||
|
Nikon3.ISOSpeed, 2, 0x0002, Nikon3, Exif.Nikon3.ISOSpeed, Short, ISO speed setting
|
||||||
|
Olympus.ISOSpeed, 4097, 0x1001, Olympus, Exif.Olympus.ISOSpeed, SRational, ISO speed value
|
||||||
|
Olympus2.ISOSpeed, 4097, 0x1001, Olympus, Exif.Olympus.ISOSpeed, SRational, ISO speed value
|
||||||
|
Sony1MltCs7D.ISOSpeed, 28, 0x001c, MinoltaCs7D, Exif.MinoltaCs7D.ISOSpeed, Short, ISO speed setting
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="tiff-test">
|
||||||
|
|
||||||
|
#### tiff-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: tiff-test file
|
||||||
|
```
|
||||||
|
|
||||||
|
Simple TIFF write test
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
|
||||||
|
<div id="werror-test">
|
||||||
|
|
||||||
|
#### werror-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: werror-test
|
||||||
|
```
|
||||||
|
|
||||||
|
Simple tests for the wide-string error class WError
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="write-test">
|
||||||
|
|
||||||
|
#### write-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: write-test file case
|
||||||
|
where case is an integer between 1 and 11
|
||||||
|
```
|
||||||
|
|
||||||
|
ExifData write unit tests
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="write2-test">
|
||||||
|
|
||||||
|
#### write2-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: write2-test file
|
||||||
|
```
|
||||||
|
|
||||||
|
ExifData write unit tests for Exif data created from scratch
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="xmpdump">
|
||||||
|
|
||||||
|
#### xmpdump
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: xmpdump file
|
||||||
|
```
|
||||||
|
|
||||||
|
Sample program to dump the XMP packet of an image
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
<div id="xmpparser-test">
|
||||||
|
|
||||||
|
#### xmpparser-test
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: xmpparser-test file
|
||||||
|
```
|
||||||
|
|
||||||
|
Read an XMP packet from a file, parse and re-serialize it.
|
||||||
|
|
||||||
|
[Sample](#TOC1) Programs [Test](#TOC2) Programs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Robin Mills<br>
|
||||||
|
robin@clanmills.com<br>
|
||||||
|
Revised: 2019-06-20
|
@ -0,0 +1,939 @@
|
|||||||
|
// ***************************************************************** -*- C++ -*-
|
||||||
|
// geotag.cpp
|
||||||
|
// Sample program to read gpx files and update images with GPS tags
|
||||||
|
|
||||||
|
// g++ geotag.cpp -o geotag -lexiv2 -lexpat
|
||||||
|
|
||||||
|
#include <exiv2/exiv2.hpp>
|
||||||
|
#include "unused.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <cassert>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <time.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <expat.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#if defined(__MINGW32__) || defined(__MINGW64__)
|
||||||
|
# ifndef __MINGW__
|
||||||
|
# define __MINGW__
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#ifndef lengthof
|
||||||
|
#define lengthof(x) (sizeof(*x)/sizeof(x))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW__)
|
||||||
|
#include <windows.h>
|
||||||
|
char* realpath(const char* file,char* path);
|
||||||
|
#define lstat _stat
|
||||||
|
#define stat _stat
|
||||||
|
#if _MSC_VER < 1400
|
||||||
|
#define strcpy_s(d,l,s) strcpy(d,s)
|
||||||
|
#define strcat_s(d,l,s) strcat(d,s)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ! defined(_MSC_VER)
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#define stricmp strcasecmp
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _MAX_PATH
|
||||||
|
#define _MAX_PATH 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// prototypes
|
||||||
|
class Options;
|
||||||
|
int getFileType(const char* path ,Options& options);
|
||||||
|
int getFileType(std::string& path,Options& options);
|
||||||
|
|
||||||
|
string getExifTime(const time_t t);
|
||||||
|
time_t parseTime(const char* ,bool bAdjust=false);
|
||||||
|
int timeZoneAdjust();
|
||||||
|
|
||||||
|
// platform specific code
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW__)
|
||||||
|
char* realpath(const char* file,char* path)
|
||||||
|
{
|
||||||
|
char* result = (char*) malloc(_MAX_PATH);
|
||||||
|
if (result) GetFullPathName(file,_MAX_PATH,result,NULL);
|
||||||
|
return result ;
|
||||||
|
UNUSED(path);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Command-line parser
|
||||||
|
class Options {
|
||||||
|
public:
|
||||||
|
bool verbose;
|
||||||
|
bool help;
|
||||||
|
bool version;
|
||||||
|
bool dst;
|
||||||
|
bool dryrun;
|
||||||
|
bool ascii;
|
||||||
|
|
||||||
|
Options()
|
||||||
|
{
|
||||||
|
verbose = false;
|
||||||
|
help = false;
|
||||||
|
version = false;
|
||||||
|
dst = false;
|
||||||
|
dryrun = false;
|
||||||
|
ascii = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~Options() {} ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
enum
|
||||||
|
{ resultOK=0
|
||||||
|
, resultSyntaxError
|
||||||
|
, resultSelectFailed
|
||||||
|
};
|
||||||
|
|
||||||
|
enum // keyword indices
|
||||||
|
{ kwHELP = 0
|
||||||
|
, kwVERSION
|
||||||
|
, kwDST
|
||||||
|
, kwDRYRUN
|
||||||
|
, kwASCII
|
||||||
|
, kwVERBOSE
|
||||||
|
, kwADJUST
|
||||||
|
, kwTZ
|
||||||
|
, kwDELTA
|
||||||
|
, kwMAX // manages keyword array
|
||||||
|
, kwNEEDVALUE // bogus keywords for error reporting
|
||||||
|
, kwSYNTAX // -- ditto --
|
||||||
|
, kwNOVALUE = -kwVERBOSE // keywords <= kwNOVALUE are flags (no value needed)
|
||||||
|
};
|
||||||
|
|
||||||
|
// file types supported
|
||||||
|
enum
|
||||||
|
{ typeUnknown = 0
|
||||||
|
, typeDirectory = 1
|
||||||
|
, typeImage = 2
|
||||||
|
, typeXML = 3
|
||||||
|
, typeFile = 4
|
||||||
|
, typeDoc = 5
|
||||||
|
, typeCode = 6
|
||||||
|
, typeMax = 7
|
||||||
|
};
|
||||||
|
|
||||||
|
// forward declaration
|
||||||
|
class Position;
|
||||||
|
|
||||||
|
// globals
|
||||||
|
typedef std::map<time_t,Position> TimeDict_t;
|
||||||
|
typedef std::map<time_t,Position>::iterator TimeDict_i;
|
||||||
|
typedef std::vector<std::string> strings_t;
|
||||||
|
const char* gDeg = NULL ; // string "°" or "deg"
|
||||||
|
TimeDict_t gTimeDict ;
|
||||||
|
strings_t gFiles;
|
||||||
|
|
||||||
|
// Position (from gpx file)
|
||||||
|
class Position
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Position(time_t time, double lat, double lon, double ele) :
|
||||||
|
time_(time)
|
||||||
|
, lon_(lon)
|
||||||
|
, lat_(lat)
|
||||||
|
, ele_(ele)
|
||||||
|
, delta_(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Position():
|
||||||
|
time_(0)
|
||||||
|
, lon_(0.0)
|
||||||
|
, lat_(0.0)
|
||||||
|
, ele_(0.0)
|
||||||
|
, delta_(0)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
virtual ~Position() {}
|
||||||
|
// copy constructor
|
||||||
|
Position(const Position& o) :
|
||||||
|
time_(o.time_)
|
||||||
|
, lon_(o.lon_)
|
||||||
|
, lat_(o.lat_)
|
||||||
|
, ele_(o.ele_)
|
||||||
|
, delta_(o.delta_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
// instance methods
|
||||||
|
bool good() { return time_ || lon_ || lat_ || ele_ ; }
|
||||||
|
std::string getTimeString() { if ( times_.empty() ) times_ = getExifTime(time_) ; return times_; }
|
||||||
|
time_t getTime() { return time_ ; }
|
||||||
|
std::string toString();
|
||||||
|
|
||||||
|
// getters/setters
|
||||||
|
double lat() {return lat_ ;}
|
||||||
|
double lon() {return lon_ ;}
|
||||||
|
double ele() {return ele_ ;}
|
||||||
|
int delta() {return delta_ ;}
|
||||||
|
void delta(int delta) {delta_=delta ;}
|
||||||
|
|
||||||
|
// data
|
||||||
|
private:
|
||||||
|
time_t time_;
|
||||||
|
double lon_ ;
|
||||||
|
double lat_ ;
|
||||||
|
double ele_ ;
|
||||||
|
std::string times_;
|
||||||
|
int delta_;
|
||||||
|
|
||||||
|
// public static data
|
||||||
|
public:
|
||||||
|
static int adjust_ ;
|
||||||
|
static int tz_ ;
|
||||||
|
static int dst_ ;
|
||||||
|
static time_t deltaMax_;
|
||||||
|
|
||||||
|
// public static member functions
|
||||||
|
public:
|
||||||
|
static int Adjust() {return Position::adjust_ + Position::tz_ + Position::dst_ ;}
|
||||||
|
static int tz() {return tz_ ;}
|
||||||
|
static int dst() {return dst_ ;}
|
||||||
|
static int adjust() {return adjust_;}
|
||||||
|
|
||||||
|
static std::string toExifString(double d,bool bRational,bool bLat);
|
||||||
|
static std::string toExifString(double d);
|
||||||
|
static std::string toExifTimeStamp(std::string& t);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string Position::toExifTimeStamp(std::string& t)
|
||||||
|
{
|
||||||
|
char result[200];
|
||||||
|
const char* arg = t.c_str();
|
||||||
|
int HH = 0 ;
|
||||||
|
int mm = 0 ;
|
||||||
|
int SS1 = 0 ;
|
||||||
|
if ( strstr(arg,":") || strstr(arg,"-") ) {
|
||||||
|
int YY,MM,DD ;
|
||||||
|
char a,b,c,d,e ;
|
||||||
|
sscanf(arg,"%d%c%d%c%d%c%d%c%d%c%d",&YY,&a,&MM,&b,&DD,&c,&HH,&d,&mm,&e,&SS1);
|
||||||
|
}
|
||||||
|
sprintf(result,"%d/1 %d/1 %d/1",HH,mm,SS1);
|
||||||
|
return std::string(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Position::toExifString(double d)
|
||||||
|
{
|
||||||
|
char result[200];
|
||||||
|
d *= 100;
|
||||||
|
sprintf(result,"%d/100",abs((int)d));
|
||||||
|
return std::string(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Position::toExifString(double d,bool bRational,bool bLat)
|
||||||
|
{
|
||||||
|
const char* NS = d>=0.0?"N":"S";
|
||||||
|
const char* EW = d>=0.0?"E":"W";
|
||||||
|
const char* NSEW = bLat ? NS: EW;
|
||||||
|
if ( d < 0 ) d = -d;
|
||||||
|
int deg = (int) d;
|
||||||
|
d -= deg;
|
||||||
|
d *= 60;
|
||||||
|
int min = (int) d ;
|
||||||
|
d -= min;
|
||||||
|
d *= 60;
|
||||||
|
int sec = (int)d;
|
||||||
|
char result[200];
|
||||||
|
if ( bRational )
|
||||||
|
sprintf(result,"%d/1 %d/1 %d/1" ,deg,min,sec);
|
||||||
|
else
|
||||||
|
sprintf(result,"%03d%s%02d'%02d\"%s" ,deg,gDeg,min,sec,NSEW);
|
||||||
|
return std::string(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Position::toString()
|
||||||
|
{
|
||||||
|
char result[200];
|
||||||
|
std::string sLat = Position::toExifString(lat_,false,true );
|
||||||
|
std::string sLon = Position::toExifString(lon_,false,false);
|
||||||
|
sprintf(result,"%s %s %-8.3f",sLon.c_str(),sLat.c_str(),ele_);
|
||||||
|
return std::string(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults
|
||||||
|
int Position::adjust_ = 0;
|
||||||
|
int Position::tz_ = timeZoneAdjust();
|
||||||
|
int Position::dst_ = 0;
|
||||||
|
time_t Position::deltaMax_ = 60 ;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// UserData - used by XML Parser
|
||||||
|
class UserData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit UserData(Options& options):
|
||||||
|
indent(0)
|
||||||
|
, count(0)
|
||||||
|
, nTrkpt(0)
|
||||||
|
, bTime(false)
|
||||||
|
, bEle(false)
|
||||||
|
, ele(0.0)
|
||||||
|
, lat(0.0)
|
||||||
|
, lon(0.0)
|
||||||
|
, options_(options)
|
||||||
|
{}
|
||||||
|
virtual ~UserData() {}
|
||||||
|
|
||||||
|
// public data members
|
||||||
|
int indent;
|
||||||
|
size_t count ;
|
||||||
|
Position now ;
|
||||||
|
Position prev;
|
||||||
|
int nTrkpt;
|
||||||
|
bool bTime ;
|
||||||
|
bool bEle ;
|
||||||
|
double ele;
|
||||||
|
double lat;
|
||||||
|
double lon;
|
||||||
|
std::string xmlt;
|
||||||
|
std::string exift;
|
||||||
|
time_t time;
|
||||||
|
Options& options_;
|
||||||
|
// static public data memembers
|
||||||
|
};
|
||||||
|
|
||||||
|
// XML Parser Callbacks
|
||||||
|
static void startElement(void* userData, const char* name, const char** atts )
|
||||||
|
{
|
||||||
|
UserData* me = (UserData*) userData;
|
||||||
|
//for ( int i = 0 ; i < me->indent ; i++ ) printf(" ");
|
||||||
|
//printf("begin %s\n",name);
|
||||||
|
me->bTime = strcmp(name,"time")==0;
|
||||||
|
me->bEle = strcmp(name,"ele")==0;
|
||||||
|
|
||||||
|
if ( strcmp(name,"trkpt")==0 ) {
|
||||||
|
me->nTrkpt++;
|
||||||
|
while ( *atts ) {
|
||||||
|
const char* a=atts[0];
|
||||||
|
const char* v=atts[1];
|
||||||
|
if ( !strcmp(a,"lat") ) me->lat = atof(v);
|
||||||
|
if ( !strcmp(a,"lon") ) me->lon = atof(v);
|
||||||
|
atts += 2 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
me->count++ ;
|
||||||
|
me->indent++ ;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void endElement(void* userData, const char* name)
|
||||||
|
{
|
||||||
|
UserData* me = (UserData*) userData;
|
||||||
|
me->indent-- ;
|
||||||
|
if ( strcmp(name,"trkpt")==0 ) {
|
||||||
|
|
||||||
|
me->nTrkpt--;
|
||||||
|
me->now = Position(me->time,me->lat,me->lon,me->ele) ;
|
||||||
|
|
||||||
|
if ( !me->prev.good() && me->options_.verbose ) {
|
||||||
|
printf("trkseg %s begin ",me->now.getTimeString().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// remember our location and put it in gTimeDict
|
||||||
|
gTimeDict[me->time] = me->now ;
|
||||||
|
me->prev = me->now ;
|
||||||
|
}
|
||||||
|
if ( strcmp(name,"trkseg")==0 && me->options_.verbose ) {
|
||||||
|
printf("%s end\n",me->now.getTimeString().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void charHandler(void* userData,const char* s,int len)
|
||||||
|
{
|
||||||
|
UserData* me = (UserData*) userData;
|
||||||
|
|
||||||
|
if ( me->nTrkpt == 1 ) {
|
||||||
|
char buffer[100];
|
||||||
|
int l_max = 98 ; // lengthof(buffer) -2 ;
|
||||||
|
|
||||||
|
if ( me->bTime && len > 5 ) {
|
||||||
|
if ( len < l_max ) {
|
||||||
|
memcpy(buffer,s,len);
|
||||||
|
buffer[len]=0;
|
||||||
|
char* b = buffer ;
|
||||||
|
while ( *b == ' ' && b < buffer+len ) b++ ;
|
||||||
|
me->xmlt = b ;
|
||||||
|
me->time = parseTime(me->xmlt.c_str());
|
||||||
|
me->exift = getExifTime(me->time);
|
||||||
|
}
|
||||||
|
me->bTime=false;
|
||||||
|
}
|
||||||
|
if ( me->bEle && len > 2 ) {
|
||||||
|
if ( len < l_max ) {
|
||||||
|
memcpy(buffer,s,len);
|
||||||
|
buffer[len]=0;
|
||||||
|
char* b = buffer ;
|
||||||
|
while ( *b == ' ' && b < buffer+len ) b++ ;
|
||||||
|
me->ele = atof(b);
|
||||||
|
}
|
||||||
|
me->bEle=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// Time Functions
|
||||||
|
time_t parseTime(const char* arg,bool bAdjust)
|
||||||
|
{
|
||||||
|
time_t result = 0 ;
|
||||||
|
try {
|
||||||
|
//559 rmills@rmills-imac:~/bin $ exiv2 -pa ~/R.jpg | grep -i date
|
||||||
|
//Exif.Image.DateTime Ascii 20 2009:08:03 08:58:57
|
||||||
|
//Exif.Photo.DateTimeOriginal Ascii 20 2009:08:03 08:58:57
|
||||||
|
//Exif.Photo.DateTimeDigitized Ascii 20 2009:08:03 08:58:57
|
||||||
|
//Exif.GPSInfo.GPSDateStamp Ascii 21 2009-08-03T15:58:57Z
|
||||||
|
|
||||||
|
// <time>2012-07-14T17:33:16Z</time>
|
||||||
|
|
||||||
|
if ( strstr(arg,":") || strstr(arg,"-") ) {
|
||||||
|
int YY,MM,DD,HH,mm,SS1 ;
|
||||||
|
char a,b,c,d,e ;
|
||||||
|
sscanf(arg,"%d%c%d%c%d%c%d%c%d%c%d",&YY,&a,&MM,&b,&DD,&c,&HH,&d,&mm,&e,&SS1);
|
||||||
|
|
||||||
|
struct tm T;
|
||||||
|
memset(&T,0,sizeof(T));
|
||||||
|
T.tm_min = mm ;
|
||||||
|
T.tm_hour = HH ;
|
||||||
|
T.tm_sec = SS1 ;
|
||||||
|
if ( bAdjust ) T.tm_sec -= Position::Adjust();
|
||||||
|
T.tm_year = YY -1900 ;
|
||||||
|
T.tm_mon = MM -1 ;
|
||||||
|
T.tm_mday = DD ;
|
||||||
|
T.tm_isdst = -1 ; // determine value automatically (otherwise hour may shift)
|
||||||
|
result = mktime(&T);
|
||||||
|
}
|
||||||
|
} catch ( ... ) {};
|
||||||
|
return result ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// West of GMT is negative (PDT = Pacific Daylight = -07:00 == -25200 seconds
|
||||||
|
int timeZoneAdjust()
|
||||||
|
{
|
||||||
|
time_t now = time(NULL);
|
||||||
|
int offset;
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW__)
|
||||||
|
TIME_ZONE_INFORMATION TimeZoneInfo;
|
||||||
|
GetTimeZoneInformation( &TimeZoneInfo );
|
||||||
|
offset = - (((int)TimeZoneInfo.Bias + (int)TimeZoneInfo.DaylightBias) * 60);
|
||||||
|
UNUSED(now);
|
||||||
|
#elif defined(__CYGWIN__)
|
||||||
|
struct tm lcopy = *localtime(&now);
|
||||||
|
time_t gmt = timegm(&lcopy) ; // timegm modifies lcopy
|
||||||
|
offset = (int) ( ((long signed int) gmt) - ((long signed int) now) ) ;
|
||||||
|
#elif defined(OS_SOLARIS) || defined(__sun__)
|
||||||
|
struct tm local = *localtime(&now) ;
|
||||||
|
time_t local_tt = (int) mktime(&local);
|
||||||
|
time_t time_gmt = (int) mktime(gmtime(&now));
|
||||||
|
offset = time_gmt - local_tt;
|
||||||
|
#else
|
||||||
|
struct tm local = *localtime(&now) ;
|
||||||
|
offset = local.tm_gmtoff ;
|
||||||
|
|
||||||
|
#if EXIV2_DEBUG_MESSAGES
|
||||||
|
struct tm utc = *gmtime(&now);
|
||||||
|
printf("utc : offset = %6d dst = %d time = %s", 0 ,utc .tm_isdst, asctime(&utc ));
|
||||||
|
printf("local: offset = %6d dst = %d time = %s", offset,local.tm_isdst, asctime(&local));
|
||||||
|
printf("timeZoneAdjust = %6d\n",offset);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
return offset ;
|
||||||
|
}
|
||||||
|
|
||||||
|
string getExifTime(const time_t t)
|
||||||
|
{
|
||||||
|
static char result[100];
|
||||||
|
strftime(result,sizeof(result),"%Y-%m-%d %H:%M:%S",localtime(&t));
|
||||||
|
return result ;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string makePath(const std::string& dir, const std::string& file)
|
||||||
|
{
|
||||||
|
return dir + std::string(EXV_SEPARATOR_STR) + file ;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* makePath(const char* dir,const char* file)
|
||||||
|
{
|
||||||
|
static char result[_MAX_PATH] ;
|
||||||
|
std::string r = makePath(std::string(dir),std::string(file));
|
||||||
|
strcpy(result,r.c_str());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// file utilities
|
||||||
|
bool readDir(const char* path,Options& options)
|
||||||
|
{
|
||||||
|
bool bResult = false;
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
DWORD attrs = GetFileAttributes(path);
|
||||||
|
bool bOKAttrs = attrs != INVALID_FILE_ATTRIBUTES;
|
||||||
|
bool bIsDir = (attrs & FILE_ATTRIBUTE_DIRECTORY) ? true : false ;
|
||||||
|
|
||||||
|
if( bOKAttrs && bIsDir ) {
|
||||||
|
bResult = true ;
|
||||||
|
|
||||||
|
char search[_MAX_PATH+10];
|
||||||
|
strcpy_s(search,_MAX_PATH,path);
|
||||||
|
strcat_s(search,_MAX_PATH,"\\*");
|
||||||
|
|
||||||
|
WIN32_FIND_DATA ffd;
|
||||||
|
HANDLE hFind = FindFirstFile(search, &ffd);
|
||||||
|
BOOL bGo = hFind != INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
|
if ( bGo ) {
|
||||||
|
while ( bGo ) {
|
||||||
|
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
|
// _tprintf(TEXT(" %s <DIR>\n"), ffd.cFileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string pathName = makePath(path,std::string(ffd.cFileName));
|
||||||
|
if ( getFileType(pathName,options) == typeImage ) {
|
||||||
|
gFiles.push_back( pathName );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bGo = FindNextFile(hFind, &ffd) != 0;
|
||||||
|
}
|
||||||
|
// CloseHandle(hFind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
DIR* dir = opendir (path);
|
||||||
|
if (dir != NULL)
|
||||||
|
{
|
||||||
|
bResult = true;
|
||||||
|
struct dirent* ent;
|
||||||
|
|
||||||
|
// print all the files and directories within directory
|
||||||
|
while ((ent = readdir (dir)) != NULL)
|
||||||
|
{
|
||||||
|
std::string pathName = makePath(path,ent->d_name);
|
||||||
|
struct stat buf ;
|
||||||
|
lstat(path, &buf );
|
||||||
|
if ( ent->d_name[0] != '.' ) {
|
||||||
|
|
||||||
|
// printf("reading %s => %s\n",ent->d_name,pathName.c_str());
|
||||||
|
if ( getFileType(pathName,options) == typeImage ) {
|
||||||
|
gFiles.push_back( pathName );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir (dir);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return bResult ;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline size_t sip(FILE* f,char* buffer,size_t max_len,size_t len)
|
||||||
|
{
|
||||||
|
while ( !feof(f) && len < max_len && buffer[len-1] != '>')
|
||||||
|
buffer[len++] = fgetc(f);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool readXML(const char* path,Options& options)
|
||||||
|
{
|
||||||
|
FILE* f = fopen(path,"r");
|
||||||
|
XML_Parser parser = XML_ParserCreate(NULL);
|
||||||
|
bool bResult = f && parser ;
|
||||||
|
if ( bResult ) {
|
||||||
|
char buffer[8*1024];
|
||||||
|
UserData me(options) ;
|
||||||
|
|
||||||
|
XML_SetUserData (parser, &me);
|
||||||
|
XML_SetElementHandler (parser, startElement, endElement);
|
||||||
|
XML_SetCharacterDataHandler(parser,charHandler);
|
||||||
|
|
||||||
|
// a little sip at the data
|
||||||
|
size_t len = fread(buffer,1,sizeof(buffer)-100,f);
|
||||||
|
const char* lead = "<?xml" ;
|
||||||
|
bResult = strncmp(lead,buffer,strlen(lead))==0;
|
||||||
|
|
||||||
|
// swallow it
|
||||||
|
if ( bResult ) {
|
||||||
|
len = sip(f,buffer,sizeof buffer,len);
|
||||||
|
bResult = XML_Parse(parser, buffer,(int)len, len == 0 ) == XML_STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// drink the rest of the file
|
||||||
|
while ( bResult && len != 0 ) {
|
||||||
|
len = fread(buffer,1,sizeof(buffer)-100,f);
|
||||||
|
len = sip(f,buffer,sizeof buffer,len);
|
||||||
|
bResult = XML_Parse(parser, buffer,(int)len, len == 0 ) == XML_STATUS_OK;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( f ) fclose(f);
|
||||||
|
if ( parser ) XML_ParserFree(parser);
|
||||||
|
|
||||||
|
return bResult ;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool readImage(const char* path,Options& /* options */)
|
||||||
|
{
|
||||||
|
using namespace Exiv2;
|
||||||
|
bool bResult = false ;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Image::AutoPtr image = ImageFactory::open(path);
|
||||||
|
if ( image.get() ) {
|
||||||
|
image->readMetadata();
|
||||||
|
ExifData &exifData = image->exifData();
|
||||||
|
bResult = !exifData.empty();
|
||||||
|
}
|
||||||
|
} catch ( ... ) {};
|
||||||
|
return bResult ;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t readImageTime(const std::string& path,std::string* pS=NULL)
|
||||||
|
{
|
||||||
|
using namespace Exiv2;
|
||||||
|
|
||||||
|
time_t result = 0 ;
|
||||||
|
|
||||||
|
const char* dateStrings[] =
|
||||||
|
{ "Exif.Photo.DateTimeOriginal"
|
||||||
|
, "Exif.Photo.DateTimeDigitized"
|
||||||
|
, "Exif.Image.DateTime"
|
||||||
|
, NULL
|
||||||
|
};
|
||||||
|
const char* dateString = dateStrings[0] ;
|
||||||
|
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
Image::AutoPtr image = ImageFactory::open(path);
|
||||||
|
if ( image.get() ) {
|
||||||
|
image->readMetadata();
|
||||||
|
ExifData &exifData = image->exifData();
|
||||||
|
// printf("%s => %s\n",dateString, exifData[dateString].toString().c_str());
|
||||||
|
result = parseTime(exifData[dateString].toString().c_str(),true);
|
||||||
|
if ( result && pS ) *pS = exifData[dateString].toString();
|
||||||
|
}
|
||||||
|
} catch ( ... ) {};
|
||||||
|
} while ( !result && ++dateString );
|
||||||
|
|
||||||
|
return result ;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sina(const char* s,const char** a)
|
||||||
|
{
|
||||||
|
bool bResult = false ;
|
||||||
|
int i = 0 ;
|
||||||
|
while ( *s == '-' ) s++;
|
||||||
|
while ( !bResult && a[i]) {
|
||||||
|
const char* A = a[i] ;
|
||||||
|
while ( *A == '-' ) A++ ;
|
||||||
|
bResult = stricmp(s,A)==0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return bResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
int readFile(const char* path,Options /* options */)
|
||||||
|
{
|
||||||
|
FILE* f = fopen(path,"r");
|
||||||
|
int nResult = f ? typeFile : typeUnknown;
|
||||||
|
if ( f ) {
|
||||||
|
const char* ext = strstr(path,".");
|
||||||
|
if ( ext ) {
|
||||||
|
const char* docs[] = { ".doc",".txt", NULL };
|
||||||
|
const char* code[] = { ".cpp",".h" ,".pl" ,".py" ,".pyc", NULL };
|
||||||
|
if ( sina(ext,docs) )
|
||||||
|
nResult = typeDoc;
|
||||||
|
if ( sina(ext,code) )
|
||||||
|
nResult = typeCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( f ) fclose(f) ;
|
||||||
|
|
||||||
|
return nResult ;
|
||||||
|
}
|
||||||
|
|
||||||
|
Position* searchTimeDict(TimeDict_t& td, const time_t& time,long long delta)
|
||||||
|
{
|
||||||
|
Position* result = NULL;
|
||||||
|
for ( int t = 0 ; !result && t < delta ; t++ ) {
|
||||||
|
for ( int x = 0 ; !result && x < 2 ; x++ ) {
|
||||||
|
int T = t * ((x==0)?-1:1);
|
||||||
|
if ( td.count(time+T) ) {
|
||||||
|
result = &td[time+T];
|
||||||
|
result->delta(T);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getFileType(std::string& path,Options& options) { return getFileType(path.c_str(),options); }
|
||||||
|
int getFileType(const char* path,Options& options)
|
||||||
|
{
|
||||||
|
return readXML (path,options) ? typeXML
|
||||||
|
: readDir (path,options) ? typeDirectory
|
||||||
|
: readImage(path,options) ? typeImage
|
||||||
|
: readFile (path,options)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
int version(const char* program)
|
||||||
|
{
|
||||||
|
printf("%s: %s %s\n",program,__DATE__,__TIME__);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int help(const char* program,char const* words[],int nWords,bool /*bVerbose*/)
|
||||||
|
{
|
||||||
|
printf("usage: %s ",program);
|
||||||
|
for ( int i = 0 ; i < nWords ; i++ ) {
|
||||||
|
if ( words[i] )
|
||||||
|
printf("%c-%s%s",i?'|':'{',words[i],i>(-kwNOVALUE)?" value":"");
|
||||||
|
}
|
||||||
|
printf("}+ path+\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int compare(const char* a,const char* b)
|
||||||
|
{
|
||||||
|
int result=*a && *b;
|
||||||
|
while ( result && *a && *b) {
|
||||||
|
char A=*a++;
|
||||||
|
char B=*b++;
|
||||||
|
result=tolower(A)==tolower(B);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int find(const char* arg,char const* words[],int nWords)
|
||||||
|
{
|
||||||
|
if ( arg[0] != '-' ) return kwSYNTAX;
|
||||||
|
|
||||||
|
int result=0;
|
||||||
|
int count =0;
|
||||||
|
|
||||||
|
for ( int i = 0 ; i < nWords ; i++) {
|
||||||
|
int j = 0 ;
|
||||||
|
while ( arg[j] == '-' ) j++;
|
||||||
|
if ( ::compare(arg+j,words[i]) ) {
|
||||||
|
result = i ;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count==1?result:kwSYNTAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
int parseTZ(const char* adjust)
|
||||||
|
{
|
||||||
|
int h=0;
|
||||||
|
int m=0;
|
||||||
|
char c ;
|
||||||
|
try {
|
||||||
|
sscanf(adjust,"%d%c%d",&h,&c,&m);
|
||||||
|
} catch ( ... ) {} ;
|
||||||
|
|
||||||
|
return (3600*h)+(60*m);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mySort(const std::string& a, const std::string& b)
|
||||||
|
{
|
||||||
|
time_t A = readImageTime(a);
|
||||||
|
time_t B = readImageTime(b);
|
||||||
|
return (A<B);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc,const char* argv[])
|
||||||
|
{
|
||||||
|
Exiv2::XmpParser::initialize();
|
||||||
|
::atexit(Exiv2::XmpParser::terminate);
|
||||||
|
|
||||||
|
int result=0;
|
||||||
|
const char* program = argv[0];
|
||||||
|
|
||||||
|
const char* types[typeMax];
|
||||||
|
types[typeUnknown ] = "unknown";
|
||||||
|
types[typeDirectory] = "directory";
|
||||||
|
types[typeImage ] = "image";
|
||||||
|
types[typeXML ] = "xml";
|
||||||
|
types[typeDoc ] = "doc";
|
||||||
|
types[typeCode ] = "code";
|
||||||
|
types[typeFile ] = "file";
|
||||||
|
|
||||||
|
char const* keywords[kwMAX];
|
||||||
|
memset(keywords,0,sizeof(keywords));
|
||||||
|
keywords[kwHELP ] = "help";
|
||||||
|
keywords[kwVERSION ] = "version";
|
||||||
|
keywords[kwVERBOSE ] = "verbose";
|
||||||
|
keywords[kwDRYRUN ] = "dryrun";
|
||||||
|
keywords[kwASCII ] = "ascii";
|
||||||
|
keywords[kwDST ] = "dst";
|
||||||
|
keywords[kwADJUST ] = "adjust";
|
||||||
|
keywords[kwTZ ] = "tz";
|
||||||
|
keywords[kwDELTA ] = "delta";
|
||||||
|
|
||||||
|
map<std::string,string> shorts;
|
||||||
|
shorts["-?"] = "-help";
|
||||||
|
shorts["-h"] = "-help";
|
||||||
|
shorts["-v"] = "-verbose";
|
||||||
|
shorts["-V"] = "-version";
|
||||||
|
shorts["-d"] = "-dst";
|
||||||
|
shorts["-a"] = "-adjust";
|
||||||
|
shorts["-t"] = "-tz";
|
||||||
|
shorts["-D"] = "-delta";
|
||||||
|
shorts["-s"] = "-delta";
|
||||||
|
shorts["-X"] = "-dryrun";
|
||||||
|
shorts["-a"] = "-ascii";
|
||||||
|
|
||||||
|
Options options ;
|
||||||
|
options.help = sina(keywords[kwHELP ],argv) || argc < 2;
|
||||||
|
options.verbose = sina(keywords[kwVERBOSE],argv);
|
||||||
|
options.dryrun = sina(keywords[kwDRYRUN ],argv);
|
||||||
|
options.version = sina(keywords[kwVERSION],argv);
|
||||||
|
options.dst = sina(keywords[kwDST ],argv);
|
||||||
|
options.ascii = sina(keywords[kwASCII ],argv);
|
||||||
|
|
||||||
|
for ( int i = 1 ; !result && i < argc ; i++ ) {
|
||||||
|
const char* arg = argv[i++];
|
||||||
|
if ( shorts.count(arg) ) arg = shorts[arg].c_str();
|
||||||
|
|
||||||
|
const char* value = argv[i ];
|
||||||
|
int ivalue = ::atoi(value?value:"0");
|
||||||
|
int key = ::find(arg,keywords,kwMAX);
|
||||||
|
int needv = key < kwMAX && key > (-kwNOVALUE);
|
||||||
|
|
||||||
|
if (!needv ) i--;
|
||||||
|
if ( needv && !value) key = kwNEEDVALUE;
|
||||||
|
|
||||||
|
switch ( key ) {
|
||||||
|
case kwDST : options.dst = true ; break;
|
||||||
|
case kwHELP : options.help = true ; break;
|
||||||
|
case kwVERSION : options.version = true ; break;
|
||||||
|
case kwDRYRUN : options.dryrun = true ; break;
|
||||||
|
case kwVERBOSE : options.verbose = true ; break;
|
||||||
|
case kwASCII : options.ascii = true ; break;
|
||||||
|
case kwTZ : Position::tz_ = parseTZ(value);break;
|
||||||
|
case kwADJUST : Position::adjust_ = ivalue;break;
|
||||||
|
case kwDELTA : Position::deltaMax_ = ivalue;break;
|
||||||
|
case kwNEEDVALUE: fprintf(stderr,"error: %s requires a value\n",arg); result = resultSyntaxError ; break ;
|
||||||
|
case kwSYNTAX : default:
|
||||||
|
{
|
||||||
|
int type = getFileType(arg,options) ;
|
||||||
|
if ( options.verbose ) printf("%s %s ",arg,types[type]) ;
|
||||||
|
if ( type == typeImage ) {
|
||||||
|
time_t t = readImageTime(std::string(arg)) ;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
char buffer[1024];
|
||||||
|
#else
|
||||||
|
char* buffer = NULL;
|
||||||
|
#endif
|
||||||
|
char* path = realpath(arg,buffer);
|
||||||
|
if ( t && path ) {
|
||||||
|
if ( options.verbose) printf("%s %ld %s",path,(long int)t,asctime(localtime(&t)));
|
||||||
|
gFiles.push_back(path);
|
||||||
|
}
|
||||||
|
if ( path && path != buffer ) ::free((void*) path);
|
||||||
|
}
|
||||||
|
if ( type == typeUnknown ) {
|
||||||
|
fprintf(stderr,"error: illegal syntax %s\n",arg);
|
||||||
|
result = resultSyntaxError ;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( options.help ) ::help(program,keywords,kwMAX,options.verbose);
|
||||||
|
if ( options.version ) ::version(program);
|
||||||
|
gDeg = options.ascii ? "deg" : "°";
|
||||||
|
|
||||||
|
if ( !result ) {
|
||||||
|
sort(gFiles.begin(),gFiles.end(),mySort);
|
||||||
|
if ( options.dst ) Position::dst_ = 3600;
|
||||||
|
if ( options.verbose ) {
|
||||||
|
int t = Position::tz();
|
||||||
|
int d = Position::dst();
|
||||||
|
int a = Position::adjust();
|
||||||
|
int A = Position::Adjust();
|
||||||
|
int s = A ;
|
||||||
|
int h = s/3600;
|
||||||
|
s-= h*3600;
|
||||||
|
s = abs(s);
|
||||||
|
int m = s/60 ;
|
||||||
|
s-= m*60 ;
|
||||||
|
printf("tz,dst,adjust = %d,%d,%d total = %dsecs (= %d:%d:%d)\n",t,d,a,A,h,m,s);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if ( options.verbose ) {
|
||||||
|
printf("Time Dictionary\n");
|
||||||
|
for ( TimeDict_i it = gTimeDict.begin() ; it != gTimeDict.end() ; it++ ) {
|
||||||
|
std::string sTime = getExifTime(it->first);
|
||||||
|
Position* pPos = &it->second;
|
||||||
|
std::string sPos = Position::toExifString(pPos->lat(),false,true)
|
||||||
|
+ " "
|
||||||
|
+ Position::toExifString(pPos->lon(),false,true)
|
||||||
|
;
|
||||||
|
printf("%s %s\n",sTime.c_str(), sPos.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
for ( size_t p = 0 ; p < gFiles.size() ; p++ ) {
|
||||||
|
std::string path = gFiles[p] ;
|
||||||
|
std::string stamp ;
|
||||||
|
try {
|
||||||
|
time_t t = readImageTime(path,&stamp) ;
|
||||||
|
Position* pPos = searchTimeDict(gTimeDict,t,Position::deltaMax_);
|
||||||
|
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path);
|
||||||
|
if ( image.get() ) {
|
||||||
|
image->readMetadata();
|
||||||
|
Exiv2::ExifData& exifData = image->exifData();
|
||||||
|
if ( pPos ) {
|
||||||
|
exifData["Exif.GPSInfo.GPSProcessingMethod" ] = "65 83 67 73 73 0 0 0 72 89 66 82 73 68 45 70 73 88"; // ASCII HYBRID-FIX
|
||||||
|
exifData["Exif.GPSInfo.GPSVersionID" ] = "2 2 0 0";
|
||||||
|
exifData["Exif.GPSInfo.GPSMapDatum" ] = "WGS-84";
|
||||||
|
|
||||||
|
exifData["Exif.GPSInfo.GPSLatitude" ] = Position::toExifString(pPos->lat(),true,true);
|
||||||
|
exifData["Exif.GPSInfo.GPSLongitude" ] = Position::toExifString(pPos->lon(),true,false);
|
||||||
|
exifData["Exif.GPSInfo.GPSAltitude" ] = Position::toExifString(pPos->ele());
|
||||||
|
|
||||||
|
exifData["Exif.GPSInfo.GPSAltitudeRef" ] = pPos->ele()<0.0?"1":"0";
|
||||||
|
exifData["Exif.GPSInfo.GPSLatitudeRef" ] = pPos->lat()>0?"N":"S";
|
||||||
|
exifData["Exif.GPSInfo.GPSLongitudeRef" ] = pPos->lon()>0?"E":"W";
|
||||||
|
|
||||||
|
exifData["Exif.GPSInfo.GPSDateStamp" ] = stamp;
|
||||||
|
exifData["Exif.GPSInfo.GPSTimeStamp" ] = Position::toExifTimeStamp(stamp);
|
||||||
|
exifData["Exif.Image.GPSTag" ] = 4908;
|
||||||
|
|
||||||
|
printf("%s %s % 2d\n",path.c_str(),pPos->toString().c_str(),pPos->delta());
|
||||||
|
} else {
|
||||||
|
printf("%s *** not in time dict ***\n",path.c_str());
|
||||||
|
}
|
||||||
|
if ( !options.dryrun ) image->writeMetadata();
|
||||||
|
}
|
||||||
|
} catch ( ... ) {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// That's all Folks!
|
||||||
|
////
|
@ -0,0 +1,27 @@
|
|||||||
|
--- show GPSInfo tags ---
|
||||||
|
Exif.GPSInfo.GPSVersionID Byte 4 2.2.0.0
|
||||||
|
Exif.GPSInfo.GPSLatitudeRef Ascii 2 North
|
||||||
|
Exif.GPSInfo.GPSLatitude Rational 3 36deg 26' 54"
|
||||||
|
Exif.GPSInfo.GPSLongitudeRef Ascii 2 West
|
||||||
|
Exif.GPSInfo.GPSLongitude Rational 3 116deg 51' 18"
|
||||||
|
Exif.GPSInfo.GPSAltitudeRef Byte 1 Below sea level
|
||||||
|
Exif.GPSInfo.GPSAltitude Rational 1 14.3 m
|
||||||
|
Exif.GPSInfo.GPSTimeStamp Rational 3 09:54:28
|
||||||
|
Exif.GPSInfo.GPSMapDatum Ascii 7 WGS-84
|
||||||
|
Exif.GPSInfo.GPSProcessingMethod Undefined 18 HYBRID-FIX
|
||||||
|
Exif.GPSInfo.GPSDateStamp Ascii 20 2008:05:08 09:54:28
|
||||||
|
--- deleting the GPSInfo tags
|
||||||
|
--- run geotag ---
|
||||||
|
116deg51'18"W 036deg26'54"N -14.282 -3
|
||||||
|
--- show GPSInfo tags ---
|
||||||
|
Exif.GPSInfo.GPSVersionID Byte 4 2.2.0.0
|
||||||
|
Exif.GPSInfo.GPSLatitudeRef Ascii 2 North
|
||||||
|
Exif.GPSInfo.GPSLatitude Rational 3 36deg 26' 54"
|
||||||
|
Exif.GPSInfo.GPSLongitudeRef Ascii 2 West
|
||||||
|
Exif.GPSInfo.GPSLongitude Rational 3 116deg 51' 18"
|
||||||
|
Exif.GPSInfo.GPSAltitudeRef Byte 1 Below sea level
|
||||||
|
Exif.GPSInfo.GPSAltitude Rational 1 14.3 m
|
||||||
|
Exif.GPSInfo.GPSTimeStamp Rational 3 09:54:28
|
||||||
|
Exif.GPSInfo.GPSMapDatum Ascii 7 WGS-84
|
||||||
|
Exif.GPSInfo.GPSProcessingMethod Undefined 58 65 83 67 73 73 0 0 0 72 89 66 82 73 68 45 70 73 88
|
||||||
|
Exif.GPSInfo.GPSDateStamp Ascii 20 2008:05:08 09:54:28
|
Loading…
Reference in New Issue