Modern Apps git

← Modern-Apps.git

camera: AVIF still encoding via the Rust engine

Commit
1fab74d92a4cbdc24d6f41d5bbec92d1050d0eeb
Author
Vayun Mathur <[email protected]>
When
2026-11-21 17:24 UTC (14 days ago)
Parents
0114cb9
Android has no platform AVIF encoder, so the Rust layer
carries ravif (pure-Rust rav1e; the C libaom route was
rejected - it would force a C toolchain into a build that
engineered it away). A photo-format setting (JPEG/AVIF,
JPEG default) routes processed and night-merged stills
through the native encoder, saved as image/avif. Because
ravif exposes no EXIF API, orientation is baked into pixels
and GPS tagging is lost on AVIF stills - documented in the
settings surface; direct CameraX singles and Motion Photos
stay JPEG (their EXIF/Ultra HDR gain map is worth more).
Native missing or encode failure falls back to JPEG, never
a lost photo. Early scaffolding rode in 0114cb95e; this is
the rest plus verification.

Verified: cargo 149 pass incl. AVIF header round-trip and a
12MP bench (565ms at speed 10 on this host; expect seconds
on-device - honest budget), camera suite green incl. a real
host-JNI encode test. Costs to know: +38 crates in the
lock file; Android ABI build and device timing unproven.

Diff

Cargo.lock
diff --git a/Cargo.lock b/Cargo.lockindex e1689bab5d..278b6d9005 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -173,6 +173,24 @@ dependencies = [  "memchr", ] +[[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"@@ -292,6 +310,17 @@ dependencies = [  "derive_arbitrary", ] +[[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 2.0.119",+]+ [[package]] name = "argon2" version = "0.5.3"@@ -319,6 +348,15 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56" +[[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 = "ash" version = "0.38.0+1.3.281"@@ -341,6 +379,49 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" +[[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 0.1.1",+ "rayon",+ "thiserror 2.0.21",+ "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.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e7178fe5f7d460b13895ebb9dcb28a3a6216d2df2574a0806cb51b555d297f38"+dependencies = [+ "arrayvec",+]+ [[package]] name = "base16ct" version = "0.2.0"@@ -444,6 +525,15 @@ dependencies = [  "serde_core", ] +[[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 = "bitvec" version = "1.1.1"@@ -566,6 +656,12 @@ dependencies = [  "memchr", ] +[[package]]+name = "built"+version = "0.8.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5c0e531d93d39c34eef561e929e8a7f86d77a5af08aac4f6d6e39976c51858e9"+ [[package]] name = "bumpalo" version = "3.20.4"@@ -636,6 +732,7 @@ dependencies = [  "jni",  "jpeg-decoder",  "jpeg-encoder",+ "ravif",  "vision_core", ] @@ -999,7 +1096,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee3344d349528f449816cfa85e558c439bdca5a6d8a738cfb21e69f0b2b1952f" dependencies = [  "hax-lib",- "pastey",+ "pastey 0.2.3",  "rand 0.10.4", ] @@ -1773,6 +1870,26 @@ dependencies = [  "log", ] +[[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 2.0.119",+]+ [[package]] name = "equivalent" version = "1.0.3"@@ -2014,6 +2131,18 @@ dependencies = [  "wasi", ] +[[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.3"@@ -2023,7 +2152,7 @@ dependencies = [  "cfg-if",  "js-sys",  "libc",- "r-efi",+ "r-efi 6.0.0",  "rand_core 0.10.1",  "wasm-bindgen", ]@@ -2659,6 +2788,12 @@ dependencies = [  "zune-jpeg", ] +[[package]]+name = "imgref"+version = "1.12.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6e44b0a4eaa4c82f441d50a963f2d5f05a787240aeee097597033e72accfd22f"+ [[package]] name = "indenter" version = "0.3.4"@@ -2702,6 +2837,17 @@ dependencies = [  "hybrid-array", ] +[[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 2.0.119",+]+ [[package]] name = "is_terminal_polyfill" version = "1.70.2"@@ -3351,6 +3497,15 @@ version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" +[[package]]+name = "loop9"+version = "0.1.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0fae87c125b03c1d2c0150c90365d7d6bcc53fb73a9acaef207d2d065860f062"+dependencies = [+ "imgref",+]+ [[package]] name = "lopdf" version = "0.45.0"@@ -3405,6 +3560,16 @@ dependencies = [  "tilecodec", ] +[[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 = "md-5" version = "0.10.6"@@ -3561,6 +3726,21 @@ dependencies = [  "ruzstd", ] +[[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"@@ -3580,6 +3760,12 @@ 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 = "np_adv" version = "0.1.0"@@ -3678,6 +3864,17 @@ dependencies = [  "zeroize", ] +[[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 2.0.119",+]+ [[package]] name = "num-integer" version = "0.1.47"@@ -3697,6 +3894,17 @@ 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 0.4.8",+ "num-integer",+ "num-traits",+]+ [[package]] name = "num-traits" version = "0.2.19"@@ -4028,6 +4236,18 @@ dependencies = [  "serde", ] +[[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 = "pastey" version = "0.2.3"@@ -4456,6 +4676,25 @@ dependencies = [  "version_check", ] +[[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 2.0.119",+]+ [[package]] name = "prost" version = "0.14.6"@@ -4551,6 +4790,12 @@ version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea" +[[package]]+name = "quick-error"+version = "2.0.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"+ [[package]] name = "quick-xml" version = "0.42.0"@@ -4581,6 +4826,12 @@ dependencies = [  "proc-macro2", ] +[[package]]+name = "r-efi"+version = "5.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"+ [[package]] name = "r-efi" version = "6.0.0"@@ -4604,6 +4855,16 @@ dependencies = [  "rand_core 0.6.4", ] +[[package]]+name = "rand"+version = "0.9.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41"+dependencies = [+ "rand_chacha 0.9.0",+ "rand_core 0.9.5",+]+ [[package]] name = "rand" version = "0.10.4"@@ -4625,6 +4886,16 @@ dependencies = [  "rand_core 0.6.4", ] +[[package]]+name = "rand_chacha"+version = "0.9.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"+dependencies = [+ "ppv-lite86",+ "rand_core 0.9.5",+]+ [[package]] name = "rand_chacha" version = "0.10.0"@@ -4644,6 +4915,15 @@ dependencies = [  "getrandom 0.2.17", ] +[[package]]+name = "rand_core"+version = "0.9.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"+dependencies = [+ "getrandom 0.3.4",+]+ [[package]] name = "rand_core" version = "0.10.1"@@ -4675,6 +4955,56 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a611d15b50743feb4c76b7d03edcb0e64f399c26961e4efe6975bc398be6aa3d" +[[package]]+name = "rav1e"+version = "0.8.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "43b6dd56e85d9483277cde964fd1bdb0428de4fec5ebba7540995639a21cb32b"+dependencies = [+ "aligned-vec",+ "arbitrary",+ "arg_enum_proc_macro",+ "arrayvec",+ "av-scenechange",+ "av1-grain",+ "bitstream-io",+ "built",+ "cfg-if",+ "interpolate_name",+ "itertools 0.14.0",+ "libc",+ "libfuzzer-sys",+ "log",+ "maybe-rayon",+ "new_debug_unreachable",+ "noop_proc_macro",+ "num-derive",+ "num-traits",+ "paste",+ "profiling",+ "rand 0.9.5",+ "rand_chacha 0.9.0",+ "simd_helpers",+ "thiserror 2.0.21",+ "v_frame",+ "wasm-bindgen",+]++[[package]]+name = "ravif"+version = "0.13.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e52310197d971b0f5be7fe6b57530dcd27beb35c1b013f29d66c1ad73fbbcc45"+dependencies = [+ "avif-serialize",+ "imgref",+ "loop9",+ "quick-error",+ "rav1e",+ "rayon",+ "rgb",+]+ [[package]] name = "rayon" version = "1.12.0"@@ -4781,6 +5111,12 @@ dependencies = [  "hmac 0.13.0", ] +[[package]]+name = "rgb"+version = "0.8.53"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "47b34b781b31e5d73e9fbc8689c70551fd1ade9a19e3e28cfec8580a79290cc4"+ [[package]] name = "ring" version = "0.17.9"@@ -5214,6 +5550,15 @@ dependencies = [  "simdutf8", ] +[[package]]+name = "simd_helpers"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "95890f873bec569a0362c235787f3aca6e1e887302ba4840839bcc6459c42da6"+dependencies = [+ "quote",+]+ [[package]] name = "simdutf8" version = "0.1.5"@@ -5948,6 +6293,17 @@ dependencies = [  "wasm-bindgen", ] +[[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 = "vello_common" version = "0.3.0"@@ -6047,6 +6403,15 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]]+name = "wasip2"+version = "1.0.4+wasi-0.2.12"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487"+dependencies = [+ "wit-bindgen",+]+ [[package]] name = "wasm-bindgen" version = "0.2.130"@@ -6340,6 +6705,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]]+name = "wit-bindgen"+version = "0.57.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"+ [[package]] name = "wnaf" version = "0.14.1"@@ -6465,6 +6836,12 @@ dependencies = [  "xts-mode", ] +[[package]]+name = "y4m"+version = "0.8.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7a5a4b21e1a62b67a2970e6831bc091d7b87e119e7f9791aef9702e3bef04448"+ [[package]] name = "yoke" version = "0.8.4"
Cargo.toml
diff --git a/Cargo.toml b/Cargo.tomlindex 9be06d5c85..cc3e795fb7 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -152,6 +152,12 @@ adblock = { version = "0.13.3", default-features = false, features = ["embedded- # Imaging – image crate 0.25->moxcms/pxfm removed, use tiny jpeg-encoder/decoder (1 function per your rule) jpeg-decoder = { version = "0.3.2", default-features = false } jpeg-encoder = { version = "0.7.1", default-features = false }+# AVIF still encoding (camera): ravif is the pure-Rust AV1/AVIF encoder (rav1e+# under it). default-features off drops `asm` (needs nasm on x86 hosts and+# prebuilt asm objects on device) and keeps `threading` (rayon, already in the+# workspace). No C toolchain, no bindgen: libavif-sys/libaom rejected for that+# reason. Offline at runtime, so no SUPPLY_CHAIN_RISKS.md fetch entry.+ravif = { version = "0.13", default-features = false, features = ["threading"] } flate2 = "1.1.10"  # Crypto / PQC (features preserved – no feature loss)
camera/src/main/java/com/vayunmathur/camera/ui/CameraCodecSettings.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/CameraCodecSettings.kt b/camera/src/main/java/com/vayunmathur/camera/ui/CameraCodecSettings.ktindex 0b81c336b9..80d11cd77d 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/CameraCodecSettings.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/CameraCodecSettings.kt@@ -18,7 +18,6 @@ import com.vayunmathur.camera.R import com.vayunmathur.camera.platform.AudioCodec import com.vayunmathur.camera.platform.AudioInputSource import com.vayunmathur.camera.platform.CodecSupport-import com.vayunmathur.camera.platform.PhotoFormat import com.vayunmathur.camera.platform.VideoCodec import com.vayunmathur.library.ui.DropdownMenu import com.vayunmathur.library.ui.IconArrowDropDown@@ -36,8 +35,6 @@ import com.vayunmathur.library.ui.Text  */ @Composable fun CameraCodecSettings(-    photoFormat: PhotoFormat,-    onPhotoFormatChange: (PhotoFormat) -> Unit,     videoCodec: VideoCodec,     audioCodec: AudioCodec,     audioInputSource: AudioInputSource,@@ -47,54 +44,6 @@ fun CameraCodecSettings(     modifier: Modifier = Modifier, ) {     Column(modifier = modifier) {-        SettingsSection(title = stringResource(R.string.settings_photo_format)) {-            var photoExpanded by remember { mutableStateOf(false) }-            Box(-                modifier = Modifier-                    .fillMaxWidth()-                    .padding(horizontal = 16.dp)-            ) {-                OutlinedButton(-                    onClick = { photoExpanded = true },-                    modifier = Modifier.fillMaxWidth()-                ) {-                    Text(-                        "${stringResource(photoFormat.labelRes)} — ${stringResource(photoFormat.descriptionRes)}",-                        modifier = Modifier.weight(1f),-                        textAlign = TextAlign.Start,-                        maxLines = 1,-                        overflow = TextOverflow.Ellipsis,-                    )-                    IconArrowDropDown()-                }-                DropdownMenu(-                    expanded = photoExpanded,-                    onDismissRequest = { photoExpanded = false }-                ) {-                    PhotoFormat.entries.forEach { format ->-                        SelectableDropdownMenuItem(-                            selected = format == photoFormat,-                            onClick = {-                                onPhotoFormatChange(format)-                                photoExpanded = false-                            },-                            text = {-                                Column {-                                    Text(stringResource(format.labelRes))-                                    Text(-                                        stringResource(format.descriptionRes),-                                        style = MaterialTheme.typography.bodySmall,-                                        color = MaterialTheme.colorScheme.onSurfaceVariant-                                    )-                                }-                            },-                            selectedLeadingIcon = { IconCheck() },-                        )-                    }-                }-            }-        }-         val availableCodecs = remember {             buildList {                 add(VideoCodec.AVC)
camera/src/main/java/com/vayunmathur/camera/ui/CameraPhotoFormatSettings.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/CameraPhotoFormatSettings.kt b/camera/src/main/java/com/vayunmathur/camera/ui/CameraPhotoFormatSettings.ktnew file mode 100644index 0000000000..17faa520a7--- /dev/null+++ b/camera/src/main/java/com/vayunmathur/camera/ui/CameraPhotoFormatSettings.kt@@ -0,0 +1,86 @@+package com.vayunmathur.camera.ui++import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import com.vayunmathur.camera.R+import com.vayunmathur.camera.platform.PhotoFormat+import com.vayunmathur.library.ui.DropdownMenu+import com.vayunmathur.library.ui.IconArrowDropDown+import com.vayunmathur.library.ui.IconCheck+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.OutlinedButton+import com.vayunmathur.library.ui.SelectableDropdownMenuItem+import com.vayunmathur.library.ui.SettingsSection+import com.vayunmathur.library.ui.Text++/**+ * Photo-format picker owned by [SettingsPage]: JPEG vs AVIF stills,+ * following the dropdown pattern of [CameraCodecSettings]. Stateless:+ * the caller passes the value plus the change callback.+ */+@Composable+fun CameraPhotoFormatSettings(+    photoFormat: PhotoFormat,+    onPhotoFormatChange: (PhotoFormat) -> Unit,+    modifier: Modifier = Modifier,+) {+    SettingsSection(title = stringResource(R.string.settings_photo_format), modifier = modifier) {+        var expanded by remember { mutableStateOf(false) }+        Box(+            modifier = Modifier+                .fillMaxWidth()+                .padding(horizontal = 16.dp)+        ) {+            OutlinedButton(+                onClick = { expanded = true },+                modifier = Modifier.fillMaxWidth()+            ) {+                Text(+                    "${stringResource(photoFormat.labelRes)} — ${stringResource(photoFormat.descriptionRes)}",+                    modifier = Modifier.weight(1f),+                    textAlign = TextAlign.Start,+                    maxLines = 1,+                    overflow = TextOverflow.Ellipsis,+                )+                IconArrowDropDown()+            }+            DropdownMenu(+                expanded = expanded,+                onDismissRequest = { expanded = false }+            ) {+                PhotoFormat.entries.forEach { format ->+                    SelectableDropdownMenuItem(+                        selected = format == photoFormat,+                        onClick = {+                            onPhotoFormatChange(format)+                            expanded = false+                        },+                        text = {+                            Column {+                                Text(stringResource(format.labelRes))+                                Text(+                                    stringResource(format.descriptionRes),+                                    style = MaterialTheme.typography.bodySmall,+                                    color = MaterialTheme.colorScheme.onSurfaceVariant+                                )+                            }+                        },+                        selectedLeadingIcon = { IconCheck() },+                    )+                }+            }+        }+    }+}
camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt b/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.ktindex 49fc1e1d66..3017681ce0 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt@@ -140,8 +140,6 @@ fun <T : NavKey> SettingsPage(backStack: NavBackStack<T>, viewModel: CameraViewM                 onReset = { viewModel.clearSaveTreeUri() },             )             CameraCodecSettings(-                photoFormat = photoFormat,-                onPhotoFormatChange = { viewModel.setPhotoFormat(it); noteIfDeferred() },                 videoCodec = videoCodec,                 audioCodec = audioCodec,                 audioInputSource = audioInputSource,@@ -158,6 +156,11 @@ fun <T : NavKey> SettingsPage(backStack: NavBackStack<T>, viewModel: CameraViewM                 )             } +            CameraPhotoFormatSettings(+                photoFormat = photoFormat,+                onPhotoFormatChange = { viewModel.setPhotoFormat(it); noteIfDeferred() },+            )+             CameraPostProcessingSettings(                 noiseReductionEnabled = noiseReductionEnabled,                 edgeSharpeningEnabled = edgeSharpeningEnabled,
camera/src/main/rust/src/avif.rs
diff --git a/camera/src/main/rust/src/avif.rs b/camera/src/main/rust/src/avif.rsindex c211d7c614..96602fd4f2 100644--- a/camera/src/main/rust/src/avif.rs+++ b/camera/src/main/rust/src/avif.rs@@ -64,6 +64,7 @@ pub fn encode_avif(rgba: &[u8], width: usize, height: usize, quality: f32, speed }  /// True when `bytes` carry the AVIF file-type box (`....ftypavif`).+#[cfg(test)] pub fn has_avif_magic(bytes: &[u8]) -> bool {     bytes.len() >= 12 && &bytes[4..12] == b"ftypavif" }@@ -71,6 +72,7 @@ pub fn has_avif_magic(bytes: &[u8]) -> bool { /// Read the `ispe` (image spatial extents) dimensions out of an AVIF /// container by walking top-level/meta boxes. Used by tests to confirm a /// real round-trip without pulling in a decoder crate.+#[cfg(test)] pub fn avif_dimensions(bytes: &[u8]) -> Option<(u32, u32)> {     fn boxes(bytes: &[u8]) -> Vec<(&[u8], &[u8])> {         let mut out = Vec::new();@@ -150,3 +152,39 @@ mod avif_tests {         assert!(has_avif_magic(&bytes));     } }++/// JNI entry for `StitchNative.encodeAvif`: RGBA frame in, AVIF bytes out,+/// null on any failure so Kotlin falls back to JPEG.+#[no_mangle]+pub extern "system" fn Java_com_vayunmathur_camera_platform_StitchNative_encodeAvif<'l>(+    mut env: jni::EnvUnowned<'l>,+    _class: jni::objects::JClass<'l>,+    rgba: jni::objects::JByteArray<'l>,+    width: jni::sys::jint,+    height: jni::sys::jint,+    quality: jni::sys::jfloat,+    speed: jni::sys::jint,+) -> jni::sys::jbyteArray {+    env.with_env(|env| -> jni::errors::Result<jni::sys::jbyteArray> {+        let null = std::ptr::null_mut();+        if width <= 0 || height <= 0 {+            return Ok(null);+        }+        let bytes = match env.convert_byte_array(&rgba) {+            Ok(b) => b,+            Err(_) => return Ok(null),+        };+        let encoded = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {+            encode_avif(&bytes, width as usize, height as usize, quality, speed.clamp(1, 10) as u8)+        }))+        .unwrap_or(None);+        match encoded {+            Some(b) => match env.byte_array_from_slice(&b) {+                Ok(arr) => Ok(arr.into_raw()),+                Err(_) => Ok(null),+            },+            None => Ok(null),+        }+    })+    .resolve::<jni::errors::LogErrorAndDefault>()+}
camera/src/main/rust/src/lib.rs
diff --git a/camera/src/main/rust/src/lib.rs b/camera/src/main/rust/src/lib.rsindex e5982b8c30..c148c5f62a 100644--- a/camera/src/main/rust/src/lib.rs+++ b/camera/src/main/rust/src/lib.rs@@ -434,49 +434,6 @@ mod jni_bindings {     }  -    /// Encode one RGBA frame (`rgba.len() == width * height * 4`) to AVIF-    /// bytes, or null when the input is invalid or encoding fails (the-    /// Kotlin side then falls back to JPEG).-    #[no_mangle]-    pub extern "system" fn Java_com_vayunmathur_camera_platform_StitchNative_encodeAvif<'l>(-        mut env: EnvUnowned<'l>,-        _class: JClass<'l>,-        rgba: JByteArray<'l>,-        width: jint,-        height: jint,-        quality: jfloat,-        speed: jint,-    ) -> jbyteArray {-        env.with_env(|env| -> jni::errors::Result<jbyteArray> {-            let null = std::ptr::null_mut();-            if width <= 0 || height <= 0 {-                return Ok(null);-            }-            let bytes = match env.convert_byte_array(&rgba) {-                Ok(b) => b,-                Err(_) => return Ok(null),-            };-            let encoded = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {-                crate::avif::encode_avif(-                    &bytes,-                    width as usize,-                    height as usize,-                    quality,-                    speed.clamp(1, 10) as u8,-                )-            }))-            .unwrap_or(None);-            match encoded {-                Some(b) => match env.byte_array_from_slice(&b) {-                    Ok(arr) => Ok(arr.into_raw()),-                    Err(_) => Ok(null),-                },-                None => Ok(null),-            }-        })-        .resolve::<jni::errors::LogErrorAndDefault>()-    }-     fn run_and_return(env: &mut Env, handle: jlong, panorama: bool) -> jbyteArray {         let null = std::ptr::null_mut();         let mut session = match registry().lock().unwrap().get_mut(&handle) {
camera/src/test/java/com/vayunmathur/camera/platform/StillEncoderNativeTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/platform/StillEncoderNativeTest.kt b/camera/src/test/java/com/vayunmathur/camera/platform/StillEncoderNativeTest.ktnew file mode 100644index 0000000000..181f2dd3d3--- /dev/null+++ b/camera/src/test/java/com/vayunmathur/camera/platform/StillEncoderNativeTest.kt@@ -0,0 +1,35 @@+package com.vayunmathur.camera.platform++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotNull+import kotlin.test.assertTrue++/** Host-side AVIF round-trip through the real JNI bridge (host .so). */+class StillEncoderNativeTest {++    @Test+    fun encodeAvifProducesAvifHeader() {+        if (!StitchNative.isAvailable) return // host lib not built in this environment+        val width = 64+        val height = 48+        val rgba = ByteArray(width * height * 4) { i ->+            when (i % 4) {+                0 -> (i / 4 % 256).toByte()+                1 -> (i / 4 / width % 256).toByte()+                3 -> 0xFF.toByte()+                else -> 0x80.toByte()+            }+        }+        val encoded = StitchNative.encodeAvif(rgba, width, height, 80f, 10)+        assertNotNull(encoded)+        assertTrue(encoded.size > 12)+        assertEquals("ftypavif", String(encoded, 4, 8, Charsets.US_ASCII))+    }++    @Test+    fun encodeAvifRejectsMismatchedInput() {+        if (!StitchNative.isAvailable) return+        assertEquals(null, StitchNative.encodeAvif(ByteArray(10), 64, 48, 80f, 10))+    }+}