├── tst ├── sample.png ├── sample.HEIC └── main.rs ├── examples ├── example.jpg ├── gps.rs └── timestamp.rs ├── .gitignore ├── .rustfmt.toml ├── .reuse └── dep5 ├── CONTRIBUTORS.md ├── Cargo.toml ├── Makefile ├── SETUP.md ├── .circleci └── config.yml ├── CONTRIBUTING.md ├── CHANGELOG.md ├── README.md ├── LICENSES ├── CC0-1.0.txt └── GPL-3.0-or-later.txt ├── LICENSE └── src └── lib.rs /tst/sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/felixc/rexiv2/HEAD/tst/sample.png -------------------------------------------------------------------------------- /tst/sample.HEIC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/felixc/rexiv2/HEAD/tst/sample.HEIC -------------------------------------------------------------------------------- /examples/example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/felixc/rexiv2/HEAD/examples/example.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2015–2022 Felix A. Crux and CONTRIBUTORS 2 | # SPDX-License-Identifier: CC0-1.0 3 | 4 | Cargo.lock 5 | target/ 6 | -------------------------------------------------------------------------------- /.rustfmt.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2015–2022 Felix A. Crux and CONTRIBUTORS 2 | # SPDX-License-Identifier: CC0-1.0 3 | 4 | blank_lines_upper_bound = 2 5 | struct_lit_width = 50 6 | -------------------------------------------------------------------------------- /.reuse/dep5: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: rexiv2 3 | Upstream-Contact: Felix Crux 4 | Source: https://github.com/felixc/rexiv2 5 | 6 | Files: examples/example.jpg tst/sample.* 7 | Copyright: Felix Crux and CONTRIBUTORS 8 | License: CC0-1.0 9 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | Project Maintainer 7 | ------------------ 8 | * Felix Crux 9 | 10 | 11 | Contributors 12 | ------------ 13 | * Einar Gangsø 14 | * Eric Trombly 15 | * Huon Wilson 16 | * Wieland Hoffmann 17 | * Jean-Baptiste Daval 18 | * Riley Trautman 19 | * Sean Dawson 20 | * Hubert Figuière 21 | * Tobias Prisching 22 | -------------------------------------------------------------------------------- /examples/gps.rs: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2015–2022 Felix A. Crux and CONTRIBUTORS 2 | // SPDX-License-Identifier: GPL-3.0-or-later 3 | 4 | extern crate rexiv2; 5 | 6 | use rexiv2::Metadata; 7 | 8 | fn main() { 9 | rexiv2::initialize().expect("Unable to initialize rexiv2"); 10 | 11 | if let Ok(meta) = Metadata::new_from_path("examples/example.jpg") { 12 | if let Some(location) = meta.get_gps_info() { 13 | println!("Location: {location:?}"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/timestamp.rs: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2015–2022 Felix A. Crux and CONTRIBUTORS 2 | // SPDX-License-Identifier: GPL-3.0-or-later 3 | 4 | extern crate rexiv2; 5 | 6 | use rexiv2::Metadata; 7 | 8 | fn main() { 9 | rexiv2::initialize().expect("Unable to initialize rexiv2"); 10 | 11 | if let Ok(meta) = Metadata::new_from_path("examples/example.jpg") { 12 | if let Ok(time) = meta.get_tag_string("Exif.Image.DateTime") { 13 | println!("Time: {time:?}"); 14 | } 15 | if meta 16 | .set_tag_string("Exif.Image.DateTime", "2008:11:01 21:15:07") 17 | .is_ok() 18 | { 19 | meta.save_to_file("examples/example.jpg") 20 | .expect("Couldn't save metadata to file"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2015–2022 Felix A. Crux and CONTRIBUTORS 2 | # SPDX-License-Identifier: GPL-3.0-or-later 3 | 4 | [package] 5 | name = "rexiv2" 6 | description = """ 7 | This library provides a Rust wrapper around the gexiv2 library, which is 8 | a GObject-based wrapper around the Exiv2 library, which provides read and 9 | write access to the Exif, XMP, and IPTC metadata in media files (typically 10 | photos) in various formats. 11 | """ 12 | 13 | version = "0.10.0" 14 | authors = ["Felix Crux "] 15 | license = "GPL-3.0-or-later" 16 | documentation = "https://felixcrux.com/files/doc/rexiv2/" 17 | homepage = "https://github.com/felixc/rexiv2" 18 | repository = "https://github.com/felixc/rexiv2" 19 | keywords = ["metadata", "exif", "iptc", "xmp", "photo"] 20 | categories = ["multimedia::images"] 21 | readme = "README.md" 22 | 23 | edition = "2021" 24 | rust-version = "1.63" 25 | 26 | include = [ 27 | "Cargo.toml", 28 | "README.md", 29 | "CHANGELOG.md", 30 | "LICENSE", 31 | "SETUP.md", 32 | "src/**/*", 33 | ] 34 | 35 | [dependencies] 36 | gexiv2-sys = "1.4" 37 | libc = "0.2" 38 | num-rational = { version = "0.4", default-features = false } 39 | glib-sys = { version = "0.16", optional = true } 40 | 41 | [features] 42 | raw-tag-access = ["gexiv2-sys/raw-tag-access", "glib-sys"] 43 | 44 | [[test]] 45 | name = "tests" 46 | path = "tst/main.rs" 47 | 48 | [badges] 49 | travis-ci = { repository = "felixc/rexiv2" } 50 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Felix A. Crux and CONTRIBUTORS 2 | # SPDX-License-Identifier: GPL-3.0-or-later 3 | 4 | 5 | MSRV=1.63 # Minimum supported Rust version 6 | 7 | 8 | help: 9 | @echo "Usage: make TARGET [-- ARGS...]\n" 10 | @echo "Available targets:" 11 | @awk -F ' +##' 'NF>1 {printf "\033[36m %-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) 12 | @echo 13 | 14 | setup: ## Install all tools for local development 15 | rustup toolchain add stable 16 | rustup toolchain add nightly 17 | rustup toolchain add $(MSRV) 18 | rustup component add llvm-tools-preview clippy rustfmt 19 | cargo install cargo-audit cargo-outdated rustfilt grcov 20 | 21 | ## 22 | 23 | format: ## Run auto-formatter 24 | cargo +nightly fmt 25 | 26 | check: ## Run linter/analysis tool 27 | cargo clippy --all-targets --all-features -- -D warnings 28 | 29 | test: ## Run all tests (or specify a test name/selector to run just that) 30 | cargo test --all-features -- $(filter-out $@, $(MAKECMDGOALS)) 31 | 32 | coverage: ## Produce a test coverage report 33 | cargo +nightly clean 34 | RUSTDOCFLAGS="-C instrument-coverage -Z unstable-options --persist-doctests target/debug/doctestbins" \ 35 | RUSTFLAGS="-C instrument-coverage" \ 36 | LLVM_PROFILE_FILE="target/coverage/%p-%m.profraw" \ 37 | cargo +nightly test --all-features 38 | grcov ./target/coverage --binary-path ./target/debug/ --source-dir . \ 39 | --ignore-not-existing --ignore "*examples*" --branch \ 40 | --output-type html --output-path ./target/coverage/html/ 41 | @printf "\nCoverage report available at: file:///$$(pwd)/target/coverage/html/index.html\n" 42 | 43 | doc: ## Generate documentation 44 | cargo clean 45 | cargo doc --no-deps --all-features 46 | @printf "\nDocs available at: file:///$$(pwd)/target/doc/rexiv2/index.html\n" 47 | 48 | ## 49 | 50 | clean: ## Remove all build artefacts 51 | cargo clean 52 | 53 | release: ## Run checks before releasing a new version 54 | rustup update 55 | cargo install $$(cargo install --list | awk '/ / {all=all$$0} END {print all}') 56 | cargo update 57 | cargo clean && cargo build --all-features && cargo test --all-features 58 | cargo clean && cargo +$(MSRV) build --all-features && cargo +$(MSRV) test --all-features 59 | cargo clean && cargo +nightly build --all-features && cargo +nightly test --all-features 60 | cargo outdated --root-deps-only 61 | cargo audit 62 | 63 | 64 | .PHONY: help setup format check test coverage doc clean release 65 | -------------------------------------------------------------------------------- /SETUP.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | Setup & Dependencies 7 | ==================== 8 | 9 | Dependencies 10 | ------------ 11 | 12 | Given that it links to gexiv2, and transitively to Exiv2, rexiv2 obviously 13 | depends on them (and on their dependencies). Having these libraries installed on 14 | your system is a prerequisite to using rexiv2, or any software built on it. 15 | 16 | gexiv2 is supported from version 0.10 onwards, and Exiv2 from version 0.23. 17 | 18 | Platform-specific instructions for how to accomplish this are below: 19 | 20 | ### GNU/Linux 21 | 22 | On a GNU/Linux system, you can typically install these dependencies through your 23 | package manager, but be aware that they may be older versions without all the 24 | features you’d like to use. 25 | 26 | On Debian and its derivatives (like Ubuntu), run `sudo apt-get install 27 | libgexiv2-dev`. On Arch, the package `libgexiv2` may have all you need. On 28 | Fedora-like distros, try `libgexiv2-devel`. All of these should come with all 29 | their dependencies as well. 30 | 31 | If you need a newer version of a library than the one provided by your current 32 | distribution version (e.g. because you are on Debian Stable, or Ubuntu LTS), you 33 | may be able to build your own “backport” of the packages provided by later 34 | distro releases. 35 | 36 | For example, on Debian, add “`deb-src http://httpredir.debian.org/debian 37 | unstable main`” to your `/etc/apt/sources.list` file, and run: 38 | 39 | ```shell 40 | mkdir /tmp/gexiv2 && cd /tmp/gexiv2 41 | apt-get update 42 | sudo apt-get build-dep libgexiv2-dev libgexiv2-2 43 | sudo apt-get -b source libgexiv2-dev libgexiv2-2 44 | sudo dpkg -i *gexiv2*.deb 45 | ``` 46 | 47 | If you really need the latest upstream versions, you can always download them 48 | directly from their project download pages and install them manually: 49 | [Exiv2][exiv2-dl]; [gexiv2][gexiv2-dl]. 50 | 51 | ### Mac OS X 52 | 53 | The simplest known way of installing the required dependencies on Mac OS X is 54 | with the Homebrew package manager, using the [gexiv2][gexiv2-brew] formula: 55 | 56 | ```shell 57 | brew update 58 | brew install gexiv2 pkg-config 59 | ``` 60 | 61 | For the build to succeed, you will have to tell `pkg-config` where Homebrew 62 | installed some relevant libraries, using: 63 | 64 | ```shell 65 | export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig" 66 | ``` 67 | 68 | It may also be possible to install dependencies via MacPorts, using the 69 | [gexiv2][gexiv2-port] port, but I have not tested this. If you have more 70 | information, please consider contributing your knowledge to this document. 71 | 72 | Otherwise, you will likely have to download the dependencies directly from their 73 | project download pages: [Exiv2][exiv2-dl]; [gexiv2][gexiv2-dl]. 74 | 75 | ### Windows 76 | 77 | I currently do not know what steps are needed to install these dependencies on 78 | Windows. If you figure it out, please consider contributing your knowledge to 79 | this document (see our sister-project gexiv2-sys’s 80 | [GitHub Issue #11](https://github.com/felixc/gexiv2-sys/issues/11)). 81 | 82 | You will likely have to download the dependencies directly from their project 83 | download pages: [Exiv2][exiv2-dl]; [gexiv2][gexiv2-dl]. 84 | 85 | [exiv2-dl]: http://www.exiv2.org/download.html 86 | [gexiv2-dl]: https://wiki.gnome.org/Projects/gexiv2/BuildingAndInstalling 87 | [gexiv2-brew]: http://brewformulas.org/Gexiv2 88 | [gexiv2-port]: https://trac.macports.org/browser/trunk/dports/gnome/gexiv2/Portfile 89 | 90 | 91 | Using rexiv2 In Your Code 92 | ------------------------- 93 | 94 | The best way to download and use rexiv2 in your own code is by depending on it 95 | via Cargo, and fetching it from [crates.io][crates-rexiv2]. You can do this by 96 | adding a dependency on rexiv2 in your crate’s `Cargo.toml` file: 97 | 98 | ```toml 99 | [dependencies] 100 | rexiv2 = "0.10" 101 | ``` 102 | 103 | Alternatively, if you’d like to work off of the bleeding edge (note that this is 104 | not recommended unless you’re actively developing on rexiv2 itself), you can 105 | depend directly on the Git repository using the line 106 | 107 | ```toml 108 | rexiv2 = { git = "https://github.com/felixc/rexiv2" } 109 | ``` 110 | 111 | or on a local copy, using the `path` option: 112 | 113 | ```toml 114 | rexiv2 = { path = "../rexiv2" } # Or wherever your copy is located 115 | ``` 116 | 117 | Now you can import and use the functions defined in rexiv2 like this: 118 | 119 | ```rust 120 | extern crate rexiv2; 121 | 122 | fn main() { 123 | let meta = rexiv2::Metadata::new_from_path("example.jpg").unwrap(); 124 | println!("{:?}", meta.get_media_type()); 125 | } 126 | ``` 127 | 128 | [crates-rexiv2]: https://crates.io/crates/rexiv2 129 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2015–2022 Felix A. Crux and CONTRIBUTORS 2 | # SPDX-License-Identifier: CC0-1.0 3 | 4 | 5 | version: 2.1 6 | 7 | 8 | commands: 9 | install_system_dependencies: 10 | description: "Install system-level libraries/tools we depend on" 11 | steps: 12 | - run: 13 | name: Install system dependencies 14 | command: | 15 | case "$(uname -s)" in 16 | Linux*) 17 | apt --quiet update 18 | apt --yes install libgexiv2-dev 19 | ;; 20 | Darwin*) 21 | brew install gexiv2 pkg-config 22 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y 23 | ;; 24 | esac 25 | build_and_test_steps: 26 | description: "Build the library and test it" 27 | steps: 28 | - checkout 29 | - install_system_dependencies 30 | - run: 31 | name: Show environment info 32 | command: | 33 | rustc --version --verbose && echo "" 34 | cargo --version --verbose && echo "" 35 | case "$(uname -s)" in 36 | Linux*) 37 | dpkg --list libgexiv2-dev libexiv2-dev ;; 38 | Darwin*) 39 | brew list --versions gexiv2 exiv2 ;; 40 | esac 41 | - run: 42 | name: Build 43 | command: cargo build --verbose --all-features 44 | - run: 45 | name: Test 46 | command: cargo test --verbose --all-features -- --test-threads 2 47 | - run: 48 | name: Run Examples 49 | command: | 50 | cargo run --example gps 51 | cargo run --example timestamp 52 | 53 | 54 | linux_job_config: &linux_job_config 55 | resource_class: small 56 | steps: 57 | - build_and_test_steps 58 | 59 | 60 | jobs: 61 | test-osx-stable: 62 | macos: 63 | xcode: "14.0.0" 64 | steps: 65 | - build_and_test_steps 66 | test-linux-msrv: 67 | docker: 68 | - image: rust:1.63-slim 69 | <<: *linux_job_config 70 | test-linux-stable: 71 | docker: 72 | - image: rust:slim 73 | <<: *linux_job_config 74 | test-linux-nightly-with-coverage: 75 | resource_class: large 76 | docker: 77 | - image: rustlang/rust:nightly-slim 78 | steps: 79 | - checkout 80 | - install_system_dependencies 81 | - run: 82 | name: Install test coverage reporting dependencies 83 | command: | 84 | rustup component add llvm-tools-preview 85 | cargo install grcov 86 | apt install --yes curl gpg git 87 | curl https://keybase.io/codecovsecurity/pgp_keys.asc \ 88 | | gpg --no-default-keyring --keyring keys.gpg --import 89 | curl -Os https://uploader.codecov.io/latest/linux/codecov 90 | curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM 91 | curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig 92 | gpg --keyring keys.gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM 93 | sha256sum --check codecov.SHA256SUM 94 | chmod +x codecov 95 | - run: 96 | name: Run tests with coverage analysis 97 | command: | 98 | RUSTFLAGS="-C instrument-coverage" \ 99 | RUSTDOCFLAGS="-C instrument-coverage -Z unstable-options --persist-doctests target/debug/doctestbins" \ 100 | LLVM_PROFILE_FILE="coverage-%p-%m.profraw" \ 101 | cargo test --all-features 102 | - run: 103 | name: Upload coverage report to Codecov 104 | command: | 105 | grcov . --binary-path ./target/debug/ -t lcov --branch \ 106 | --keep-only '/root/project/src/*' -o ./lcov.info 107 | ./codecov -Z 108 | check-lint-and-format: 109 | resource_class: small 110 | docker: 111 | - image: rustlang/rust:nightly-slim 112 | steps: 113 | - checkout 114 | - install_system_dependencies 115 | - run: 116 | name: Run linter 117 | command: cargo +nightly clippy --all-targets --all-features -- -D warnings 118 | - run: 119 | name: Check formatting 120 | command: cargo +nightly fmt --check 121 | check-spdx: 122 | resource_class: small 123 | docker: 124 | - image: fsfe/reuse:latest 125 | steps: 126 | - checkout 127 | - run: 128 | name: Check SPDX licensing metadata 129 | command: reuse lint 130 | 131 | 132 | workflows: 133 | build-and-test: 134 | jobs: 135 | - test-osx-stable 136 | - test-linux-msrv 137 | - test-linux-stable 138 | - test-linux-nightly-with-coverage 139 | - check-lint-and-format 140 | - check-spdx 141 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | Contributing 7 | ============ 8 | 9 | Contributions are gladly accepted, either through GitHub pull requests or by 10 | mailing patches to `felixc@felixcrux.com` (PGP key [8569B6311EE485F8][pgp-key]). 11 | 12 | Reports of security issues can also be sent privately to the email address and 13 | PGP key given above. 14 | 15 | **By contributing, you are agreeing to make your contribution available under 16 | the same license terms as the rest of the project.** 17 | 18 | Contributions of feature code, test code, documentation, bug reports, etc. are 19 | all appreciated, and I’d be happy to help guide you through the process if you 20 | have any questions. 21 | 22 | [pgp-key]: http://hkps.pool.sks-keyservers.net/pks/lookup?op=vindex&search=0x8569B6311EE485F8 23 | 24 | 25 | Bug Reports & Feature Requests 26 | ------------------------------ 27 | 28 | Outstanding work for the project is tracked with GitHub’s “Issues” feature. You 29 | can see the current list of [open issues here][issues]. This covers all of bugs, 30 | feature requests, documentation improvements, and any other kind of enhancement. 31 | 32 | If you encounter any problems with the software, or would like it to be improved 33 | in some way, please feel free to file a new GitHub Issue or send a report by 34 | email to `felixc@felixcrux.com`. The more detail you can provide, the better. 35 | 36 | If you’d like to contribute to the project, the [issue tracker][issues] is also 37 | the place to start. Please indicate your interest in addressing the issue by 38 | leaving a comment, potentially describing at a high level what you intend to do. 39 | This helps avoid duplication of work when two people silently work on the same 40 | problem, and also needless churn that can arise if the implementation you submit 41 | is surprising to the parties interested in the issue and hasn’t been explained 42 | in advance. **If there is no issue already open for the work you’d like to do, 43 | please create one.** 44 | 45 | ### Issue Labels 46 | Issues in the GitHub tracker are categorized with “labels”. These mostly 47 | describe what kind of work the issue covers (e.g. there are labels for 48 | “infrastructure”, “documentation”, “feature”, “bug”…). 49 | 50 | Of particular note, however, is the “[good-first-bug][g-f-b]” label. Issues 51 | tagged in this way are believed to be especially suitable for new contributors 52 | (whether to the project, or to Rust code, or to Free Software/Open Source in 53 | general). Anyone is welcome to work on any issue, but if you’re unsure about how 54 | to get going, that may be the place to start. 55 | 56 | [issues]: https://github.com/felixc/rexiv2/issues 57 | [g-f-b]: https://github.com/felixc/rexiv2/issues?q=is%3Aissue+is%3Aopen+label%3Agood-first-bug 58 | 59 | 60 | Setting Up Your Development Environment 61 | --------------------------------------- 62 | 63 | You’ll first need to be able to run the code. For instructions on getting the 64 | requisite system library dependencies, consult the [`SETUP`](SETUP.md) file. 65 | 66 | You can get by doing basic development with just the stable Rust and Cargo 67 | toolchain, and nothing else. However, if you want to run more complex workflows 68 | like generating test coverage reports or getting a Clippy static analysis/lint 69 | check, you can install the prerequisites with `make setup`. 70 | 71 | The `Makefile` in the project root defines a few useful commands for common 72 | needs, like `make test`, `make format`, and `make check`. For a full list of 73 | available commands, run `make help`. 74 | 75 | 76 | Code Conventions and Expectations 77 | --------------------------------- 78 | 79 | Code should be automatically formatted with `rustfmt`. 80 | 81 | For the moment we have to to use the nightly version of Cargo/rustfmt, because 82 | we really want to preserve multiple newlines between sections of code, and that 83 | requires the `blank_lines_upper_bound` configuration option in `.rustfmt.toml`. 84 | See https://github.com/rust-lang/rustfmt/issues/3381 for the bug tracking the 85 | stabilization of this configuration option. 86 | 87 | This means you can run the auto-formatter with `cargo +nightly fmt`. 88 | 89 | Code should be checked/linted with `clippy`. You can run this manually with 90 | `cargo clippy --all-targets --all-features`. 91 | 92 | Code should generally come with accompanying tests, but it’s understood 93 | that it’s not always possible to reach 100% line/branch coverage. 94 | 95 | 96 | Copyright & Licensing of Contributions 97 | -------------------------------------- 98 | 99 | The copyright to any contribution to this software project is retained by the 100 | original author of the contribution. However, by contributing, you are agreeing 101 | to make your contribution available as part of this project under the terms of 102 | the GNU General Public License (version 3 of the License, or any later version). 103 | 104 | Please refer to the [`LICENSE`](LICENSE) file for a full copy of the license. 105 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | ## [NEXT] - Unreleased 7 | * Bugfix: Stop reducing/simplifying rational values like apertures. 8 | * Breaking API change/bugfix: The altitude part of GpsInfo is now Optional. 9 | This works around an upstream change that caused `get_gps_info` to return 10 | `None` if altitude was unset, even if lat/long were present. Now lat/long 11 | will be returned, but altitude will be `None`. Altitudes that may have been 12 | previously shown as `0.0` will now be `None`. Calls to `set_gps_info` will 13 | also need updating. Thank you Jonas Hagen for the report and investigation. 14 | 15 | ## [v0.10.0] - 2023-01-21 16 | * New API: `new_from_app1_segment` allows reading metadata from a buffer. 17 | * Added support for Windows file paths. 18 | * Require Rust 1.63 as the minimum supported language version. 19 | * Adopt 2021 edition of the language. 20 | * Dependency upgrades. 21 | 22 | ## [v0.9.1] - 2020-07-12 23 | * Fixed build failure on arm32 due to invalid assumptions about int size. 24 | * Fixed null pointer crash when using `get_tag_raw()`. 25 | 26 | ## [v0.9.0] - 2019-11-23 27 | * Added functionality to get and set log levels, thanks to GitHub user t1ra. 28 | 29 | ## [v0.8.0] - 2019-09-02 30 | * Added operations on metadata thumbnail images. 31 | * Added way to get raw byte values of metadata. 32 | * Added methods on preview images. All of these thanks to Jean-Baptiste Daval! 33 | * Require Rust 1.31 as the minimum supported version (and use 2018 edition). 34 | 35 | ## [v0.7.0] - 2018-11-25 36 | * Added `initialize()` method for safe multi-threaded use. 37 | * Dependency upgrades. 38 | 39 | ## [v0.6.0] - 2018-02-19 40 | * Require Rust 1.20 as the minimum supported version to match dependencies. 41 | * Fixed segfault bug in `get_tag_multiple_strings` when there are no results. 42 | * Updated gexiv2-sys internal dependency. 43 | 44 | ## [v0.5.0] - 2017-06-21 45 | * Require Rust 1.8 as the minimum supported version to match dependencies. 46 | 47 | ## [v0.4.3] - 2017-06-21 48 | * Pin version of num-traits to unbreak builds on older rustc versions. 49 | 50 | ## [v0.4.2] - 2017-04-11 51 | * Upgraded gexiv2-sys dependency to 0.7. 52 | * Replaced num dependency with num-rational for faster builds. 53 | 54 | ## [v0.4.1] - 2016-10-04 55 | * Fix for potential crash due to dereferencing null pointer. 56 | 57 | ## [v0.4.0] - 2016-07-21 58 | * Path operations now accept anything that implements AsRef, 59 | which enables support for path::Paths in addition to strs. 60 | * Breaking change: Image media types are now represented by an enum instead of 61 | magic strings. It is easy to convert between the two forms using ::from(). 62 | * Breaking change: get/set_tag_long() are renamed get/set_tag_numeric(). 63 | * Breaking change: get/set_exif_tag_rational() renamed get/set_tag_rational(). 64 | * Breaking change: get/set_tag_long() now operate on i32 values, not i64. 65 | * Breaking change: Errors are now wrapped in a new rexiv2::Rexiv2Error type. 66 | * Breaking change: Results are now using a library-specific alias that fixes 67 | all Err() instances as Rexiv2Error. 68 | 69 | ## [v0.3.3] - 2016-03-30 70 | * Dependency cleanup: removed rustc-serialize & bumped gexiv2-sys. 71 | * Types implement more common useful traits. 72 | * Documentation improvements, including bundling setup instructions. 73 | 74 | ## [v0.3.2] - 2015-09-11 75 | * Dependency version bump (gexiv2-sys to 0.5 and libc to 0.2). 76 | 77 | ## [v0.3.1] - 2015-09-20 78 | * Fixed memory leak of some values returned over FFI boundary. 79 | 80 | ## [v0.3.0] - 2015-09-13 81 | * All instances of success/failure boolean return values are now Results. 82 | * Fixed critical bug that caused dangling pointers and mysterious errors. 83 | * Updated to use latest gexiv2-sys FFI declarations. 84 | 85 | ## [v0.2.3] - 2015-04-30 86 | * Library now builds with regular stable rustc. 87 | 88 | ## [v0.2.2] - 2015-04-03 89 | * Updated to work with 1.0.0-nightly (d17d6e7f1 2015-04-02) (Note: not Beta!). 90 | * More permissive and up-to-date dependency version requirements. 91 | 92 | ## [v0.2.1] - 2015-03-02 93 | * Added support for loading metadata from byte-array data buffers. 94 | * Split gexiv2 FFI declarations off into separate gexiv2-sys crate dependency. 95 | 96 | ## [v0.2.0] - 2015-03-01 97 | * The "get_tag_type" function now returns an item from an enum of data types. 98 | * Some methods that used to return magic numbers on error now return Options. 99 | * The "get_mime_type" method is renamed "get_media_type" for correctness. 100 | * Custom Rational type replaced by common num::rational::Ratio. 101 | 102 | ## [v0.1.0] - 2015-02-25 103 | * First development release. 104 | * Added ability to set multiple string values for a tag. 105 | * Fixed array terminator bug when getting list of Exif tags. 106 | 107 | ## [v0.1.0-pre] - 2015-02-21 108 | * First preview release to solicit code review and feedback. 109 | 110 | 111 | [v0.10.0]: https://github.com/felixc/rexiv2/compare/v0.9.1...v0.10.0 112 | [v0.9.1]: https://github.com/felixc/rexiv2/compare/v0.9.0...v0.9.1 113 | [v0.9.0]: https://github.com/felixc/rexiv2/compare/v0.8.0...v0.9.0 114 | [v0.8.0]: https://github.com/felixc/rexiv2/compare/v0.7.0...v0.8.0 115 | [v0.7.0]: https://github.com/felixc/rexiv2/compare/v0.6.0...v0.7.0 116 | [v0.6.0]: https://github.com/felixc/rexiv2/compare/v0.5.0...v0.6.0 117 | [v0.5.0]: https://github.com/felixc/rexiv2/compare/v0.4.3...v0.5.0 118 | [v0.4.3]: https://github.com/felixc/rexiv2/compare/v0.4.2...v0.4.3 119 | [v0.4.2]: https://github.com/felixc/rexiv2/compare/v0.4.1...v0.4.2 120 | [v0.4.1]: https://github.com/felixc/rexiv2/compare/v0.4.0...v0.4.1 121 | [v0.4.0]: https://github.com/felixc/rexiv2/compare/v0.3.3...v0.4.0 122 | [v0.3.3]: https://github.com/felixc/rexiv2/compare/v0.3.2...v0.3.3 123 | [v0.3.2]: https://github.com/felixc/rexiv2/compare/v0.3.1...v0.3.2 124 | [v0.3.1]: https://github.com/felixc/rexiv2/compare/v0.3.0...v0.3.1 125 | [v0.3.0]: https://github.com/felixc/rexiv2/compare/v0.2.3...v0.3.0 126 | [v0.2.3]: https://github.com/felixc/rexiv2/compare/v0.2.2...v0.2.3 127 | [v0.2.2]: https://github.com/felixc/rexiv2/compare/v0.2.1...v0.2.2 128 | [v0.2.1]: https://github.com/felixc/rexiv2/compare/v0.2.0...v0.2.1 129 | [v0.2.0]: https://github.com/felixc/rexiv2/compare/v0.1.0...v0.2.0 130 | [v0.1.0]: https://github.com/felixc/rexiv2/compare/25c31ad...v0.1.0 131 | [v0.1.0-pre]: https://github.com/felixc/rexiv2/commit/25c31ad5a0bdbc51ce95e416f1931771fdfd950d 132 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | rexiv2 7 | ====== 8 | 9 | [![docs-badge][]][docs]  10 | [![build-badge][]][build]  11 | [![coverage-badge][]][coverage]  12 | [![downloads-badge][]][crates-io]  13 | [![version-badge][]][crates-io]  14 | [![license-badge][]][license]  15 | [![reuse-badge][]][reuse]  16 | [![best-practices-badge][]][best-practices]  17 | 18 | [docs]: https://felixcrux.com/files/doc/rexiv2/ 19 | [docs-badge]: https://img.shields.io/docsrs/rexiv2 20 | [build]: https://dl.circleci.com/status-badge/redirect/gh/felixc/rexiv2/tree/main 21 | [build-badge]: https://dl.circleci.com/status-badge/img/gh/felixc/rexiv2/tree/main.svg?style=shield 22 | [coverage]: https://codecov.io/gh/felixc/rexiv2 23 | [coverage-badge]: https://codecov.io/gh/felixc/rexiv2/branch/main/graph/badge.svg?token=FT6WmJ9pD1 24 | [crates-io]: https://crates.io/crates/rexiv2 25 | [downloads-badge]: https://img.shields.io/crates/d/rexiv2.svg 26 | [version-badge]: https://img.shields.io/crates/v/rexiv2.svg 27 | [license]: https://github.com/felixc/rexiv2/blob/master/LICENSE 28 | [license-badge]: https://img.shields.io/crates/l/rexiv2.svg 29 | [reuse]: https://api.reuse.software/info/github.com/felixc/rexiv2 30 | [reuse-badge]: https://api.reuse.software/badge/github.com/felixc/rexiv2 31 | [best-practices]: https://bestpractices.coreinfrastructure.org/projects/6330 32 | [best-practices-badge]: https://bestpractices.coreinfrastructure.org/projects/6330/badge 33 | 34 | 35 | Rust library for working with media file metadata 36 | ------------------------------------------------- 37 | 38 | This crate provides a Rust wrapper around the [gexiv2][gexiv2] library, which is 39 | a GObject-based wrapper around [Exiv2][exiv2], which provides read and write 40 | access to the Exif, XMP, and IPTC metadata in media files (typically photos) in 41 | various formats. 42 | 43 | [gexiv2]: https://wiki.gnome.org/Projects/gexiv2 44 | [exiv2]: http://www.exiv2.org/ 45 | 46 | 47 | Documentation 48 | ------------- 49 | 50 | API documentation is [available online][rexiv2-doc]. 51 | 52 | Exiv2’s homepage has documentation on available [namespaces and tags][tags-doc]. 53 | 54 | [gexiv2’s APIs][gexiv2-api] may also be a useful reference, along with [Exiv2’s 55 | API docs][exiv2-api]. 56 | 57 | During development and testing, the [Exiv2 command-line utility][exiv2-cli] may 58 | come in handy. 59 | 60 | [rexiv2-doc]: https://felixcrux.com/files/doc/rexiv2/ 61 | [tags-doc]: http://exiv2.org/metadata.html 62 | [gexiv2-api]: https://git.gnome.org/browse/gexiv2/tree/gexiv2/gexiv2-metadata.h 63 | [exiv2-api]: http://exiv2.org/doc/index.html 64 | [exiv2-cli]: http://exiv2.org/manpage.html 65 | 66 | 67 | Setup & Dependencies 68 | -------------------- 69 | 70 | rexiv2 requires Rust 1.63 or newer, and uses the 2021 edition of the language. 71 | 72 | Being a wrapper for gexiv2 and Exiv2, rexiv2 obviously depends on them. These 73 | libraries are not bundled with rexiv2: you will need to install them separately. 74 | 75 | gexiv2 is supported from version 0.10 onwards, and Exiv2 from version 0.23. 76 | 77 | For full instructions on how to get started with rexiv2, including how to 78 | install the prerequisite dependencies, refer to the [`SETUP`](SETUP.md) file. 79 | 80 | Note that if you want BMFF support (e.g. HEIC, HEIF, AVIF, CR3, JXL/bmff files) 81 | you will need an up-to-date version of the underlying libraries (at least gexiv2 82 | v0.13.0 and Exiv2 v0.27.4). You will also need to ensure that your version of 83 | Exiv2 has BMFF support enabled. This is generally enabled by default, but may be 84 | switched off in certain distributions due to licensing issues. 85 | 86 | 87 | Versioning & History 88 | -------------------- 89 | 90 | rexiv2 is currently available as a pre-1.0 development version. 91 | 92 | Version numbers follow the principles of [Semantic Versioning][semver]. 93 | 94 | No further breaking API changes are planned, but they are possible as a result 95 | of feedback on the API as more users try it out. Such feedback is welcome, and 96 | having the API tried out in real applications is part of ensuring it’s ready for 97 | a 1.0 release. 98 | 99 | See the [`CHANGELOG`](CHANGELOG.md) file for a history of released versions. 100 | 101 | [semver]: http://semver.org/spec/v2.0.0.html 102 | 103 | 104 | Optional Features 105 | ----------------- 106 | 107 | **raw-tag-access**: If you need access to the raw byte values of tags, you can 108 | enable this feature and gain the `get_tag_raw` function. 109 | 110 | This feature is disabled by default because it introduces a new dependency on 111 | [`glib-sys`][glib-sys], and consequently on the GLib system library. 112 | 113 | [glib-sys]: https://crates.io/crates/glib-sys/ 114 | 115 | 116 | Contributions & Bug Reports 117 | --------------------------- 118 | 119 | Contributions are gladly accepted, either through GitHub pull requests or by 120 | mailing patches to `felixc@felixcrux.com` (PGP key [8569B6311EE485F8][pgp-key]). 121 | 122 | **By contributing, you are agreeing to make your contribution available under 123 | the same license terms as the rest of the project.** 124 | 125 | Bug reports and feature requests can also be sent through GitHub Issues or by 126 | email, and are very welcome and appreciated. 127 | 128 | Reports of security issues can also be sent privately to the email address and 129 | PGP key given above. 130 | 131 | For more information, see the [`CONTRIBUTING`](CONTRIBUTING.md) file. 132 | 133 | [pgp-key]: http://hkps.pool.sks-keyservers.net/pks/lookup?op=vindex&search=0x8569B6311EE485F8 134 | 135 | 136 | Copyright & License 137 | ------------------- 138 | 139 | The Exiv2 and gexiv2 libraries are both released under the terms of the GNU 140 | General Public License (GPL), and since rexiv2 is linked to them, it too is 141 | made available under the terms of the GPL. Specifically: 142 | 143 | This program is free software: you can redistribute it and/or modify it 144 | under the terms of the GNU General Public License as published by the Free 145 | Software Foundation, either version 3 of the License, or (at your option) 146 | any later version. 147 | 148 | This program is distributed in the hope that it will be useful, but WITHOUT 149 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 150 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 151 | 152 | You should have received a copy of the GNU General Public License along with 153 | this program. If not, see . 154 | 155 | Please refer to the [`LICENSE`](LICENSE) file for a full copy of the license. 156 | -------------------------------------------------------------------------------- /tst/main.rs: -------------------------------------------------------------------------------- 1 | // Copyright © 2016–2022 Felix A. Crux and CONTRIBUTORS 2 | // 3 | // SPDX-FileCopyrightText: 2015–2022 Felix A. Crux and CONTRIBUTORS 4 | // SPDX-License-Identifier: GPL-3.0-or-later 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | extern crate gexiv2_sys as gexiv2; 20 | extern crate rexiv2; 21 | 22 | use std::path::Path; 23 | 24 | use std::sync::Once; 25 | 26 | static INIT: Once = Once::new(); 27 | 28 | /// Should be called before any test runs. Will ensure that the library is initialized at most once. 29 | fn test_setup() { 30 | INIT.call_once(|| rexiv2::initialize().expect("Unable to initialize rexiv2")); 31 | } 32 | 33 | #[test] 34 | fn new_from_str_path() { 35 | test_setup(); 36 | let sample_path = concat!(env!("CARGO_MANIFEST_DIR"), "/tst/sample.png"); 37 | let meta = rexiv2::Metadata::new_from_path(sample_path).unwrap(); 38 | assert_eq!(meta.get_media_type().unwrap(), rexiv2::MediaType::Png); 39 | } 40 | 41 | #[test] 42 | fn new_from_path() { 43 | test_setup(); 44 | let sample_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tst/sample.png")); 45 | let meta = rexiv2::Metadata::new_from_path(sample_path).unwrap(); 46 | assert_eq!(meta.get_media_type().unwrap(), rexiv2::MediaType::Png); 47 | } 48 | 49 | #[test] 50 | fn new_from_buffer() { 51 | test_setup(); 52 | let meta = rexiv2::Metadata::new_from_buffer(include_bytes!("sample.png")).unwrap(); 53 | assert_eq!(meta.get_media_type().unwrap(), rexiv2::MediaType::Png); 54 | } 55 | 56 | #[test] 57 | fn new_from_app1() { 58 | test_setup(); 59 | static APP1_SEGMENT: &[u8] = &[ 60 | 255, 225, 0, 232, 69, 120, 105, 102, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 2, 0, 50, 1, 2, 0, 61 | 20, 0, 0, 0, 38, 0, 0, 0, 37, 136, 4, 0, 1, 0, 0, 0, 58, 0, 0, 0, 0, 0, 0, 0, 50, 48, 48, 62 | 56, 58, 49, 49, 58, 48, 49, 32, 50, 49, 58, 49, 53, 58, 48, 55, 0, 8, 0, 0, 0, 1, 0, 4, 0, 63 | 0, 0, 2, 0, 0, 0, 1, 0, 2, 0, 2, 0, 0, 0, 78, 0, 0, 0, 2, 0, 5, 0, 3, 0, 0, 0, 160, 0, 0, 64 | 0, 3, 0, 2, 0, 2, 0, 0, 0, 69, 0, 0, 0, 4, 0, 5, 0, 3, 0, 0, 0, 184, 0, 0, 0, 5, 0, 1, 0, 65 | 1, 0, 0, 0, 0, 0, 0, 0, 6, 0, 10, 0, 1, 0, 0, 0, 208, 0, 0, 0, 18, 0, 2, 0, 7, 0, 0, 0, 66 | 216, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 64, 67 | 66, 15, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 64, 66, 15, 0, 3, 0, 68 | 0, 0, 1, 0, 0, 0, 87, 71, 83, 45, 56, 52, 0, 69 | ]; 70 | let meta = rexiv2::Metadata::new_from_app1_segment(APP1_SEGMENT).unwrap(); 71 | assert_eq!(meta.get_media_type().unwrap(), rexiv2::MediaType::Jpeg); 72 | } 73 | 74 | #[test] 75 | fn new_from_buffer_error() { 76 | test_setup(); 77 | let mut bytes = include_bytes!("sample.png").to_vec(); 78 | bytes.swap(0, 1); 79 | let meta_result = rexiv2::Metadata::new_from_buffer(&bytes); 80 | assert_eq!( 81 | meta_result, 82 | Err(rexiv2::Rexiv2Error::Internal(Some( 83 | "unsupported format".to_string() 84 | ))) 85 | ); 86 | } 87 | 88 | #[test] 89 | fn supports_exif() { 90 | test_setup(); 91 | let meta = rexiv2::Metadata::new_from_buffer(include_bytes!("sample.png")).unwrap(); 92 | assert!(meta.supports_exif()); 93 | } 94 | 95 | #[test] 96 | fn supports_iptc() { 97 | test_setup(); 98 | let meta = rexiv2::Metadata::new_from_buffer(include_bytes!("sample.png")).unwrap(); 99 | assert!(meta.supports_iptc()); 100 | } 101 | 102 | #[test] 103 | fn supports_xmp() { 104 | test_setup(); 105 | let meta = rexiv2::Metadata::new_from_buffer(include_bytes!("sample.png")).unwrap(); 106 | assert!(meta.supports_xmp()); 107 | } 108 | 109 | #[test] 110 | fn supports_bmff() { 111 | test_setup(); 112 | 113 | // iPhone devices use the HEIC (BMFF) file format which only works properly 114 | // after gexiv2 has been initialized (and the underlying libraries are the 115 | // right version gexiv2 v0.13.0/Exiv2 v0.27.4) 116 | if unsafe { gexiv2::gexiv2_get_version() } < 1300 { 117 | return; 118 | } 119 | 120 | let meta = rexiv2::Metadata::new_from_buffer(include_bytes!("sample.HEIC")).unwrap(); 121 | let gps = meta.get_gps_info().unwrap(); 122 | assert_eq!(gps.latitude as i32, -27); 123 | assert_eq!(gps.longitude as i32, 114); 124 | let phone_model = meta.get_tag_string("Exif.Image.Model").unwrap(); 125 | assert_eq!(phone_model, "iPhone XS"); 126 | 127 | // This seems strange since we can read the above information 128 | // We may be missing a "supports" function for bmff tags, or the functions may be returning incorrectly 129 | assert!(!meta.supports_exif()); 130 | assert!(!meta.supports_iptc()); 131 | assert!(!meta.supports_xmp()); 132 | } 133 | 134 | #[test] 135 | fn get_tag_rational_values_are_not_reduced() { 136 | test_setup(); 137 | let meta = rexiv2::Metadata::new_from_buffer(include_bytes!("sample.png")).unwrap(); 138 | meta.set_tag_rational( 139 | "Exif.Photo.ApertureValue", 140 | &num_rational::Ratio::new_raw(16, 10), 141 | ) 142 | .unwrap(); 143 | let result = meta.get_tag_rational("Exif.Photo.ApertureValue").unwrap(); 144 | assert_eq!(*result.numer(), 16); 145 | assert_eq!(*result.denom(), 10); 146 | } 147 | 148 | #[test] 149 | fn get_exposure_time_values_are_not_reduced() { 150 | test_setup(); 151 | let meta = rexiv2::Metadata::new_from_buffer(include_bytes!("sample.png")).unwrap(); 152 | meta.set_tag_rational( 153 | "Exif.Photo.ExposureTime", 154 | &num_rational::Ratio::new_raw(10, 1000), 155 | ) 156 | .unwrap(); 157 | let result = meta.get_exposure_time().unwrap(); 158 | assert_eq!(*result.numer(), 10); 159 | assert_eq!(*result.denom(), 1000); 160 | } 161 | 162 | #[test] 163 | fn log_levels() { 164 | test_setup(); 165 | assert_eq!(rexiv2::get_log_level(), rexiv2::LogLevel::WARN); 166 | rexiv2::set_log_level(rexiv2::LogLevel::INFO); 167 | assert_eq!(rexiv2::get_log_level(), rexiv2::LogLevel::INFO); 168 | } 169 | 170 | #[test] 171 | #[cfg(feature = "raw-tag-access")] 172 | fn get_tag_raw() { 173 | test_setup(); 174 | let meta = rexiv2::Metadata::new_from_buffer(include_bytes!("sample.png")).unwrap(); 175 | meta.set_tag_string("Exif.Image.DateTime", "2020:07:12 11:16:35") 176 | .unwrap(); 177 | assert_eq!( 178 | meta.get_tag_raw("Exif.Image.DateTime").unwrap(), 179 | b"2020:07:12 11:16:35\0" 180 | ); 181 | } 182 | -------------------------------------------------------------------------------- /LICENSES/CC0-1.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /LICENSES/GPL-3.0-or-later.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright © 2015–2022 Felix A. Crux and CONTRIBUTORS 2 | // 3 | // SPDX-FileCopyrightText: 2015–2022 Felix A. Crux and CONTRIBUTORS 4 | // SPDX-License-Identifier: GPL-3.0-or-later 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #![allow(clippy::needless_doctest_main)] 20 | 21 | //! This library provides a Rust wrapper around the [gexiv2][gexiv2] library, 22 | //! which is itself a GObject-based wrapper around the [Exiv2][exiv2] library, 23 | //! which provides read and write access to the Exif, XMP, and IPTC metadata 24 | //! for media files in various formats. 25 | //! 26 | //! Most functionality is exposed through methods on the [`Metadata`][struct-meta] type. 27 | //! 28 | //! ## Usage 29 | //! A typical use of the library might look something like this: 30 | //! 31 | //! ```no_run 32 | //! let file = "myimage.jpg"; 33 | //! let tag = "Iptc.Application2.Keywords"; 34 | //! let meta = rexiv2::Metadata::new_from_path(&file)?; 35 | //! println!("{:?}", meta.get_tag_multiple_strings(tag)); 36 | //! # Ok::<(), Box>(()) 37 | //! ``` 38 | //! 39 | //! [gexiv2]: https://wiki.gnome.org/Projects/gexiv2 40 | //! [exiv2]: http://exiv2.org/ 41 | //! [struct-meta]: struct.Metadata.html 42 | 43 | #![crate_type = "lib"] 44 | #![crate_name = "rexiv2"] 45 | 46 | extern crate gexiv2_sys as gexiv2; 47 | pub use gexiv2::GExiv2LogLevel as LogLevel; 48 | 49 | use std::ffi; 50 | use std::ptr; 51 | use std::str; 52 | 53 | /// A wrapper type for the kinds of errors one might encounter when using the library. 54 | #[derive(Debug, PartialEq, Eq)] 55 | pub enum Rexiv2Error { 56 | /// No value found 57 | NoValue, 58 | /// See std::str::Utf8Error 59 | Utf8(str::Utf8Error), 60 | /// An error generated from the wrapped gexiv2 or Exiv2 libraries. 61 | /// 62 | /// May or may not contain a description message. 63 | Internal(Option), 64 | } 65 | 66 | impl std::fmt::Display for Rexiv2Error { 67 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 68 | match *self { 69 | Rexiv2Error::NoValue => write!(f, "No value found"), 70 | Rexiv2Error::Utf8(ref err) => write!(f, "IO error: {err}"), 71 | Rexiv2Error::Internal(Some(ref msg)) => write!(f, "Internal error: {msg}"), 72 | Rexiv2Error::Internal(None) => write!(f, "Unknown internal error"), 73 | } 74 | } 75 | } 76 | 77 | impl std::error::Error for Rexiv2Error { 78 | fn cause(&self) -> Option<&dyn std::error::Error> { 79 | match *self { 80 | Rexiv2Error::NoValue => None, 81 | Rexiv2Error::Utf8(ref err) => Some(err), 82 | Rexiv2Error::Internal(_) => None, 83 | } 84 | } 85 | } 86 | 87 | impl From for Rexiv2Error { 88 | fn from(err: str::Utf8Error) -> Rexiv2Error { 89 | Rexiv2Error::Utf8(err) 90 | } 91 | } 92 | 93 | impl From for Rexiv2Error { 94 | fn from(err: std::ffi::NulError) -> Rexiv2Error { 95 | Rexiv2Error::Internal(Some(format!( 96 | "Couldn't convert the given bytes to a C string. Nul byte at position {} of {:?}.", 97 | err.nul_position(), 98 | err.into_vec() 99 | ))) 100 | } 101 | } 102 | 103 | /// A specialized Result type that specifies the Err instances will be Rexiv2Errors. 104 | pub type Result = std::result::Result; 105 | 106 | /// An opaque structure that serves as a container for a media file's metadata. 107 | #[derive(Debug, PartialEq, Eq)] 108 | pub struct Metadata { 109 | raw: *mut gexiv2::GExiv2Metadata, 110 | } 111 | 112 | /// An opaque structure that serves as a container for a preview image. 113 | #[derive(Debug, PartialEq, Eq)] 114 | pub struct PreviewImage<'a> { 115 | raw: *mut gexiv2::GExiv2PreviewProperties, 116 | metadata: &'a Metadata, // Parent metadata to load a PreviewImage from a PreviewProperties. 117 | } 118 | 119 | /// Container for the three GPS coordinates: longitude, latitude, and altitude. 120 | #[derive(Clone, Copy, Debug, Default, PartialEq)] 121 | pub struct GpsInfo { 122 | pub longitude: f64, 123 | pub latitude: f64, 124 | pub altitude: Option, 125 | } 126 | 127 | /// The possible data types that a tag can have. 128 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 129 | pub enum TagType { 130 | /// Exif BYTE type, 8-bit unsigned integer. 131 | UnsignedByte, 132 | /// Exif ASCII type, 8-bit byte. 133 | AsciiString, 134 | /// Exif SHORT type, 16-bit (2-byte) unsigned integer. 135 | UnsignedShort, 136 | /// Exif LONG type, 32-bit (4-byte) unsigned integer. 137 | UnsignedLong, 138 | /// Exif RATIONAL type, two LONGs: numerator and denumerator of a fraction. 139 | UnsignedRational, 140 | /// Exif SBYTE type, an 8-bit signed (twos-complement) integer. 141 | SignedByte, 142 | /// Exif UNDEFINED type, an 8-bit byte that may contain anything. 143 | Undefined, 144 | /// Exif SSHORT type, a 16-bit (2-byte) signed (twos-complement) integer. 145 | SignedShort, 146 | /// Exif SLONG type, a 32-bit (4-byte) signed (twos-complement) integer. 147 | SignedLong, 148 | /// Exif SRATIONAL type, two SLONGs: numerator and denumerator of a fraction. 149 | SignedRational, 150 | /// TIFF FLOAT type, single precision (4-byte) IEEE format. 151 | TiffFloat, 152 | /// TIFF DOUBLE type, double precision (8-byte) IEEE format. 153 | TiffDouble, 154 | /// TIFF IFD type, 32-bit (4-byte) unsigned integer. 155 | TiffIfd, 156 | /// IPTC string type. 157 | String, 158 | /// IPTC date type. 159 | Date, 160 | /// IPTC time type. 161 | Time, 162 | /// Exiv2 type for the Exif user comment. 163 | Comment, 164 | /// Exiv2 type for a CIFF directory. 165 | Directory, 166 | /// XMP text type. 167 | XmpText, 168 | /// XMP alternative type. 169 | XmpAlt, 170 | /// XMP bag type. 171 | XmpBag, 172 | /// XMP sequence type. 173 | XmpSeq, 174 | /// XMP language alternative type. 175 | LangAlt, 176 | /// Invalid type. 177 | Invalid, 178 | /// Unknown type. 179 | Unknown, 180 | } 181 | 182 | /// The media types that an image might have. 183 | /// 184 | /// This can be easily converted to/created from an Internet Media Type string with the `::from()` 185 | /// method, thanks to the `std::convert::From` trait. 186 | #[derive(Clone, Debug, Eq, PartialEq, Hash)] 187 | pub enum MediaType { 188 | /// image/x-ms-bmp 189 | Bmp, 190 | /// image/x-canon-cr2 191 | CanonCr2, 192 | /// image/x-canon-crw 193 | CanonCrw, 194 | /// application/postscript 195 | Eps, 196 | /// image/x-fuji-raf 197 | FujiRaf, 198 | /// image/gif 199 | Gif, 200 | /// image/jp2 201 | Jp2, 202 | /// image/jpeg 203 | Jpeg, 204 | /// image/x-minolta-mrw 205 | MinoltaMrw, 206 | /// image/x-olympus-orf 207 | OlympusOrf, 208 | /// image/png 209 | Png, 210 | /// image/x-photoshop 211 | Psd, 212 | /// image/x-panasonic-rw2 213 | PanasonicRw2, 214 | /// image/targa 215 | Tga, 216 | /// image/tiff 217 | Tiff, 218 | /// Some other, unrecognized, media type, contained within. 219 | Other(String), 220 | } 221 | 222 | impl<'a> std::convert::From<&'a MediaType> for String { 223 | fn from(t: &MediaType) -> String { 224 | match *t { 225 | MediaType::Bmp => "image/x-ms-bmp".to_string(), 226 | MediaType::CanonCr2 => "image/x-canon-cr2".to_string(), 227 | MediaType::CanonCrw => "image/x-canon-crw".to_string(), 228 | MediaType::Eps => "application/postscript".to_string(), 229 | MediaType::FujiRaf => "image/x-fuji-raf".to_string(), 230 | MediaType::Gif => "image/gif".to_string(), 231 | MediaType::Jp2 => "image/jp2".to_string(), 232 | MediaType::Jpeg => "image/jpeg".to_string(), 233 | MediaType::MinoltaMrw => "image/x-minolta-mrw".to_string(), 234 | MediaType::OlympusOrf => "image/x-olympus-orf".to_string(), 235 | MediaType::Png => "image/png".to_string(), 236 | MediaType::Psd => "image/x-photoshop".to_string(), 237 | MediaType::PanasonicRw2 => "image/x-panasonic-rw2".to_string(), 238 | MediaType::Tga => "image/targa".to_string(), 239 | MediaType::Tiff => "image/tiff".to_string(), 240 | MediaType::Other(ref s) => s.clone(), 241 | } 242 | } 243 | } 244 | 245 | impl<'a> std::convert::From<&'a str> for MediaType { 246 | fn from(t: &str) -> MediaType { 247 | match t { 248 | "image/x-ms-bmp" => MediaType::Bmp, 249 | "image/x-canon-cr2" => MediaType::CanonCr2, 250 | "image/x-canon-crw" => MediaType::CanonCrw, 251 | "application/postscript" => MediaType::Eps, 252 | "image/x-fuji-raf" => MediaType::FujiRaf, 253 | "image/gif" => MediaType::Gif, 254 | "image/jp2" => MediaType::Jp2, 255 | "image/jpeg" => MediaType::Jpeg, 256 | "image/x-minolta-mrw" => MediaType::MinoltaMrw, 257 | "image/x-olympus-orf" => MediaType::OlympusOrf, 258 | "image/png" => MediaType::Png, 259 | "image/x-photoshop" => MediaType::Psd, 260 | "image/x-panasonic-rw2" => MediaType::PanasonicRw2, 261 | "image/targa" => MediaType::Tga, 262 | "image/tiff" => MediaType::Tiff, 263 | _ => MediaType::Other(t.to_string()), 264 | } 265 | } 266 | } 267 | 268 | impl std::fmt::Display for MediaType { 269 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 270 | write!(f, "{}", String::from(self)) 271 | } 272 | } 273 | 274 | pub use gexiv2::Orientation; 275 | 276 | impl Metadata { 277 | /// Load the metadata from the file found at the given path. 278 | /// 279 | /// # Examples 280 | /// ```no_run 281 | /// let path = "myphoto.jpg"; 282 | /// let meta = rexiv2::Metadata::new_from_path(&path)?; 283 | /// assert_eq!(meta.get_media_type()?, rexiv2::MediaType::Jpeg); 284 | /// # Ok::<(), Box>(()) 285 | /// ``` 286 | pub fn new_from_path>(path: S) -> Result { 287 | let c_str_path = os_str_to_c_string(path)?; 288 | let mut err: *mut gexiv2::GError = ptr::null_mut(); 289 | 290 | unsafe { 291 | let metadata = gexiv2::gexiv2_metadata_new(); 292 | let ok = gexiv2::gexiv2_metadata_open_path(metadata, c_str_path.as_ptr(), &mut err); 293 | if ok != 1 { 294 | let err_msg = ffi::CStr::from_ptr((*err).message).to_str(); 295 | return Err(Rexiv2Error::Internal( 296 | err_msg.ok().map(|msg| msg.to_string()), 297 | )); 298 | } 299 | Ok(Metadata { raw: metadata }) 300 | } 301 | } 302 | 303 | /// Load the metadata from the given Exif data buffer. 304 | /// 305 | /// This is usually the data in the JPEG APP1 segment. 306 | pub fn new_from_app1_segment(data: &[u8]) -> Result { 307 | let mut err: *mut gexiv2::GError = ptr::null_mut(); 308 | unsafe { 309 | let metadata = gexiv2::gexiv2_metadata_new(); 310 | let ok = gexiv2::gexiv2_metadata_from_app1_segment( 311 | metadata, 312 | data.as_ptr(), 313 | data.len() as libc::c_long, 314 | &mut err, 315 | ); 316 | if ok != 1 { 317 | let err_msg = ffi::CStr::from_ptr((*err).message).to_str(); 318 | return Err(Rexiv2Error::Internal( 319 | err_msg.ok().map(|msg| msg.to_string()), 320 | )); 321 | } 322 | Ok(Metadata { raw: metadata }) 323 | } 324 | } 325 | 326 | /// Load the metadata from the given data buffer. 327 | /// 328 | /// # Examples 329 | /// ``` 330 | /// let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, 331 | /// 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 84, 332 | /// 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 69, 333 | /// 78, 68, 174, 66, 96, 130]; 334 | /// let meta = rexiv2::Metadata::new_from_buffer(&minipng)?; 335 | /// assert_eq!(meta.get_media_type()?, rexiv2::MediaType::Png); 336 | /// # Ok::<(), Box>(()) 337 | /// ``` 338 | pub fn new_from_buffer(data: &[u8]) -> Result { 339 | let mut err: *mut gexiv2::GError = ptr::null_mut(); 340 | unsafe { 341 | let metadata = gexiv2::gexiv2_metadata_new(); 342 | let ok = gexiv2::gexiv2_metadata_open_buf( 343 | metadata, 344 | data.as_ptr(), 345 | data.len() as libc::c_long, 346 | &mut err, 347 | ); 348 | if ok != 1 { 349 | let err_msg = ffi::CStr::from_ptr((*err).message).to_str(); 350 | return Err(Rexiv2Error::Internal( 351 | err_msg.ok().map(|msg| msg.to_string()), 352 | )); 353 | } 354 | Ok(Metadata { raw: metadata }) 355 | } 356 | } 357 | 358 | /// Save metadata to the file found at the given path, which must already exist. 359 | pub fn save_to_file>(&self, path: S) -> Result<()> { 360 | let c_str_path = os_str_to_c_string(path)?; 361 | let mut err: *mut gexiv2::GError = ptr::null_mut(); 362 | 363 | unsafe { 364 | let ok = gexiv2::gexiv2_metadata_save_file(self.raw, c_str_path.as_ptr(), &mut err); 365 | if ok != 1 { 366 | let err_msg = ffi::CStr::from_ptr((*err).message).to_str(); 367 | return Err(Rexiv2Error::Internal( 368 | err_msg.ok().map(|msg| msg.to_string()), 369 | )); 370 | } 371 | Ok(()) 372 | } 373 | } 374 | 375 | 376 | // Image information. 377 | 378 | /// Determine whether the type of file loaded supports Exif metadata. 379 | pub fn supports_exif(&self) -> bool { 380 | unsafe { gexiv2::gexiv2_metadata_get_supports_exif(self.raw) == 1 } 381 | } 382 | 383 | /// Determine whether the type of file loaded supports IPTC metadata. 384 | pub fn supports_iptc(&self) -> bool { 385 | unsafe { gexiv2::gexiv2_metadata_get_supports_iptc(self.raw) == 1 } 386 | } 387 | 388 | /// Determine whether the type of file loaded supports XMP metadata. 389 | pub fn supports_xmp(&self) -> bool { 390 | unsafe { gexiv2::gexiv2_metadata_get_supports_xmp(self.raw) == 1 } 391 | } 392 | 393 | /// Return the media type of the loaded file. 394 | pub fn get_media_type(&self) -> Result { 395 | unsafe { 396 | let c_str_val = gexiv2::gexiv2_metadata_get_mime_type(self.raw); 397 | if c_str_val.is_null() { 398 | return Err(Rexiv2Error::NoValue); 399 | } 400 | Ok(MediaType::from(ffi::CStr::from_ptr(c_str_val).to_str()?)) 401 | } 402 | } 403 | 404 | /// Get the actual un-rotated/un-oriented pixel width of the loaded image. 405 | /// 406 | /// Note that this may be different from the values reported by some metadata tags 407 | /// that take into account the intended orientation of the image. 408 | /// 409 | /// # Examples 410 | /// ``` 411 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 412 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 413 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 414 | /// # 69, 78, 68, 174, 66, 96, 130]; 415 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 416 | /// assert_eq!(meta.get_pixel_width(), 1); 417 | /// ``` 418 | pub fn get_pixel_width(&self) -> i32 { 419 | unsafe { gexiv2::gexiv2_metadata_get_pixel_width(self.raw) } 420 | } 421 | 422 | /// Get the actual un-rotated/un-oriented pixel height of the loaded image. 423 | /// 424 | /// Note that this may be different from the values reported by some metadata tags 425 | /// that take into account the intended orientation of the image. 426 | /// 427 | /// # Examples 428 | /// ``` 429 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 430 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 431 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 432 | /// # 69, 78, 68, 174, 66, 96, 130]; 433 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 434 | /// assert_eq!(meta.get_pixel_height(), 1); 435 | /// ``` 436 | pub fn get_pixel_height(&self) -> i32 { 437 | unsafe { gexiv2::gexiv2_metadata_get_pixel_height(self.raw) } 438 | } 439 | 440 | 441 | // Tag management. 442 | 443 | /// Indicates whether the given tag is present/populated in the loaded metadata. 444 | /// 445 | /// # Examples 446 | /// ``` 447 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 448 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 449 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 450 | /// # 69, 78, 68, 174, 66, 96, 130]; 451 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 452 | /// assert!(!meta.has_tag("Exif.Image.DateTime")); 453 | /// meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44"); 454 | /// assert!(meta.has_tag("Exif.Image.DateTime")); 455 | /// ``` 456 | pub fn has_tag(&self, tag: &str) -> bool { 457 | let c_str_tag = ffi::CString::new(tag).unwrap(); 458 | unsafe { gexiv2::gexiv2_metadata_has_tag(self.raw, c_str_tag.as_ptr()) == 1 } 459 | } 460 | 461 | /// Removes the tag from the metadata if it exists. Returns whether it was there originally. 462 | /// 463 | /// # Examples 464 | /// ``` 465 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 466 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 467 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 468 | /// # 69, 78, 68, 174, 66, 96, 130]; 469 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 470 | /// # meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44"); 471 | /// assert!(meta.has_tag("Exif.Image.DateTime")); 472 | /// assert!(meta.clear_tag("Exif.Image.DateTime")); 473 | /// assert!(!meta.has_tag("Exif.Image.DateTime")); 474 | /// ``` 475 | pub fn clear_tag(&self, tag: &str) -> bool { 476 | let c_str_tag = ffi::CString::new(tag).unwrap(); 477 | unsafe { gexiv2::gexiv2_metadata_clear_tag(self.raw, c_str_tag.as_ptr()) == 1 } 478 | } 479 | 480 | /// Remove all tag values from the metadata. 481 | /// 482 | /// # Examples 483 | /// ``` 484 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 485 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 486 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 487 | /// # 69, 78, 68, 174, 66, 96, 130]; 488 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 489 | /// # meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44"); 490 | /// assert!(meta.has_tag("Exif.Image.DateTime")); 491 | /// meta.clear(); 492 | /// assert!(!meta.has_tag("Exif.Image.DateTime")); 493 | /// ``` 494 | pub fn clear(&self) { 495 | unsafe { gexiv2::gexiv2_metadata_clear(self.raw) } 496 | } 497 | 498 | /// Indicates whether the loaded file contains any Exif metadata. 499 | /// 500 | /// # Examples 501 | /// ``` 502 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 503 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 504 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 505 | /// # 69, 78, 68, 174, 66, 96, 130]; 506 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 507 | /// assert!(!meta.has_exif()); 508 | /// meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44"); 509 | /// assert!(meta.has_exif()); 510 | /// ``` 511 | pub fn has_exif(&self) -> bool { 512 | unsafe { gexiv2::gexiv2_metadata_has_exif(self.raw) == 1 } 513 | } 514 | 515 | /// Removes all Exif metadata, leaving other types of metadata intact. 516 | /// 517 | /// # Examples 518 | /// ``` 519 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 520 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 521 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 522 | /// # 69, 78, 68, 174, 66, 96, 130]; 523 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 524 | /// meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44"); 525 | /// meta.set_tag_string("Xmp.dc.Title", "Test"); 526 | /// assert!(meta.has_exif()); 527 | /// assert!(meta.has_xmp()); 528 | /// meta.clear_exif(); 529 | /// assert!(!meta.has_exif()); 530 | /// assert!(meta.has_xmp()); 531 | /// ``` 532 | pub fn clear_exif(&self) { 533 | unsafe { gexiv2::gexiv2_metadata_clear_exif(self.raw) } 534 | } 535 | 536 | /// List all Exif tags present in the loaded metadata. 537 | /// 538 | /// # Examples 539 | /// ``` 540 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 541 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 542 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 543 | /// # 69, 78, 68, 174, 66, 96, 130]; 544 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 545 | /// # meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44"); 546 | /// assert_eq!(meta.get_exif_tags(), Ok(vec!["Exif.Image.DateTime".to_string()])); 547 | /// ``` 548 | pub fn get_exif_tags(&self) -> Result> { 549 | let mut tags = vec![]; 550 | unsafe { 551 | let c_tags = gexiv2::gexiv2_metadata_get_exif_tags(self.raw); 552 | let mut cur_offset = 0; 553 | while !(*c_tags.offset(cur_offset)).is_null() { 554 | let tag = ffi::CStr::from_ptr(*c_tags.offset(cur_offset)).to_str(); 555 | match tag { 556 | Ok(v) => tags.push(v.to_string()), 557 | Err(e) => { 558 | free_array_of_pointers(c_tags as *mut *mut libc::c_void); 559 | return Err(Rexiv2Error::from(e)); 560 | } 561 | } 562 | cur_offset += 1; 563 | } 564 | free_array_of_pointers(c_tags as *mut *mut libc::c_void); 565 | } 566 | Ok(tags) 567 | } 568 | 569 | /// Indicates whether the loaded file contains any XMP metadata. 570 | /// 571 | /// # Examples 572 | /// ``` 573 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 574 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 575 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 576 | /// # 69, 78, 68, 174, 66, 96, 130]; 577 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 578 | /// assert!(!meta.has_xmp()); 579 | /// meta.set_tag_string("Xmp.dc.Title", "Test Image"); 580 | /// assert!(meta.has_xmp()); 581 | /// ``` 582 | pub fn has_xmp(&self) -> bool { 583 | unsafe { gexiv2::gexiv2_metadata_has_xmp(self.raw) == 1 } 584 | } 585 | 586 | /// Removes all XMP metadata, leaving all other types of metadata intact. 587 | /// 588 | /// # Examples 589 | /// ``` 590 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 591 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 592 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 593 | /// # 69, 78, 68, 174, 66, 96, 130]; 594 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 595 | /// meta.set_tag_string("Xmp.dc.Title", "Test Image"); 596 | /// meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44"); 597 | /// assert!(meta.has_xmp()); 598 | /// assert!(meta.has_exif()); 599 | /// meta.clear_xmp(); 600 | /// assert!(!meta.has_xmp()); 601 | /// assert!(meta.has_exif()); 602 | /// ``` 603 | pub fn clear_xmp(&self) { 604 | unsafe { gexiv2::gexiv2_metadata_clear_xmp(self.raw) } 605 | } 606 | 607 | /// List all XMP tags present in the loaded metadata. 608 | /// 609 | /// # Examples 610 | /// ``` 611 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 612 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 613 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 614 | /// # 69, 78, 68, 174, 66, 96, 130]; 615 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 616 | /// meta.set_tag_string("Xmp.dc.Title", "Test Image"); 617 | /// assert_eq!(meta.get_xmp_tags(), Ok(vec!["Xmp.dc.Title".to_string()])); 618 | /// ``` 619 | pub fn get_xmp_tags(&self) -> Result> { 620 | let mut tags = vec![]; 621 | unsafe { 622 | let c_tags = gexiv2::gexiv2_metadata_get_xmp_tags(self.raw); 623 | let mut cur_offset = 0; 624 | while !(*c_tags.offset(cur_offset)).is_null() { 625 | let tag = ffi::CStr::from_ptr(*c_tags.offset(cur_offset)).to_str(); 626 | match tag { 627 | Ok(v) => tags.push(v.to_string()), 628 | Err(e) => { 629 | free_array_of_pointers(c_tags as *mut *mut libc::c_void); 630 | return Err(Rexiv2Error::from(e)); 631 | } 632 | } 633 | cur_offset += 1; 634 | } 635 | free_array_of_pointers(c_tags as *mut *mut libc::c_void); 636 | } 637 | Ok(tags) 638 | } 639 | 640 | /// Indicates whether the loaded file contains any IPTC metadata. 641 | /// 642 | /// # Examples 643 | /// ``` 644 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 645 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 646 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 647 | /// # 69, 78, 68, 174, 66, 96, 130]; 648 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 649 | /// assert!(!meta.has_iptc()); 650 | /// meta.set_tag_string("Iptc.Application2.Subject", "Test Image"); 651 | /// assert!(meta.has_iptc()); 652 | /// ``` 653 | pub fn has_iptc(&self) -> bool { 654 | unsafe { gexiv2::gexiv2_metadata_has_iptc(self.raw) == 1 } 655 | } 656 | 657 | /// Removes all XMP metadata, leaving all other types of metadata intact. 658 | /// 659 | /// # Examples 660 | /// ``` 661 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 662 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 663 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 664 | /// # 69, 78, 68, 174, 66, 96, 130]; 665 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 666 | /// meta.set_tag_string("Iptc.Application2.Subject", "Test Image"); 667 | /// meta.set_tag_string("Exif.Image.DateTime", "2022-08-07 11:19:44"); 668 | /// assert!(meta.has_iptc()); 669 | /// assert!(meta.has_exif()); 670 | /// meta.clear_iptc(); 671 | /// assert!(!meta.has_iptc()); 672 | /// assert!(meta.has_exif()); 673 | /// ``` 674 | pub fn clear_iptc(&self) { 675 | unsafe { gexiv2::gexiv2_metadata_clear_iptc(self.raw) } 676 | } 677 | 678 | /// List all IPTC tags present in the loaded metadata. 679 | /// 680 | /// # Examples 681 | /// ``` 682 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 683 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 684 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 685 | /// # 69, 78, 68, 174, 66, 96, 130]; 686 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 687 | /// meta.set_tag_string("Iptc.Application2.Subject", "Test Image"); 688 | /// assert_eq!(meta.get_iptc_tags(), Ok(vec!["Iptc.Application2.Subject".to_string()])); 689 | /// ``` 690 | pub fn get_iptc_tags(&self) -> Result> { 691 | let mut tags = vec![]; 692 | unsafe { 693 | let c_tags = gexiv2::gexiv2_metadata_get_iptc_tags(self.raw); 694 | let mut cur_offset = 0; 695 | while !(*c_tags.offset(cur_offset)).is_null() { 696 | let tag = ffi::CStr::from_ptr(*c_tags.offset(cur_offset)).to_str(); 697 | match tag { 698 | Ok(v) => tags.push(v.to_string()), 699 | Err(e) => { 700 | free_array_of_pointers(c_tags as *mut *mut libc::c_void); 701 | return Err(Rexiv2Error::from(e)); 702 | } 703 | } 704 | cur_offset += 1; 705 | } 706 | free_array_of_pointers(c_tags as *mut *mut libc::c_void); 707 | } 708 | Ok(tags) 709 | } 710 | 711 | /// Get the value of a tag as a string. 712 | /// 713 | /// Only safe if the tag is really of a string type. 714 | /// 715 | /// # Examples 716 | /// ``` 717 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 718 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 719 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 720 | /// # 69, 78, 68, 174, 66, 96, 130]; 721 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 722 | /// # meta.set_tag_string("Iptc.Application2.Subject", "Test Image"); 723 | /// assert_eq!(meta.get_tag_string("Iptc.Application2.Subject"), Ok("Test Image".to_string())); 724 | /// ``` 725 | pub fn get_tag_string(&self, tag: &str) -> Result { 726 | let c_str_tag = ffi::CString::new(tag)?; 727 | unsafe { 728 | let c_str_val = gexiv2::gexiv2_metadata_get_tag_string(self.raw, c_str_tag.as_ptr()); 729 | if c_str_val.is_null() { 730 | return Err(Rexiv2Error::NoValue); 731 | } 732 | let value = ffi::CStr::from_ptr(c_str_val).to_str()?.to_string(); 733 | libc::free(c_str_val as *mut libc::c_void); 734 | Ok(value) 735 | } 736 | } 737 | 738 | /// Set the value of a tag to the given string. 739 | /// 740 | /// Only safe if the tag is really of a string type. 741 | /// 742 | /// # Examples 743 | /// ``` 744 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 745 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 746 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 747 | /// # 69, 78, 68, 174, 66, 96, 130]; 748 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 749 | /// meta.set_tag_string("Iptc.Application2.Subject", "Test Image"); 750 | /// assert_eq!(meta.get_tag_string("Iptc.Application2.Subject"), Ok("Test Image".to_string())); 751 | /// ``` 752 | pub fn set_tag_string(&self, tag: &str, value: &str) -> Result<()> { 753 | let c_str_tag = ffi::CString::new(tag)?; 754 | let c_str_val = ffi::CString::new(value)?; 755 | unsafe { 756 | int_bool_to_result(gexiv2::gexiv2_metadata_set_tag_string( 757 | self.raw, 758 | c_str_tag.as_ptr(), 759 | c_str_val.as_ptr(), 760 | )) 761 | } 762 | } 763 | 764 | /// Get the value of a tag as a string, potentially formatted for user-visible display. 765 | /// 766 | /// Only safe if the tag is really of a string type. 767 | pub fn get_tag_interpreted_string(&self, tag: &str) -> Result { 768 | let c_str_tag = ffi::CString::new(tag)?; 769 | unsafe { 770 | let c_str_val = 771 | gexiv2::gexiv2_metadata_get_tag_interpreted_string(self.raw, c_str_tag.as_ptr()); 772 | if c_str_val.is_null() { 773 | return Err(Rexiv2Error::NoValue); 774 | } 775 | let value = ffi::CStr::from_ptr(c_str_val).to_str()?.to_string(); 776 | libc::free(c_str_val as *mut libc::c_void); 777 | Ok(value) 778 | } 779 | } 780 | 781 | /// Retrieve the list of string values of the given tag. 782 | /// 783 | /// Only safe if the tag is in fact of a string type. 784 | pub fn get_tag_multiple_strings(&self, tag: &str) -> Result> { 785 | let c_str_tag = ffi::CString::new(tag)?; 786 | let mut vals = vec![]; 787 | unsafe { 788 | let c_vals = gexiv2::gexiv2_metadata_get_tag_multiple(self.raw, c_str_tag.as_ptr()); 789 | if c_vals.is_null() { 790 | return Err(Rexiv2Error::NoValue); 791 | } 792 | let mut cur_offset = 0; 793 | while !(*c_vals.offset(cur_offset)).is_null() { 794 | let value = ffi::CStr::from_ptr(*c_vals.offset(cur_offset)).to_str(); 795 | match value { 796 | Ok(v) => vals.push(v.to_string()), 797 | Err(e) => { 798 | free_array_of_pointers(c_vals as *mut *mut libc::c_void); 799 | return Err(Rexiv2Error::from(e)); 800 | } 801 | } 802 | cur_offset += 1; 803 | } 804 | free_array_of_pointers(c_vals as *mut *mut libc::c_void); 805 | } 806 | Ok(vals) 807 | } 808 | 809 | /// Store the given strings as the values of a tag. 810 | pub fn set_tag_multiple_strings(&self, tag: &str, values: &[&str]) -> Result<()> { 811 | let c_str_tag = ffi::CString::new(tag)?; 812 | let c_strs: std::result::Result, _> = 813 | values.iter().map(|&s| ffi::CString::new(s)).collect(); 814 | let c_strs = c_strs?; 815 | let mut ptrs: Vec<_> = c_strs.iter().map(|c| c.as_ptr()).collect(); 816 | ptrs.push(ptr::null()); 817 | unsafe { 818 | int_bool_to_result(gexiv2::gexiv2_metadata_set_tag_multiple( 819 | self.raw, 820 | c_str_tag.as_ptr(), 821 | ptrs.as_mut_ptr(), 822 | )) 823 | } 824 | } 825 | 826 | /// Get the value of a tag as a number. 827 | /// 828 | /// Only safe if the tag is really of a numeric type. 829 | /// 830 | /// # Examples 831 | /// ``` 832 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 833 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 834 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 835 | /// # 69, 78, 68, 174, 66, 96, 130]; 836 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 837 | /// # meta.set_tag_numeric("Exif.Photo.MaxApertureValue", 5); 838 | /// assert_eq!(meta.get_tag_numeric("Exif.Photo.MaxApertureValue"), 5); 839 | /// ``` 840 | pub fn get_tag_numeric(&self, tag: &str) -> i32 { 841 | let c_str_tag = ffi::CString::new(tag).unwrap(); 842 | unsafe { gexiv2::gexiv2_metadata_get_tag_long(self.raw, c_str_tag.as_ptr()) as i32 } 843 | } 844 | 845 | /// Set the value of a tag to the given number. 846 | /// 847 | /// Only safe if the tag is really of a numeric type. 848 | /// 849 | /// # Examples 850 | /// ``` 851 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 852 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 853 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 854 | /// # 69, 78, 68, 174, 66, 96, 130]; 855 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 856 | /// # meta.set_tag_numeric("Exif.Photo.MaxApertureValue", 5); 857 | /// assert_eq!(meta.get_tag_numeric("Exif.Photo.MaxApertureValue"), 5); 858 | /// ``` 859 | pub fn set_tag_numeric(&self, tag: &str, value: i32) -> Result<()> { 860 | let c_str_tag = ffi::CString::new(tag)?; 861 | unsafe { 862 | int_bool_to_result(gexiv2::gexiv2_metadata_set_tag_long( 863 | self.raw, 864 | c_str_tag.as_ptr(), 865 | value as libc::c_long, 866 | )) 867 | } 868 | } 869 | 870 | /// Get the value of a tag as a Rational. 871 | /// 872 | /// Only safe if the tag is in fact of a rational type. 873 | /// 874 | /// # Examples 875 | /// ``` 876 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 877 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 878 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 879 | /// # 69, 78, 68, 174, 66, 96, 130]; 880 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 881 | /// let ratio = num_rational::Ratio::new_raw(16, 10); 882 | /// # meta.set_tag_rational("Exif.Photo.MaxApertureValue", &ratio); 883 | /// assert_eq!(meta.get_tag_rational("Exif.Photo.MaxApertureValue"), Some(ratio)); 884 | /// ``` 885 | pub fn get_tag_rational(&self, tag: &str) -> Option> { 886 | let c_str_tag = ffi::CString::new(tag).ok()?; 887 | let num = &mut 0; 888 | let den = &mut 0; 889 | match unsafe { 890 | gexiv2::gexiv2_metadata_get_exif_tag_rational(self.raw, c_str_tag.as_ptr(), num, den) 891 | } { 892 | 0 => None, 893 | _ => { 894 | if *den != 0 { 895 | Some(num_rational::Ratio::new_raw(*num, *den)) 896 | } else { 897 | None 898 | } 899 | } 900 | } 901 | } 902 | 903 | /// Set the value of a tag to a Rational. 904 | /// 905 | /// Only safe if the tag is in fact of a rational type. 906 | /// 907 | /// # Examples 908 | /// ``` 909 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 910 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 911 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 912 | /// # 69, 78, 68, 174, 66, 96, 130]; 913 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 914 | /// let ratio = num_rational::Ratio::new_raw(16, 10); 915 | /// meta.set_tag_rational("Exif.Photo.MaxApertureValue", &ratio); 916 | /// assert_eq!(meta.get_tag_rational("Exif.Photo.MaxApertureValue"), Some(ratio)); 917 | /// ``` 918 | pub fn set_tag_rational(&self, tag: &str, value: &num_rational::Ratio) -> Result<()> { 919 | let c_str_tag = ffi::CString::new(tag)?; 920 | unsafe { 921 | int_bool_to_result(gexiv2::gexiv2_metadata_set_exif_tag_rational( 922 | self.raw, 923 | c_str_tag.as_ptr(), 924 | *value.numer(), 925 | *value.denom(), 926 | )) 927 | } 928 | } 929 | 930 | /// Get the value of a tag as raw data. 931 | /// 932 | /// # Examples 933 | /// ``` 934 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 935 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 936 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 937 | /// # 69, 78, 68, 174, 66, 96, 130]; 938 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 939 | /// # meta.set_tag_rational("Exif.Photo.MaxApertureValue", &num_rational::Ratio::new_raw(16, 10)); 940 | /// assert_eq!(meta.get_tag_raw("Exif.Photo.MaxApertureValue"), Ok(vec![0, 0, 0, 16, 0, 0, 0, 10])); 941 | /// ``` 942 | #[cfg(feature = "raw-tag-access")] 943 | pub fn get_tag_raw(&self, tag: &str) -> Result> { 944 | let c_str_tag = ffi::CString::new(tag)?; 945 | unsafe { 946 | let raw_tag_value = gexiv2::gexiv2_metadata_get_tag_raw(self.raw, c_str_tag.as_ptr()); 947 | let size = &mut 0; 948 | let ptr = glib_sys::g_bytes_get_data(raw_tag_value, size) as *const u8; 949 | let result = if ptr.is_null() { 950 | Err(Rexiv2Error::NoValue) 951 | } else { 952 | // Make a copy here 953 | // Could be optimized out but need to keep a reference to the returned GByte object 954 | Ok(std::slice::from_raw_parts(ptr, *size).to_owned()) 955 | }; 956 | glib_sys::g_bytes_unref(raw_tag_value); 957 | result 958 | } 959 | } 960 | 961 | // Helper & convenience getters/setters. 962 | 963 | /// Find out the orientation the image should have, according to the metadata tag. 964 | /// 965 | /// # Examples 966 | /// ``` 967 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 968 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 969 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 970 | /// # 69, 78, 68, 174, 66, 96, 130]; 971 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 972 | /// assert_eq!(meta.get_orientation(), rexiv2::Orientation::Unspecified); 973 | /// ``` 974 | pub fn get_orientation(&self) -> Orientation { 975 | unsafe { gexiv2::gexiv2_metadata_get_orientation(self.raw) } 976 | } 977 | 978 | /// Set the intended orientation for the image. 979 | /// 980 | /// # Examples 981 | /// ``` 982 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 983 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 984 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 985 | /// # 69, 78, 68, 174, 66, 96, 130]; 986 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 987 | /// assert_eq!(meta.get_orientation(), rexiv2::Orientation::Unspecified); 988 | /// meta.set_orientation(rexiv2::Orientation::VerticalFlip); 989 | /// assert_eq!(meta.get_orientation(), rexiv2::Orientation::VerticalFlip); 990 | /// ``` 991 | pub fn set_orientation(&self, orientation: Orientation) { 992 | unsafe { gexiv2::gexiv2_metadata_set_orientation(self.raw, orientation) } 993 | } 994 | 995 | /// Returns the camera exposure time of the photograph. 996 | /// 997 | /// # Examples 998 | /// ``` 999 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1000 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 1001 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 1002 | /// # 69, 78, 68, 174, 66, 96, 130]; 1003 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 1004 | /// # meta.set_tag_rational("Exif.Photo.ExposureTime", &num_rational::Ratio::new_raw(1, 1000)); 1005 | /// assert_eq!(meta.get_exposure_time(), Some(num_rational::Ratio::new_raw(1, 1000))); 1006 | /// ``` 1007 | pub fn get_exposure_time(&self) -> Option> { 1008 | let num = &mut 0; 1009 | let den = &mut 0; 1010 | match unsafe { gexiv2::gexiv2_metadata_get_exposure_time(self.raw, num, den) } { 1011 | 0 => None, 1012 | _ => { 1013 | if *den != 0 { 1014 | Some(num_rational::Ratio::new_raw(*num, *den)) 1015 | } else { 1016 | None 1017 | } 1018 | } 1019 | } 1020 | } 1021 | 1022 | /// Returns the f-number used by the camera taking the photograph. 1023 | pub fn get_fnumber(&self) -> Option { 1024 | match unsafe { gexiv2::gexiv2_metadata_get_fnumber(self.raw) } { 1025 | error_value if error_value < 0.0 => None, // gexiv2 returns -1.0 on error 1026 | fnumber => Some(fnumber), 1027 | } 1028 | } 1029 | 1030 | /// Returns the focal length used by the camera taking the photograph. 1031 | pub fn get_focal_length(&self) -> Option { 1032 | match unsafe { gexiv2::gexiv2_metadata_get_focal_length(self.raw) } { 1033 | error_value if error_value < 0.0 => None, // gexiv2 returns -1.0 on error 1034 | focal => Some(focal), 1035 | } 1036 | } 1037 | 1038 | /// Returns the ISO speed used by the camera taking the photograph. 1039 | /// 1040 | /// # Examples 1041 | /// ``` 1042 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1043 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 1044 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 1045 | /// # 69, 78, 68, 174, 66, 96, 130]; 1046 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 1047 | /// # meta.set_tag_numeric("Exif.Photo.ISOSpeedRatings", 600); 1048 | /// assert_eq!(meta.get_iso_speed(), Some(600)); 1049 | /// ``` 1050 | pub fn get_iso_speed(&self) -> Option { 1051 | match unsafe { gexiv2::gexiv2_metadata_get_iso_speed(self.raw) } { 1052 | 0 => None, 1053 | speed => Some(speed), 1054 | } 1055 | } 1056 | 1057 | // Thumbnail related methods. 1058 | 1059 | /// Get the thumbnail stored in the EXIF data. 1060 | pub fn get_thumbnail(&self) -> Option<&[u8]> { 1061 | let mut data: *mut u8 = ptr::null_mut(); 1062 | let mut size: libc::c_int = 0; 1063 | unsafe { 1064 | match gexiv2::gexiv2_metadata_get_exif_thumbnail(self.raw, &mut data, &mut size) { 1065 | 0 => None, 1066 | _ => Some(std::slice::from_raw_parts_mut(data, size as usize)), 1067 | } 1068 | } 1069 | } 1070 | 1071 | /// Remove the thumbnail from the EXIF data. 1072 | pub fn erase_thumbnail(&self) { 1073 | unsafe { gexiv2::gexiv2_metadata_erase_exif_thumbnail(self.raw) } 1074 | } 1075 | 1076 | /// Set or replace the EXIF thumbnail with the image in the file. 1077 | pub fn set_thumbnail_from_file>(&self, path: S) -> Result<()> { 1078 | let c_str_path = os_str_to_c_string(path)?; 1079 | let mut err: *mut gexiv2::GError = ptr::null_mut(); 1080 | 1081 | unsafe { 1082 | let ok = gexiv2::gexiv2_metadata_set_exif_thumbnail_from_file( 1083 | self.raw, 1084 | c_str_path.as_ptr(), 1085 | &mut err, 1086 | ); 1087 | if ok != 1 { 1088 | let err_msg = ffi::CStr::from_ptr((*err).message).to_str(); 1089 | return Err(Rexiv2Error::Internal( 1090 | err_msg.ok().map(|msg| msg.to_string()), 1091 | )); 1092 | } 1093 | Ok(()) 1094 | } 1095 | } 1096 | 1097 | /// Set or replace the EXIF thumbnail with the content of a buffer. 1098 | pub fn set_thumbnail_from_buffer(&self, data: &[u8]) { 1099 | unsafe { 1100 | gexiv2::gexiv2_metadata_set_exif_thumbnail_from_buffer( 1101 | self.raw, 1102 | data.as_ptr(), 1103 | data.len() as libc::c_int, 1104 | ) 1105 | } 1106 | } 1107 | 1108 | // Preview image related methods. 1109 | 1110 | /// Return the all the preview images found in this EXIF data. 1111 | pub fn get_preview_images(&self) -> Option> { 1112 | unsafe { 1113 | let ptr = gexiv2::gexiv2_metadata_get_preview_properties(self.raw); 1114 | if ptr.is_null() { 1115 | return None; 1116 | } 1117 | 1118 | let mut previews: Vec = vec![]; 1119 | let mut n = 0; 1120 | while !(*ptr.offset(n)).is_null() { 1121 | let preview_prop = *ptr.offset(n); 1122 | previews.push(PreviewImage { raw: preview_prop, metadata: self }); 1123 | n += 1; 1124 | } 1125 | Some(previews) 1126 | } 1127 | } 1128 | 1129 | // GPS-related methods. 1130 | 1131 | /// Retrieve the stored GPS information from the loaded file. 1132 | /// 1133 | /// # Examples 1134 | /// ``` 1135 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1136 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 1137 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 1138 | /// # 69, 78, 68, 174, 66, 96, 130]; 1139 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 1140 | /// meta.set_gps_info(&rexiv2::GpsInfo { longitude: 0.2, latitude: 0.3, altitude: Some(0.4) }); 1141 | /// assert_eq!( 1142 | /// meta.get_gps_info(), 1143 | /// Some(rexiv2::GpsInfo { longitude: 0.2, latitude: 0.3, altitude: Some(0.4) }), 1144 | /// ); 1145 | /// # Ok::<(), Box>(()) 1146 | /// ``` 1147 | pub fn get_gps_info(&self) -> Option { 1148 | let lon = &mut 0.0; 1149 | let lat = &mut 0.0; 1150 | let alt = &mut 0.0; 1151 | match unsafe { gexiv2::gexiv2_metadata_get_gps_info(self.raw, lon, lat, alt) } { 1152 | 0 => { 1153 | // If we get a "false" result, it might just be because the altitude is missing. 1154 | // This is the behaviour since gexiv2 0.12.2. In 0.12.1 and earlier, we'd still 1155 | // get a "true" result but altitude would be set to 0.0, which we handle below. 1156 | if *lon != 0.0 && *lat != 0.0 && *alt == 0.0 { 1157 | Some(GpsInfo { longitude: *lon, latitude: *lat, altitude: None }) 1158 | } else { 1159 | None 1160 | } 1161 | } 1162 | _ => Some(GpsInfo { 1163 | longitude: *lon, 1164 | latitude: *lat, 1165 | altitude: if *alt != 0.0 { Some(*alt) } else { None }, 1166 | }), 1167 | } 1168 | } 1169 | 1170 | /// Save the specified GPS values to the metadata. 1171 | /// 1172 | /// # Examples 1173 | /// ``` 1174 | /// # let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1175 | /// # 1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65, 1176 | /// # 84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73, 1177 | /// # 69, 78, 68, 174, 66, 96, 130]; 1178 | /// # let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap(); 1179 | /// assert_eq!(meta.get_gps_info(), None); 1180 | /// meta.set_gps_info(&rexiv2::GpsInfo { longitude: 0.8, latitude: 0.9, altitude: None }); 1181 | /// assert_eq!( 1182 | /// meta.get_gps_info(), 1183 | /// Some(rexiv2::GpsInfo { longitude: 0.8, latitude: 0.9, altitude: None }), 1184 | /// ); 1185 | /// # Ok::<(), Box>(()) 1186 | /// ``` 1187 | pub fn set_gps_info(&self, gps: &GpsInfo) -> Result<()> { 1188 | unsafe { 1189 | int_bool_to_result(gexiv2::gexiv2_metadata_set_gps_info( 1190 | self.raw, 1191 | gps.longitude, 1192 | gps.latitude, 1193 | gps.altitude.unwrap_or(0.0), 1194 | )) 1195 | } 1196 | } 1197 | 1198 | /// Remove all saved GPS information from the metadata. 1199 | pub fn delete_gps_info(&self) { 1200 | unsafe { gexiv2::gexiv2_metadata_delete_gps_info(self.raw) } 1201 | } 1202 | } 1203 | 1204 | impl Drop for Metadata { 1205 | fn drop(&mut self) { 1206 | unsafe { gexiv2::gexiv2_metadata_free(self.raw) } 1207 | } 1208 | } 1209 | 1210 | impl PreviewImage<'_> { 1211 | /// Return the size of the preview image in bytes. 1212 | pub fn get_size(&self) -> u32 { 1213 | unsafe { gexiv2::gexiv2_preview_properties_get_size(self.raw) } 1214 | } 1215 | 1216 | /// Return the width of the preview image. 1217 | pub fn get_width(&self) -> u32 { 1218 | unsafe { gexiv2::gexiv2_preview_properties_get_width(self.raw) } 1219 | } 1220 | 1221 | /// Return the height of the preview image. 1222 | pub fn get_height(&self) -> u32 { 1223 | unsafe { gexiv2::gexiv2_preview_properties_get_height(self.raw) } 1224 | } 1225 | 1226 | /// Return the media type of the preview image. 1227 | pub fn get_media_type(&self) -> Result { 1228 | unsafe { 1229 | let c_str_val = gexiv2::gexiv2_preview_properties_get_mime_type(self.raw); 1230 | if c_str_val.is_null() { 1231 | return Err(Rexiv2Error::NoValue); 1232 | } 1233 | Ok(MediaType::from(ffi::CStr::from_ptr(c_str_val).to_str()?)) 1234 | } 1235 | } 1236 | 1237 | /// Return the preview image's recommended file extension. 1238 | pub fn get_extension(&self) -> Result { 1239 | unsafe { 1240 | let c_str_val = gexiv2::gexiv2_preview_properties_get_extension(self.raw); 1241 | if c_str_val.is_null() { 1242 | return Err(Rexiv2Error::NoValue); 1243 | } 1244 | Ok((ffi::CStr::from_ptr(c_str_val).to_str())?.to_string()) 1245 | } 1246 | } 1247 | 1248 | /// Get the preview image data. 1249 | pub fn get_data(&self) -> Result> { 1250 | let image = 1251 | unsafe { gexiv2::gexiv2_metadata_get_preview_image(self.metadata.raw, self.raw) }; 1252 | 1253 | let mut size: libc::c_uint = 0; 1254 | unsafe { 1255 | let data = gexiv2::gexiv2_preview_image_get_data(image, &mut size); 1256 | let result = if data.is_null() { 1257 | Err(Rexiv2Error::NoValue) 1258 | } else { 1259 | Ok(std::slice::from_raw_parts_mut(data as *mut u8, size as usize).to_vec()) 1260 | }; 1261 | gexiv2::gexiv2_preview_image_free(image); 1262 | result 1263 | } 1264 | } 1265 | 1266 | /// Save the preview image to a file. 1267 | pub fn save_to_file>(&self, path: S) -> Result<()> { 1268 | let c_str_path = os_str_to_c_string(path)?; 1269 | let image = 1270 | unsafe { gexiv2::gexiv2_metadata_get_preview_image(self.metadata.raw, self.raw) }; 1271 | 1272 | unsafe { 1273 | let ok = gexiv2::gexiv2_preview_image_write_file(image, c_str_path.as_ptr()); 1274 | gexiv2::gexiv2_preview_image_free(image); 1275 | 1276 | let expected = self.get_size() as libc::c_long; 1277 | if ok != expected { 1278 | Err(Rexiv2Error::Internal(None)) 1279 | } else { 1280 | Ok(()) 1281 | } 1282 | } 1283 | } 1284 | } 1285 | 1286 | 1287 | // Tag information. 1288 | 1289 | /// Indicates whether the given tag is from the Exif domain. 1290 | /// 1291 | /// # Examples 1292 | /// ``` 1293 | /// assert!(rexiv2::is_exif_tag("Exif.Photo.FocalLength")); 1294 | /// assert!(!rexiv2::is_exif_tag("Iptc.Application2.Subject")); 1295 | /// ``` 1296 | pub fn is_exif_tag(tag: &str) -> bool { 1297 | let c_str_tag = ffi::CString::new(tag).unwrap(); 1298 | unsafe { gexiv2::gexiv2_metadata_is_exif_tag(c_str_tag.as_ptr()) == 1 } 1299 | } 1300 | 1301 | /// Indicates whether the given tag is part of the IPTC domain. 1302 | /// 1303 | /// # Examples 1304 | /// ``` 1305 | /// assert!(rexiv2::is_iptc_tag("Iptc.Application2.Subject")); 1306 | /// assert!(!rexiv2::is_iptc_tag("Xmp.dc.Title")); 1307 | /// ``` 1308 | pub fn is_iptc_tag(tag: &str) -> bool { 1309 | let c_str_tag = ffi::CString::new(tag).unwrap(); 1310 | unsafe { gexiv2::gexiv2_metadata_is_iptc_tag(c_str_tag.as_ptr()) == 1 } 1311 | } 1312 | 1313 | /// Indicates whether the given tag is from the XMP domain. 1314 | /// 1315 | /// # Examples 1316 | /// ``` 1317 | /// assert!(rexiv2::is_xmp_tag("Xmp.dc.Title")); 1318 | /// assert!(!rexiv2::is_xmp_tag("Exif.Photo.FocalLength")); 1319 | /// ``` 1320 | pub fn is_xmp_tag(tag: &str) -> bool { 1321 | let c_str_tag = ffi::CString::new(tag).unwrap(); 1322 | unsafe { gexiv2::gexiv2_metadata_is_xmp_tag(c_str_tag.as_ptr()) == 1 } 1323 | } 1324 | 1325 | /// Get a short label for a tag. 1326 | /// 1327 | /// # Examples 1328 | /// ``` 1329 | /// assert_eq!(rexiv2::get_tag_label("Iptc.Application2.Subject"), Ok("Subject".to_string())); 1330 | /// ``` 1331 | pub fn get_tag_label(tag: &str) -> Result { 1332 | let c_str_tag = ffi::CString::new(tag)?; 1333 | unsafe { 1334 | let c_str_val = gexiv2::gexiv2_metadata_get_tag_label(c_str_tag.as_ptr()); 1335 | if c_str_val.is_null() { 1336 | return Err(Rexiv2Error::NoValue); 1337 | } 1338 | Ok(ffi::CStr::from_ptr(c_str_val).to_str()?.to_string()) 1339 | } 1340 | } 1341 | 1342 | /// Get the long-form description of a tag. 1343 | /// 1344 | /// # Examples 1345 | /// ``` 1346 | /// assert_eq!(rexiv2::get_tag_description("Iptc.Application2.Subject"), 1347 | /// Ok("The Subject Reference is a structured definition of the subject matter.".to_string())); 1348 | /// ``` 1349 | pub fn get_tag_description(tag: &str) -> Result { 1350 | let c_str_tag = ffi::CString::new(tag)?; 1351 | unsafe { 1352 | let c_str_val = gexiv2::gexiv2_metadata_get_tag_description(c_str_tag.as_ptr()); 1353 | if c_str_val.is_null() { 1354 | return Err(Rexiv2Error::NoValue); 1355 | } 1356 | Ok(ffi::CStr::from_ptr(c_str_val).to_str()?.to_string()) 1357 | } 1358 | } 1359 | 1360 | /// Determine the type of the given tag. 1361 | /// 1362 | /// # Examples 1363 | /// ``` 1364 | /// assert_eq!(rexiv2::get_tag_type("Iptc.Application2.Subject"), Ok(rexiv2::TagType::String)); 1365 | /// assert_eq!(rexiv2::get_tag_type("Iptc.Application2.DateCreated"), Ok(rexiv2::TagType::Date)); 1366 | /// ``` 1367 | pub fn get_tag_type(tag: &str) -> Result { 1368 | let c_str_tag = ffi::CString::new(tag)?; 1369 | let tag_type = unsafe { 1370 | let c_str_val = gexiv2::gexiv2_metadata_get_tag_type(c_str_tag.as_ptr()); 1371 | if c_str_val.is_null() { 1372 | return Err(Rexiv2Error::NoValue); 1373 | } 1374 | ffi::CStr::from_ptr(c_str_val).to_str()? 1375 | }; 1376 | match tag_type { 1377 | "Byte" => Ok(TagType::UnsignedByte), 1378 | "Ascii" => Ok(TagType::AsciiString), 1379 | "Short" => Ok(TagType::UnsignedShort), 1380 | "Long" => Ok(TagType::UnsignedLong), 1381 | "Rational" => Ok(TagType::UnsignedRational), 1382 | "SByte" => Ok(TagType::SignedByte), 1383 | "Undefined" => Ok(TagType::Undefined), 1384 | "SShort" => Ok(TagType::SignedShort), 1385 | "SLong" => Ok(TagType::SignedLong), 1386 | "SRational" => Ok(TagType::SignedRational), 1387 | "Float" => Ok(TagType::TiffFloat), 1388 | "Double" => Ok(TagType::TiffDouble), 1389 | "Ifd" => Ok(TagType::TiffIfd), 1390 | "String" => Ok(TagType::String), 1391 | "Date" => Ok(TagType::Date), 1392 | "Time" => Ok(TagType::Time), 1393 | "Comment" => Ok(TagType::Comment), 1394 | "Directory" => Ok(TagType::Directory), 1395 | "XmpText" => Ok(TagType::XmpText), 1396 | "XmpAlt" => Ok(TagType::XmpAlt), 1397 | "XmpBag" => Ok(TagType::XmpBag), 1398 | "XmpSeq" => Ok(TagType::XmpSeq), 1399 | "LangAlt" => Ok(TagType::LangAlt), 1400 | "Invalid" => Ok(TagType::Invalid), 1401 | _ => Ok(TagType::Unknown), 1402 | } 1403 | } 1404 | 1405 | /// Initialize gexiv2. 1406 | /// 1407 | /// This must be called in a thread-safe fashion before using rexiv2. 1408 | /// The library may appear to work without calling this, but some 1409 | /// features such as HEIC/BMFF will silently fail, and the underlying 1410 | /// libraries make the assumption that this will be called so it 1411 | /// is safer to do so. 1412 | /// 1413 | /// Calling it first thing in the main function should ensure that 1414 | /// it is executed on the main thread and is thread safe. Do not call 1415 | /// it in a threaded or async context (such as in a tokio context). 1416 | /// 1417 | /// # See also 1418 | /// 1419 | /// Associated Gexiv2 source code: 1420 | /// 1421 | /// # Examples 1422 | /// 1423 | /// It is normally sufficient to simply call the function in the usual 1424 | /// obvious way: 1425 | /// 1426 | /// ``` 1427 | /// fn main() { 1428 | /// rexiv2::initialize().expect("Unable to initialize rexiv2"); 1429 | /// } 1430 | /// ``` 1431 | /// 1432 | /// However if you have a more complex multi-threaded environment, you 1433 | /// might want to ensure the function only gets set up once: 1434 | /// 1435 | /// ``` 1436 | /// use std::sync::Once; 1437 | /// 1438 | /// fn main() { 1439 | /// static START: Once = Once::new(); 1440 | /// 1441 | /// START.call_once(|| unsafe { 1442 | /// rexiv2::initialize().expect("Unable to initialize rexiv2"); 1443 | /// }); 1444 | /// } 1445 | /// ``` 1446 | pub fn initialize() -> Result<()> { 1447 | unsafe { int_bool_to_result(gexiv2::gexiv2_initialize()) } 1448 | } 1449 | 1450 | 1451 | // XMP namespace management. 1452 | 1453 | /// Add a new XMP namespace for tags to exist under. 1454 | /// 1455 | /// It is an error to register a duplicate namespace. 1456 | /// 1457 | /// # Examples 1458 | /// ``` 1459 | /// assert_eq!(rexiv2::register_xmp_namespace("http://creativecommons.org/ns#/", "cc"), Ok(())); 1460 | /// // But note you can't duplicate a namespace that has already been registered: 1461 | /// assert_eq!(rexiv2::register_xmp_namespace("http://creativecommons.org/ns#/", "cc"), 1462 | /// Err(rexiv2::Rexiv2Error::Internal(None))); 1463 | /// ``` 1464 | pub fn register_xmp_namespace(name: &str, prefix: &str) -> Result<()> { 1465 | let c_str_name = ffi::CString::new(name)?; 1466 | let c_str_prefix = ffi::CString::new(prefix)?; 1467 | unsafe { 1468 | int_bool_to_result(gexiv2::gexiv2_metadata_register_xmp_namespace( 1469 | c_str_name.as_ptr(), 1470 | c_str_prefix.as_ptr(), 1471 | )) 1472 | } 1473 | } 1474 | 1475 | /// Remove an XMP namespace from the set of known ones. 1476 | /// 1477 | /// It is an error to unregister a namespace that isn't registered. 1478 | /// 1479 | /// # Examples 1480 | /// ``` 1481 | /// assert_eq!(rexiv2::register_xmp_namespace("http://creativecommons.org/ns#/", "cc"), Ok(())); 1482 | /// assert_eq!(rexiv2::unregister_xmp_namespace("http://creativecommons.org/ns#/"), Ok(())); 1483 | /// // But note you can't unregister a namespace that has already been removed: 1484 | /// assert_eq!(rexiv2::unregister_xmp_namespace("http://creativecommons.org/ns#/"), 1485 | /// Err(rexiv2::Rexiv2Error::Internal(None))); 1486 | /// ``` 1487 | pub fn unregister_xmp_namespace(name: &str) -> Result<()> { 1488 | let c_str_name = ffi::CString::new(name)?; 1489 | unsafe { 1490 | int_bool_to_result(gexiv2::gexiv2_metadata_unregister_xmp_namespace( 1491 | c_str_name.as_ptr(), 1492 | )) 1493 | } 1494 | } 1495 | 1496 | /// Forget all known XMP namespaces. 1497 | /// 1498 | /// # Examples 1499 | /// ``` 1500 | /// assert_eq!(rexiv2::register_xmp_namespace("http://creativecommons.org/ns#/", "cc"), Ok(())); 1501 | /// rexiv2::unregister_all_xmp_namespaces(); 1502 | /// assert_eq!(rexiv2::register_xmp_namespace("http://creativecommons.org/ns#/", "cc"), Ok(())); 1503 | /// ``` 1504 | pub fn unregister_all_xmp_namespaces() { 1505 | unsafe { gexiv2::gexiv2_metadata_unregister_all_xmp_namespaces() } 1506 | } 1507 | 1508 | 1509 | // Logging 1510 | 1511 | /// Get the GExiv2 log level. 1512 | /// 1513 | /// # Examples 1514 | /// ``` 1515 | /// assert_eq!(rexiv2::get_log_level(), rexiv2::LogLevel::WARN); 1516 | /// rexiv2::set_log_level(rexiv2::LogLevel::INFO); 1517 | /// assert_eq!(rexiv2::get_log_level(), rexiv2::LogLevel::INFO); 1518 | /// ``` 1519 | pub fn get_log_level() -> LogLevel { 1520 | unsafe { gexiv2::gexiv2_log_get_level() } 1521 | } 1522 | 1523 | /// Set the GExiv2 log level. 1524 | /// 1525 | /// # Examples 1526 | /// ``` 1527 | /// assert_eq!(rexiv2::get_log_level(), rexiv2::LogLevel::WARN); 1528 | /// rexiv2::set_log_level(rexiv2::LogLevel::INFO); 1529 | /// assert_eq!(rexiv2::get_log_level(), rexiv2::LogLevel::INFO); 1530 | /// ``` 1531 | pub fn set_log_level(level: LogLevel) { 1532 | unsafe { gexiv2::gexiv2_log_set_level(level) } 1533 | } 1534 | 1535 | 1536 | // Private internal helpers. 1537 | 1538 | /// Helper function to free an array of pointers, such as those returned by some gexiv2 functions. 1539 | fn free_array_of_pointers(list: *mut *mut libc::c_void) { 1540 | unsafe { 1541 | let mut idx = 0; 1542 | while !(*list.offset(idx)).is_null() { 1543 | libc::free(*list.offset(idx)); 1544 | idx += 1; 1545 | } 1546 | libc::free(list as *mut libc::c_void); 1547 | } 1548 | } 1549 | 1550 | /// Convert a success/failure integer representing a boolean into a Result. 1551 | fn int_bool_to_result(success: libc::c_int) -> Result<()> { 1552 | match success { 1553 | 0 => Err(Rexiv2Error::Internal(None)), 1554 | _ => Ok(()), 1555 | } 1556 | } 1557 | 1558 | /// Convert an OS string to a UTF-8 CString 1559 | fn os_str_to_c_string>(path: S) -> Result { 1560 | let path_as_utf8_result = path 1561 | .as_ref() 1562 | .to_str() 1563 | .ok_or_else(|| Rexiv2Error::Internal(Some("Couldn't convert path to UTF-8".to_string())))?; 1564 | Ok(ffi::CString::new(path_as_utf8_result.as_bytes())?) 1565 | } 1566 | --------------------------------------------------------------------------------