Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.
Rust androiddocument-scannerdocximage-editorjetpack-composekotlinliquid-glassofflineopen-sourcepdfpdf-compressorpdf-editorpdf-mergerpdf-readerpdf-splitterpdf-toolspdf-viewerpptxspreadsheet-editorxlsx
Edit the pictures in notes with LightCraft, credit GridCraft and LightCraft
chethan616e44acbc239d5
diff --git a/HANDOFF.md b/HANDOFF.mdindex d864bff..e581e1c 100644--- a/HANDOFF.md+++ b/HANDOFF.md@@ -22,7 +22,7 @@ Read this first after a `/clear`. The roadmap is `PLAN.md`.`adb shell cmd package compile -f -m speed-profile com.chethan616.clearpdf.debug` to compile theprofile at once. A debuggable build runs Compose several times slower.-## Office documents (Word and PowerPoint in; Excel next)+## Office documents and pictures (Word, PowerPoint, Excel, LightCraft photos in)Plan and status: PLAN.md "Office documents". How the Word bridge works:@@ -35,12 +35,26 @@ Plan and status: PLAN.md "Office documents". How the Word bridge works:(Word's PDF export needs the suite's krilla, and Cargo ignores a dependency's own patches).Upstream draft (not filed, don't file without the owner): `docs/upstream/wordcraft-android.md`.- **Bridge**: `engine/mobile/src/office.rs` is the shared part: the `OfficeDoc` trait (info, render,- text layer, links, thumbnail, release_memory), `sniff` (zip part names / CFB streams / `{ tf`),+ text layer, links, thumbnail, release_memory), `sniff` (zip part names / CFB streams / `{+tf`),`text_glyph` (a glyph box through an `Affine`), ids from `OFFICE_IDS` = 2^40. `word.rs` and`slides.rs` implement it; `MobileSession` keeps `office: HashMap<u64, Arc<dyn OfficeDoc>>`.Slides: `deckcraft_pptx::import`, `deckcraft_render::render_slide` (tiles via `RenderOpts.offset`and `size`, 2 threads), text from `place_slide(..).texts` (runs' glyphs + `cells` chars, through`PlacedText.transform`), links from `place_slide(..).links` (URL actions).+- **Excel** (`sheets.rs`): `SheetBook` (an `OfficeDoc` whose `as_sheets()` is Some) opens through+ `gridcraft_engine::io::open_bytes_with_password` then `Calc::recalc_all`; `MobileSession.sheets`,+ `sheet_axes` (points; gridcraft keeps 96-dpi px), `sheet_cells` (≤ 20 000 cells a window; only cells+ with text, fill or border), `sheet_merges`, `sheet_find`. The app's `ui/sheets/SheetViewer.kt` draws+ it (ClearApp's `Viewer` picks it for `doc.isSheets`); `render_page` is only a fill/grid sketch for+ thumbnails.+- **Photos** (`photo.rs`): `PhotoEditor` object (not in the session): `render(path, settings_json,+ max_side)` decodes once at ≤ 2048 px and re-develops; `export_jpeg` decodes full size. Settings are+ LightCraft's `DevelopSettings` JSON (`{"light":{"exposure":1}}`, ranges in its `controls.rs`).+ App: `ui/notes/PhotoEditor.kt`, opened by `vm.editingPhoto` from a note's picture.+- **Selection lens and menu** (2026-11-07): `SelectionLens` in `ViewerScreen.kt` draws the pages+ backdrop magnified in a glass capsule (the platform magnifier showed nothing over the backdrop+ layer); `SelectionMenu` is a glass popover.- **Word** (`engine/mobile/src/word.rs`): `MobileSession.open(path)` sniffs the bytes(`word_extension`: zip with `word/document.xml`, ODF text, CFB `WordDocument`, `{tf`; an encrypted@@ -217,5 +231,8 @@ still sees a flash on the Files/Pdf collection cards (a route change, not a docu## Next upSee PLAN.md "Office documents" and "Next". Immediate: when Artefact is in front on the phone,-check Word and slides viewing (Files, Recent, Quick Preview with the samples), the desk flicker fix-and the squircle Quick Preview card; then slides present mode, then Excel viewing (gridcraft).+check on the phone (all built, none seen there yet; the phone dropped off adb): Word, slides and+sheets (samples in Download: Artefact-Word-Sample.docx, Artefact-Slides-Sample.pptx,+Artefact-Sheet-Sample.xlsx), the selection lens and glass menu, the photo editor (tap a note's+picture), the desk flicker fix and the squircle Quick Preview. Then: slides present mode, sheet+search UI, export to PDF for all three, editing.diff --git a/NOTICE b/NOTICEindex 840849a..38ee837 100644--- a/NOTICE+++ b/NOTICE@@ -22,6 +22,10 @@ by storytold and the DeckCraft contributors, MIT OR Apache-2.0, pinned by commitvendored with Artefact's Android patch (engine/vendor/deckcraft-fonts). Its last-resort face isUbuntu Light (Canonical Ltd. / Dalton Maag, Ubuntu Font Licence 1.0), from epaint_default_fonts.+Workbooks: the engine of GridCraft (https://github.com/storytold/gridcraft) and pictures: the+codecs, develop settings and CPU pipeline of LightCraft (https://github.com/storytold/lightcraft),+both by storytold and their contributors, MIT OR Apache-2.0, pinned by commit (engine/Cargo.toml).+Liquid glass: the backdrop library from AndroidLiquidGlass by Kyant0(https://github.com/Kyant0/AndroidLiquidGlass), Apache-2.0, adapted. The velocity squash-and-stretchof glass thumbs follows LiquidTracker from AndroidLiquidGlassView by Donny Yalediff --git a/PLAN.md b/PLAN.mdindex 7d29778..be8b856 100644--- a/PLAN.md+++ b/PLAN.md@@ -135,8 +135,16 @@ all three → editing, one format at a time, each built and run on the phone beflists and filters; same reading-only viewer as Word. [ ] seen on the phone; [ ] present mode(full-screen slides, tap/swipe to advance; transitions from `deckcraft-render::render_transition`).Password-protected decks are refused with a message (deckcraft can't decrypt).-- [ ] Excel viewing (gridcraft): pannable Compose grid with frozen headers from cell text, styles,- column widths and row heights; charts rendered by gridcraft-chart.+- [x] **Excel viewing** (gridcraft `6a8eb4f`, 2026-11-07, built and host-tested): `sheets.rs` opens+ .xlsx/.xlsb/.ods/.csv (recalculated on open) and serves tabs, axes, cell windows with looks,+ merges, find; `ui/sheets/SheetViewer.kt` draws the grid on a canvas (pan, pinch zoom, heading+ strips, frozen panes, cells in 50×20 blocks) under glass. [ ] seen on the phone; [ ] search UI+ (bridge `sheet_find` is there); [ ] charts (gridcraft-chart) and pictures on sheets.+- [x] **Pictures in notes** (lightcraft `8a0b91a`, 2026-11-07, built and host-tested): `photo.rs`+ (`PhotoEditor`: decode, develop with LightCraft's `DevelopSettings` JSON, export JPEG; codecs,+ develop, pipeline only: no GPU, faces or catalog). Tap a note's picture: glass editor with+ Exposure, Contrast, Highlights, Shadows, Vibrance, Saturation and rotate; Done saves a new JPEG.+ [ ] seen on the phone; [ ] crop; [ ] markup.- [ ] Export to PDF for all three (wordcraft-pdf / deckcraft-pdf through craft-pdf + krilla, alreadypatched in; gridcraft's own writer: check non-Latin text).- [ ] Editing, one format at a time (wordcraft's 422 commands through `Session::run`, then deckcraft's@@ -144,7 +152,7 @@ all three → editing, one format at a time, each built and run on the phone bef## Later-1. **Pictures** (storytold/lightcraft) and **voice** (storytold/soundcraft) for notes.+1. **Voice** (storytold/soundcraft) for notes; more of LightCraft (crop, presets, markup).2. **Notes and lists on the Word engine**: once wordcraft is in (it reads and writes Markdown),move the notes and the shopping/to-do lists onto it instead of the app's own light Markdown, witha few adjustments to feel like Apple Notes: checklists, quick formatting tools (headings, bold,diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/AppViewModel.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/AppViewModel.ktindex e4368ae..3684aff 100644--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/AppViewModel.kt+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/AppViewModel.kt@@ -2381,6 +2381,9 @@ class AppViewModel(app: Application, private val saved: SavedStateHandle) : Andr/** The note open in the editor. */var openNote by mutableStateOf<String?>(null)+ /** A note's picture being edited (note id, picture name), over everything. */+ var editingPhoto by mutableStateOf<Pair<String, String>?>(null)+/** The desk's dock is turning into the open note's toolbar: the toolbar waits, unseen, until it has. */var noteBarHidden by mutableStateOf(false)diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/ClearApp.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/ClearApp.ktindex d1f2c92..0673474 100644--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/ClearApp.kt+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/ClearApp.kt@@ -207,6 +207,7 @@ private fun Shell(vm: AppViewModel, onBrowse: () -> Unit, onPickSignatureImage:vm.toolScreen?.let { ToolScreenHost(vm, it) }vm.signaturePad?.let { SignaturePadScreen(vm, it, onPickSignatureImage) }vm.certSign?.let { CertSignScreen(vm, it) }+ vm.editingPhoto?.let { (note, picture) -> com.chethan616.clearpdf.ui.notes.PhotoEditScreen(vm, note, picture) { vm.editingPhoto = null } }if (vm.idCreate) CreateIdScreen(vm)}},diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/SettingsScreen.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/SettingsScreen.ktindex 45d0595..4411e88 100644--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/SettingsScreen.kt+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/SettingsScreen.kt@@ -447,6 +447,8 @@ private fun LicencesPage(onBack: () -> Unit) {Credit(stringResource(R.string.root_licence_pdfcraft), stringResource(R.string.root_licence_pdfcraft_terms)),Credit(stringResource(R.string.root_licence_wordcraft), stringResource(R.string.root_licence_wordcraft_terms)),Credit(stringResource(R.string.root_licence_deckcraft), stringResource(R.string.root_licence_wordcraft_terms)),+ Credit(stringResource(R.string.root_licence_gridcraft), stringResource(R.string.root_licence_wordcraft_terms)),+ Credit(stringResource(R.string.root_licence_lightcraft), stringResource(R.string.root_licence_wordcraft_terms)),Credit("Ubuntu Light", "Ubuntu Font Licence 1.0, Canonical Ltd. / Dalton Maag"),Credit("AndroidLiquidGlass (backdrop)", "Apache-2.0, Kyant0"),Credit("AndroidLiquidGlassView (LiquidTracker)", "MIT, Donny Yale (QmDeve)"),diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/NoteEditor.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/NoteEditor.ktindex 8d4ce11..8f85533 100644--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/NoteEditor.kt+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/NoteEditor.kt@@ -243,7 +243,8 @@ fun NoteEditor(vm: AppViewModel, id: String) {LazyRow(Modifier.padding(top = 18.dp), horizontalArrangement = Arrangement.spacedBy(12.dp)) {items(note.images, key = { it }) { name ->Box {- NoteImage(name, Modifier.size(150.dp, 120.dp).clip(RoundedRectangle(22.dp)))+ // a tap develops the picture with LightCraft (PhotoEditScreen)+ NoteImage(name, Modifier.size(150.dp, 120.dp).clip(RoundedRectangle(22.dp)).pressable({ vm.editingPhoto = id to name }))Box(Modifier.align(Alignment.TopEnd).padding(6.dp).size(28.dp).pressable({ vm.notes.get(id)?.let { n -> vm.notes.put(n.copy(images = n.images - name)) } })diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/PhotoEditor.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/PhotoEditor.ktnew file mode 100644index 0000000..631d889--- /dev/null+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/PhotoEditor.kt@@ -0,0 +1,163 @@+package com.chethan616.clearpdf.ui.notes++import androidx.compose.foundation.Image+import androidx.compose.foundation.background+import androidx.compose.foundation.horizontalScroll+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.WindowInsets+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.navigationBars+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.statusBars+import androidx.compose.foundation.layout.windowInsetsBottomHeight+import androidx.compose.foundation.layout.windowInsetsTopHeight+import androidx.compose.foundation.rememberScrollState+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.CompositionLocalProvider+import androidx.compose.runtime.DisposableEffect+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateMapOf+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.rememberCoroutineScope+import androidx.compose.runtime.setValue+import androidx.compose.runtime.snapshotFlow+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.ImageBitmap+import androidx.compose.ui.graphics.asImageBitmap+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.chethan616.clearpdf.R+import com.chethan616.clearpdf.core.PhotoEditor+import com.chethan616.clearpdf.engine.toBitmap+import com.chethan616.clearpdf.ui.AppViewModel+import com.chethan616.clearpdf.ui.LucideIcons+import com.chethan616.clearpdf.ui.glass.GlassChip+import com.chethan616.clearpdf.ui.glass.GlassCircle+import com.chethan616.clearpdf.ui.glass.GlassIcon+import com.chethan616.clearpdf.ui.glass.GlassSlider+import com.chethan616.clearpdf.ui.glass.LocalBackdrop+import com.chethan616.clearpdf.ui.glass.glassBar+import com.chethan616.clearpdf.ui.theme.Candy+import com.chethan616.clearpdf.ui.theme.ClearType+import com.kyant.backdrop.backdrops.layerBackdrop+import com.kyant.backdrop.backdrops.rememberLayerBackdrop+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.flow.collectLatest+import kotlinx.coroutines.launch+import kotlinx.coroutines.withContext+import org.json.JSONObject+import java.io.File++/** One adjustment of LightCraft's develop settings: its section, field, label and range. */+private enum class Adjust(val section: String, val field: String, val label: Int, val min: Float, val max: Float) {+ Exposure("light", "exposure", R.string.photo_exposure, -3f, 3f),+ Contrast("light", "contrast", R.string.photo_contrast, -100f, 100f),+ Highlights("light", "highlights", R.string.photo_highlights, -100f, 100f),+ Shadows("light", "shadows", R.string.photo_shadows, -100f, 100f),+ Vibrance("color", "vibrance", R.string.photo_vibrance, -100f, 100f),+ Saturation("color", "saturation", R.string.photo_saturation, -100f, 100f),+}++/** The quarter turns LightCraft's orientation names, clockwise from as shot. */+private val TURNS = listOf("Normal", "Rotate90", "Rotate180", "Rotate270")++/**+ * A note's picture developed with LightCraft: the picture large, glass chips to pick an adjustment+ * and a glass slider for it, a quarter turn, and Done, which saves the developed picture in place of+ * the note's (a new file, so the desk's thumbnails see the change).+ */+@Composable+fun PhotoEditScreen(vm: AppViewModel, noteId: String, name: String, onClose: () -> Unit) {+ val source = remember(name) { vm.notes.file(name) }+ val editor = remember { PhotoEditor() }+ DisposableEffect(editor) { onDispose { editor.release(); editor.close() } }+ val values = remember { mutableStateMapOf<Adjust, Float>() }+ var turn by remember { mutableStateOf(0) }+ var chosen by remember { mutableStateOf(Adjust.Exposure) }+ var shown by remember { mutableStateOf<ImageBitmap?>(null) }+ var saving by remember { mutableStateOf(false) }+ val scope = rememberCoroutineScope()++ fun settings(): String {+ val o = JSONObject()+ for ((a, v) in values) if (v != 0f) (o.optJSONObject(a.section) ?: JSONObject().also { o.put(a.section, it) }).put(a.field, v.toDouble())+ if (turn != 0) o.put("orientation", TURNS[turn])+ return o.toString()+ }++ // re-develop as the sliders move; a newer value cancels the render still running+ LaunchedEffect(Unit) {+ snapshotFlow { values.toMap() to turn }.collectLatest {+ val json = settings()+ shown = withContext(Dispatchers.Default) { runCatching { editor.render(source.absolutePath, json, 1600u).toBitmap().asImageBitmap() }.getOrNull() } ?: shown+ }+ }++ val backdrop = rememberLayerBackdrop()+ Box(Modifier.fillMaxSize().background(Color(0xFF0B0C10))) {+ Box(Modifier.fillMaxSize().layerBackdrop(backdrop), contentAlignment = Alignment.Center) {+ shown?.let { Image(it, null, Modifier.fillMaxSize().padding(vertical = 120.dp), contentScale = ContentScale.Fit) }+ }+ CompositionLocalProvider(LocalBackdrop provides backdrop) {+ Column(Modifier.fillMaxWidth().align(Alignment.TopCenter)) {+ Spacer(Modifier.windowInsetsTopHeight(WindowInsets.statusBars))+ Row(Modifier.fillMaxWidth().padding(12.dp), verticalAlignment = Alignment.CenterVertically) {+ GlassCircle(onClick = onClose, label = stringResource(R.string.common_cancel), ink = Color.White) { GlassIcon(LucideIcons.X, null, Modifier.size(20.dp)) }+ Spacer(Modifier.weight(1f))+ GlassCircle(onClick = { turn = (turn + 1) % 4 }, label = stringResource(R.string.photo_rotate), ink = Color.White) { GlassIcon(LucideIcons.RotateCw, null, Modifier.size(20.dp)) }+ Spacer(Modifier.size(10.dp))+ GlassCircle(+ onClick = {+ if (saving) return@GlassCircle+ saving = true+ scope.launch {+ val out = File(source.parentFile, "edited-${System.currentTimeMillis()}.jpg")+ val ok = withContext(Dispatchers.Default) { runCatching { editor.exportJpeg(source.absolutePath, settings(), out.absolutePath, 92u) }.isSuccess }+ if (ok) vm.notes.get(noteId)?.let { n -> vm.notes.put(n.copy(images = n.images.map { if (it == name) out.name else it })) }+ saving = false+ onClose()+ }+ },+ tint = Candy.Sky, label = stringResource(R.string.common_done),+ ) { GlassIcon(LucideIcons.Check, null, Modifier.size(20.dp)) }+ }+ }+ Column(Modifier.fillMaxWidth().align(Alignment.BottomCenter).padding(horizontal = 12.dp)) {+ Column(Modifier.fillMaxWidth().glassBar(com.chethan616.clearpdf.ui.glass.RoundedRectangle(28.dp)).padding(16.dp)) {+ Text(+ stringResource(chosen.label) + " " + "%.2f".format(values[chosen] ?: 0f).trimEnd('0').trimEnd('.'),+ style = ClearType.Caption.copy(fontSize = 13.sp), color = Color.White.copy(alpha = 0.8f),+ )+ Spacer(Modifier.size(8.dp))+ GlassSlider(values[chosen] ?: 0f, { values[chosen] = it }, range = chosen.min..chosen.max, accent = Candy.Sky)+ Spacer(Modifier.size(12.dp))+ Row(Modifier.horizontalScroll(rememberScrollState()), horizontalArrangement = Arrangement.spacedBy(8.dp)) {+ for (a in Adjust.entries) {+ GlassChip(+ onClick = { chosen = a },+ fill = if (a == chosen) ({ Candy.Lemon }) else null,+ ink = if (a == chosen) Color(0xFF172033) else Color.White,+ onLongClick = { values.remove(a) },+ ) { Text(stringResource(a.label), style = ClearType.Body.copy(fontSize = 14.sp)) }+ }+ }+ }+ Spacer(Modifier.size(8.dp))+ Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars))+ }+ }+ }+}diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xmlindex 193d4c4..1ed197a 100644--- a/android/app/src/main/res/values/strings.xml+++ b/android/app/src/main/res/values/strings.xml@@ -337,6 +337,8 @@<string name="root_licence_pdfcraft_terms">MIT OR Apache-2.0, by storytold, the ArtCraft Team and contributors</string><string name="root_licence_wordcraft">WordCraft (Word engine)</string><string name="root_licence_deckcraft">DeckCraft (slides engine)</string>+ <string name="root_licence_gridcraft">GridCraft (spreadsheet engine)</string>+ <string name="root_licence_lightcraft">LightCraft (photo engine)</string><string name="root_licence_wordcraft_terms">MIT OR Apache-2.0, by storytold and contributors</string><string name="root_licence_lucide">Lucide icons</string><string name="root_licence_dancing_script">Dancing Script typeface (typed signatures)</string>@@ -956,6 +958,14 @@<string name="msg_word_reading_only">Word documents and presentations open for reading for now. Editing them is coming.</string><string name="sheet_kind_word">Word</string><string name="sheet_kind_slides">Slides</string>+ <string name="photo_exposure">Exposure</string>+ <string name="photo_contrast">Contrast</string>+ <string name="photo_highlights">Highlights</string>+ <string name="photo_shadows">Shadows</string>+ <string name="photo_vibrance">Vibrance</string>+ <string name="photo_saturation">Saturation</string>+ <string name="photo_rotate">Rotate</string>+ <string name="photo_edit">Edit picture</string><!-- Draw tool: lines drawn are turned into neat shapes. --><string name="msg_snap_to_shape_on">Snap to shape on</string>diff --git a/engine/Cargo.lock b/engine/Cargo.lockindex de6e6e0..1e7454f 100644--- a/engine/Cargo.lock+++ b/engine/Cargo.lock@@ -134,6 +134,10 @@ dependencies = ["gridcraft-engine","gridcraft-xlsx","kurbo",+ "lightcraft-codecs",+ "lightcraft-develop",+ "lightcraft-pipeline",+ "lightcraft-raster","log","pdfcraft-automation","pdfcraft-engine",@@ -1016,6 +1020,14 @@ dependencies = ["libc",]+[[package]]+name = "craft-crw"+version = "0.1.0"+source = "git+https://github.com/storytold/craft-libs?rev=f3b62ec61f45534392376492fc5ad33047375205#f3b62ec61f45534392376492fc5ad33047375205"+dependencies = [+ "thiserror 2.0.21",+]+[[package]]name = "craft-docpath"version = "0.1.0"@@ -2278,7 +2290,7 @@ dependencies = ["hayro-cmap","hayro-syntax","kurbo",- "moxcms",+ "moxcms 0.8.1","phf 0.13.1","rustc-hash","siphasher",@@ -2603,7 +2615,7 @@ dependencies = ["color_quant","gif","image-webp",- "moxcms",+ "moxcms 0.8.1","num-traits","png","tiff",@@ -2735,6 +2747,21 @@ dependencies = ["libc",]+[[package]]+name = "jpeg-decoder"+version = "0.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "00810f1d8b74be64b13dbf3db89ac67740615d6c891f0e7b6179326533011a07"+dependencies = [+ "rayon",+]++[[package]]+name = "jpeg-encoder"+version = "0.7.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a0370574b86f7eca156b9f298392b5e69a23f8c86f3f865add60bbc2e79467a6"+[[package]]name = "js-sys"version = "0.3.106"@@ -2746,6 +2773,182 @@ dependencies = ["wasm-bindgen",]+[[package]]+name = "jxl-bitstream"+version = "1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b480e752277e29eb4054f69546887a9b84656fe78c08f54ba5850ced98a378fe"+dependencies = [+ "tracing",+]++[[package]]+name = "jxl-coding"+version = "1.0.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cd972bcd125e776f1eb241ac50e39f956095a1c2770c64736c968f8946bd9a3c"+dependencies = [+ "jxl-bitstream",+ "tracing",+]++[[package]]+name = "jxl-color"+version = "0.11.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f316b1358c1711755b3ee8e8cb5c4a1dad12e796233088a7a513440782de80b2"+dependencies = [+ "jxl-bitstream",+ "jxl-coding",+ "jxl-grid",+ "jxl-image",+ "jxl-oxide-common",+ "jxl-threadpool",+ "tracing",+]++[[package]]+name = "jxl-frame"+version = "0.13.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2d967c6fd669c7c01060b5022d8835fa82fd46b06ffc98b549f17600a097c2b3"+dependencies = [+ "jxl-bitstream",+ "jxl-coding",+ "jxl-grid",+ "jxl-image",+ "jxl-modular",+ "jxl-oxide-common",+ "jxl-threadpool",+ "jxl-vardct",+ "tracing",+]++[[package]]+name = "jxl-grid"+version = "0.6.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "01671307879a033bfa52e6e8784b941aca770b3f3a7d33830b455b6844f793fb"+dependencies = [+ "tracing",+]++[[package]]+name = "jxl-image"+version = "0.13.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c5f752d62577c702a94dbbce4045caf08cb58639e8a4d56464b40ecf33ffe565"+dependencies = [+ "jxl-bitstream",+ "jxl-grid",+ "jxl-oxide-common",+ "tracing",+]++[[package]]+name = "jxl-jbr"+version = "0.2.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e35d032bcec660647828527ff42c6f5776d2fd44b8357f9f6d9ac6dc07218e46"+dependencies = [+ "brotli-decompressor 5.0.3",+ "jxl-bitstream",+ "jxl-frame",+ "jxl-grid",+ "jxl-image",+ "jxl-modular",+ "jxl-oxide-common",+ "jxl-threadpool",+ "jxl-vardct",+ "tracing",+]++[[package]]+name = "jxl-modular"+version = "0.11.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2a2f045b24c738dd91d482be385512b512721ae08a671bd4b27bf1c47f215235"+dependencies = [+ "jxl-bitstream",+ "jxl-coding",+ "jxl-grid",+ "jxl-oxide-common",+ "jxl-threadpool",+ "tracing",+]++[[package]]+name = "jxl-oxide"+version = "0.12.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d36c662923f47586880211f3bc7c0d83fb3a9b410d278c7bde93450748abeef3"+dependencies = [+ "brotli-decompressor 5.0.3",+ "jxl-bitstream",+ "jxl-color",+ "jxl-frame",+ "jxl-grid",+ "jxl-image",+ "jxl-jbr",+ "jxl-oxide-common",+ "jxl-render",+ "jxl-threadpool",+ "tracing",+]++[[package]]+name = "jxl-oxide-common"+version = "1.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b62394c5021b3a9e7e0dbb2d639d555d019090c9946c39f6d3b09d390db4157b"+dependencies = [+ "jxl-bitstream",+]++[[package]]+name = "jxl-render"+version = "0.12.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d34386bfdb6a19b5a30cc9beb4d475d537422c31ae8c39bb69640fcce3fcaf19"+dependencies = [+ "bytemuck",+ "jxl-bitstream",+ "jxl-coding",+ "jxl-color",+ "jxl-frame",+ "jxl-grid",+ "jxl-image",+ "jxl-modular",+ "jxl-oxide-common",+ "jxl-threadpool",+ "jxl-vardct",+ "tracing",+]++[[package]]+name = "jxl-threadpool"+version = "1.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "25f15eb830aa77a7f21148d72e153562a26bfe570139bd4922eab1908dd499d3"+dependencies = [+ "tracing",+]++[[package]]+name = "jxl-vardct"+version = "0.11.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ce72a18c6d3a47172ab6c479be2bdb56f22066b5d7092663f03b4490820b4511"+dependencies = [+ "jxl-bitstream",+ "jxl-coding",+ "jxl-grid",+ "jxl-modular",+ "jxl-oxide-common",+ "jxl-threadpool",+ "tracing",+]+[[package]]name = "keccak"version = "0.2.2"@@ -2801,6 +3004,135 @@ version = "0.2.189"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"+[[package]]+name = "lightcraft-codecs"+version = "0.18.0"+source = "git+https://github.com/storytold/lightcraft?rev=8a0b91a95c30618b690374dd2db9d0684ebc9b23#8a0b91a95c30618b690374dd2db9d0684ebc9b23"+dependencies = [+ "bytemuck",+ "image",+ "image-webp",+ "jpeg-decoder",+ "jpeg-encoder",+ "lightcraft-color",+ "lightcraft-geom",+ "lightcraft-raster",+ "moxcms 0.9.1",+ "png",+ "rayon",+ "serde",+ "thiserror 2.0.21",+ "tiff",+ "zune-core",+ "zune-jpeg",+]++[[package]]+name = "lightcraft-color"+version = "0.18.0"+source = "git+https://github.com/storytold/lightcraft?rev=8a0b91a95c30618b690374dd2db9d0684ebc9b23#8a0b91a95c30618b690374dd2db9d0684ebc9b23"+dependencies = [+ "lightcraft-geom",+ "serde",+]++[[package]]+name = "lightcraft-develop"+version = "0.18.0"+source = "git+https://github.com/storytold/lightcraft?rev=8a0b91a95c30618b690374dd2db9d0684ebc9b23#8a0b91a95c30618b690374dd2db9d0684ebc9b23"+dependencies = [+ "lightcraft-color",+ "lightcraft-geom",+ "miniz_oxide 0.9.1",+ "serde",+ "serde_json",+]++[[package]]+name = "lightcraft-geom"+version = "0.18.0"+source = "git+https://github.com/storytold/lightcraft?rev=8a0b91a95c30618b690374dd2db9d0684ebc9b23#8a0b91a95c30618b690374dd2db9d0684ebc9b23"+dependencies = [+ "serde",+]++[[package]]+name = "lightcraft-inpaint"+version = "0.18.0"+source = "git+https://github.com/storytold/lightcraft?rev=8a0b91a95c30618b690374dd2db9d0684ebc9b23#8a0b91a95c30618b690374dd2db9d0684ebc9b23"+dependencies = [+ "rayon",+]++[[package]]+name = "lightcraft-meta"+version = "0.18.0"+source = "git+https://github.com/storytold/lightcraft?rev=8a0b91a95c30618b690374dd2db9d0684ebc9b23#8a0b91a95c30618b690374dd2db9d0684ebc9b23"+dependencies = [+ "chrono",+ "lightcraft-geom",+ "lightcraft-tiff",+ "quick-xml",+ "serde",+]++[[package]]+name = "lightcraft-pipeline"+version = "0.18.0"+source = "git+https://github.com/storytold/lightcraft?rev=8a0b91a95c30618b690374dd2db9d0684ebc9b23#8a0b91a95c30618b690374dd2db9d0684ebc9b23"+dependencies = [+ "lightcraft-color",+ "lightcraft-develop",+ "lightcraft-geom",+ "lightcraft-inpaint",+ "lightcraft-raster",+ "lightcraft-raw",+ "rayon",+ "serde",+]++[[package]]+name = "lightcraft-raster"+version = "0.18.0"+source = "git+https://github.com/storytold/lightcraft?rev=8a0b91a95c30618b690374dd2db9d0684ebc9b23#8a0b91a95c30618b690374dd2db9d0684ebc9b23"+dependencies = [+ "lightcraft-color",+ "lightcraft-geom",+ "rayon",+ "serde",+]++[[package]]+name = "lightcraft-raw"+version = "0.18.0"+source = "git+https://github.com/storytold/lightcraft?rev=8a0b91a95c30618b690374dd2db9d0684ebc9b23#8a0b91a95c30618b690374dd2db9d0684ebc9b23"+dependencies = [+ "chrono",+ "craft-crw",+ "jpeg-encoder",+ "jxl-oxide",+ "lightcraft-color",+ "lightcraft-geom",+ "lightcraft-meta",+ "lightcraft-raster",+ "lightcraft-tiff",+ "miniz_oxide 0.9.1",+ "rayon",+ "serde",+ "thiserror 2.0.21",+ "zune-core",+ "zune-jpeg",+]++[[package]]+name = "lightcraft-tiff"+version = "0.18.0"+source = "git+https://github.com/storytold/lightcraft?rev=8a0b91a95c30618b690374dd2db9d0684ebc9b23#8a0b91a95c30618b690374dd2db9d0684ebc9b23"+dependencies = [+ "serde",+ "thiserror 2.0.21",+]+[[package]]name = "linebender_resource_handle"version = "0.1.1"@@ -2945,6 +3277,16 @@ dependencies = ["pxfm",]+[[package]]+name = "moxcms"+version = "0.9.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "396077b717181ce3f9a6b66739b269b82d756be5ec0f76be0bc40a7c51775830"+dependencies = [+ "num-traits",+ "pxfm",+]+[[package]]name = "multiversion_no_op"version = "1.0.0"diff --git a/engine/Cargo.toml b/engine/Cargo.tomlindex e9bedd4..2fdbc2f 100644--- a/engine/Cargo.toml+++ b/engine/Cargo.toml@@ -70,6 +70,13 @@ deckcraft-render = { git = "https://github.com/storytold/deckcraft", rev = "159egridcraft-engine = { git = "https://github.com/storytold/gridcraft", rev = "6a8eb4ff42cfa88b5bdd3eec13c6db3874d95214", version = "0.16.0" }gridcraft-xlsx = { git = "https://github.com/storytold/gridcraft", rev = "6a8eb4ff42cfa88b5bdd3eec13c6db3874d95214", version = "0.16.0" }+# Pictures (notes' photos): storytold/lightcraft's codecs, develop settings and CPU pipeline, pinned.+# Not its engine (GPU, faces, catalog); no AVIF or JPEG XL encoders.+lightcraft-codecs = { git = "https://github.com/storytold/lightcraft", rev = "8a0b91a95c30618b690374dd2db9d0684ebc9b23", version = "0.18.0", default-features = false, features = ["parallel"] }+lightcraft-develop = { git = "https://github.com/storytold/lightcraft", rev = "8a0b91a95c30618b690374dd2db9d0684ebc9b23", version = "0.18.0" }+lightcraft-pipeline = { git = "https://github.com/storytold/lightcraft", rev = "8a0b91a95c30618b690374dd2db9d0684ebc9b23", version = "0.18.0" }+lightcraft-raster = { git = "https://github.com/storytold/lightcraft", rev = "8a0b91a95c30618b690374dd2db9d0684ebc9b23", version = "0.18.0" }+hayro = "0.7.1"hayro-syntax = "0.7.2"diff --git a/engine/mobile/Cargo.toml b/engine/mobile/Cargo.tomlindex b1bb620..e6d11e6 100644--- a/engine/mobile/Cargo.toml+++ b/engine/mobile/Cargo.toml@@ -29,6 +29,11 @@ deckcraft-render = { workspace = true }# Excel workbooks (src/sheets.rs): GridCraft's enginegridcraft-engine = { workspace = true }gridcraft-xlsx = { workspace = true }+# Pictures (src/photo.rs): LightCraft's decoding, develop settings and pipeline+lightcraft-codecs = { workspace = true }+lightcraft-develop = { workspace = true }+lightcraft-pipeline = { workspace = true }+lightcraft-raster = { workspace = true }kurbo = { workspace = true }thiserror = { workspace = true }log = { workspace = true }diff --git a/engine/mobile/src/lib.rs b/engine/mobile/src/lib.rsindex f8d5467..391f709 100644--- a/engine/mobile/src/lib.rs+++ b/engine/mobile/src/lib.rs@@ -26,9 +26,11 @@ use serde_json::{Value, json};uniffi::setup_scaffolding!();mod office;+mod photo;mod sheets;mod slides;+pub use photo::PhotoEditor;pub use sheets::{CellEdge, CellSpan, CellView, SheetAxes, SheetInfo};#[cfg(test)]mod tests;diff --git a/engine/mobile/src/photo.rs b/engine/mobile/src/photo.rsnew file mode 100644index 0000000..fa531b4--- /dev/null+++ b/engine/mobile/src/photo.rs@@ -0,0 +1,93 @@+//! Pictures through storytold/lightcraft: a photo decoded into linear light, developed with+//! LightCraft's own settings (exposure, contrast, white balance, crop, orientation, … as its+//! `DevelopSettings` JSON, every field optional) by its CPU pipeline, and saved as a JPEG. The app+//! uses it to edit the photos in notes.++use std::sync::{Arc, Mutex, PoisonError};++use lightcraft_codecs::{ChromaSubsampling, DecodeOptions, EncodeImage, EncodeMeta};+use lightcraft_develop::DevelopSettings;+use lightcraft_pipeline::{RenderRequest, SourceInfo};+use lightcraft_raster::Rgb32f;++use crate::{MobileError, RenderedImage};++/// The largest side a preview source is decoded at: the editor's sliders re-develop it on every+/// change, so it is kept small (exports decode the full picture again).+const PREVIEW_SOURCE: u32 = 2048;++/// The decoded picture last asked for (path, preview or full size), kept for the next render.+type Source = Option<(String, bool, Arc<Rgb32f>)>;++/// LightCraft's develop pipeline, with the last decoded picture kept so slider moves only re-develop.+#[derive(uniffi::Object)]+pub struct PhotoEditor {+ source: Mutex<Source>,+}++fn settings(json: &str) -> Result<DevelopSettings, MobileError> {+ if json.trim().is_empty() {+ return Ok(DevelopSettings::default());+ }+ serde_json::from_str(json).map_err(|e| MobileError::Command(format!("the develop settings are not valid: {e}")))+}++impl PhotoEditor {+ fn source(&self, path: &str, preview: bool) -> Result<Arc<Rgb32f>, MobileError> {+ let mut s = self.source.lock().unwrap_or_else(PoisonError::into_inner);+ if let Some((p, pv, img)) = &*s+ && p == path+ && *pv == preview+ {+ return Ok(img.clone());+ }+ let bytes = crate::office::read(path)?;+ let opts = DecodeOptions { max_size: preview.then_some((PREVIEW_SOURCE, PREVIEW_SOURCE)), ..DecodeOptions::default() };+ let decoded = lightcraft_codecs::decode(&bytes, opts).map_err(|e| MobileError::Open(format!("{path}: {e}")))?;+ let img = Arc::new(decoded.image);+ *s = Some((path.to_string(), preview, img.clone()));+ Ok(img)+ }+}++#[uniffi::export]+impl PhotoEditor {+ #[uniffi::constructor]+ #[allow(clippy::new_without_default)]+ pub fn new() -> Arc<Self> {+ Arc::new(PhotoEditor { source: Mutex::new(None) })+ }++ /// The picture at `path` developed with `settings_json` (LightCraft's develop settings; empty:+ /// as shot), fitted within `max_side` pixels: what the editor shows while sliders move.+ pub fn render(&self, path: String, settings_json: String, max_side: u32) -> Result<RenderedImage, MobileError> {+ let s = settings(&settings_json)?;+ let src = self.source(&path, true)?;+ let side = max_side.clamp(16, PREVIEW_SOURCE) as usize;+ let out = lightcraft_pipeline::render(&src, &SourceInfo::default(), &s, &RenderRequest::fit(side, side));+ let img = out.image;+ Ok(RenderedImage { width: img.width as u32, height: img.height as u32, rgba: img.data.as_flattened().to_vec() })+ }++ /// Develop the full picture at `path` with `settings_json` and write it to `out_path` as a JPEG+ /// of `quality` (1–100).+ pub fn export_jpeg(&self, path: String, settings_json: String, out_path: String, quality: u8) -> Result<(), MobileError> {+ let s = settings(&settings_json)?;+ let src = self.source(&path, false)?;+ let (w, h) = (src.width, src.height);+ let out = lightcraft_pipeline::render(&src, &SourceInfo::default(), &s, &RenderRequest::fit(w.max(h), w.max(h)));+ let jpeg = lightcraft_codecs::encode_jpeg(+ &EncodeImage::rgba8(&out.image),+ quality.clamp(1, 100),+ ChromaSubsampling::default(),+ &EncodeMeta::default(),+ )+ .map_err(|e| MobileError::Command(format!("the picture could not be saved: {e}")))?;+ std::fs::write(&out_path, jpeg).map_err(|e| MobileError::Command(format!("{out_path}: {e}")))+ }++ /// Let go of the decoded picture (the editor closed, or memory is short).+ pub fn release(&self) {+ *self.source.lock().unwrap_or_else(PoisonError::into_inner) = None;+ }+}diff --git a/engine/mobile/src/tests.rs b/engine/mobile/src/tests.rsindex c541bcf..b37c04f 100644--- a/engine/mobile/src/tests.rs+++ b/engine/mobile/src/tests.rs@@ -607,3 +607,23 @@ fn opens_a_workbook_and_serves_its_cells() {let pdf = s.open(blank_pdf(1), None).unwrap();assert!(s.sheets(pdf.id).is_err());}++#[test]+fn develops_a_photo_and_saves_it() {+ let (w, h) = (64usize, 48usize);+ let img = lightcraft_raster::Rgba8 { width: w, height: h, data: vec![[90u8, 110, 130, 255]; w * h] };+ let png = lightcraft_codecs::encode_png(&lightcraft_codecs::EncodeImage::rgba8(&img), &lightcraft_codecs::EncodeMeta::default()).unwrap();+ let dir = scratch();+ let path = dir.join("photo.png").to_string_lossy().into_owned();+ std::fs::write(&path, png).unwrap();+ let e = PhotoEditor::new();+ let plain = e.render(path.clone(), String::new(), 32).unwrap();+ assert_eq!((plain.width, plain.height), (32, 24));+ let bright = e.render(path.clone(), r#"{"light":{"exposure":1.5}}"#.into(), 32).unwrap();+ let mean = |r: &RenderedImage| r.rgba.iter().step_by(4).map(|v| u32::from(*v)).sum::<u32>() / (r.width * r.height);+ assert!(mean(&bright) > mean(&plain) + 10, "{} vs {}", mean(&bright), mean(&plain));+ assert!(e.render(path.clone(), "{not json".into(), 32).is_err());+ let out = dir.join("out.jpg").to_string_lossy().into_owned();+ e.export_jpeg(path, r#"{"light":{"exposure":0.5}}"#.into(), out.clone(), 90).unwrap();+ assert!(std::fs::read(out).unwrap().starts_with(&[0xFF, 0xD8]));+}