# Download image processing

Settings → Downloads now includes tall-image splitting and image data saver.
Both are off by default. Their policies and integrations work on Android, iOS,
desktop and web. New settings live in `DbSettings.features` to preserve database
compatibility and avoid the JVM constructor-parameter limit.

## Tall images

Long manga pages can be saved as ordered JPEG tiles (quality 90), with a maximum
height from 1024–8192 pixels. Pages must be taller than twice their width.
Processing uses one permit across profiles, bounds encoded inputs to 32 MiB and
decoded inputs to 24 million pixels, and emits one tile at a time. Animated images,
unusual EXIF orientation and images exceeding the limits retain the original.
The final tile preserves the last row; transparent backgrounds become white.

The original page and its completion marker remain until every tile and a bounded
split manifest have been committed. A restart validates the sizes of all tiles,
finishes any pending original-file deletion, or retries from the original/source.
Cancelled and failed decodes preserve the original. Uncommitted outputs are
removed before retry, and deletion failures prevent falsely completing a chapter.
Only managed manga downloads are processed; existing completed downloads and local
library originals are unchanged. Retried, incomplete pages can use the new policy.

## Image data saver

Optional providers:

- **wsrv.nl:** JPEG, WebP or source format, quality, grayscale.
- **reSmush.it:** source format/colors and quality. Its API is intended for images
  under 5 MB; quality above 90 is recommended. Because its current API returns HTTP
  CDN URLs (and sampled CDN HTTPS certificates are invalid), those URLs are served
  through wsrv.nl over HTTPS with the selected quality. This is disclosed in settings.
- **Bandwidth Hero:** a user-owned public HTTPS server, JPEG/WebP, quality and grayscale.
  The server must allow browser CORS access to support the web target.

Reader pages/covers and manga downloads can be enabled independently. JPEG/GIF URLs
and selected sources can be excluded. Reader requests carry chapter identity;
cover identity is indexed once per changed title list when exclusions are enabled.
Unidentified images retain their original when source exclusions are configured.

Source cookies, authorization or unrecognized request headers, local/IP addresses,
plain HTTP origins, URL credentials and unrecognized query parameters bypass the
provider. No source headers are forwarded. Provider requests use Yokan's own
headers and profile-owned HTTP resources. No upstream credentials are embedded.

Image loading retries the original on network/decoding failure. Downloads reject
non-image optimizer responses before saving a completion marker and retry through
the normal source transport. Cancellation propagates. Provider failures have a
bounded one-minute cooldown; reSmush URL caching is bounded to 128 entries and one
minute. Cache keys separate provider, quality, format and grayscale variants while
retaining reader identity and transformations. Internal progress headers are
removed before transport.

Protocols: [wsrv format](https://wsrv.nl/docs/format),
[wsrv adjustment](https://wsrv.nl/docs/adjustment),
[reSmush API](https://resmush.it/api/),
[Bandwidth Hero parameters](https://github.com/ayastreb/bandwidth-hero-proxy/blob/master/src/params.js).

## Browser CBZ

The browser now streams chapter images and metadata into an OPFS CBZ, verifies the
archive index, then publishes it before removing its source folder. Active writers,
unarchived files and nested files prevent destructive folder replacement. Failed
archive writes retain the original folder. Reloads retain the completed archive.

The offline media worker streams individual ZIP entries with backpressure, checks
CRC-32 and expanded sizes, and supports compressed images and nested image paths.
Downloaded images are naturally ordered by the shared reader adapter. HTML remains
sandboxed. Encrypted, split/ZIP64, traversal/duplicate entries and archives outside
the limits fail explicitly: archive size below 4 GiB, at most 10,000 entries, central
directory at most 4 MiB, and expanded individual files at most 64 MiB.

zip.js 2.23.0 is vendored with its BSD license and verified package digest. The page
loads its 173 KiB bundle only for archive operations. The media worker imports it
at initialization because service workers prohibit fetching new imported scripts
after installation. Broader browser local-library import/management remains stage 5.

Verification: the final broader run passed 249 desktop regression tests and 26
Kotlin/Wasm browser tests, with all four targets compiling. The browser's real
Skia codec decoded a tall PNG and emitted readable JPEG tiles. Real Chrome checks
passed streamed 12 MiB CBZ creation/reading, reload, compressed entries, CRC failures,
index/path limits, archive write-failure recovery and preservation of unsupported
or nested original files. The browser streaming test uses a 30-second Mocha timeout
while retaining its >64 MiB byte-count and backpressure assertions.
