Yokan / rebuild
Course 1 8624561

COLORIZATION.md

docs/COLORIZATION.md

documentation / design asset114 lines
1# Local manga panel colorization23An experimental, on-demand reader tool for Android, iOS, and desktop. Long-press a4page, choose **Colorize locally**, then colorize the whole page or select a panel.5The result is a separate PNG preview with Save and Share actions. Source pages,6downloads, and the library database are not replaced.78## Model setup9101. In the colorizer, choose **Model source**. This opens the pinned export page:11   [Faridzar/manga-colorization-v2-onnx](https://huggingface.co/Faridzar/manga-colorization-v2-onnx/tree/5515e06d31b08ffd107af686cba5e98e95e8d4cf).122. Review its terms and download `manga-colorize-fp16.onnx` (61,650,260 bytes).133. Return to Yokan and choose **Import model**. Select the downloaded file.144. Drag a rectangle over a panel, use **Adjust panel bounds** for keyboard or15   accessibility controls, or choose **Whole page**. Then **Colorize selection**.165. Compare with the original page, save a PNG, or share it using the platform UI.1718Only this exact export is accepted. Its SHA-256 is:1920```text2139660d0047ea6f1a0ddee6aa89054997f95ea566f4d56ff762f66dbcf1a1a7ef22```2324Import validates size and digest before atomically replacing the local copy.25Inference verifies the stored copy whenever it loads it into the native runtime. Model files26are held under the application cache's `colorizer/` directory; clearing the app27cache may require reimporting. **Remove local model** releases its disk space.28Yokan does not download weights automatically or upload pages for inference.2930## Model provenance3132The export is attributed to33[qweasdd/manga-colorization-v2](https://github.com/qweasdd/manga-colorization-v2).34The export's model card labels it MIT; the original repository did not include a35license file at review time. Yokan ships inference code and links to the export,36not model weights. The publisher's labeling is not independent verification of37rights to redistribute the original weights or training material.3839## Platform integration4041- Android: ONNX Runtime Android 1.24.2; BitmapFactory subsampling and PNG encoding.42- Desktop: ONNX Runtime Java 1.24.2; ImageIO subsampling and PNG encoding. Intel43  macOS uses 1.22.0 because newer Java artifacts omit its native JNI binaries.44  Packaged platforms are Windows x64, macOS ARM64/x64, and Linux ARM64/x64.45- iOS: ONNX Runtime 1.24.2 through Microsoft's official Swift package, linked to46  the Xcode app. `PanelColorizerBridge.mm` provides ImageIO/CoreGraphics codecs47  and synchronous Objective-C runtime inference to Kotlin. No Python is needed.48- Web: the action explains that local colorization requires a native app; no49  model or ONNX runtime is loaded in the browser.5051Minified Android and desktop builds keep ONNX Runtime's JNI classes because52`composeApp/release-rules.pro` keeps every class outside the Material icon53packages, as the54[ONNX Runtime Android guidance](https://onnxruntime.ai/docs/build/android.html)55requires.5657The iOS package version and revision are locked in `Package.resolved`. Open the58existing `iosApp` Xcode scheme; package resolution supplies the runtime. The59Gradle-generated framework expects the bridge in the host app, like the existing60embedded extension bridge.6162## Resource and quality limits6364- Only one inference/import/removal operation can hold the process-wide gate.65- One CPU inference thread; no GPU setup or background chapter processing.66- A 64 × 64, five-channel model input with aspect-preserving white padding; hints67  and hint masks are zero. Color estimation is deliberately coarse.68- Output uses original luminance and linework with interpolated model chroma.69  White speech bubbles and black ink remain neutral.70- Source payloads are limited to 25 MB; rasterization is subsampled to a maximum71  dimension of 1600 pixels before allocating the output image.72- Runtime tensors are scoped to each job. On Android and desktop the native session73  stays loaded between panels and closes after a minute without use or when the74  model is removed; iOS still opens one per job. Preview images bypass75  Coil's memory/disk caches. Only the current result is retained by the reader.76- Cancelling dismisses the UI and discards the result. An in-flight synchronous77  native call finishes before releasing resources and allowing the next job.78  It is not forcibly interrupted or destroyed while running.7980The exploratory CPU test on Apple Silicon peaked around **430 MB for the entire81standalone Python test process**, compared with over 1 GB at a 256-pixel input.82This is evidence for choosing a conservative default, not a device-memory cap or83an Android/iOS memory profile. The model remains too expensive for some low-memory84phones. Colors are approximate, can bleed between regions, and need not match85character designs or remain consistent between panels. Selecting a single panel86usually gives better results than coloring a full page at this input resolution.8788PNG and JPEG are the portable baseline. Decoder support for other formats varies89by platform. Output is a preview/export feature, not a persistent reader filter,90automatic panel detector, reference-guided colorizer, or chapter batch job.9192## Validation9394Targeted tests cover crop geometry, white padding and hints, preservation of ink95and white areas, corrupt model rejection, atomic import cleanup, decoder bounds,96and serialization across a cancelled native call. Optional real-model tests run97repeated inference and write PNG previews under `composeApp/build/reports/colorizer/`.9899```sh100YOKAN_COLORIZER_TEST_MODEL=/path/to/manga-colorize-fp16.onnx \101YOKAN_COLORIZER_TEST_IMAGE=/path/to/page.jpg \102./gradlew :composeApp:desktopTest --no-daemon --no-parallel --max-workers=1 \103  -Pkotlin.compiler.execution.strategy=in-process \104  --tests '*PanelColorizerTest' --tests '*PanelColorizerDesktopTest' \105  --tests '*PanelColorizerRenderTest' --tests '*ReaderViewModelStreamTest'106```107108The real-model test is explicitly skipped when the two environment variables are109absent. Model weights and test artwork are not checked into the repository.110Desktop real-model inference, the targeted tests, and Android, iOS device/simulator,111and Wasm Kotlin compilation passed. The Objective-C bridge also passed syntax112checks for iOS device and simulator SDKs. This does not verify a signed iOS app113or inference on physical Android/iOS devices. Device profiling and real mobile114reading-plus-colorization testing are still needed before production use.115

Search chapters, reference and source filenames.