Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[rust] Rust crate organizational changes regarding photos (#10305)

laurens-pilotabd662305d9b
diff --git a/mobile/apps/photos/rust/Cargo.lock b/mobile/apps/photos/rust/Cargo.lock
index e514df2105..37b779891d 100644
--- a/mobile/apps/photos/rust/Cargo.lock
+++ b/mobile/apps/photos/rust/Cargo.lock
@@ -132,9 +132,9 @@ checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1"
[[package]]
name = "archmage"
-version = "0.8.6"
+version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b6d08808218c9a8bb39ac0490adc5d65a666cc38ddb730baf9ed57e32d803ee"
+checksum = "c0fb818f2e02ca08cc6416725044fadc84bcf5a96e2eb7ab103c966123667d86"
dependencies = [
"archmage-macros",
"safe_unaligned_simd",
@@ -142,9 +142,9 @@ dependencies = [
[[package]]
name = "archmage-macros"
-version = "0.8.6"
+version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4320e26657ff06e4cb353df04642c3faa5390cae53705e846b788b59d14bc52e"
+checksum = "1886761e37995842cfbaf8c24d483e62d9b8c174254d29146f596d4d87efff2d"
dependencies = [
"proc-macro2",
"quote",
@@ -744,22 +744,26 @@ dependencies = [
]
[[package]]
-name = "enough"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "177a59811828ea5dbc8927662d444ffee7b55a44696486f1b1a245ae9e652533"
+name = "ente_image"
+version = "0.1.0"
+dependencies = [
+ "heic_decoder",
+ "image",
+ "kamadak-exif",
+ "thiserror 2.0.18",
+ "tiff",
+]
[[package]]
-name = "ente_media_inspector"
+name = "ente_photos"
version = "0.1.0"
dependencies = [
+ "ente_image",
"fast_image_resize",
"half",
"html-escape",
"image",
"imageproc",
- "kamadak-exif",
- "libheic-rs",
"nalgebra 0.33.2",
"ndarray 0.16.1",
"once_cell",
@@ -768,7 +772,6 @@ dependencies = [
"quick-xml",
"regex",
"thiserror 2.0.18",
- "tiff",
"usearch",
]
@@ -776,7 +779,8 @@ dependencies = [
name = "ente_photos_rust"
version = "0.0.1"
dependencies = [
- "ente_media_inspector",
+ "ente_image",
+ "ente_photos",
"flutter_rust_bridge",
]
@@ -1131,14 +1135,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
-name = "heic-decoder"
+name = "heic_decoder"
version = "0.1.0"
-source = "git+https://github.com/laurens-pilot/libheic-rs.git?tag=v0.1.5#18307d94c72c13eb9526655b748c333722ee145b"
+source = "git+https://github.com/ente-io/heic-decoder.git?rev=53303b2936ec19467c61cf75f77e30b399c10445#53303b2936ec19467c61cf75f77e30b399c10445"
dependencies = [
"archmage",
- "enough",
+ "brotli",
+ "flate2",
+ "image",
+ "libc",
+ "png",
+ "rav1d",
"safe_unaligned_simd",
- "whereat",
+ "scuffle-h265",
]
[[package]]
@@ -1709,21 +1718,6 @@ dependencies = [
"cc",
]
-[[package]]
-name = "libheic-rs"
-version = "0.1.5"
-source = "git+https://github.com/laurens-pilot/libheic-rs.git?tag=v0.1.5#18307d94c72c13eb9526655b748c333722ee145b"
-dependencies = [
- "brotli",
- "flate2",
- "heic-decoder",
- "image",
- "libc",
- "png",
- "rav1d",
- "scuffle-h265",
-]
-
[[package]]
name = "libloading"
version = "0.8.9"
@@ -1817,9 +1811,9 @@ dependencies = [
[[package]]
name = "memchr"
-version = "2.7.6"
+version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
+checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
[[package]]
name = "miniz_oxide"
@@ -2395,7 +2389,7 @@ dependencies = [
[[package]]
name = "rav1d"
version = "1.1.0"
-source = "git+https://github.com/laurens-pilot/libheic-rs.git?tag=v0.1.5#18307d94c72c13eb9526655b748c333722ee145b"
+source = "git+https://github.com/ente-io/rav1d.git?branch=1.1.0_arm32_stable#05db46f1046b43a14019f31d51f74513a15cd2d0"
dependencies = [
"assert_matches",
"atomig",
@@ -2579,9 +2573,9 @@ dependencies = [
[[package]]
name = "safe_unaligned_simd"
-version = "0.2.4"
+version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1d612ce01a584cfab72164fb3f689112249fafeab7b4181c14601d19b34cb0a"
+checksum = "f9c874fb993656d484725d58fbfddb39dfcf98ebcadc1a1d09568aa6b39bafba"
[[package]]
name = "scopeguard"
@@ -3099,12 +3093,6 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88"
-[[package]]
-name = "whereat"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3ec598a1ade4224cfe3c5dace0d5d7deec9ed670503ff99d4946973c8c094534"
-
[[package]]
name = "wide"
version = "0.7.33"
diff --git a/mobile/apps/photos/rust/Cargo.toml b/mobile/apps/photos/rust/Cargo.toml
index 3266517f05..8781925746 100644
--- a/mobile/apps/photos/rust/Cargo.toml
+++ b/mobile/apps/photos/rust/Cargo.toml
@@ -8,7 +8,8 @@ crate-type = ["cdylib", "staticlib"]
[dependencies]
flutter_rust_bridge = "=2.12.0"
-ente_media_inspector = { path = "../../../../rust/photos" }
+ente_photos = { path = "../../../../rust/photos" }
+ente_image = { path = "../../../../rust/crates/image" }
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(frb_expand)'] }
diff --git a/mobile/apps/photos/rust/src/api/image_processing_api.rs b/mobile/apps/photos/rust/src/api/image_processing_api.rs
index dda3dc84dd..285cc5c3c0 100644
--- a/mobile/apps/photos/rust/src/api/image_processing_api.rs
+++ b/mobile/apps/photos/rust/src/api/image_processing_api.rs
@@ -1,9 +1,9 @@
-use ente_media_inspector::{
- image::{
- decode::decode_image_from_path,
- image_compression::{EncodedImageFormat, encode_rgb},
- },
- ml::face::thumbnail::{FaceBox, generate_face_thumbnails as generate_face_thumbnails_impl},
+use ente_image::{
+ decode::decode_image_from_path,
+ image_compression::{EncodedImageFormat, encode_rgb},
+};
+use ente_photos::ml::face::thumbnail::{
+ FaceBox, generate_face_thumbnails as generate_face_thumbnails_impl,
};
#[derive(Clone, Debug)]
@@ -31,7 +31,7 @@ pub fn generate_face_thumbnails(
generate_face_thumbnails_impl(&decoded, &face_boxes).map_err(|e| e.to_string())
}
-/// Decode an image (including HEIC/HEIF) to JPEG bytes using libheic-rs,
+/// Decode an image (including HEIC/HEIF) to JPEG bytes using ente_heic,
/// bypassing the platform's potentially broken image decoder.
pub fn decode_to_jpeg(image_path: String, quality: Option<u8>) -> Result<Vec<u8>, String> {
let decoded = decode_image_from_path(&image_path).map_err(|e| e.to_string())?;
diff --git a/mobile/apps/photos/rust/src/api/ml_indexing_api.rs b/mobile/apps/photos/rust/src/api/ml_indexing_api.rs
index 0762637190..6d11d75c91 100644
--- a/mobile/apps/photos/rust/src/api/ml_indexing_api.rs
+++ b/mobile/apps/photos/rust/src/api/ml_indexing_api.rs
@@ -1,4 +1,4 @@
-use ente_media_inspector::ml::{
+use ente_photos::ml::{
indexing as shared_indexing,
runtime::{ExecutionProviderPolicy, MlRuntimeConfig, ModelPaths},
types as shared_types,
diff --git a/mobile/apps/photos/rust/src/api/motion_photo_api.rs b/mobile/apps/photos/rust/src/api/motion_photo_api.rs
index 2cfc9467ff..a4aa992001 100644
--- a/mobile/apps/photos/rust/src/api/motion_photo_api.rs
+++ b/mobile/apps/photos/rust/src/api/motion_photo_api.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
-use ente_media_inspector::{
+use ente_photos::{
VideoIndex as CoreVideoIndex, extract_motion_video_file_from_path, extract_xmp_from_path,
get_motion_video_index_from_path,
};
diff --git a/mobile/apps/photos/rust/src/api/usearch_api.rs b/mobile/apps/photos/rust/src/api/usearch_api.rs
index d3539858e9..e7887b1de1 100644
--- a/mobile/apps/photos/rust/src/api/usearch_api.rs
+++ b/mobile/apps/photos/rust/src/api/usearch_api.rs
@@ -1,4 +1,4 @@
-use ente_media_inspector::vector_db;
+use ente_photos::ml::vector_db;
use flutter_rust_bridge::frb;
type SearchMatch = (Vec<u64>, Vec<f32>);
@@ -81,7 +81,6 @@ fn validate_semantic_search_exact_queries(
Ok(())
}
-
fn flatten_semantic_search_exact_image_embeddings(
image_embeddings: &[Vec<f32>],
expected_dimension: Option<usize>,
@@ -201,7 +200,6 @@ pub struct SemanticSearchExactResponse {
pub matches_per_query: Vec<Vec<SemanticSearchExactMatch>>,
}
-
#[frb(opaque)]
pub struct SemanticSearchExactCache {
image_file_ids: Vec<i64>,
@@ -259,7 +257,6 @@ pub fn semantic_search_exact(
)
}
-
#[frb(opaque)]
pub struct VectorDB {
inner: vector_db::VectorDB,
@@ -486,5 +483,4 @@ mod tests {
assert!(err.contains("embedding dimension mismatch"));
}
-
}
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index 00359137cf..4350dca1f8 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -2,12 +2,104 @@
# It is not intended for manual editing.
version = 4
+[[package]]
+name = "adler2"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
+
+[[package]]
+name = "aligned"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ee4508988c62edf04abd8d92897fca0c2995d907ce1dfeaf369dac3716a40685"
+dependencies = [
+ "as-slice",
+]
+
+[[package]]
+name = "aligned-vec"
+version = "0.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc890384c8602f339876ded803c97ad529f3842aba97f6392b3dba0dd171769b"
+dependencies = [
+ "equator",
+]
+
+[[package]]
+name = "alloc-no-stdlib"
+version = "2.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3"
+
+[[package]]
+name = "alloc-stdlib"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece"
+dependencies = [
+ "alloc-no-stdlib",
+]
+
[[package]]
name = "anyhow"
version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
+[[package]]
+name = "arbitrary"
+version = "1.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1"
+
+[[package]]
+name = "archmage"
+version = "0.8.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c0fb818f2e02ca08cc6416725044fadc84bcf5a96e2eb7ab103c966123667d86"
+dependencies = [
+ "archmage-macros",
+ "safe_unaligned_simd",
+]
+
+[[package]]
+name = "archmage-macros"
+version = "0.8.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1886761e37995842cfbaf8c24d483e62d9b8c174254d29146f596d4d87efff2d"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "arg_enum_proc_macro"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "arrayvec"
+version = "0.7.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
+
+[[package]]
+name = "as-slice"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "516b6b4f0e40d50dcda9365d53964ec74560ad4284da2e7fc97122cd83174516"
+dependencies = [
+ "stable_deref_trait",
+]
+
[[package]]
name = "askama"
version = "0.14.0"
@@ -50,12 +142,81 @@ dependencies = [
"winnow 0.7.15",
]
+[[package]]
+name = "assert_matches"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9"
+
+[[package]]
+name = "atomig"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cd0f41f4bb89f5c6450325e283fb78c4a3d042181b54f3855ee2f872919f9863"
+dependencies = [
+ "atomig-macro",
+]
+
+[[package]]
+name = "atomig-macro"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49c98dba06b920588de7d63f6acc23f1e6a9fade5fd6198e564506334fb5a4f5"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "autocfg"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
+[[package]]
+name = "av-scenechange"
+version = "0.14.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0f321d77c20e19b92c39e7471cf986812cbb46659d2af674adc4331ef3f18394"
+dependencies = [
+ "aligned",
+ "anyhow",
+ "arg_enum_proc_macro",
+ "arrayvec",
+ "log",
+ "num-rational",
+ "num-traits",
+ "pastey",
+ "rayon",
+ "thiserror",
+ "v_frame",
+ "y4m",
+]
+
+[[package]]
+name = "av1-grain"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8cfddb07216410377231960af4fcab838eaa12e013417781b78bd95ee22077f8"
+dependencies = [
+ "anyhow",
+ "arrayvec",
+ "log",
+ "nom 8.0.0",
+ "num-rational",
+ "v_frame",
+]
+
+[[package]]
+name = "avif-serialize"
+version = "0.8.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "375082f007bd67184fb9c0374614b29f9aaa604ec301635f72338bb65386a53d"
+dependencies = [
+ "arrayvec",
+]
+
[[package]]
name = "basic-toml"
version = "0.1.10"
@@ -65,12 +226,93 @@ dependencies = [
"serde",
]
+[[package]]
+name = "bit_field"
+version = "0.10.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6"
+
[[package]]
name = "bitflags"
version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
+[[package]]
+name = "bitstream-io"
+version = "4.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7eff00be299a18769011411c9def0d827e8f2d7bf0c3dbf53633147a8867fd1f"
+dependencies = [
+ "no_std_io2",
+]
+
+[[package]]
+name = "brotli"
+version = "8.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4bd8b9603c7aa97359dbd97ecf258968c95f3adddd6db2f7e7a5bef101c84560"
+dependencies = [
+ "alloc-no-stdlib",
+ "alloc-stdlib",
+ "brotli-decompressor",
+]
+
+[[package]]
+name = "brotli-decompressor"
+version = "5.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "874bb8112abecc98cbd6d81ea4fa7e94fb9449648c93cc89aa40c81c24d7de03"
+dependencies = [
+ "alloc-no-stdlib",
+ "alloc-stdlib",
+]
+
+[[package]]
+name = "built"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f4ad8f11f288f48ca24471bbd51ac257aaeaaa07adae295591266b792902ae64"
+
+[[package]]
+name = "bumpalo"
+version = "3.20.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb"
+
+[[package]]
+name = "bytemuck"
+version = "1.25.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec"
+
+[[package]]
+name = "byteorder"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
+
+[[package]]
+name = "byteorder-lite"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
+
+[[package]]
+name = "bytes"
+version = "1.11.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
+
+[[package]]
+name = "bytestring"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "86566c496f2f47d9b8147a4c8b02ffdb69c919fe0c2b2e7195d22cbba0e635c9"
+dependencies = [
+ "bytes",
+]
+
[[package]]
name = "camino"
version = "1.2.2"
@@ -103,6 +345,18 @@ dependencies = [
"thiserror",
]
+[[package]]
+name = "cc"
+version = "1.2.61"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d16d90359e986641506914ba71350897565610e87ce0ad9e6f28569db3dd5c6d"
+dependencies = [
+ "find-msvc-tools",
+ "jobserver",
+ "libc",
+ "shlex",
+]
+
[[package]]
name = "cfg-if"
version = "1.0.4"
@@ -117,6 +371,89 @@ dependencies = [
"uniffi_bindgen",
]
+[[package]]
+name = "color_quant"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
+
+[[package]]
+name = "crc32fast"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "crossbeam-deque"
+version = "0.8.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
+dependencies = [
+ "crossbeam-epoch",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-epoch"
+version = "0.9.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
+dependencies = [
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-utils"
+version = "0.8.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
+
+[[package]]
+name = "crunchy"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
+
+[[package]]
+name = "either"
+version = "1.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
+
+[[package]]
+name = "ente_image"
+version = "0.1.0"
+dependencies = [
+ "heic_decoder",
+ "image",
+ "kamadak-exif",
+ "thiserror",
+ "tiff 0.10.3",
+]
+
+[[package]]
+name = "equator"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4711b213838dfee0117e3be6ac926007d7f433d7bbe33595975d4190cb07e6fc"
+dependencies = [
+ "equator-macro",
+]
+
+[[package]]
+name = "equator-macro"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "44f23cf4b44bfce11a86ace86f8a73ffdec849c9fd00a386a53d278bd9e81fb3"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "equivalent"
version = "1.0.2"
@@ -133,12 +470,58 @@ dependencies = [
"windows-sys",
]
+[[package]]
+name = "exr"
+version = "1.74.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4300e043a56aa2cb633c01af81ca8f699a321879a7854d3896a0ba89056363be"
+dependencies = [
+ "bit_field",
+ "half",
+ "lebe",
+ "miniz_oxide",
+ "rayon-core",
+ "smallvec",
+ "zune-inflate",
+]
+
[[package]]
name = "fastrand"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"
+[[package]]
+name = "fax"
+version = "0.2.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "caf1079563223d5d59d83c85886a56e586cfd5c1a26292e971a0fa266531ac5a"
+
+[[package]]
+name = "fdeflate"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c"
+dependencies = [
+ "simd-adler32",
+]
+
+[[package]]
+name = "find-msvc-tools"
+version = "0.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
+
+[[package]]
+name = "flate2"
+version = "1.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c"
+dependencies = [
+ "crc32fast",
+ "miniz_oxide",
+]
+
[[package]]
name = "foldhash"
version = "0.1.5"
@@ -154,6 +537,18 @@ dependencies = [
"autocfg",
]
+[[package]]
+name = "getrandom"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "r-efi 5.3.0",
+ "wasip2",
+]
+
[[package]]
name = "getrandom"
version = "0.4.2"
@@ -162,11 +557,21 @@ checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555"
dependencies = [
"cfg-if",
"libc",
- "r-efi",
+ "r-efi 6.0.0",
"wasip2",
"wasip3",
]
+[[package]]
+name = "gif"
+version = "0.14.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ee8cfcc411d9adbbaba82fb72661cc1bcca13e8bba98b364e62b2dba8f960159"
+dependencies = [
+ "color_quant",
+ "weezl",
+]
+
[[package]]
name = "glob"
version = "0.3.3"
@@ -184,6 +589,17 @@ dependencies = [
"scroll",
]
+[[package]]
+name = "half"
+version = "2.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
+dependencies = [
+ "cfg-if",
+ "crunchy",
+ "zerocopy 0.8.48",
+]
+
[[package]]
name = "hashbrown"
version = "0.15.5"
@@ -206,126 +622,636 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
-name = "id-arena"
-version = "2.3.0"
+name = "heic_decoder"
+version = "0.1.0"
+source = "git+https://github.com/ente-io/heic-decoder.git?rev=53303b2936ec19467c61cf75f77e30b399c10445#53303b2936ec19467c61cf75f77e30b399c10445"
+dependencies = [
+ "archmage",
+ "brotli",
+ "flate2",
+ "image",
+ "libc",
+ "png",
+ "rav1d",
+ "safe_unaligned_simd",
+ "scuffle-h265",
+]
+
+[[package]]
+name = "id-arena"
+version = "2.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
+
+[[package]]
+name = "image"
+version = "0.25.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104"
+dependencies = [
+ "bytemuck",
+ "byteorder-lite",
+ "color_quant",
+ "exr",
+ "gif",
+ "image-webp",
+ "moxcms",
+ "num-traits",
+ "png",
+ "qoi",
+ "ravif",
+ "rayon",
+ "rgb",
+ "tiff 0.11.3",
+ "zune-core 0.5.1",
+ "zune-jpeg 0.5.15",
+]
+
+[[package]]
+name = "image-webp"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3"
+dependencies = [
+ "byteorder-lite",
+ "quick-error",
+]
+
+[[package]]
+name = "imgref"
+version = "1.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40fac9d56ed6437b198fddba683305e8e2d651aa42647f00f5ae542e7f5c94a2"
+
+[[package]]
+name = "indexmap"
+version = "2.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
+dependencies = [
+ "equivalent",
+ "hashbrown 0.17.0",
+ "serde",
+ "serde_core",
+]
+
+[[package]]
+name = "interpolate_name"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "itertools"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
+dependencies = [
+ "either",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
+
+[[package]]
+name = "jobserver"
+version = "0.1.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33"
+dependencies = [
+ "getrandom 0.3.4",
+ "libc",
+]
+
+[[package]]
+name = "kamadak-exif"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1130d80c7374efad55a117d715a3af9368f0fa7a2c54573afc15a188cd984837"
+dependencies = [
+ "mutate_once",
+]
+
+[[package]]
+name = "leb128fmt"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
+
+[[package]]
+name = "lebe"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a79a3332a6609480d7d0c9eab957bca6b455b91bb84e66d19f5ff66294b85b8"
+
+[[package]]
+name = "libc"
+version = "0.2.184"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "48f5d2a454e16a5ea0f4ced81bd44e4cfc7bd3a507b61887c99fd3538b28e4af"
+
+[[package]]
+name = "libfuzzer-sys"
+version = "0.4.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f12a681b7dd8ce12bff52488013ba614b869148d54dd79836ab85aafdd53f08d"
+dependencies = [
+ "arbitrary",
+ "cc",
+]
+
+[[package]]
+name = "linux-raw-sys"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
+
+[[package]]
+name = "lock_api"
+version = "0.4.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
+dependencies = [
+ "scopeguard",
+]
+
+[[package]]
+name = "log"
+version = "0.4.29"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
+
+[[package]]
+name = "loop9"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fae87c125b03c1d2c0150c90365d7d6bcc53fb73a9acaef207d2d065860f062"
+dependencies = [
+ "imgref",
+]
+
+[[package]]
+name = "maybe-rayon"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ea1f30cedd69f0a2954655f7188c6a834246d2bcf1e315e2ac40c4b24dc9519"
+dependencies = [
+ "cfg-if",
+ "rayon",
+]
+
+[[package]]
+name = "memchr"
+version = "2.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
+
+[[package]]
+name = "minimal-lexical"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
+
+[[package]]
+name = "miniz_oxide"
+version = "0.8.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
+dependencies = [
+ "adler2",
+ "simd-adler32",
+]
+
+[[package]]
+name = "moxcms"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb85c154ba489f01b25c0d36ae69a87e4a1c73a72631fc6c0eb6dde34a73e44b"
+dependencies = [
+ "num-traits",
+ "pxfm",
+]
+
+[[package]]
+name = "mutate_once"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "13d2233c9842d08cfe13f9eac96e207ca6a2ea10b80259ebe8ad0268be27d2af"
+
+[[package]]
+name = "nasm-rs"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "706bf8a5e8c8ddb99128c3291d31bd21f4bcde17f0f4c20ec678d85c74faa149"
+dependencies = [
+ "jobserver",
+ "log",
+]
+
+[[package]]
+name = "new_debug_unreachable"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
+
+[[package]]
+name = "no_std_io2"
+version = "0.9.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "418abd1b6d34fbf6cae440dc874771b0525a604428704c76e48b29a5e67b8003"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "nom"
+version = "7.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
+dependencies = [
+ "memchr",
+ "minimal-lexical",
+]
+
+[[package]]
+name = "nom"
+version = "8.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "noop_proc_macro"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8"
+
+[[package]]
+name = "num-bigint"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
+dependencies = [
+ "num-integer",
+ "num-traits",
+]
+
+[[package]]
+name = "num-derive"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "num-integer"
+version = "0.1.46"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
+dependencies = [
+ "num-traits",
+]
+
+[[package]]
+name = "num-rational"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
+dependencies = [
+ "num-bigint",
+ "num-integer",
+ "num-traits",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "nutype-enum"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1e13adea6de269faa0724df58f43f6fe2a81af7094f1dcb8b5b968eb2103cb3"
+dependencies = [
+ "scuffle-workspace-hack",
+]
+
+[[package]]
+name = "once_cell"
+version = "1.21.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
+
+[[package]]
+name = "parking_lot"
+version = "0.12.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
+dependencies = [
+ "lock_api",
+ "parking_lot_core",
+]
+
+[[package]]
+name = "parking_lot_core"
+version = "0.9.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "redox_syscall",
+ "smallvec",
+ "windows-link",
+]
+
+[[package]]
+name = "paste"
+version = "1.0.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
+
+[[package]]
+name = "pastey"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "35fb2e5f958ec131621fdd531e9fc186ed768cbe395337403ae56c17a74c68ec"
+
+[[package]]
+name = "percent-encoding"
+version = "2.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
+
+[[package]]
+name = "plain"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
+
+[[package]]
+name = "png"
+version = "0.18.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60769b8b31b2a9f263dae2776c37b1b28ae246943cf719eb6946a1db05128a61"
+dependencies = [
+ "bitflags",
+ "crc32fast",
+ "fdeflate",
+ "flate2",
+ "miniz_oxide",
+]
+
+[[package]]
+name = "ppv-lite86"
+version = "0.2.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
+dependencies = [
+ "zerocopy 0.8.48",
+]
+
+[[package]]
+name = "prettyplease"
+version = "0.2.37"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
+dependencies = [
+ "proc-macro2",
+ "syn",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.106"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "profiling"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3d595e54a326bc53c1c197b32d295e14b169e3cfeaa8dc82b529f947fba6bcf5"
+dependencies = [
+ "profiling-procmacros",
+]
+
+[[package]]
+name = "profiling-procmacros"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4488a4a36b9a4ba6b9334a32a39971f77c1436ec82c38707bce707699cc3bbcb"
+dependencies = [
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "pxfm"
+version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
+checksum = "e0c5ccf5294c6ccd63a74f1565028353830a9c2f5eb0c682c355c471726a6e3f"
[[package]]
-name = "indexmap"
-version = "2.14.0"
+name = "qoi"
+version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
+checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001"
dependencies = [
- "equivalent",
- "hashbrown 0.17.0",
- "serde",
- "serde_core",
+ "bytemuck",
]
[[package]]
-name = "itoa"
-version = "1.0.18"
+name = "quick-error"
+version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
+checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
[[package]]
-name = "leb128fmt"
-version = "0.1.0"
+name = "quote"
+version = "1.0.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
+checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
+dependencies = [
+ "proc-macro2",
+]
[[package]]
-name = "libc"
-version = "0.2.184"
+name = "r-efi"
+version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "48f5d2a454e16a5ea0f4ced81bd44e4cfc7bd3a507b61887c99fd3538b28e4af"
+checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
-name = "linux-raw-sys"
-version = "0.12.1"
+name = "r-efi"
+version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
+checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]]
-name = "log"
-version = "0.4.29"
+name = "rand"
+version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
+checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea"
+dependencies = [
+ "rand_chacha",
+ "rand_core",
+]
[[package]]
-name = "memchr"
-version = "2.8.0"
+name = "rand_chacha"
+version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
+checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
+dependencies = [
+ "ppv-lite86",
+ "rand_core",
+]
[[package]]
-name = "minimal-lexical"
-version = "0.2.1"
+name = "rand_core"
+version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
+checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
+dependencies = [
+ "getrandom 0.3.4",
+]
[[package]]
-name = "nom"
-version = "7.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
+name = "rav1d"
+version = "1.1.0"
+source = "git+https://github.com/ente-io/rav1d.git?branch=1.1.0_arm32_stable#05db46f1046b43a14019f31d51f74513a15cd2d0"
dependencies = [
- "memchr",
- "minimal-lexical",
+ "assert_matches",
+ "atomig",
+ "bitflags",
+ "cc",
+ "cfg-if",
+ "libc",
+ "nasm-rs",
+ "parking_lot",
+ "paste",
+ "raw-cpuid",
+ "strum",
+ "to_method",
+ "zerocopy 0.7.35",
]
[[package]]
-name = "once_cell"
-version = "1.21.4"
+name = "rav1e"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
+checksum = "43b6dd56e85d9483277cde964fd1bdb0428de4fec5ebba7540995639a21cb32b"
+dependencies = [
+ "aligned-vec",
+ "arbitrary",
+ "arg_enum_proc_macro",
+ "arrayvec",
+ "av-scenechange",
+ "av1-grain",
+ "bitstream-io",
+ "built",
+ "cfg-if",
+ "interpolate_name",
+ "itertools",
+ "libc",
+ "libfuzzer-sys",
+ "log",
+ "maybe-rayon",
+ "new_debug_unreachable",
+ "noop_proc_macro",
+ "num-derive",
+ "num-traits",
+ "paste",
+ "profiling",
+ "rand",
+ "rand_chacha",
+ "simd_helpers",
+ "thiserror",
+ "v_frame",
+ "wasm-bindgen",
+]
[[package]]
-name = "percent-encoding"
-version = "2.3.2"
+name = "ravif"
+version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
+checksum = "e52310197d971b0f5be7fe6b57530dcd27beb35c1b013f29d66c1ad73fbbcc45"
+dependencies = [
+ "avif-serialize",
+ "imgref",
+ "loop9",
+ "quick-error",
+ "rav1e",
+ "rayon",
+ "rgb",
+]
[[package]]
-name = "plain"
-version = "0.2.3"
+name = "raw-cpuid"
+version = "11.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
+checksum = "498cd0dc59d73224351ee52a95fee0f1a617a2eae0e7d9d720cc622c73a54186"
+dependencies = [
+ "bitflags",
+]
[[package]]
-name = "prettyplease"
-version = "0.2.37"
+name = "rayon"
+version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
+checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d"
dependencies = [
- "proc-macro2",
- "syn",
+ "either",
+ "rayon-core",
]
[[package]]
-name = "proc-macro2"
-version = "1.0.106"
+name = "rayon-core"
+version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
+checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
dependencies = [
- "unicode-ident",
+ "crossbeam-deque",
+ "crossbeam-utils",
]
[[package]]
-name = "quote"
-version = "1.0.45"
+name = "redox_syscall"
+version = "0.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
+checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
dependencies = [
- "proc-macro2",
+ "bitflags",
]
[[package]]
-name = "r-efi"
-version = "6.0.0"
+name = "rgb"
+version = "0.8.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
+checksum = "47b34b781b31e5d73e9fbc8689c70551fd1ade9a19e3e28cfec8580a79290cc4"
[[package]]
name = "rustc-hash"
@@ -346,6 +1272,24 @@ dependencies = [
"windows-sys",
]
+[[package]]
+name = "rustversion"
+version = "1.0.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
+
+[[package]]
+name = "safe_unaligned_simd"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f9c874fb993656d484725d58fbfddb39dfcf98ebcadc1a1d09568aa6b39bafba"
+
+[[package]]
+name = "scopeguard"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
+
[[package]]
name = "scroll"
version = "0.12.0"
@@ -366,6 +1310,49 @@ dependencies = [
"syn",
]
+[[package]]
+name = "scuffle-bytes-util"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0417748c2a42f4a08d4e634b68b1d64f22a8c24bef2e7ac93df33aa61202a45b"
+dependencies = [
+ "byteorder",
+ "bytes",
+ "bytestring",
+ "scuffle-workspace-hack",
+]
+
+[[package]]
+name = "scuffle-expgolomb"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "48d21330974c941e4c0aedc1e7255ea809e8cbac51e135209f6d67843ad1b94d"
+dependencies = [
+ "scuffle-bytes-util",
+ "scuffle-workspace-hack",
+]
+
+[[package]]
+name = "scuffle-h265"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b04b276c2f79846b7968abe6f87cedf951e06fd2a2b72d99c457e85d7e40f3fb"
+dependencies = [
+ "bitflags",
+ "byteorder",
+ "bytes",
+ "nutype-enum",
+ "scuffle-bytes-util",
+ "scuffle-expgolomb",
+ "scuffle-workspace-hack",
+]
+
+[[package]]
+name = "scuffle-workspace-hack"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8028ded836a0d9fabdfa4d713389b76a2098b5153f50a135c8faed7e3a3d5ae2"
+
[[package]]
name = "semver"
version = "1.0.28"
@@ -428,18 +1415,73 @@ dependencies = [
"serde_core",
]
+[[package]]
+name = "shlex"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
+
+[[package]]
+name = "simd-adler32"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
+
+[[package]]
+name = "simd_helpers"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95890f873bec569a0362c235787f3aca6e1e887302ba4840839bcc6459c42da6"
+dependencies = [
+ "quote",
+]
+
[[package]]
name = "siphasher"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
+[[package]]
+name = "smallvec"
+version = "1.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
+
[[package]]
name = "smawk"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
+[[package]]
+name = "stable_deref_trait"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
+
+[[package]]
+name = "strum"
+version = "0.26.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06"
+dependencies = [
+ "strum_macros",
+]
+
+[[package]]
+name = "strum_macros"
+version = "0.26.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "rustversion",
+ "syn",
+]
+
[[package]]
name = "syn"
version = "2.0.117"
@@ -458,7 +1500,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
dependencies = [
"fastrand",
- "getrandom",
+ "getrandom 0.4.2",
"once_cell",
"rustix",
"windows-sys",
@@ -493,6 +1535,40 @@ dependencies = [
"syn",
]
+[[package]]
+name = "tiff"
+version = "0.10.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af9605de7fee8d9551863fd692cce7637f548dbd9db9180fcc07ccc6d26c336f"
+dependencies = [
+ "fax",
+ "flate2",
+ "half",
+ "quick-error",
+ "weezl",
+ "zune-jpeg 0.4.21",
+]
+
+[[package]]
+name = "tiff"
+version = "0.11.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b63feaf3343d35b6ca4d50483f94843803b0f51634937cc2ec519fc32232bc52"
+dependencies = [
+ "fax",
+ "flate2",
+ "half",
+ "quick-error",
+ "weezl",
+ "zune-jpeg 0.5.15",
+]
+
+[[package]]
+name = "to_method"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c7c4ceeeca15c8384bbc3e011dbd8fccb7f068a440b752b7d9b32ceb0ca0e2e8"
+
[[package]]
name = "toml"
version = "0.9.12+spec-1.1.0"
@@ -620,6 +1696,17 @@ dependencies = [
"weedle2",
]
+[[package]]
+name = "v_frame"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "666b7727c8875d6ab5db9533418d7c764233ac9c0cff1d469aec8fa127597be2"
+dependencies = [
+ "aligned-vec",
+ "num-traits",
+ "wasm-bindgen",
+]
+
[[package]]
name = "wasip2"
version = "1.0.2+wasi-0.2.9"
@@ -638,6 +1725,51 @@ dependencies = [
"wit-bindgen",
]
+[[package]]
+name = "wasm-bindgen"
+version = "0.2.120"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
+dependencies = [
+ "cfg-if",
+ "once_cell",
+ "rustversion",
+ "wasm-bindgen-macro",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-macro"
+version = "0.2.120"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
+dependencies = [
+ "quote",
+ "wasm-bindgen-macro-support",
+]
+
+[[package]]
+name = "wasm-bindgen-macro-support"
+version = "0.2.120"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
+dependencies = [
+ "bumpalo",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-shared"
+version = "0.2.120"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
+dependencies = [
+ "unicode-ident",
+]
+
[[package]]
name = "wasm-encoder"
version = "0.244.0"
@@ -678,9 +1810,15 @@ version = "5.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "998d2c24ec099a87daf9467808859f9d82b61f1d9c9701251aea037f514eae0e"
dependencies = [
- "nom",
+ "nom 7.1.3",
]
+[[package]]
+name = "weezl"
+version = "0.1.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88"
+
[[package]]
name = "windows-link"
version = "0.2.1"
@@ -799,8 +1937,94 @@ dependencies = [
"wasmparser",
]
+[[package]]
+name = "y4m"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a5a4b21e1a62b67a2970e6831bc091d7b87e119e7f9791aef9702e3bef04448"
+
+[[package]]
+name = "zerocopy"
+version = "0.7.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
+dependencies = [
+ "byteorder",
+ "zerocopy-derive 0.7.35",
+]
+
+[[package]]
+name = "zerocopy"
+version = "0.8.48"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9"
+dependencies = [
+ "zerocopy-derive 0.8.48",
+]
+
+[[package]]
+name = "zerocopy-derive"
+version = "0.7.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "zerocopy-derive"
+version = "0.8.48"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "zmij"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
+
+[[package]]
+name = "zune-core"
+version = "0.4.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a"
+
+[[package]]
+name = "zune-core"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cb8a0807f7c01457d0379ba880ba6322660448ddebc890ce29bb64da71fb40f9"
+
+[[package]]
+name = "zune-inflate"
+version = "0.2.54"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02"
+dependencies = [
+ "simd-adler32",
+]
+
+[[package]]
+name = "zune-jpeg"
+version = "0.4.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29ce2c8a9384ad323cf564b67da86e21d3cfdff87908bc1223ed5c99bc792713"
+dependencies = [
+ "zune-core 0.4.12",
+]
+
+[[package]]
+name = "zune-jpeg"
+version = "0.5.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296"
+dependencies = [
+ "zune-core 0.5.1",
+]
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index efe0e62dbe..cbd26ad342 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
-members = ["apps/codegen"]
+members = ["apps/codegen", "crates/image"]
exclude = [
"accounts",
"apps/ensu/src-tauri",
diff --git a/rust/README.md b/rust/README.md
index c870592553..02091b532d 100644
--- a/rust/README.md
+++ b/rust/README.md
@@ -41,7 +41,7 @@
## Contents (this repo)
- `rust/core/` (`ente-core`) - shared, pure Rust code used by clients (crypto + auth, plus small HTTP/URL helpers).
-- `rust/photos/` (`ente_media_inspector`) - shared Photos Rust logic (motion photo, ML, image processing, vector DB).
+- `rust/photos/` (`ente_photos`) - shared Photos Rust logic (motion photo, ML, image processing, vector DB).
- `rust/cli/` (`ente-rs`) - Rust CLI.
- `rust/e2e/` (`ente-e2e`) - live Museum-backed Rust end-to-end tests.
- `rust/ensu/` - LLM chat stack (see `rust/ensu/README.md`).
@@ -113,7 +113,7 @@ mobile/apps/photos/rust/ # Photos app-specific FRB bindings
- `ente-core` - shared business logic (pure Rust, no FFI)
- Docs: `rust/core/docs/crypto.md`, `rust/core/docs/auth.md`
-- `ente_media_inspector` - shared Photos Rust logic
+- `ente_photos` - shared Photos Rust logic
- `ente-rs` - CLI binary
- `ente-e2e` - ignored Rust integration tests that run against a live Museum
- `ente-wasm` - wasm-bindgen wrappers for web
diff --git a/rust/crates/image/Cargo.toml b/rust/crates/image/Cargo.toml
new file mode 100644
index 0000000000..225ff64d89
--- /dev/null
+++ b/rust/crates/image/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "ente_image"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+image = { version = "0.25.5", default-features = true }
+kamadak-exif = "0.6.1"
+ente_heic = { package = "heic_decoder", git = "https://github.com/ente-io/heic-decoder.git", rev = "53303b2936ec19467c61cf75f77e30b399c10445", features = [
+ "image-integration",
+] }
+thiserror = "2.0.11"
+tiff = "0.10.3"
diff --git a/rust/photos/src/image/decode.rs b/rust/crates/image/src/decode.rs
similarity index 86%
rename from rust/photos/src/image/decode.rs
rename to rust/crates/image/src/decode.rs
index e8a93e4b72..269e10653f 100644
--- a/rust/photos/src/image/decode.rs
+++ b/rust/crates/image/src/decode.rs
@@ -1,27 +1,27 @@
use std::{ffi::OsStr, fs::File, io::BufReader, path::Path, sync::Once};
-use exif::{In, Reader as ExifReader, Tag};
-use image::{DynamicImage, ImageFormat, ImageReader, hooks::decoding_hook_registered};
-use libheic_rs::{
+use ente_heic::{
DecodeGuardrails, exif_orientation_hint_from_path,
image_integration::{
apply_exif_orientation_dynamic, register_image_decoder_hooks_with_guardrails,
},
path_extension_is_heif,
};
+use exif::{In, Reader as ExifReader, Tag};
+use image::{DynamicImage, ImageFormat, ImageReader, hooks::decoding_hook_registered};
use tiff::{
ColorType as TiffColorType,
decoder::{Decoder as TiffDecoder, DecodingResult as TiffDecodingResult},
};
-use crate::ml::{
- error::{MlError, MlResult},
+use crate::{
+ error::{ImageError, ImageResult},
types::{DecodedImage, Dimensions},
};
static IMAGE_DECODER_HOOKS_INIT: Once = Once::new();
-pub fn decode_image_from_path(image_path: &str) -> MlResult<DecodedImage> {
+pub fn decode_image_from_path(image_path: &str) -> ImageResult<DecodedImage> {
let decoded_dynamic = decode_with_image_crate(image_path)?;
let oriented = orient_decoded_image(decoded_dynamic, image_path).to_rgb8();
@@ -34,13 +34,13 @@ pub fn decode_image_from_path(image_path: &str) -> MlResult<DecodedImage> {
})
}
-fn decode_with_image_crate(image_path: &str) -> MlResult<DynamicImage> {
+fn decode_with_image_crate(image_path: &str) -> ImageResult<DynamicImage> {
init_image_decoders();
let reader = ImageReader::open(image_path)
- .map_err(|e| MlError::Decode(format!("failed to open image file '{image_path}': {e}")))?
+ .map_err(|e| ImageError::Decode(format!("failed to open image file '{image_path}': {e}")))?
.with_guessed_format()
- .map_err(|e| MlError::Decode(format!("failed to guess image format: {e}")))?;
+ .map_err(|e| ImageError::Decode(format!("failed to guess image format: {e}")))?;
let guessed_format = reader.format();
match reader.decode() {
@@ -53,7 +53,7 @@ fn decode_with_image_crate(image_path: &str) -> MlResult<DynamicImage> {
match decode_with_tiff_crate(image_path) {
Ok(decoded) => Ok(decoded),
- Err(MlError::Decode(fallback_error)) => Err(MlError::Decode(format!(
+ Err(ImageError::Decode(fallback_error)) => Err(ImageError::Decode(format!(
"failed to decode TIFF with image crate: {primary_error}; fallback with tiff crate also failed: {fallback_error}"
))),
Err(other) => Err(other),
@@ -67,20 +67,20 @@ fn should_attempt_tiff_fallback(format: Option<ImageFormat>) -> bool {
matches!(format, Some(ImageFormat::Tiff))
}
-fn decode_with_tiff_crate(image_path: &str) -> MlResult<DynamicImage> {
+fn decode_with_tiff_crate(image_path: &str) -> ImageResult<DynamicImage> {
let file = File::open(image_path)
- .map_err(|e| MlError::Decode(format!("failed to open TIFF file '{image_path}': {e}")))?;
+ .map_err(|e| ImageError::Decode(format!("failed to open TIFF file '{image_path}': {e}")))?;
let mut decoder = TiffDecoder::new(BufReader::new(file))
- .map_err(|e| MlError::Decode(format!("failed to initialize TIFF decoder: {e}")))?;
+ .map_err(|e| ImageError::Decode(format!("failed to initialize TIFF decoder: {e}")))?;
let (width, height) = decoder
.dimensions()
- .map_err(|e| MlError::Decode(format!("failed to read TIFF dimensions: {e}")))?;
+ .map_err(|e| ImageError::Decode(format!("failed to read TIFF dimensions: {e}")))?;
let color_type = decoder
.colortype()
- .map_err(|e| MlError::Decode(format!("failed to read TIFF color type: {e}")))?;
+ .map_err(|e| ImageError::Decode(format!("failed to read TIFF color type: {e}")))?;
let decoded = decoder
.read_image()
- .map_err(|e| MlError::Decode(format!("failed to decode TIFF image data: {e}")))?;
+ .map_err(|e| ImageError::Decode(format!("failed to decode TIFF image data: {e}")))?;
dynamic_image_from_tiff(image_path, width, height, color_type, decoded)
}
@@ -91,7 +91,7 @@ fn dynamic_image_from_tiff(
height: u32,
color_type: TiffColorType,
decoded: TiffDecodingResult,
-) -> MlResult<DynamicImage> {
+) -> ImageResult<DynamicImage> {
match (color_type, decoded) {
(TiffColorType::Gray(8), TiffDecodingResult::U8(data)) => {
let image = image::GrayImage::from_raw(width, height, data)
@@ -134,7 +134,7 @@ fn dynamic_image_from_tiff(
.ok_or_else(|| tiff_buffer_mismatch_error(image_path, width, height, "RGBA(16)"))?;
Ok(DynamicImage::ImageRgba16(image))
}
- (observed_color_type, observed_result_type) => Err(MlError::Decode(format!(
+ (observed_color_type, observed_result_type) => Err(ImageError::Decode(format!(
"unsupported TIFF pixel format for '{image_path}': color_type={observed_color_type:?}, sample_type={}",
tiff_result_type_name(&observed_result_type)
))),
@@ -146,8 +146,8 @@ fn tiff_buffer_mismatch_error(
width: u32,
height: u32,
color_type: &str,
-) -> MlError {
- MlError::Decode(format!(
+) -> ImageError {
+ ImageError::Decode(format!(
"decoded TIFF buffer length does not match dimensions for '{image_path}': {width}x{height}, color_type={color_type}"
))
}
@@ -186,7 +186,7 @@ fn init_image_decoders() {
);
} else if !registration.all_decoder_hooks_registered() {
eprintln!(
- "[ml][decode] libheic-rs decoder hooks only partially registered (usually because another initializer registered first); registration_result=(heic:{}, heif:{}, avif:{}), active_hooks=(heic:{}, heif:{}, avif:{})",
+ "[ml][decode] ente_heic decoder hooks only partially registered (usually because another initializer registered first); registration_result=(heic:{}, heif:{}, avif:{}), active_hooks=(heic:{}, heif:{}, avif:{})",
registration.heic_decoder_hook_registered,
registration.heif_decoder_hook_registered,
registration.avif_decoder_hook_registered,
@@ -198,7 +198,7 @@ fn init_image_decoders() {
debug_assert!(
heic_hook_active || heif_hook_active || avif_hook_active,
- "no libheic-rs image decoder hooks are active"
+ "no ente_heic image decoder hooks are active"
);
});
}
diff --git a/rust/crates/image/src/error.rs b/rust/crates/image/src/error.rs
new file mode 100644
index 0000000000..2137e9c11d
--- /dev/null
+++ b/rust/crates/image/src/error.rs
@@ -0,0 +1,17 @@
+use thiserror::Error;
+
+pub type ImageResult<T> = Result<T, ImageError>;
+
+#[derive(Debug, Error)]
+pub enum ImageError {
+ #[error("decode error: {0}")]
+ Decode(String),
+ #[error("postprocess error: {0}")]
+ Postprocess(String),
+}
+
+impl From<image::ImageError> for ImageError {
+ fn from(value: image::ImageError) -> Self {
+ ImageError::Decode(value.to_string())
+ }
+}
diff --git a/rust/photos/src/image/image_compression.rs b/rust/crates/image/src/image_compression.rs
similarity index 86%
rename from rust/photos/src/image/image_compression.rs
rename to rust/crates/image/src/image_compression.rs
index d381f2c1c7..81af457a9b 100644
--- a/rust/photos/src/image/image_compression.rs
+++ b/rust/crates/image/src/image_compression.rs
@@ -3,7 +3,7 @@ use image::{
codecs::{jpeg::JpegEncoder, png::PngEncoder},
};
-use crate::ml::error::{MlError, MlResult};
+use crate::error::{ImageError, ImageResult};
pub const FACE_THUMBNAIL_JPEG_QUALITY: u8 = 90;
pub const FACE_THUMBNAIL_MIN_DIMENSION: u32 = 512;
@@ -19,16 +19,16 @@ pub fn encode_rgb(
width: u32,
height: u32,
format: EncodedImageFormat,
-) -> MlResult<Vec<u8>> {
+) -> ImageResult<Vec<u8>> {
if width == 0 || height == 0 {
- return Err(MlError::Postprocess(
+ return Err(ImageError::Postprocess(
"cannot encode image with zero width or height".to_string(),
));
}
let expected_len = width as usize * height as usize * 3;
if rgb_bytes.len() != expected_len {
- return Err(MlError::Postprocess(format!(
+ return Err(ImageError::Postprocess(format!(
"invalid RGB buffer length {}, expected {} for {}x{}",
rgb_bytes.len(),
expected_len,
@@ -42,12 +42,12 @@ pub fn encode_rgb(
EncodedImageFormat::Jpeg { quality } => {
JpegEncoder::new_with_quality(&mut encoded, quality)
.write_image(rgb_bytes, width, height, ColorType::Rgb8.into())
- .map_err(|e| MlError::Postprocess(format!("failed to encode JPEG: {e}")))?;
+ .map_err(|e| ImageError::Postprocess(format!("failed to encode JPEG: {e}")))?;
}
EncodedImageFormat::Png => {
PngEncoder::new(&mut encoded)
.write_image(rgb_bytes, width, height, ColorType::Rgb8.into())
- .map_err(|e| MlError::Postprocess(format!("failed to encode PNG: {e}")))?;
+ .map_err(|e| ImageError::Postprocess(format!("failed to encode PNG: {e}")))?;
}
}
Ok(encoded)
diff --git a/rust/crates/image/src/lib.rs b/rust/crates/image/src/lib.rs
new file mode 100644
index 0000000000..6cb7500e83
--- /dev/null
+++ b/rust/crates/image/src/lib.rs
@@ -0,0 +1,7 @@
+pub mod decode;
+pub mod error;
+pub mod image_compression;
+pub mod types;
+
+pub use error::{ImageError, ImageResult};
+pub use types::{DecodedImage, Dimensions};
diff --git a/rust/crates/image/src/types.rs b/rust/crates/image/src/types.rs
new file mode 100644
index 0000000000..3acbe65861
--- /dev/null
+++ b/rust/crates/image/src/types.rs
@@ -0,0 +1,11 @@
+#[derive(Clone, Debug, PartialEq)]
+pub struct Dimensions {
+ pub width: u32,
+ pub height: u32,
+}
+
+#[derive(Clone, Debug)]
+pub struct DecodedImage {
+ pub dimensions: Dimensions,
+ pub rgb: Vec<u8>,
+}
diff --git a/rust/photos/Cargo.lock b/rust/photos/Cargo.lock
index 06f8d3055d..8af2bc83aa 100644
--- a/rust/photos/Cargo.lock
+++ b/rust/photos/Cargo.lock
@@ -608,22 +608,26 @@ dependencies = [
]
[[package]]
-name = "enough"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "177a59811828ea5dbc8927662d444ffee7b55a44696486f1b1a245ae9e652533"
+name = "ente_image"
+version = "0.1.0"
+dependencies = [
+ "heic_decoder",
+ "image",
+ "kamadak-exif",
+ "thiserror 2.0.18",
+ "tiff",
+]
[[package]]
-name = "ente_media_inspector"
+name = "ente_photos"
version = "0.1.0"
dependencies = [
+ "ente_image",
"fast_image_resize",
"half",
"html-escape",
"image",
"imageproc",
- "kamadak-exif",
- "libheic-rs",
"nalgebra 0.33.2",
"ndarray 0.16.1",
"once_cell",
@@ -633,7 +637,6 @@ dependencies = [
"regex",
"tempfile",
"thiserror 2.0.18",
- "tiff",
"usearch",
]
@@ -869,14 +872,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
-name = "heic-decoder"
+name = "heic_decoder"
version = "0.1.0"
-source = "git+https://github.com/laurens-pilot/libheic-rs.git?tag=v0.1.5#18307d94c72c13eb9526655b748c333722ee145b"
+source = "git+https://github.com/ente-io/heic-decoder.git?rev=53303b2936ec19467c61cf75f77e30b399c10445#53303b2936ec19467c61cf75f77e30b399c10445"
dependencies = [
"archmage",
- "enough",
+ "brotli",
+ "flate2",
+ "image",
+ "libc",
+ "png",
+ "rav1d",
"safe_unaligned_simd",
- "whereat",
+ "scuffle-h265",
]
[[package]]
@@ -1455,21 +1463,6 @@ dependencies = [
"cc",
]
-[[package]]
-name = "libheic-rs"
-version = "0.1.5"
-source = "git+https://github.com/laurens-pilot/libheic-rs.git?tag=v0.1.5#18307d94c72c13eb9526655b748c333722ee145b"
-dependencies = [
- "brotli",
- "flate2",
- "heic-decoder",
- "image",
- "libc",
- "png",
- "rav1d",
- "scuffle-h265",
-]
-
[[package]]
name = "libloading"
version = "0.8.9"
@@ -2108,7 +2101,7 @@ dependencies = [
[[package]]
name = "rav1d"
version = "1.1.0"
-source = "git+https://github.com/laurens-pilot/libheic-rs.git?tag=v0.1.5#18307d94c72c13eb9526655b748c333722ee145b"
+source = "git+https://github.com/ente-io/rav1d.git?branch=1.1.0_arm32_stable#05db46f1046b43a14019f31d51f74513a15cd2d0"
dependencies = [
"assert_matches",
"atomig",
@@ -2857,12 +2850,6 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88"
-[[package]]
-name = "whereat"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3ec598a1ade4224cfe3c5dace0d5d7deec9ed670503ff99d4946973c8c094534"
-
[[package]]
name = "wide"
version = "0.7.33"
diff --git a/rust/photos/Cargo.toml b/rust/photos/Cargo.toml
index ea3042bfa6..d012c4527c 100644
--- a/rust/photos/Cargo.toml
+++ b/rust/photos/Cargo.toml
@@ -1,19 +1,15 @@
[package]
-name = "ente_media_inspector"
+name = "ente_photos"
version = "0.1.0"
edition = "2024"
[dependencies]
+ente_image = { path = "../crates/image" }
quick-xml = "0.37"
usearch = "2.21.3"
fast_image_resize = { version = "5.5.0", features = ["image", "rayon"] }
image = { version = "0.25.5", default-features = true }
imageproc = "0.25.0"
-kamadak-exif = "0.6.1"
-libheic-rs = { git = "https://github.com/laurens-pilot/libheic-rs.git", tag = "v0.1.5", features = [
- "image-integration",
-] }
-tiff = "0.10.3"
nalgebra = "0.33.2"
ndarray = "0.16.1"
half = "2.1"
diff --git a/rust/photos/src/image/mod.rs b/rust/photos/src/image/mod.rs
deleted file mode 100644
index 0e18d4e62f..0000000000
--- a/rust/photos/src/image/mod.rs
+++ /dev/null
@@ -1,2 +0,0 @@
-pub mod decode;
-pub mod image_compression;
diff --git a/rust/photos/src/lib.rs b/rust/photos/src/lib.rs
index c3df25e4a5..032470eb92 100644
--- a/rust/photos/src/lib.rs
+++ b/rust/photos/src/lib.rs
@@ -1,535 +1,7 @@
-pub mod image;
pub mod ml;
-pub mod vector_db;
+pub mod motion_photo;
-use std::collections::HashMap;
-use std::fmt::{Display, Formatter};
-use std::fs;
-use std::path::{Path, PathBuf};
-
-const XMP_MARKER_BEGIN: &[u8] = b"<x:xmpmeta";
-const XMP_MARKER_END: &[u8] = b"</x:xmpmeta>";
-const ITEM_LENGTH_OFFSET_KEY: &str = "Item:Length";
-const GCAMERA_MOTION_PHOTO: &str = "GCamera:MotionPhoto";
-const ITEM_MIME_TYPE: &str = "Item:Mime";
-const FILE_OFFSET_KEYS: [&str; 2] = [ITEM_LENGTH_OFFSET_KEY, "GCamera:MicroVideoOffset"];
-/// Minimum valid ftyp box size: 4 (size) + 4 (type) = 8 bytes.
-const FTYP_BOX_MIN_SIZE: u32 = 8;
-
-/// Maximum ftyp box size we consider plausible for an embedded motion video.
-/// Real ftyp boxes are typically 16–32 bytes. We use a generous ceiling to
-/// handle exotic compatible-brand lists while rejecting garbage matches.
-const FTYP_BOX_MAX_SIZE: u32 = 1024;
-
-/// Known major brands for MP4, QuickTime, and related video container formats.
-/// Image-only brands (heic, heif, mif1, avif) are intentionally excluded.
-const KNOWN_VIDEO_BRANDS: &[[u8; 4]] = &[
- *b"isom", *b"iso2", *b"iso5", *b"iso6", *b"mp41", *b"mp42", *b"mp71", *b"M4V ", *b"M4VP",
- *b"avc1", *b"mmp4", *b"3gp4", *b"3gp5", *b"3gp6", *b"qt ", *b"MSNV", *b"dash", *b"f4v ",
-];
-
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct VideoIndex {
- pub start: usize,
- pub end: usize,
-}
-
-#[derive(Debug)]
-pub enum MotionPhotoError {
- Io(std::io::Error),
- Xml(String),
- InvalidIndex,
- VideoNotFound,
-}
-
-impl Display for MotionPhotoError {
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- match self {
- Self::Io(err) => write!(f, "io error: {err}"),
- Self::Xml(err) => write!(f, "xmp parse error: {err}"),
- Self::InvalidIndex => write!(f, "invalid video index"),
- Self::VideoNotFound => write!(f, "unable to find video index"),
- }
- }
-}
-
-impl std::error::Error for MotionPhotoError {}
-
-impl From<std::io::Error> for MotionPhotoError {
- fn from(value: std::io::Error) -> Self {
- Self::Io(value)
- }
-}
-
-pub fn get_motion_video_index_from_path<P: AsRef<Path>>(
- file_path: P,
-) -> Result<Option<VideoIndex>, MotionPhotoError> {
- let bytes = fs::read(file_path)?;
- Ok(get_motion_video_index(&bytes))
-}
-
-fn get_motion_video_index(bytes: &[u8]) -> Option<VideoIndex> {
- if let Some(index) = find_largest_ftyp_segment(bytes) {
- return Some(index);
- }
-
- extract_video_index_from_xmp(bytes)
-}
-
-pub fn extract_motion_video_from_path<P: AsRef<Path>>(
- file_path: P,
- index: Option<VideoIndex>,
-) -> Result<Option<Vec<u8>>, MotionPhotoError> {
- let bytes = fs::read(file_path)?;
- extract_motion_video(&bytes, index).map(Some)
-}
-
-fn extract_motion_video(
- bytes: &[u8],
- index: Option<VideoIndex>,
-) -> Result<Vec<u8>, MotionPhotoError> {
- let video_index = index.or_else(|| get_motion_video_index(bytes));
- let video_index = match video_index {
- Some(value) => value,
- None => return Err(MotionPhotoError::VideoNotFound),
- };
-
- if video_index.start >= video_index.end || video_index.end > bytes.len() {
- return Err(MotionPhotoError::InvalidIndex);
- }
-
- Ok(bytes[video_index.start..video_index.end].to_vec())
-}
-
-pub fn extract_motion_video_file_from_path<P: AsRef<Path>, Q: AsRef<Path>>(
- file_path: P,
- destination_directory: Q,
- file_name: &str,
- index: Option<VideoIndex>,
-) -> Result<Option<PathBuf>, MotionPhotoError> {
- let video = match extract_motion_video_from_path(file_path, index)? {
- Some(data) => data,
- None => return Ok(None),
- };
- fs::create_dir_all(destination_directory.as_ref())?;
- let output = destination_directory.as_ref().join(file_name);
- fs::write(&output, video)?;
- Ok(Some(output))
-}
-
-pub fn extract_xmp_from_path<P: AsRef<Path>>(
- file_path: P,
-) -> Result<HashMap<String, String>, MotionPhotoError> {
- let bytes = fs::read(file_path)?;
- extract_xmp(&bytes)
-}
-
-fn extract_xmp(source: &[u8]) -> Result<HashMap<String, String>, MotionPhotoError> {
- let (begin, end) = extract_xmp_bounds(source)
- .ok_or_else(|| MotionPhotoError::Xml("xmp markers not found".to_string()))?;
- let xml_bytes = &source[begin..end];
- parse_xmp_attributes(xml_bytes)
-}
-
-fn extract_video_index_from_xmp(bytes: &[u8]) -> Option<VideoIndex> {
- let xmp_data = extract_xmp(bytes).ok()?;
- let size = bytes.len();
-
- for offset_key in FILE_OFFSET_KEYS {
- let Some(raw_offset) = xmp_data.get(offset_key) else {
- continue;
- };
- let Ok(offset_from_end) = raw_offset.parse::<usize>() else {
- continue;
- };
-
- if offset_key == ITEM_LENGTH_OFFSET_KEY
- && offset_from_end + offset_from_end < size
- && !has_motion_photo_tags(&xmp_data)
- {
- continue;
- }
-
- if offset_from_end == 0 || offset_from_end > size {
- continue;
- }
-
- return Some(VideoIndex {
- start: size - offset_from_end,
- end: size,
- });
- }
-
- None
-}
-
-fn has_motion_photo_tags(xmp_data: &HashMap<String, String>) -> bool {
- if xmp_data.contains_key(GCAMERA_MOTION_PHOTO) {
- return true;
- }
-
- xmp_data
- .get(ITEM_MIME_TYPE)
- .map(|value| value.starts_with("video"))
- .unwrap_or(false)
-}
-
-fn extract_xmp_bounds(source: &[u8]) -> Option<(usize, usize)> {
- let offset_begin = find_subslice(source, XMP_MARKER_BEGIN)?;
- let offset_end_start = find_subslice(&source[offset_begin..], XMP_MARKER_END)? + offset_begin;
- let offset_end = offset_end_start + XMP_MARKER_END.len();
- Some((offset_begin, offset_end))
-}
-
-fn parse_xmp_attributes(xml_bytes: &[u8]) -> Result<HashMap<String, String>, MotionPhotoError> {
- use quick_xml::Reader;
- use quick_xml::events::Event;
-
- let xml_buffer = String::from_utf8_lossy(xml_bytes);
- let mut reader = Reader::from_str(&xml_buffer);
- let mut result = HashMap::<String, String>::new();
- let mut scratch = Vec::<u8>::new();
-
- loop {
- match reader.read_event_into(&mut scratch) {
- Ok(Event::Start(element)) | Ok(Event::Empty(element)) => {
- for attribute in element.attributes() {
- let attribute = attribute.map_err(|err| {
- MotionPhotoError::Xml(format!("invalid attribute: {err}"))
- })?;
- let key = std::str::from_utf8(attribute.key.as_ref())
- .map_err(|err| MotionPhotoError::Xml(format!("invalid key bytes: {err}")))?
- .trim()
- .to_string();
- if key.starts_with("xmlns:") || key.starts_with("xml:") {
- continue;
- }
-
- let value = attribute
- .decode_and_unescape_value(reader.decoder())
- .map_err(|err| MotionPhotoError::Xml(format!("invalid value: {err}")))?
- .to_string();
- result.insert(key, value);
- }
- }
- Ok(Event::Eof) => break,
- Ok(_) => {}
- Err(err) => return Err(MotionPhotoError::Xml(format!("xml parse failed: {err}"))),
- }
- scratch.clear();
- }
-
- Ok(result)
-}
-
-fn find_subslice(haystack: &[u8], needle: &[u8]) -> Option<usize> {
- if needle.is_empty() {
- return Some(0);
- }
- haystack
- .windows(needle.len())
- .position(|window| window == needle)
-}
-
-/// Finds all valid embedded MP4/QuickTime ftyp boxes and returns the bounds of
-/// the **largest** individual segment.
-///
-/// Some motion photos embed two MP4s: a short preview clip and the full
-/// video. The ordering varies by device, so we cannot simply pick the first
-/// or last. Instead we measure each segment from one ftyp to the next
-/// candidate, or to EOF for the last one, and return the largest slice.
-///
-/// A candidate ftyp is accepted when:
-/// 1. The 4 bytes before `ftyp` encode a box size in [8, 1024].
-/// 2. The 4 bytes after `ftyp` are a recognised video brand.
-/// 3. The box does not start at byte 0 (that would be a standalone MP4).
-fn find_largest_ftyp_segment(bytes: &[u8]) -> Option<VideoIndex> {
- let len = bytes.len();
- if len < 12 {
- return None;
- }
-
- // Collect all valid ftyp box starts.
- let mut starts: Vec<usize> = Vec::new();
- let last = len.saturating_sub(8);
- let mut i = 4;
- while i <= last {
- if bytes[i] == b'f' && bytes[i + 1] == b't' && bytes[i + 2] == b'y' && bytes[i + 3] == b'p'
- {
- let box_start = i - 4;
- let box_size = u32::from_be_bytes([
- bytes[box_start],
- bytes[box_start + 1],
- bytes[box_start + 2],
- bytes[box_start + 3],
- ]);
- if (FTYP_BOX_MIN_SIZE..=FTYP_BOX_MAX_SIZE).contains(&box_size) && box_start > 0 {
- let brand: [u8; 4] = [bytes[i + 4], bytes[i + 5], bytes[i + 6], bytes[i + 7]];
- if KNOWN_VIDEO_BRANDS.contains(&brand) {
- starts.push(box_start);
- }
- }
- }
- i += 1;
- }
-
- if starts.is_empty() {
- return None;
- }
- if starts.len() == 1 {
- return Some(VideoIndex {
- start: starts[0],
- end: len,
- });
- }
-
- // Pick the segment with the most bytes.
- // Segment size = next_ftyp_start - this_ftyp_start (or EOF for last).
- let mut best_index = VideoIndex {
- start: starts[0],
- end: starts[1],
- };
- let mut best_size = 0usize;
- for (idx, &start) in starts.iter().enumerate() {
- let end = if idx + 1 < starts.len() {
- starts[idx + 1]
- } else {
- len
- };
- let size = end - start;
- if size > best_size {
- best_size = size;
- best_index = VideoIndex { start, end };
- }
- }
- Some(best_index)
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use tempfile::tempdir;
-
- /// Build a minimal ftyp box with the given major brand (16 bytes).
- fn make_ftyp_box(brand: &[u8; 4]) -> Vec<u8> {
- let mut buf = Vec::with_capacity(16);
- buf.extend_from_slice(&16u32.to_be_bytes()); // box size
- buf.extend_from_slice(b"ftyp");
- buf.extend_from_slice(brand);
- buf.extend_from_slice(&0u32.to_be_bytes()); // minor version
- buf
- }
-
- fn xmp_with_offset(offset: usize, extra_attributes: &str) -> String {
- format!(
- r#"<x:xmpmeta><rdf:RDF><rdf:Description xmlns:x="adobe:ns:meta/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" Item:Length="{offset}" {extra_attributes} /></rdf:RDF></x:xmpmeta>"#
- )
- }
-
- fn append_video_payload(mut bytes: Vec<u8>, payload_len: usize) -> Vec<u8> {
- bytes.extend(std::iter::repeat_n(0xAB, payload_len));
- bytes
- }
-
- fn bytes_with_xmp_and_video(offset: usize, extra_attributes: &str) -> Vec<u8> {
- let mut bytes = b"jpeg-prefix-data".to_vec();
- bytes.extend_from_slice(xmp_with_offset(offset, extra_attributes).as_bytes());
- append_video_payload(bytes, offset)
- }
-
- #[test]
- fn finds_ftyp_box_in_jpeg_like_file() {
- let mut bytes = b"jpeg-prefix".to_vec();
- bytes.extend_from_slice(&make_ftyp_box(b"mp42"));
- bytes.extend_from_slice(&[1, 2, 3, 4]);
-
- let index = get_motion_video_index(&bytes).expect("video index should exist");
- assert_eq!(index.start, "jpeg-prefix".len());
- assert_eq!(index.end, bytes.len());
- }
-
- #[test]
- fn picks_largest_segment_when_multiple_ftyp_exist() {
- // Scenario 1: first segment is larger (full video first, preview second)
- let mut bytes = b"jpeg-prefix".to_vec();
- let first_start = bytes.len();
- bytes.extend_from_slice(&make_ftyp_box(b"mp42"));
- bytes.extend_from_slice(&[0xAA; 500]); // large segment
- let second_start = bytes.len();
- bytes.extend_from_slice(&make_ftyp_box(b"isom"));
- bytes.extend_from_slice(&[0xBB; 50]); // small segment
-
- let index = get_motion_video_index(&bytes).expect("video index should exist");
- assert_eq!(index.start, first_start);
- assert_eq!(index.end, second_start);
- let extracted =
- extract_motion_video(&bytes, Some(index)).expect("video bytes should extract");
- assert_eq!(extracted.len(), second_start - first_start);
-
- // Scenario 2: second segment is larger (preview first, full video second)
- let mut bytes2 = b"jpeg-prefix".to_vec();
- bytes2.extend_from_slice(&make_ftyp_box(b"mp42"));
- bytes2.extend_from_slice(&[0xCC; 50]); // small segment
- let second_start = bytes2.len();
- bytes2.extend_from_slice(&make_ftyp_box(b"isom"));
- bytes2.extend_from_slice(&[0xDD; 500]); // large segment
-
- let index2 = get_motion_video_index(&bytes2).expect("video index should exist");
- assert_eq!(index2.start, second_start);
- assert_eq!(index2.end, bytes2.len());
- }
-
- #[test]
- fn detects_various_mp4_brands() {
- for brand in [
- b"isom", b"mp41", b"mp42", b"avc1", b"iso2", b"M4V ", b"qt ",
- ] {
- let mut bytes = b"jpeg-prefix-data".to_vec();
- bytes.extend_from_slice(&make_ftyp_box(brand));
- bytes.extend_from_slice(&[0xDE, 0xAD]);
- let index = get_motion_video_index(&bytes)
- .unwrap_or_else(|| panic!("should detect brand {:?}", std::str::from_utf8(brand)));
- assert_eq!(index.start, b"jpeg-prefix-data".len());
- }
- }
-
- #[test]
- fn rejects_non_video_ftyp_brands() {
- for brand in [b"heic", b"heif", b"mif1", b"avif"] {
- let mut bytes = b"jpeg-prefix-data".to_vec();
- bytes.extend_from_slice(&make_ftyp_box(brand));
- bytes.extend_from_slice(&[0xDE, 0xAD]);
- assert_eq!(
- get_motion_video_index(&bytes),
- None,
- "brand {:?} should not be detected as video",
- std::str::from_utf8(brand)
- );
- }
- }
-
- #[test]
- fn detects_ftyp_with_larger_box_size() {
- let mut bytes = b"jpeg-prefix-data".to_vec();
- let box_start = bytes.len();
- // 28-byte ftyp box (like Pixel 6): size + "ftyp" + brand + version + compat brands
- bytes.extend_from_slice(&28u32.to_be_bytes());
- bytes.extend_from_slice(b"ftyp");
- bytes.extend_from_slice(b"isom");
- bytes.extend_from_slice(&0x00020000u32.to_be_bytes());
- bytes.extend_from_slice(b"isomiso2mp41");
- bytes.extend_from_slice(b"video-payload");
-
- let index = get_motion_video_index(&bytes).expect("should detect 28-byte ftyp box");
- assert_eq!(index.start, box_start);
- }
-
- #[test]
- fn rejects_ftyp_at_file_start() {
- let mut bytes = make_ftyp_box(b"mp42");
- bytes.extend_from_slice(b"moov-data-here");
- assert_eq!(get_motion_video_index(&bytes), None);
- }
-
- #[test]
- fn rejects_ftyp_with_implausible_box_size() {
- let mut bytes = b"jpeg-prefix-data".to_vec();
- bytes.extend_from_slice(&0u32.to_be_bytes()); // box size 0 (invalid)
- bytes.extend_from_slice(b"ftyp");
- bytes.extend_from_slice(b"mp42");
- bytes.extend_from_slice(&0u32.to_be_bytes());
- assert_eq!(get_motion_video_index(&bytes), None);
- }
-
- #[test]
- fn finds_xmp_offset_for_jpeg_like_file() {
- let bytes = bytes_with_xmp_and_video(24, "GCamera:MotionPhoto=\"1\"");
- let index = get_motion_video_index(&bytes).expect("video index should exist");
- assert_eq!(index.start, bytes.len() - 24);
- assert_eq!(index.end, bytes.len());
- }
-
- #[test]
- fn finds_xmp_offset_for_heic_like_file() {
- let mut bytes = b"heic-prefix-data".to_vec();
- bytes.extend_from_slice(xmp_with_offset(32, "Item:Mime=\"video/mp4\"").as_bytes());
- bytes = append_video_payload(bytes, 32);
-
- let index = get_motion_video_index(&bytes).expect("video index should exist");
- assert_eq!(index.start, bytes.len() - 32);
- assert_eq!(index.end, bytes.len());
- }
-
- #[test]
- fn returns_none_for_non_motion_file() {
- let bytes = b"plain-still-image-data-without-motion-video-or-xmp".to_vec();
- assert_eq!(get_motion_video_index(&bytes), None);
- }
-
- #[test]
- fn skips_invalid_item_length_without_motion_tags() {
- let mut bytes = b"prefix-data".to_vec();
- bytes.extend_from_slice(xmp_with_offset(8, "").as_bytes());
- bytes.extend_from_slice(b"small-tail");
- assert_eq!(get_motion_video_index(&bytes), None);
- }
-
- #[test]
- fn extracts_video_bytes_for_valid_index() {
- let bytes = bytes_with_xmp_and_video(20, "GCamera:MotionPhoto=\"1\"");
- let video = extract_motion_video(&bytes, None).expect("video bytes should extract");
- assert_eq!(video.len(), 20);
- assert!(video.iter().all(|byte| *byte == 0xAB));
- }
-
- #[test]
- fn extracts_xmp_attributes() {
- let bytes = bytes_with_xmp_and_video(
- 16,
- "GPano:ProjectionType=\"equirectangular\" GCamera:MotionPhoto=\"1\"",
- );
- let xmp = extract_xmp(&bytes).expect("xmp must parse");
- assert_eq!(
- xmp.get("GPano:ProjectionType"),
- Some(&"equirectangular".to_string())
- );
- assert_eq!(xmp.get("GCamera:MotionPhoto"), Some(&"1".to_string()));
- }
-
- #[test]
- fn path_apis_work_for_various_file_types() {
- let temp = tempdir().expect("temp dir");
- let jpeg_motion = temp.path().join("motion.jpg");
- let heic_motion = temp.path().join("motion.heic");
- let non_motion = temp.path().join("normal.jpg");
-
- fs::write(
- &jpeg_motion,
- bytes_with_xmp_and_video(40, "GCamera:MotionPhoto=\"1\""),
- )
- .expect("write jpeg motion");
-
- fs::write(
- &heic_motion,
- bytes_with_xmp_and_video(28, "Item:Mime=\"video/mp4\""),
- )
- .expect("write heic motion");
-
- fs::write(&non_motion, b"non-motion-image").expect("write still");
-
- assert!(
- get_motion_video_index_from_path(&jpeg_motion)
- .expect("jpeg read")
- .is_some()
- );
- assert!(
- get_motion_video_index_from_path(&heic_motion)
- .expect("heic read")
- .is_some()
- );
- assert_eq!(
- get_motion_video_index_from_path(&non_motion).expect("still read"),
- None
- );
- }
-}
+pub use motion_photo::{
+ MotionPhotoError, VideoIndex, extract_motion_video_file_from_path,
+ extract_motion_video_from_path, extract_xmp_from_path, get_motion_video_index_from_path,
+};
diff --git a/rust/photos/src/ml/error.rs b/rust/photos/src/ml/error.rs
index 86c1511556..bf76b4be7a 100644
--- a/rust/photos/src/ml/error.rs
+++ b/rust/photos/src/ml/error.rs
@@ -29,3 +29,12 @@ impl From<image::ImageError> for MlError {
MlError::Decode(value.to_string())
}
}
+
+impl From<ente_image::ImageError> for MlError {
+ fn from(value: ente_image::ImageError) -> Self {
+ match value {
+ ente_image::ImageError::Decode(message) => MlError::Decode(message),
+ ente_image::ImageError::Postprocess(message) => MlError::Postprocess(message),
+ }
+ }
+}
diff --git a/rust/photos/src/ml/face/thumbnail.rs b/rust/photos/src/ml/face/thumbnail.rs
index f1b5fd1fdf..febffd936d 100644
--- a/rust/photos/src/ml/face/thumbnail.rs
+++ b/rust/photos/src/ml/face/thumbnail.rs
@@ -3,9 +3,10 @@ use fast_image_resize::{
images::{Image as FirImage, ImageRef as FirImageRef},
};
-use crate::image::image_compression::{
+use ente_image::image_compression::{
EncodedImageFormat, FACE_THUMBNAIL_JPEG_QUALITY, FACE_THUMBNAIL_MIN_DIMENSION, encode_rgb,
};
+
use crate::ml::{
error::{MlError, MlResult},
types::DecodedImage,
diff --git a/rust/photos/src/ml/indexing.rs b/rust/photos/src/ml/indexing.rs
index 86689f80c9..7659a55060 100644
--- a/rust/photos/src/ml/indexing.rs
+++ b/rust/photos/src/ml/indexing.rs
@@ -1,21 +1,19 @@
-use crate::{
- image::decode::decode_image_from_path,
- ml::{
- clip::{
- image::run_clip_image, text::run_clip_text_query,
- tokenizer::tokenize_clip_text as tokenize_clip_text_impl,
- },
- error::{MlError, MlResult},
- face::{align::run_face_alignment, detect::run_face_detection, embed::run_face_embedding},
- pet::{
- align::run_pet_face_alignment,
- detect::{run_pet_body_detection, run_pet_face_detection},
- embed::{run_pet_body_embedding, run_pet_face_embedding},
- },
- runtime::{self, ExecutionProviderPolicy, MlRuntimeConfig, ModelPaths},
- types::{self, ClipResult, Dimensions, FaceResult, PetBodyResult, PetFaceResult},
+use crate::ml::{
+ clip::{
+ image::run_clip_image, text::run_clip_text_query,
+ tokenizer::tokenize_clip_text as tokenize_clip_text_impl,
+ },
+ error::{MlError, MlResult},
+ face::{align::run_face_alignment, detect::run_face_detection, embed::run_face_embedding},
+ pet::{
+ align::run_pet_face_alignment,
+ detect::{run_pet_body_detection, run_pet_face_detection},
+ embed::{run_pet_body_embedding, run_pet_face_embedding},
},
+ runtime::{self, ExecutionProviderPolicy, MlRuntimeConfig, ModelPaths},
+ types::{self, ClipResult, Dimensions, FaceResult, PetBodyResult, PetFaceResult},
};
+use ente_image::decode::decode_image_from_path;
#[derive(Clone, Debug)]
pub struct AnalyzeImageRequest {
diff --git a/rust/photos/src/ml/mod.rs b/rust/photos/src/ml/mod.rs
index a492cbe1ad..2d13e41afc 100644
--- a/rust/photos/src/ml/mod.rs
+++ b/rust/photos/src/ml/mod.rs
@@ -7,3 +7,4 @@ pub mod pet;
pub mod preprocess;
pub mod runtime;
pub mod types;
+pub mod vector_db;
diff --git a/rust/photos/src/ml/types.rs b/rust/photos/src/ml/types.rs
index 2a64859d6a..39413c7834 100644
--- a/rust/photos/src/ml/types.rs
+++ b/rust/photos/src/ml/types.rs
@@ -1,14 +1,4 @@
-#[derive(Clone, Debug, PartialEq)]
-pub struct Dimensions {
- pub width: u32,
- pub height: u32,
-}
-
-#[derive(Clone, Debug)]
-pub struct DecodedImage {
- pub dimensions: Dimensions,
- pub rgb: Vec<u8>,
-}
+pub use ente_image::{DecodedImage, Dimensions};
#[derive(Clone, Debug)]
pub struct FaceDetection {
diff --git a/rust/photos/src/vector_db.rs b/rust/photos/src/ml/vector_db.rs
similarity index 100%
rename from rust/photos/src/vector_db.rs
rename to rust/photos/src/ml/vector_db.rs
diff --git a/rust/photos/src/motion_photo/ftyp.rs b/rust/photos/src/motion_photo/ftyp.rs
new file mode 100644
index 0000000000..fa7977e44e
--- /dev/null
+++ b/rust/photos/src/motion_photo/ftyp.rs
@@ -0,0 +1,90 @@
+use super::VideoIndex;
+
+/// Minimum valid ftyp box size: 4 (size) + 4 (type) = 8 bytes.
+const FTYP_BOX_MIN_SIZE: u32 = 8;
+
+/// Maximum ftyp box size we consider plausible for an embedded motion video.
+/// Real ftyp boxes are typically 16-32 bytes. We use a generous ceiling to
+/// handle exotic compatible-brand lists while rejecting garbage matches.
+const FTYP_BOX_MAX_SIZE: u32 = 1024;
+
+/// Known major brands for MP4, QuickTime, and related video container formats.
+/// Image-only brands (heic, heif, mif1, avif) are intentionally excluded.
+const KNOWN_VIDEO_BRANDS: &[[u8; 4]] = &[
+ *b"isom", *b"iso2", *b"iso5", *b"iso6", *b"mp41", *b"mp42", *b"mp71", *b"M4V ", *b"M4VP",
+ *b"avc1", *b"mmp4", *b"3gp4", *b"3gp5", *b"3gp6", *b"qt ", *b"MSNV", *b"dash", *b"f4v ",
+];
+
+/// Finds all valid embedded MP4/QuickTime ftyp boxes and returns the bounds of
+/// the **largest** individual segment.
+///
+/// Some motion photos embed two MP4s: a short preview clip and the full
+/// video. The ordering varies by device, so we cannot simply pick the first
+/// or last. Instead we measure each segment from one ftyp to the next
+/// candidate, or to EOF for the last one, and return the largest slice.
+///
+/// A candidate ftyp is accepted when:
+/// 1. The 4 bytes before `ftyp` encode a box size in [8, 1024].
+/// 2. The 4 bytes after `ftyp` are a recognised video brand.
+/// 3. The box does not start at byte 0 (that would be a standalone MP4).
+pub(super) fn find_largest_ftyp_segment(bytes: &[u8]) -> Option<VideoIndex> {
+ let len = bytes.len();
+ if len < 12 {
+ return None;
+ }
+
+ // Collect all valid ftyp box starts.
+ let mut starts: Vec<usize> = Vec::new();
+ let last = len.saturating_sub(8);
+ let mut i = 4;
+ while i <= last {
+ if bytes[i] == b'f' && bytes[i + 1] == b't' && bytes[i + 2] == b'y' && bytes[i + 3] == b'p'
+ {
+ let box_start = i - 4;
+ let box_size = u32::from_be_bytes([
+ bytes[box_start],
+ bytes[box_start + 1],
+ bytes[box_start + 2],
+ bytes[box_start + 3],
+ ]);
+ if (FTYP_BOX_MIN_SIZE..=FTYP_BOX_MAX_SIZE).contains(&box_size) && box_start > 0 {
+ let brand: [u8; 4] = [bytes[i + 4], bytes[i + 5], bytes[i + 6], bytes[i + 7]];
+ if KNOWN_VIDEO_BRANDS.contains(&brand) {
+ starts.push(box_start);
+ }
+ }
+ }
+ i += 1;
+ }
+
+ if starts.is_empty() {
+ return None;
+ }
+ if starts.len() == 1 {
+ return Some(VideoIndex {
+ start: starts[0],
+ end: len,
+ });
+ }
+
+ // Pick the segment with the most bytes.
+ // Segment size = next_ftyp_start - this_ftyp_start (or EOF for last).
+ let mut best_index = VideoIndex {
+ start: starts[0],
+ end: starts[1],
+ };
+ let mut best_size = 0usize;
+ for (idx, &start) in starts.iter().enumerate() {
+ let end = if idx + 1 < starts.len() {
+ starts[idx + 1]
+ } else {
+ len
+ };
+ let size = end - start;
+ if size > best_size {
+ best_size = size;
+ best_index = VideoIndex { start, end };
+ }
+ }
+ Some(best_index)
+}
diff --git a/rust/photos/src/motion_photo/mod.rs b/rust/photos/src/motion_photo/mod.rs
new file mode 100644
index 0000000000..5e4a248750
--- /dev/null
+++ b/rust/photos/src/motion_photo/mod.rs
@@ -0,0 +1,382 @@
+mod ftyp;
+mod xmp;
+
+use ftyp::find_largest_ftyp_segment;
+use std::collections::HashMap;
+use std::fmt::{Display, Formatter};
+use std::fs;
+use std::path::{Path, PathBuf};
+
+const ITEM_LENGTH_OFFSET_KEY: &str = "Item:Length";
+const GCAMERA_MOTION_PHOTO: &str = "GCamera:MotionPhoto";
+const ITEM_MIME_TYPE: &str = "Item:Mime";
+const FILE_OFFSET_KEYS: [&str; 2] = [ITEM_LENGTH_OFFSET_KEY, "GCamera:MicroVideoOffset"];
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct VideoIndex {
+ pub start: usize,
+ pub end: usize,
+}
+
+#[derive(Debug)]
+pub enum MotionPhotoError {
+ Io(std::io::Error),
+ Xml(String),
+ InvalidIndex,
+ VideoNotFound,
+}
+
+impl Display for MotionPhotoError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ match self {
+ Self::Io(err) => write!(f, "io error: {err}"),
+ Self::Xml(err) => write!(f, "xmp parse error: {err}"),
+ Self::InvalidIndex => write!(f, "invalid video index"),
+ Self::VideoNotFound => write!(f, "unable to find video index"),
+ }
+ }
+}
+
+impl std::error::Error for MotionPhotoError {}
+
+impl From<std::io::Error> for MotionPhotoError {
+ fn from(value: std::io::Error) -> Self {
+ Self::Io(value)
+ }
+}
+
+pub fn get_motion_video_index_from_path<P: AsRef<Path>>(
+ file_path: P,
+) -> Result<Option<VideoIndex>, MotionPhotoError> {
+ let bytes = fs::read(file_path)?;
+ Ok(get_motion_video_index(&bytes))
+}
+
+fn get_motion_video_index(bytes: &[u8]) -> Option<VideoIndex> {
+ if let Some(index) = find_largest_ftyp_segment(bytes) {
+ return Some(index);
+ }
+
+ extract_video_index_from_xmp(bytes)
+}
+
+pub fn extract_motion_video_from_path<P: AsRef<Path>>(
+ file_path: P,
+ index: Option<VideoIndex>,
+) -> Result<Option<Vec<u8>>, MotionPhotoError> {
+ let bytes = fs::read(file_path)?;
+ extract_motion_video(&bytes, index).map(Some)
+}
+
+fn extract_motion_video(
+ bytes: &[u8],
+ index: Option<VideoIndex>,
+) -> Result<Vec<u8>, MotionPhotoError> {
+ let video_index = index.or_else(|| get_motion_video_index(bytes));
+ let video_index = match video_index {
+ Some(value) => value,
+ None => return Err(MotionPhotoError::VideoNotFound),
+ };
+
+ if video_index.start >= video_index.end || video_index.end > bytes.len() {
+ return Err(MotionPhotoError::InvalidIndex);
+ }
+
+ Ok(bytes[video_index.start..video_index.end].to_vec())
+}
+
+pub fn extract_motion_video_file_from_path<P: AsRef<Path>, Q: AsRef<Path>>(
+ file_path: P,
+ destination_directory: Q,
+ file_name: &str,
+ index: Option<VideoIndex>,
+) -> Result<Option<PathBuf>, MotionPhotoError> {
+ let video = match extract_motion_video_from_path(file_path, index)? {
+ Some(data) => data,
+ None => return Ok(None),
+ };
+ fs::create_dir_all(destination_directory.as_ref())?;
+ let output = destination_directory.as_ref().join(file_name);
+ fs::write(&output, video)?;
+ Ok(Some(output))
+}
+
+pub fn extract_xmp_from_path<P: AsRef<Path>>(
+ file_path: P,
+) -> Result<HashMap<String, String>, MotionPhotoError> {
+ let bytes = fs::read(file_path)?;
+ xmp::extract_xmp(&bytes)
+}
+
+fn extract_video_index_from_xmp(bytes: &[u8]) -> Option<VideoIndex> {
+ let xmp_data = xmp::extract_xmp(bytes).ok()?;
+ let size = bytes.len();
+
+ for offset_key in FILE_OFFSET_KEYS {
+ let Some(raw_offset) = xmp_data.get(offset_key) else {
+ continue;
+ };
+ let Ok(offset_from_end) = raw_offset.parse::<usize>() else {
+ continue;
+ };
+
+ if offset_key == ITEM_LENGTH_OFFSET_KEY
+ && offset_from_end + offset_from_end < size
+ && !has_motion_photo_tags(&xmp_data)
+ {
+ continue;
+ }
+
+ if offset_from_end == 0 || offset_from_end > size {
+ continue;
+ }
+
+ return Some(VideoIndex {
+ start: size - offset_from_end,
+ end: size,
+ });
+ }
+
+ None
+}
+
+fn has_motion_photo_tags(xmp_data: &HashMap<String, String>) -> bool {
+ if xmp_data.contains_key(GCAMERA_MOTION_PHOTO) {
+ return true;
+ }
+
+ xmp_data
+ .get(ITEM_MIME_TYPE)
+ .map(|value| value.starts_with("video"))
+ .unwrap_or(false)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use std::fs;
+ use tempfile::tempdir;
+
+ /// Build a minimal ftyp box with the given major brand (16 bytes).
+ fn make_ftyp_box(brand: &[u8; 4]) -> Vec<u8> {
+ let mut buf = Vec::with_capacity(16);
+ buf.extend_from_slice(&16u32.to_be_bytes()); // box size
+ buf.extend_from_slice(b"ftyp");
+ buf.extend_from_slice(brand);
+ buf.extend_from_slice(&0u32.to_be_bytes()); // minor version
+ buf
+ }
+
+ fn xmp_with_offset(offset: usize, extra_attributes: &str) -> String {
+ format!(
+ r#"<x:xmpmeta><rdf:RDF><rdf:Description xmlns:x="adobe:ns:meta/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" Item:Length="{offset}" {extra_attributes} /></rdf:RDF></x:xmpmeta>"#
+ )
+ }
+
+ fn append_video_payload(mut bytes: Vec<u8>, payload_len: usize) -> Vec<u8> {
+ bytes.extend(std::iter::repeat_n(0xAB, payload_len));
+ bytes
+ }
+
+ fn bytes_with_xmp_and_video(offset: usize, extra_attributes: &str) -> Vec<u8> {
+ let mut bytes = b"jpeg-prefix-data".to_vec();
+ bytes.extend_from_slice(xmp_with_offset(offset, extra_attributes).as_bytes());
+ append_video_payload(bytes, offset)
+ }
+
+ #[test]
+ fn finds_ftyp_box_in_jpeg_like_file() {
+ let mut bytes = b"jpeg-prefix".to_vec();
+ bytes.extend_from_slice(&make_ftyp_box(b"mp42"));
+ bytes.extend_from_slice(&[1, 2, 3, 4]);
+
+ let index = get_motion_video_index(&bytes).expect("video index should exist");
+ assert_eq!(index.start, "jpeg-prefix".len());
+ assert_eq!(index.end, bytes.len());
+ }
+
+ #[test]
+ fn picks_largest_segment_when_multiple_ftyp_exist() {
+ // Scenario 1: first segment is larger (full video first, preview second)
+ let mut bytes = b"jpeg-prefix".to_vec();
+ let first_start = bytes.len();
+ bytes.extend_from_slice(&make_ftyp_box(b"mp42"));
+ bytes.extend_from_slice(&[0xAA; 500]); // large segment
+ let second_start = bytes.len();
+ bytes.extend_from_slice(&make_ftyp_box(b"isom"));
+ bytes.extend_from_slice(&[0xBB; 50]); // small segment
+
+ let index = get_motion_video_index(&bytes).expect("video index should exist");
+ assert_eq!(index.start, first_start);
+ assert_eq!(index.end, second_start);
+ let extracted =
+ extract_motion_video(&bytes, Some(index)).expect("video bytes should extract");
+ assert_eq!(extracted.len(), second_start - first_start);
+
+ // Scenario 2: second segment is larger (preview first, full video second)
+ let mut bytes2 = b"jpeg-prefix".to_vec();
+ bytes2.extend_from_slice(&make_ftyp_box(b"mp42"));
+ bytes2.extend_from_slice(&[0xCC; 50]); // small segment
+ let second_start = bytes2.len();
+ bytes2.extend_from_slice(&make_ftyp_box(b"isom"));
+ bytes2.extend_from_slice(&[0xDD; 500]); // large segment
+
+ let index2 = get_motion_video_index(&bytes2).expect("video index should exist");
+ assert_eq!(index2.start, second_start);
+ assert_eq!(index2.end, bytes2.len());
+ }
+
+ #[test]
+ fn detects_various_mp4_brands() {
+ for brand in [
+ b"isom", b"mp41", b"mp42", b"avc1", b"iso2", b"M4V ", b"qt ",
+ ] {
+ let mut bytes = b"jpeg-prefix-data".to_vec();
+ bytes.extend_from_slice(&make_ftyp_box(brand));
+ bytes.extend_from_slice(&[0xDE, 0xAD]);
+ let index = get_motion_video_index(&bytes)
+ .unwrap_or_else(|| panic!("should detect brand {:?}", std::str::from_utf8(brand)));
+ assert_eq!(index.start, b"jpeg-prefix-data".len());
+ }
+ }
+
+ #[test]
+ fn rejects_non_video_ftyp_brands() {
+ for brand in [b"heic", b"heif", b"mif1", b"avif"] {
+ let mut bytes = b"jpeg-prefix-data".to_vec();
+ bytes.extend_from_slice(&make_ftyp_box(brand));
+ bytes.extend_from_slice(&[0xDE, 0xAD]);
+ assert_eq!(
+ get_motion_video_index(&bytes),
+ None,
+ "brand {:?} should not be detected as video",
+ std::str::from_utf8(brand)
+ );
+ }
+ }
+
+ #[test]
+ fn detects_ftyp_with_larger_box_size() {
+ let mut bytes = b"jpeg-prefix-data".to_vec();
+ let box_start = bytes.len();
+ // 28-byte ftyp box (like Pixel 6): size + "ftyp" + brand + version + compat brands
+ bytes.extend_from_slice(&28u32.to_be_bytes());
+ bytes.extend_from_slice(b"ftyp");
+ bytes.extend_from_slice(b"isom");
+ bytes.extend_from_slice(&0x00020000u32.to_be_bytes());
+ bytes.extend_from_slice(b"isomiso2mp41");
+ bytes.extend_from_slice(b"video-payload");
+
+ let index = get_motion_video_index(&bytes).expect("should detect 28-byte ftyp box");
+ assert_eq!(index.start, box_start);
+ }
+
+ #[test]
+ fn rejects_ftyp_at_file_start() {
+ let mut bytes = make_ftyp_box(b"mp42");
+ bytes.extend_from_slice(b"moov-data-here");
+ assert_eq!(get_motion_video_index(&bytes), None);
+ }
+
+ #[test]
+ fn rejects_ftyp_with_implausible_box_size() {
+ let mut bytes = b"jpeg-prefix-data".to_vec();
+ bytes.extend_from_slice(&0u32.to_be_bytes()); // box size 0 (invalid)
+ bytes.extend_from_slice(b"ftyp");
+ bytes.extend_from_slice(b"mp42");
+ bytes.extend_from_slice(&0u32.to_be_bytes());
+ assert_eq!(get_motion_video_index(&bytes), None);
+ }
+
+ #[test]
+ fn finds_xmp_offset_for_jpeg_like_file() {
+ let bytes = bytes_with_xmp_and_video(24, "GCamera:MotionPhoto=\"1\"");
+ let index = get_motion_video_index(&bytes).expect("video index should exist");
+ assert_eq!(index.start, bytes.len() - 24);
+ assert_eq!(index.end, bytes.len());
+ }
+
+ #[test]
+ fn finds_xmp_offset_for_heic_like_file() {
+ let mut bytes = b"heic-prefix-data".to_vec();
+ bytes.extend_from_slice(xmp_with_offset(32, "Item:Mime=\"video/mp4\"").as_bytes());
+ bytes = append_video_payload(bytes, 32);
+
+ let index = get_motion_video_index(&bytes).expect("video index should exist");
+ assert_eq!(index.start, bytes.len() - 32);
+ assert_eq!(index.end, bytes.len());
+ }
+
+ #[test]
+ fn returns_none_for_non_motion_file() {
+ let bytes = b"plain-still-image-data-without-motion-video-or-xmp".to_vec();
+ assert_eq!(get_motion_video_index(&bytes), None);
+ }
+
+ #[test]
+ fn skips_invalid_item_length_without_motion_tags() {
+ let mut bytes = b"prefix-data".to_vec();
+ bytes.extend_from_slice(xmp_with_offset(8, "").as_bytes());
+ bytes.extend_from_slice(b"small-tail");
+ assert_eq!(get_motion_video_index(&bytes), None);
+ }
+
+ #[test]
+ fn extracts_video_bytes_for_valid_index() {
+ let bytes = bytes_with_xmp_and_video(20, "GCamera:MotionPhoto=\"1\"");
+ let video = extract_motion_video(&bytes, None).expect("video bytes should extract");
+ assert_eq!(video.len(), 20);
+ assert!(video.iter().all(|byte| *byte == 0xAB));
+ }
+
+ #[test]
+ fn extracts_xmp_attributes() {
+ let bytes = bytes_with_xmp_and_video(
+ 16,
+ "GPano:ProjectionType=\"equirectangular\" GCamera:MotionPhoto=\"1\"",
+ );
+ let xmp = xmp::extract_xmp(&bytes).expect("xmp must parse");
+ assert_eq!(
+ xmp.get("GPano:ProjectionType"),
+ Some(&"equirectangular".to_string())
+ );
+ assert_eq!(xmp.get("GCamera:MotionPhoto"), Some(&"1".to_string()));
+ }
+
+ #[test]
+ fn path_apis_work_for_various_file_types() {
+ let temp = tempdir().expect("temp dir");
+ let jpeg_motion = temp.path().join("motion.jpg");
+ let heic_motion = temp.path().join("motion.heic");
+ let non_motion = temp.path().join("normal.jpg");
+
+ fs::write(
+ &jpeg_motion,
+ bytes_with_xmp_and_video(40, "GCamera:MotionPhoto=\"1\""),
+ )
+ .expect("write jpeg motion");
+
+ fs::write(
+ &heic_motion,
+ bytes_with_xmp_and_video(28, "Item:Mime=\"video/mp4\""),
+ )
+ .expect("write heic motion");
+
+ fs::write(&non_motion, b"non-motion-image").expect("write still");
+
+ assert!(
+ get_motion_video_index_from_path(&jpeg_motion)
+ .expect("jpeg read")
+ .is_some()
+ );
+ assert!(
+ get_motion_video_index_from_path(&heic_motion)
+ .expect("heic read")
+ .is_some()
+ );
+ assert_eq!(
+ get_motion_video_index_from_path(&non_motion).expect("still read"),
+ None
+ );
+ }
+}
diff --git a/rust/photos/src/motion_photo/xmp.rs b/rust/photos/src/motion_photo/xmp.rs
new file mode 100644
index 0000000000..af44eae6c5
--- /dev/null
+++ b/rust/photos/src/motion_photo/xmp.rs
@@ -0,0 +1,69 @@
+use super::MotionPhotoError;
+use std::collections::HashMap;
+
+const XMP_MARKER_BEGIN: &[u8] = b"<x:xmpmeta";
+const XMP_MARKER_END: &[u8] = b"</x:xmpmeta>";
+
+pub(crate) fn extract_xmp(source: &[u8]) -> Result<HashMap<String, String>, MotionPhotoError> {
+ let (begin, end) = extract_xmp_bounds(source)
+ .ok_or_else(|| MotionPhotoError::Xml("xmp markers not found".to_string()))?;
+ let xml_bytes = &source[begin..end];
+ parse_xmp_attributes(xml_bytes)
+}
+
+fn extract_xmp_bounds(source: &[u8]) -> Option<(usize, usize)> {
+ let offset_begin = find_subslice(source, XMP_MARKER_BEGIN)?;
+ let offset_end_start = find_subslice(&source[offset_begin..], XMP_MARKER_END)? + offset_begin;
+ let offset_end = offset_end_start + XMP_MARKER_END.len();
+ Some((offset_begin, offset_end))
+}
+
+fn parse_xmp_attributes(xml_bytes: &[u8]) -> Result<HashMap<String, String>, MotionPhotoError> {
+ use quick_xml::Reader;
+ use quick_xml::events::Event;
+
+ let xml_buffer = String::from_utf8_lossy(xml_bytes);
+ let mut reader = Reader::from_str(&xml_buffer);
+ let mut result = HashMap::<String, String>::new();
+ let mut scratch = Vec::<u8>::new();
+
+ loop {
+ match reader.read_event_into(&mut scratch) {
+ Ok(Event::Start(element)) | Ok(Event::Empty(element)) => {
+ for attribute in element.attributes() {
+ let attribute = attribute.map_err(|err| {
+ MotionPhotoError::Xml(format!("invalid attribute: {err}"))
+ })?;
+ let key = std::str::from_utf8(attribute.key.as_ref())
+ .map_err(|err| MotionPhotoError::Xml(format!("invalid key bytes: {err}")))?
+ .trim()
+ .to_string();
+ if key.starts_with("xmlns:") || key.starts_with("xml:") {
+ continue;
+ }
+
+ let value = attribute
+ .decode_and_unescape_value(reader.decoder())
+ .map_err(|err| MotionPhotoError::Xml(format!("invalid value: {err}")))?
+ .to_string();
+ result.insert(key, value);
+ }
+ }
+ Ok(Event::Eof) => break,
+ Ok(_) => {}
+ Err(err) => return Err(MotionPhotoError::Xml(format!("xml parse failed: {err}"))),
+ }
+ scratch.clear();
+ }
+
+ Ok(result)
+}
+
+fn find_subslice(haystack: &[u8], needle: &[u8]) -> Option<usize> {
+ if needle.is_empty() {
+ return Some(0);
+ }
+ haystack
+ .windows(needle.len())
+ .position(|window| window == needle)
+}
diff --git a/rust/photos/tests/motion_photos_assets_test.rs b/rust/photos/tests/motion_photos_assets_test.rs
index 487ccadb7f..10812d716f 100644
--- a/rust/photos/tests/motion_photos_assets_test.rs
+++ b/rust/photos/tests/motion_photos_assets_test.rs
@@ -1,4 +1,4 @@
-use ente_media_inspector::{extract_motion_video_from_path, get_motion_video_index_from_path};
+use ente_photos::{extract_motion_video_from_path, get_motion_video_index_from_path};
use std::path::{Path, PathBuf};
fn fixture_dir() -> Option<PathBuf> {