asciianything 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CREDITS.md +34 -0
- package/README.md +124 -58
- package/package.json +3 -2
- package/src/cli.js +6 -0
- package/src/render.js +177 -3
package/CREDITS.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Credits
|
|
2
|
+
|
|
3
|
+
## Footage
|
|
4
|
+
|
|
5
|
+
**Night highway** — [Night Traffic Flow in Urban Highway View](https://www.pexels.com/video/night-traffic-flow-in-urban-highway-view-35835506/)
|
|
6
|
+
by [Sururi Ballıdağ](https://www.pexels.com/@drector/) (İstanbul).
|
|
7
|
+
Source file `15195617_1440_2560_30fps.mp4`, 1440 × 2560, 29.97 fps, 19.42 s.
|
|
8
|
+
Used under the [Pexels license](https://www.pexels.com/license/). The clips in `assets/demo.mp4` and
|
|
9
|
+
`assets/night-highway-1080p.mp4` are ASCII derivatives of it; the 1080p version is a 16:9 crop of the vertical original.
|
|
10
|
+
|
|
11
|
+
**Sunset** — [Stunning Beach Sunset with Vibrant Colors](https://www.pexels.com/video/stunning-beach-sunset-with-vibrant-colors-29045884/)
|
|
12
|
+
by [Manoo Media](https://www.pexels.com/@manoo-media-65214113/).
|
|
13
|
+
Source file `12556562_3840_2160_60fps.mp4`, 3840 × 2160, 60 fps, 11.57 s.
|
|
14
|
+
Used under the [Pexels license](https://www.pexels.com/license/). `assets/sunset-ascii.mp4` is the ASCII derivative.
|
|
15
|
+
|
|
16
|
+
The Pexels license allows free use, including commercial use and modification, without attribution.
|
|
17
|
+
The credits above are given because the footage is the other half of these renders, not because the licence demands it.
|
|
18
|
+
|
|
19
|
+
## Typeface
|
|
20
|
+
|
|
21
|
+
**JetBrains Mono** — [JetBrains/JetBrainsMono](https://github.com/JetBrains/JetBrainsMono),
|
|
22
|
+
licensed under the SIL Open Font License 1.1. The variable font is bundled at
|
|
23
|
+
`assets/JetBrainsMono-Variable.ttf` with the licence text in `assets/OFL.txt`.
|
|
24
|
+
|
|
25
|
+
## Prose
|
|
26
|
+
|
|
27
|
+
The bundled sentence bank (`assets/prose.json`) was written for this project. It is deterministic
|
|
28
|
+
generated text, not sampled from any other work. The sunset demo uses a separate 256-sentence bank
|
|
29
|
+
written for that clip.
|
|
30
|
+
|
|
31
|
+
## Code
|
|
32
|
+
|
|
33
|
+
MIT — see [`LICENSE`](LICENSE). The renderer uses [`@napi-rs/canvas`](https://github.com/Brooooooklyn/canvas)
|
|
34
|
+
(Skia bindings, MIT) for glyph rasterisation, and `ffmpeg` for decoding and encoding.
|
package/README.md
CHANGED
|
@@ -1,106 +1,172 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# asciianything
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
**A video rebuilt from coloured lowercase prose. One command, every frame, at the source's own resolution and frame rate.**
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
[](https://www.npmjs.com/package/asciianything)
|
|
8
|
+
[](https://www.npmjs.com/package/asciianything)
|
|
9
|
+
[](https://github.com/sloemo01/asciianything/stargazers)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
[](package.json)
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
<p>
|
|
14
|
+
<a href="assets/night-highway-1080p.mp4"><img src="https://raw.githubusercontent.com/sloemo01/asciianything/main/assets/night-highway-1080p.jpg" width="32%" alt="Night highway in ASCII prose, 1920x1080"></a>
|
|
15
|
+
<a href="assets/sunset-ascii.mp4"><img src="https://raw.githubusercontent.com/sloemo01/asciianything/main/assets/sunset.jpg" width="32%" alt="Sunset in ASCII prose, 3840x2160 at 60 fps"></a>
|
|
16
|
+
<a href="assets/demo.mp4"><img src="https://raw.githubusercontent.com/sloemo01/asciianything/main/assets/portrait.jpg" width="32%" alt="Night highway in ASCII prose, vertical 1440x2560"></a>
|
|
17
|
+
</p>
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
<sub><b>Night highway</b>, 19.4 s, 1920×1080 · <b>Sunset</b>, 11.6 s, 3840×2160·60 · <b>Night highway</b>, 19.4 s, 1440×2560</sub>
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
<sub>Three clips rendered by this package. Click a tile for the MP4.</sub>
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
[**Run it**](#run-it) · [What it is](#what-it-is) · [Options](#options) · [How it works](#how-it-works) · [Verification](#verification)
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
</div>
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
Every cell of the picture holds one stable English character. Close up it is lowercase prose you can read; at normal
|
|
28
|
+
viewing distance the same cells add up to the footage — same framing, same colour, same exposure, same motion. Nothing is
|
|
29
|
+
painted under the letters: all visible structure comes from glyph ink, weight and colour.
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
This is not an `@%#*+=-:.` brightness ramp, and it is not text laid over a video. One source frame goes in, one rendered
|
|
32
|
+
frame comes out, and the only things that change between frames are scene colour, sampled luminance, glyph weight and
|
|
33
|
+
emitted colour. No zoom, pan, transition, grain or vignette is ever added.
|
|
24
34
|
|
|
25
|
-
|
|
35
|
+

|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
- **Subcell sampling.** Each cell integrates a `cellW × cellH` block of the full-resolution frame, recovering percentiles and the bright-quartile colour, so a light smaller than a cell still lifts it.
|
|
29
|
-
- **Linear light.** sRGB is decoded to linear before any averaging or compensation, then encoded once on output.
|
|
30
|
-
- **No synthetic cinematography.** No zoom, pan, transitions, grain, vignette or animated font size. One source frame in, one rendered frame out.
|
|
37
|
+
## What it is
|
|
31
38
|
|
|
32
|
-
|
|
39
|
+
A small Node CLI around a deterministic renderer.
|
|
33
40
|
|
|
34
|
-
-
|
|
35
|
-
|
|
41
|
+
- **Prose, not noise.** A sentence bank is shuffled per row with a deterministic hash: every row is a different slice of
|
|
42
|
+
the bank, no row repeats the row above it, and each cell keeps the same character for the whole video.
|
|
43
|
+
- **Fidelity first.** One fixed cover transform, one fixed grid, one rendered frame per decoded source frame. Frame
|
|
44
|
+
count, duration, resolution and frame rate are probed from the source and reproduced exactly.
|
|
45
|
+
- **Linear light.** sRGB is decoded before any averaging, compensation or comparison, and encoded once on the way out.
|
|
46
|
+
- **Zero disk churn.** Raw frames are piped from `ffmpeg` into the renderer and straight into `libx264`; no PNG sequence
|
|
47
|
+
is ever written.
|
|
36
48
|
|
|
37
|
-
##
|
|
49
|
+
## Run it
|
|
38
50
|
|
|
39
51
|
```bash
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
npx asciianything night-drive.mp4
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
That writes `night-drive-ascii.mp4` at the source's resolution, frame rate and duration. Node 18+ and `ffmpeg` /
|
|
56
|
+
`ffprobe` on `PATH` are the only requirements.
|
|
42
57
|
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
```bash
|
|
59
|
+
# a specific output, larger letters
|
|
60
|
+
npx asciianything clip.mp4 -o poster.mp4 --font-size 32
|
|
45
61
|
|
|
46
|
-
# one still
|
|
47
|
-
npx asciianything
|
|
62
|
+
# one still, 8 seconds in
|
|
63
|
+
npx asciianything clip.mp4 --still 8 -o frame.png
|
|
48
64
|
|
|
49
|
-
#
|
|
50
|
-
npx asciianything
|
|
65
|
+
# 60 frames to check a look before committing to the whole reel
|
|
66
|
+
npx asciianything clip.mp4 --limit 60 -o preview.mp4
|
|
51
67
|
|
|
52
|
-
# your own
|
|
53
|
-
npx asciianything
|
|
68
|
+
# your own sentences instead of the bundled bank
|
|
69
|
+
npx asciianything clip.mp4 --prose my-words.txt
|
|
54
70
|
```
|
|
55
71
|
|
|
56
|
-
|
|
72
|
+
## Options
|
|
57
73
|
|
|
58
74
|
| flag | default | meaning |
|
|
59
75
|
| --- | --- | --- |
|
|
60
76
|
| `-o, --out <file>` | `<input>-ascii.mp4` | output path |
|
|
61
|
-
| `--font-size <px>` | `20` | glyph size in output pixels
|
|
77
|
+
| `--font-size <px>` | `20` | glyph size in output pixels — cells are `0.6 × fs` wide, `1.12 × fs` tall |
|
|
62
78
|
| `--cell-ratio <r>` | `1.12` | cell height ÷ font size |
|
|
63
|
-
| `--weights <a,b,…>` | `400,500,600,700,800` | font weights
|
|
64
|
-
| `--weight-min /
|
|
65
|
-
| `--stroke <px>` | `0.5` |
|
|
66
|
-
| `--calibration <n>` | `0.86` | ink-coverage calibration for the
|
|
79
|
+
| `--weights <a,b,…>` | `400,500,600,700,800` | font weights rasterised into the atlas |
|
|
80
|
+
| `--weight-min` / `--weight-max` | `600` / `800` | weight range picked from scene luminance |
|
|
81
|
+
| `--stroke <px>` | `0.5` | outline that raises ink coverage |
|
|
82
|
+
| `--calibration <n>` | `0.86` | ink-coverage calibration for the whole field |
|
|
83
|
+
| `--halo <n>` / `--halo-radius <px>` | `0` / `0.9 × cell width` | re-emit light the ink cannot carry (sun, specular paths, lamps) |
|
|
67
84
|
| `--diffusion <n>` | `0.1` | base softening of ink into the gaps |
|
|
68
|
-
| `--diffusion-adaptive <n>` | `0.25` | extra softening for bright cells
|
|
69
|
-
| `--detail <n>` | `0.14` | subcell luminance recovery |
|
|
70
|
-
| `--
|
|
71
|
-
| `--prose <file>` | bundled bank | `.txt` (sentences) or `.json` (array of sentences) |
|
|
85
|
+
| `--diffusion-adaptive <n>` | `0.25` | extra softening for bright cells |
|
|
86
|
+
| `--detail <n>` / `--color-detail <n>` | `0.14` / `0.1` | subcell luminance and colour recovery |
|
|
87
|
+
| `--prose <file>` | bundled bank | `.txt` sentences or a `.json` array |
|
|
72
88
|
| `--crf <n>` / `--preset <p>` | `17` / `slow` | x264 quality and speed |
|
|
73
|
-
| `--still <seconds>` | — | render
|
|
89
|
+
| `--still <seconds>` | — | render one PNG instead of a video |
|
|
74
90
|
| `--limit <n>` | — | stop after n frames |
|
|
75
|
-
| `--info` | — | print grid, cell size and measured coverage |
|
|
91
|
+
| `--info` | — | print grid, cell size and measured coverage, then exit |
|
|
92
|
+
|
|
93
|
+
## How it works
|
|
94
|
+
|
|
95
|
+
**A glyph inks only part of its cell, so the colour is divided by that part.** Drawing the sampled source colour into a
|
|
96
|
+
letter would multiply the scene by the ink fraction — the classic dark wall of text. Instead the atlas is measured: every
|
|
97
|
+
character at every weight is rasterised through Skia at 4× and box-averaged down to the cell pitch, and its real coverage
|
|
98
|
+
is stored. The renderer then emits
|
|
76
99
|
|
|
77
|
-
|
|
100
|
+
```text
|
|
101
|
+
emitted = scene / (coverage × calibration)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
so individual letters are brighter than their source cell and the integrated cell — ink plus the black gaps — lands back
|
|
105
|
+
on the sampled colour.
|
|
106
|
+
|
|
107
|
+
**Spaces carry no ink, and they are about a fifth of the field.** Coverage compensation alone still leaves the field mean
|
|
108
|
+
at `p_ink × scene`, because spaces draw nothing. `--calibration` is therefore set near the measured non-space fraction
|
|
109
|
+
(sunset: `0.8025`, night highway: `0.76–0.86`), which restores the field mean. Flat-field tests confirm the arithmetic: at
|
|
110
|
+
calibration `1.0` a flat midtone renders at `p_ink` of its source, and the ratio rises as `1/calibration` predicts.
|
|
78
111
|
|
|
79
|
-
|
|
112
|
+
**Highlights have a ceiling, and the halo pays for it.** Coverage caps how bright one cell can get, so a sun disc or a
|
|
113
|
+
specular path physically cannot be reproduced by ink alone. `--halo` measures what each cell's ink actually delivers and
|
|
114
|
+
re-emits the shortfall as a bloom shaped by the glyph itself; cells that already match contribute nothing, so smooth sky,
|
|
115
|
+
sand and rock are untouched. It is off by default.
|
|
80
116
|
|
|
81
|
-
|
|
117
|
+
**Prose stays still.** Rows are shuffled deterministically from the sentence bank, every row starts at a deterministic
|
|
118
|
+
offset, and the character grid is frozen for the whole clip. Motion in the output is the source's motion, sampled — never
|
|
119
|
+
reshuffled text.
|
|
82
120
|
|
|
83
|
-
##
|
|
121
|
+
## Verification
|
|
84
122
|
|
|
85
|
-
|
|
123
|
+
Measured against the sources after encoding, in linear light, one-cell blur:
|
|
86
124
|
|
|
87
|
-
|
|
125
|
+
| clip | grid | whole-frame luminance | settings |
|
|
126
|
+
| --- | --- | --- | --- |
|
|
127
|
+
| night highway · 1920×1080 | 320 × 99 (31,680) | +2.5 % | `--font-size 10 --calibration 0.76 --halo 1.2 --halo-radius 8` |
|
|
128
|
+
| night highway · 1440×2560 | 120 × 117 (14,040) | +0.5 … +7 % | `--font-size 20`, six sampled times |
|
|
129
|
+
| sunset · 3840×2160·60 | 384 × 114 (43,776) | +0.9 % | `--font-size 17 --calibration 0.8025 --halo 1.7 --halo-radius 14` |
|
|
88
130
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
- `src/prose.js` builds the fixed character field from the sentence bank.
|
|
92
|
-
- `src/cli.js` pipes raw frames from `ffmpeg` into the renderer and rendered frames straight into `libx264`, so no intermediate frame sequence ever touches disk.
|
|
131
|
+
Frame counts, durations, dimensions and colour tags are probed independently after encoding. The sunset run additionally
|
|
132
|
+
holds every measured region — top sky, cirrus, cloud fan, sea band, wet sand, rocks — inside ±1.6 %.
|
|
93
133
|
|
|
94
|
-
|
|
134
|
+
## Demos
|
|
135
|
+
|
|
136
|
+
The three clips above are rendered with this package:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# 1920x1080, cropped from a 1440x2560 source, 582 frames at 29.97 fps
|
|
140
|
+
npx asciianything night-1080p.mp4 --font-size 10 --calibration 0.76 \
|
|
141
|
+
--halo 1.2 --halo-radius 8 -o night-highway-1080p.mp4
|
|
142
|
+
|
|
143
|
+
# 3840x2160 at 60 fps, 694 frames, custom 256-sentence sunset bank
|
|
144
|
+
npx asciianything sunset.mp4 --font-size 17 --calibration 0.8025 \
|
|
145
|
+
--halo 1.7 --halo-radius 14 --prose sunset-prose.txt -o sunset-ascii.mp4
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The bundled bank (`assets/prose.json`) holds 1,844 deterministic sentences about night highways, sodium light and distant
|
|
149
|
+
towers — the house voice for the night-highway clips. Any lowercase English works; longer sentences read better at small
|
|
150
|
+
font sizes.
|
|
95
151
|
|
|
96
152
|
## Limits
|
|
97
153
|
|
|
98
|
-
Large glyphs mean fewer cells, and
|
|
154
|
+
Large glyphs mean fewer cells, and one cell can only average as bright as its ink coverage allows. A very large, very
|
|
155
|
+
bright highlight will top out below the source unless `--halo` makes up the difference. Lowering `--calibration` brightens
|
|
156
|
+
the whole field; raising it darkens it. Small font sizes preserve more detail and read as a finer texture; large ones read
|
|
157
|
+
as a poster and are legible from across a room.
|
|
99
158
|
|
|
100
159
|
## Credits
|
|
101
160
|
|
|
102
|
-
|
|
161
|
+
Night highway footage: [Night Traffic Flow in Urban Highway View](https://www.pexels.com/video/night-traffic-flow-in-urban-highway-view-35835506/)
|
|
162
|
+
by [Sururi Ballıdağ](https://www.pexels.com/@drector/), used under the [Pexels license](https://www.pexels.com/license/).
|
|
163
|
+
|
|
164
|
+
Sunset footage: [Stunning Beach Sunset with Vibrant Colors](https://www.pexels.com/video/stunning-beach-sunset-with-vibrant-colors-29045884/) by [Manoo Media](https://www.pexels.com/@manoo-media-65214113/), used under the [Pexels license](https://www.pexels.com/license/).
|
|
165
|
+
|
|
166
|
+
Bundled typeface: [JetBrains Mono](https://github.com/JetBrains/JetBrainsMono), SIL OFL 1.1 — see `assets/OFL.txt`.
|
|
167
|
+
|
|
168
|
+
Full sourcing and licence notes: [CREDITS.md](CREDITS.md).
|
|
103
169
|
|
|
104
170
|
## Licence
|
|
105
171
|
|
|
106
|
-
MIT for the code.
|
|
172
|
+
MIT for the code.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "asciianything",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Turn any video into a mosaic of coloured lowercase prose, frame-accurate, with ffmpeg.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ascii",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"src",
|
|
24
24
|
"assets/JetBrainsMono-Variable.ttf",
|
|
25
25
|
"assets/prose.json",
|
|
26
|
-
"assets/OFL.txt"
|
|
26
|
+
"assets/OFL.txt",
|
|
27
|
+
"CREDITS.md"
|
|
27
28
|
],
|
|
28
29
|
"engines": {
|
|
29
30
|
"node": ">=18"
|
package/src/cli.js
CHANGED
|
@@ -25,6 +25,8 @@ options:
|
|
|
25
25
|
--calibration <n> ink-coverage calibration (default 0.86)
|
|
26
26
|
--diffusion <n> base ink softening, 0..1 (default 0.1)
|
|
27
27
|
--diffusion-adaptive extra softening for bright cells (default 0.25)
|
|
28
|
+
--halo <n> highlight halo for light the ink cannot carry (default 0)
|
|
29
|
+
--halo-radius <px> halo blur radius (default 0.9 x cell width)
|
|
28
30
|
--detail <n> subcell luminance detail recovery (default 0.14)
|
|
29
31
|
--color-detail <n> subcell colour recovery (default 0.1)
|
|
30
32
|
--prose <file> sentence bank (.txt or .json) instead of the bundled one
|
|
@@ -129,6 +131,8 @@ async function main() {
|
|
|
129
131
|
calibration: { type: 'string' },
|
|
130
132
|
diffusion: { type: 'string' },
|
|
131
133
|
'diffusion-adaptive': { type: 'string' },
|
|
134
|
+
halo: { type: 'string' },
|
|
135
|
+
'halo-radius': { type: 'string' },
|
|
132
136
|
detail: { type: 'string' },
|
|
133
137
|
'color-detail': { type: 'string' },
|
|
134
138
|
prose: { type: 'string' },
|
|
@@ -174,6 +178,8 @@ async function main() {
|
|
|
174
178
|
calibration: num(values.calibration, 0.86),
|
|
175
179
|
diffusion: num(values.diffusion, 0.1),
|
|
176
180
|
diffusionAdaptive: num(values['diffusion-adaptive'], 0.25),
|
|
181
|
+
halo: num(values.halo, 0),
|
|
182
|
+
haloRadius: values['halo-radius'] === undefined ? undefined : num(values['halo-radius'], 0),
|
|
177
183
|
detailLuma: num(values.detail, 0.14),
|
|
178
184
|
detailColor: num(values['color-detail'], 0.1),
|
|
179
185
|
prosePath: values.prose,
|
package/src/render.js
CHANGED
|
@@ -156,6 +156,54 @@ class Renderer {
|
|
|
156
156
|
|
|
157
157
|
this.rgb = new Uint8Array(this.width * this.height * 3);
|
|
158
158
|
this.alpha = new Float32Array(this.width * this.height);
|
|
159
|
+
|
|
160
|
+
// highlight halo: light the ink cannot carry is re-emitted as a local
|
|
161
|
+
// glow shaped by the glyph itself, so a sun or a specular path keeps the
|
|
162
|
+
// energy the source has instead of topping out at the coverage ceiling.
|
|
163
|
+
this.halo = cfg.halo === undefined ? 0 : cfg.halo;
|
|
164
|
+
this.haloRadius = Math.max(
|
|
165
|
+
1,
|
|
166
|
+
Math.round(cfg.haloRadius === undefined ? this.cellw * 0.9 : cfg.haloRadius)
|
|
167
|
+
);
|
|
168
|
+
this.haloGain = new Float32Array(this.cells * 3);
|
|
169
|
+
this.sumR = new Float32Array(this.cells);
|
|
170
|
+
this.sumG = new Float32Array(this.cells);
|
|
171
|
+
this.sumB = new Float32Array(this.cells);
|
|
172
|
+
this.count = new Uint16Array(this.cells);
|
|
173
|
+
this.glowBuf = this.halo > 0 ? new Float32Array(this.width * this.height * 3) : null;
|
|
174
|
+
if (this.halo > 0) this._buildGlowTiles();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Pre-blurred glyph tiles, used to scatter each clipped cell's lost light. */
|
|
178
|
+
_buildGlowTiles() {
|
|
179
|
+
const R = this.haloRadius;
|
|
180
|
+
const gw = this.cellw + 2 * R;
|
|
181
|
+
const gh = this.cellh + 2 * R;
|
|
182
|
+
const n = this.atlas.weights.length * this.atlas.chars.length;
|
|
183
|
+
this.glowTiles = new Float32Array(n * gw * gh);
|
|
184
|
+
this.glowW = gw;
|
|
185
|
+
this.glowH = gh;
|
|
186
|
+
|
|
187
|
+
const tile = new Float32Array(gw * gh);
|
|
188
|
+
const tmp = new Float32Array(gw * gh);
|
|
189
|
+
const atile = this.atlas;
|
|
190
|
+
for (let wi = 0; wi < atile.weights.length; wi++) {
|
|
191
|
+
for (let ci = 0; ci < atile.chars.length; ci++) {
|
|
192
|
+
const src = (wi * atile.chars.length + ci) * atile.area;
|
|
193
|
+
tile.fill(0);
|
|
194
|
+
if (atile.chars[ci] !== ' ') {
|
|
195
|
+
for (let y = 0; y < this.cellh; y++) {
|
|
196
|
+
const srow = src + (atile.pad + y) * atile.tilew + atile.pad;
|
|
197
|
+
const drow = (y + R) * gw + R;
|
|
198
|
+
for (let x = 0; x < this.cellw; x++) tile[drow + x] = atile.alpha[srow + x];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// two separable box passes -> soft bloom with the cell's own shape
|
|
202
|
+
boxBlurR(tile, tmp, gw, gh, Math.max(1, R >> 1));
|
|
203
|
+
boxBlurR(tmp, tile, gw, gh, Math.max(1, R >> 1));
|
|
204
|
+
this.glowTiles.set(tile, (wi * atile.chars.length + ci) * gw * gh);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
159
207
|
}
|
|
160
208
|
|
|
161
209
|
stats() {
|
|
@@ -292,9 +340,16 @@ class Renderer {
|
|
|
292
340
|
}
|
|
293
341
|
|
|
294
342
|
this.wgrid[c] = wi;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
343
|
+
// a space carries no ink: emit nothing rather than dividing by the floor
|
|
344
|
+
if (ch === 0) {
|
|
345
|
+
this.colors[c * 3] = 0;
|
|
346
|
+
this.colors[c * 3 + 1] = 0;
|
|
347
|
+
this.colors[c * 3 + 2] = 0;
|
|
348
|
+
} else {
|
|
349
|
+
this.colors[c * 3] = Math.min(gr, maxEmitted);
|
|
350
|
+
this.colors[c * 3 + 1] = Math.min(gg, maxEmitted);
|
|
351
|
+
this.colors[c * 3 + 2] = Math.min(gb, maxEmitted);
|
|
352
|
+
}
|
|
298
353
|
}
|
|
299
354
|
}
|
|
300
355
|
|
|
@@ -325,6 +380,9 @@ class Renderer {
|
|
|
325
380
|
}
|
|
326
381
|
}
|
|
327
382
|
|
|
383
|
+
let glow = null;
|
|
384
|
+
if (this.halo > 0) glow = this._halo();
|
|
385
|
+
|
|
328
386
|
for (let i = 0; i < px; i++) {
|
|
329
387
|
const cell = cellId[i];
|
|
330
388
|
const ink = a[i];
|
|
@@ -334,6 +392,12 @@ class Renderer {
|
|
|
334
392
|
let r = ink * cr;
|
|
335
393
|
let g = ink * cg;
|
|
336
394
|
let b = ink * cb;
|
|
395
|
+
if (glow) {
|
|
396
|
+
const o3 = i * 3;
|
|
397
|
+
r += glow[o3];
|
|
398
|
+
g += glow[o3 + 1];
|
|
399
|
+
b += glow[o3 + 2];
|
|
400
|
+
}
|
|
337
401
|
const y = LUMA_R * r + LUMA_G * g + LUMA_B * b;
|
|
338
402
|
r = y + (r - y) * sat;
|
|
339
403
|
g = y + (g - y) * sat;
|
|
@@ -348,6 +412,84 @@ class Renderer {
|
|
|
348
412
|
}
|
|
349
413
|
return out;
|
|
350
414
|
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Measure what each cell's ink actually delivers, and re-emit the shortfall
|
|
418
|
+
* as a bloom shaped by the glyph. Only cells whose source light exceeds what
|
|
419
|
+
* their coverage can carry contribute, so smooth sky is untouched.
|
|
420
|
+
*/
|
|
421
|
+
_halo() {
|
|
422
|
+
const { cols, rows, cellw, cellh, cellId, colors, chars, wgrid } = this;
|
|
423
|
+
const a = this.alpha;
|
|
424
|
+
const px = this.width * this.height;
|
|
425
|
+
const sumR = this.sumR, sumG = this.sumG, sumB = this.sumB, count = this.count;
|
|
426
|
+
const gains = this.haloGain;
|
|
427
|
+
sumR.fill(0); sumG.fill(0); sumB.fill(0); count.fill(0);
|
|
428
|
+
|
|
429
|
+
for (let i = 0; i < px; i++) {
|
|
430
|
+
const c = cellId[i];
|
|
431
|
+
const ink = a[i];
|
|
432
|
+
sumR[c] += Math.min(ink * colors[c * 3], 1);
|
|
433
|
+
sumG[c] += Math.min(ink * colors[c * 3 + 1], 1);
|
|
434
|
+
sumB[c] += Math.min(ink * colors[c * 3 + 2], 1);
|
|
435
|
+
count[c]++;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const calib = this.calibration;
|
|
439
|
+
const nw = this.atlas.chars.length;
|
|
440
|
+
const cov = this.atlas.coverage;
|
|
441
|
+
let any = false;
|
|
442
|
+
for (let c = 0; c < this.cells; c++) {
|
|
443
|
+
const n = count[c] || 1;
|
|
444
|
+
if (chars[c] === 0) {
|
|
445
|
+
gains[c * 3] = 0; gains[c * 3 + 1] = 0; gains[c * 3 + 2] = 0;
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
const C = Math.max(cov[wgrid[c] * nw + chars[c]], 0.02);
|
|
449
|
+
const wantR = this.sceneRGB[c * 3] / calib;
|
|
450
|
+
const wantG = this.sceneRGB[c * 3 + 1] / calib;
|
|
451
|
+
const wantB = this.sceneRGB[c * 3 + 2] / calib;
|
|
452
|
+
const defR = wantR - sumR[c] / n;
|
|
453
|
+
const defG = wantG - sumG[c] / n;
|
|
454
|
+
const defB = wantB - sumB[c] / n;
|
|
455
|
+
const gR = defR > 0 ? (this.halo * defR) / C : 0;
|
|
456
|
+
const gG = defG > 0 ? (this.halo * defG) / C : 0;
|
|
457
|
+
const gB = defB > 0 ? (this.halo * defB) / C : 0;
|
|
458
|
+
gains[c * 3] = gR; gains[c * 3 + 1] = gG; gains[c * 3 + 2] = gB;
|
|
459
|
+
if (gR > 0 || gG > 0 || gB > 0) any = true;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const glow = this.glowBuf;
|
|
463
|
+
glow.fill(0);
|
|
464
|
+
if (!any) return glow;
|
|
465
|
+
|
|
466
|
+
const gw = this.glowW, gh = this.glowH, R = this.haloRadius, W = this.width, H = this.height;
|
|
467
|
+
for (let c = 0; c < this.cells; c++) {
|
|
468
|
+
const gR = gains[c * 3], gG = gains[c * 3 + 1], gB = gains[c * 3 + 2];
|
|
469
|
+
if (gR === 0 && gG === 0 && gB === 0) continue;
|
|
470
|
+
const tile = this.glowTiles.subarray(
|
|
471
|
+
(wgrid[c] * nw + chars[c]) * gw * gh,
|
|
472
|
+
(wgrid[c] * nw + chars[c] + 1) * gw * gh
|
|
473
|
+
);
|
|
474
|
+
const cx = (c % cols) * cellw - R;
|
|
475
|
+
const cy = ((c / cols) | 0) * cellh - R;
|
|
476
|
+
const y0 = Math.max(0, -cy), y1 = Math.min(gh, H - cy);
|
|
477
|
+
const x0 = Math.max(0, -cx), x1 = Math.min(gw, W - cx);
|
|
478
|
+
for (let y = y0; y < y1; y++) {
|
|
479
|
+
const row = (cy + y) * W;
|
|
480
|
+
const trow = y * gw;
|
|
481
|
+
for (let x = x0; x < x1; x++) {
|
|
482
|
+
const t = tile[trow + x];
|
|
483
|
+
if (t === 0) continue;
|
|
484
|
+
const o = (row + cx + x) * 3;
|
|
485
|
+
glow[o] += gR * t;
|
|
486
|
+
glow[o + 1] += gG * t;
|
|
487
|
+
glow[o + 2] += gB * t;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return glow;
|
|
492
|
+
}
|
|
351
493
|
}
|
|
352
494
|
|
|
353
495
|
function buildOutputLUT(n = 4096) {
|
|
@@ -360,6 +502,38 @@ function buildOutputLUT(n = 4096) {
|
|
|
360
502
|
return lut;
|
|
361
503
|
}
|
|
362
504
|
|
|
505
|
+
/** separable box blur of radius r, energy preserving with edge clamping */
|
|
506
|
+
function boxBlurR(src, dst, width, height, r) {
|
|
507
|
+
if (r < 1) {
|
|
508
|
+
dst.set(src);
|
|
509
|
+
return dst;
|
|
510
|
+
}
|
|
511
|
+
const norm = 1 / (2 * r + 1);
|
|
512
|
+
const tmp = new Float32Array(src.length);
|
|
513
|
+
for (let y = 0; y < height; y++) {
|
|
514
|
+
const row = y * width;
|
|
515
|
+
let sum = 0;
|
|
516
|
+
for (let k = -r; k <= r; k++) sum += src[row + Math.min(width - 1, Math.max(0, k))];
|
|
517
|
+
for (let x = 0; x < width; x++) {
|
|
518
|
+
tmp[row + x] = sum * norm;
|
|
519
|
+
const add = Math.min(width - 1, x + r + 1);
|
|
520
|
+
const sub = Math.max(0, x - r);
|
|
521
|
+
sum += src[row + add] - src[row + sub];
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
for (let x = 0; x < width; x++) {
|
|
525
|
+
let sum = 0;
|
|
526
|
+
for (let k = -r; k <= r; k++) sum += tmp[Math.min(height - 1, Math.max(0, k)) * width + x];
|
|
527
|
+
for (let y = 0; y < height; y++) {
|
|
528
|
+
dst[y * width + x] = sum * norm;
|
|
529
|
+
const add = Math.min(height - 1, y + r + 1);
|
|
530
|
+
const sub = Math.max(0, y - r);
|
|
531
|
+
sum += tmp[add * width + x] - tmp[sub * width + x];
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return dst;
|
|
535
|
+
}
|
|
536
|
+
|
|
363
537
|
/** separable 1-2-1 blur over a float image, energy preserving */
|
|
364
538
|
function box3(src, width, height, dst) {
|
|
365
539
|
const out = dst || new Float32Array(src.length);
|