kinescript 1.1.0__tar.gz
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.
- kinescript-1.1.0/LICENSE +25 -0
- kinescript-1.1.0/PKG-INFO +192 -0
- kinescript-1.1.0/README.md +153 -0
- kinescript-1.1.0/kinescript/__init__.py +6 -0
- kinescript-1.1.0/kinescript/cli.py +167 -0
- kinescript-1.1.0/kinescript/color.py +89 -0
- kinescript-1.1.0/kinescript/components.py +272 -0
- kinescript-1.1.0/kinescript/docs.py +345 -0
- kinescript-1.1.0/kinescript/ease.py +143 -0
- kinescript-1.1.0/kinescript/fonts/IBMPlexMono-Bold.ttf +0 -0
- kinescript-1.1.0/kinescript/fonts/IBMPlexMono-Medium.ttf +0 -0
- kinescript-1.1.0/kinescript/fonts/IBMPlexMono-OFL.txt +93 -0
- kinescript-1.1.0/kinescript/fonts/IBMPlexMono-Regular.ttf +0 -0
- kinescript-1.1.0/kinescript/fonts/IBMPlexMono-SemiBold.ttf +0 -0
- kinescript-1.1.0/kinescript/fonts/SpaceGrotesk-Bold.ttf +0 -0
- kinescript-1.1.0/kinescript/fonts/SpaceGrotesk-Medium.ttf +0 -0
- kinescript-1.1.0/kinescript/fonts/SpaceGrotesk-OFL.txt +93 -0
- kinescript-1.1.0/kinescript/fonts/SpaceGrotesk-Regular.ttf +0 -0
- kinescript-1.1.0/kinescript/fonts/SpaceGrotesk-SemiBold.ttf +0 -0
- kinescript-1.1.0/kinescript/mcp.py +148 -0
- kinescript-1.1.0/kinescript/media.py +220 -0
- kinescript-1.1.0/kinescript/mesh.py +390 -0
- kinescript-1.1.0/kinescript/models.py +339 -0
- kinescript-1.1.0/kinescript/output.py +370 -0
- kinescript-1.1.0/kinescript/presets.py +170 -0
- kinescript-1.1.0/kinescript/props.py +185 -0
- kinescript-1.1.0/kinescript/render.py +1204 -0
- kinescript-1.1.0/kinescript/render3d.py +393 -0
- kinescript-1.1.0/kinescript/scene.py +362 -0
- kinescript-1.1.0/kinescript/schema.py +701 -0
- kinescript-1.1.0/kinescript/shaders.py +79 -0
- kinescript-1.1.0/kinescript/space.py +81 -0
- kinescript-1.1.0/kinescript/svgpath.py +80 -0
- kinescript-1.1.0/kinescript/timing.py +169 -0
- kinescript-1.1.0/kinescript/verify.py +261 -0
- kinescript-1.1.0/kinescript.egg-info/PKG-INFO +192 -0
- kinescript-1.1.0/kinescript.egg-info/SOURCES.txt +47 -0
- kinescript-1.1.0/kinescript.egg-info/dependency_links.txt +1 -0
- kinescript-1.1.0/kinescript.egg-info/entry_points.txt +2 -0
- kinescript-1.1.0/kinescript.egg-info/requires.txt +7 -0
- kinescript-1.1.0/kinescript.egg-info/top_level.txt +1 -0
- kinescript-1.1.0/pyproject.toml +50 -0
- kinescript-1.1.0/setup.cfg +4 -0
- kinescript-1.1.0/tests/test_color_pipeline.py +105 -0
- kinescript-1.1.0/tests/test_core.py +489 -0
- kinescript-1.1.0/tests/test_docs.py +114 -0
- kinescript-1.1.0/tests/test_models.py +218 -0
- kinescript-1.1.0/tests/test_motion_blur.py +84 -0
- kinescript-1.1.0/tests/test_schema.py +257 -0
kinescript-1.1.0/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dr. Know How
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
The fonts in kinescript/fonts/ (Space Grotesk, IBM Plex Mono) are not covered by
|
|
24
|
+
this license. They are distributed under the SIL Open Font License 1.1; see the
|
|
25
|
+
-OFL.txt files next to them.
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kinescript
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Motion graphics and video edits written as JSON, checked by agents, rendered on the GPU.
|
|
5
|
+
Author: Dr. Know How
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/drknowhow/kinescript
|
|
8
|
+
Project-URL: Source, https://github.com/drknowhow/kinescript
|
|
9
|
+
Project-URL: Issues, https://github.com/drknowhow/kinescript/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/drknowhow/kinescript/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: video,motion graphics,animation,skia,ffmpeg,mcp,agents
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Environment :: GPU
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
25
|
+
Classifier: Topic :: Multimedia :: Video
|
|
26
|
+
Classifier: Topic :: Multimedia :: Video :: Conversion
|
|
27
|
+
Requires-Python: >=3.10
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
License-File: kinescript/fonts/IBMPlexMono-OFL.txt
|
|
31
|
+
License-File: kinescript/fonts/SpaceGrotesk-OFL.txt
|
|
32
|
+
Requires-Dist: skia-python>=87
|
|
33
|
+
Requires-Dist: numpy>=1.24
|
|
34
|
+
Requires-Dist: glfw>=2.5
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
37
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
<p align="center"><img src="https://raw.githubusercontent.com/drknowhow/kinescript/main/brand/logo-dark.png" width="460" alt="kinescript"></p>
|
|
41
|
+
|
|
42
|
+
<p align="center"><b>Video you can diff.</b><br>Motion graphics and video edits written as JSON, checked by agents, rendered on the GPU.</p>
|
|
43
|
+
|
|
44
|
+
<p align="center"><img src="https://raw.githubusercontent.com/drknowhow/kinescript/main/docs/hero.gif" width="720" alt="The Kinescript launch video, rendered by Kinescript"></p>
|
|
45
|
+
|
|
46
|
+
Kinescript turns a JSON scene into video. Every layer, keyframe and cut is a line of data, so a scene can be
|
|
47
|
+
generated, reviewed in a pull request, and changed by a script or an agent. The renderer is a pure function of
|
|
48
|
+
the frame number: any frame renders on its own, which makes previews instant and lets a render split across
|
|
49
|
+
processes.
|
|
50
|
+
|
|
51
|
+
The launch video in `docs/promo.mp4` is a Kinescript scene (`marketing/promo.json`). It is 35 seconds of 1080p
|
|
52
|
+
and renders, with audio, in about 3.5 seconds on the development machine.
|
|
53
|
+
|
|
54
|
+
## What it does
|
|
55
|
+
|
|
56
|
+
- **Cue timing.** Start and end times can name other layers: `"at": "title.out+0.2"`. Lengthen one layer and
|
|
57
|
+
everything cued after it moves. Cycles and missing references are reported with the ids involved.
|
|
58
|
+
- **Animate anything.** Numbers and colours take constants, keyframes (`[[0, 0], [0.6, 1, "outBack"]]`, with
|
|
59
|
+
negative times counted from the layer's end), a tween object, or an expression such as `"=540 + sin(t*3)*40"`.
|
|
60
|
+
Colours interpolate in OKLab.
|
|
61
|
+
- **Text that moves per letter.** `"split": "chars"` with a staggered enter motion, typewriter reveal with a caret,
|
|
62
|
+
`**emphasis**` markup, per-unit expressions (`"unitY": "=sin(T*4 + i)*12"` for a wave).
|
|
63
|
+
- **Footage.** Video layers with trim, speed, loop, cover/contain fit, punch-in `zoom` around a `focus` point, and
|
|
64
|
+
rounded picture-in-picture. A `sequence` turns a cut list into clips with fade, wipe, slide, zoom or blur
|
|
65
|
+
transitions. Clip audio and music beds are mixed automatically.
|
|
66
|
+
- **Captions** from `.srt`/`.vtt` or inline cues, with karaoke and pop modes.
|
|
67
|
+
- **Depth.** Any layer takes `z`, `rotateX` and `rotateY`; a scene `camera` pans, dollies and orbits with real
|
|
68
|
+
perspective; `flip`, `flip-up`, `tumble` and `push` motions; two-sided cards with `"backface": "hidden"`.
|
|
69
|
+
- **3D models.** Lit cubes, spheres, cylinders, cones, tori and planes, or several merged as `parts`, with
|
|
70
|
+
shine, metal, rim light and toon bands; light presets; `explode` and a `build` motion. 3D text and extruded
|
|
71
|
+
SVG paths (filled or stroked) with an optional bevel. Models from `.glb`, `.gltf` and `.obj` files, and a soft
|
|
72
|
+
`ground` shadow under any model.
|
|
73
|
+
- **Shaders.** SkSL layers with `mesh`, `aurora`, `grid` and `score` presets, or your own source.
|
|
74
|
+
- **Finishing.** Per-layer blur, shadow, blend modes and colour adjustments; a scene grade with vignette and film
|
|
75
|
+
grain; optional motion blur.
|
|
76
|
+
- **Components.** `lowerThird`, `titleCard`, `callout`, `focus` (dim everything but a region), `progress`,
|
|
77
|
+
`kinetic`, plus your own with `{{param}}` placeholders.
|
|
78
|
+
- **Outputs.** H.264 `.mp4`, ProRes 4444 `.mov` and VP9 `.webm` with alpha for compositing, `.gif`, PNG sequences.
|
|
79
|
+
|
|
80
|
+
## Built for agents
|
|
81
|
+
|
|
82
|
+
An agent cannot watch a video, so Kinescript gives it things it can read:
|
|
83
|
+
|
|
84
|
+
| Command | What the agent gets |
|
|
85
|
+
|---|---|
|
|
86
|
+
| `kine docs` | the full scene reference, short enough to keep in context |
|
|
87
|
+
| `kine check scene.json` | JSON issues with layer ids and time ranges: unknown keys (with the intended name first), bad values, missing media and out-of-range trims, text off canvas or in the safe margin, overlapping text, contrast under 3:1 against what is actually behind it, tiny text, too little reading time. Every problem is listed at once. Common names from other tools (`color`, `fontSize`, `duration`, `position`) are read and reported as info notes. |
|
|
88
|
+
| `kine look scene.json --boxes` | one PNG of many labelled frames, with every layer outlined and named |
|
|
89
|
+
| `kine probe scene.json --at 3.2` | resolved in/out of every layer and each visible layer's screen box |
|
|
90
|
+
| `kine still` / `kine render` | a frame, a range (`--from/--to`), a draft (`-q draft --scale 0.5`) or the final file |
|
|
91
|
+
|
|
92
|
+
The same tools are available over MCP (`kine mcp`), and `kine_look` / `kine_still` return images inline.
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"mcpServers": {
|
|
97
|
+
"kinescript": {"command": "kine", "args": ["mcp"]}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Install
|
|
103
|
+
|
|
104
|
+
Requires Python 3.10+ and ffmpeg on `PATH`.
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
pip install kinescript
|
|
108
|
+
kine doctor # ffmpeg path, GPU availability, default font
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
From a checkout: `pip install -e .`
|
|
112
|
+
|
|
113
|
+
Dependencies are `skia-python`, `numpy` and `glfw`. Space Grotesk and IBM Plex Mono (both SIL Open Font License)
|
|
114
|
+
ship with the package, so default text looks the same on every machine.
|
|
115
|
+
|
|
116
|
+
## Quick start
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
kine new scene.json
|
|
120
|
+
kine check scene.json
|
|
121
|
+
kine look scene.json --boxes
|
|
122
|
+
kine render scene.json -o scene.mp4
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"canvas": {"w": 1920, "h": 1080, "fps": 30, "bg": "#0a0c10"},
|
|
128
|
+
"grade": {"vignette": 0.35, "grain": 0.04},
|
|
129
|
+
"layers": [
|
|
130
|
+
{"id": "dot", "type": "circle", "x": "50%", "y": "50%", "r": 26, "fill": "$accent", "dur": 1.1,
|
|
131
|
+
"enter": {"name": "pop", "dur": 0.4}, "exit": "fade"},
|
|
132
|
+
{"id": "title", "type": "text", "text": "Motion, **written.**", "x": "50%", "y": "46%", "size": 140,
|
|
133
|
+
"weight": 700, "split": "chars", "at": "dot.out-0.1", "dur": 3.2,
|
|
134
|
+
"enter": {"name": "snap", "stagger": 0.03}, "exit": "fade"},
|
|
135
|
+
{"id": "sub", "type": "text", "text": "scenes as data", "x": "50%", "y": "62%", "size": 40,
|
|
136
|
+
"fill": "$muted", "at": "title.in+0.6", "until": "title.out", "enter": "rise"}
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
More in `examples/`: `hello.json` (title animation) and `edit.json` (a cut list with a punch-in, crossfade,
|
|
142
|
+
lower third, callout, karaoke captions and a music bed). Run `python examples/make_media.py` first to generate the
|
|
143
|
+
sample footage.
|
|
144
|
+
|
|
145
|
+
## Performance
|
|
146
|
+
|
|
147
|
+
Measured on the development machine (Intel Core Ultra 7 265, 20 threads, NVIDIA RTX 5060 Ti, Windows 11),
|
|
148
|
+
2026-10-30:
|
|
149
|
+
|
|
150
|
+
| Workload | Result |
|
|
151
|
+
|---|---|
|
|
152
|
+
| Drawing one 1080p frame of the launch video on the GPU, converted to I420 and read back as a render does | median 2.7 ms, p95 3.3 ms (all 1038 frames) |
|
|
153
|
+
| Launch video, 34.6 s at 1080p30, `-q high`, with audio | 3.5 s wall, about 300 frames/s (median of 5 runs) |
|
|
154
|
+
| `examples/edit.json`, 10.4 s with two decoded video clips | 2.05 s wall, 152 frames/s (median of 5 runs) |
|
|
155
|
+
|
|
156
|
+
`python bench/stages.py` splits the time per frame into drawing, conversion and readback, and writing to
|
|
157
|
+
ffmpeg for several workloads, and times whole renders.
|
|
158
|
+
|
|
159
|
+
Rendering uses Skia on the GPU through a hidden OpenGL context, one per worker process. Frames are split into
|
|
160
|
+
chunks, encoded in parallel and joined without re-encoding, while another ffmpeg process mixes the audio.
|
|
161
|
+
Within one process, such as the MCP server, the workers stay warm for two minutes between renders.
|
|
162
|
+
|
|
163
|
+
## Limits
|
|
164
|
+
|
|
165
|
+
- Without a usable GPU, Kinescript falls back to Skia's CPU rasteriser. With the Windows `skia-python` wheel this is
|
|
166
|
+
very slow (about 0.65 s per 1080p frame for the launch video); use `--scale 0.5` for previews on such machines.
|
|
167
|
+
`KINE_BACKEND=cpu` forces this path.
|
|
168
|
+
- 3D is drawn by Skia with a depth sort, not a GL pipeline: models have no image textures, skeletal animation or
|
|
169
|
+
shadows cast on each other, and separate model layers do not hide each other per pixel (merge touching
|
|
170
|
+
objects as `parts` of one model).
|
|
171
|
+
- Audio is mixing (trim, gain, fades, speed), not editing or effects.
|
|
172
|
+
- Video is decoded and resampled by ffmpeg to the scene frame rate. Jumping backwards or far ahead reopens the
|
|
173
|
+
decoder, which is slower than sequential playback.
|
|
174
|
+
- Text layout is single-script left-to-right with greedy wrapping. No shaping for complex scripts or bidi.
|
|
175
|
+
- Expressions are limited to arithmetic and the listed helpers; attribute access and other names are rejected.
|
|
176
|
+
|
|
177
|
+
## Project layout
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
kinescript/ engine: timing, props, presets, render, output, verify (check/look/probe), mcp, cli
|
|
181
|
+
examples/ scenes and the generator for sample media
|
|
182
|
+
marketing/ the launch video, as a scene and its builder script
|
|
183
|
+
brand/ logo files, generated art and the brand guide
|
|
184
|
+
content/ launch post and social copy
|
|
185
|
+
site/ landing page
|
|
186
|
+
tests/ pytest suite
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
MIT, see `LICENSE`. The bundled fonts are under the SIL Open Font License 1.1; their notices are in
|
|
192
|
+
`kinescript/fonts/`.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/drknowhow/kinescript/main/brand/logo-dark.png" width="460" alt="kinescript"></p>
|
|
2
|
+
|
|
3
|
+
<p align="center"><b>Video you can diff.</b><br>Motion graphics and video edits written as JSON, checked by agents, rendered on the GPU.</p>
|
|
4
|
+
|
|
5
|
+
<p align="center"><img src="https://raw.githubusercontent.com/drknowhow/kinescript/main/docs/hero.gif" width="720" alt="The Kinescript launch video, rendered by Kinescript"></p>
|
|
6
|
+
|
|
7
|
+
Kinescript turns a JSON scene into video. Every layer, keyframe and cut is a line of data, so a scene can be
|
|
8
|
+
generated, reviewed in a pull request, and changed by a script or an agent. The renderer is a pure function of
|
|
9
|
+
the frame number: any frame renders on its own, which makes previews instant and lets a render split across
|
|
10
|
+
processes.
|
|
11
|
+
|
|
12
|
+
The launch video in `docs/promo.mp4` is a Kinescript scene (`marketing/promo.json`). It is 35 seconds of 1080p
|
|
13
|
+
and renders, with audio, in about 3.5 seconds on the development machine.
|
|
14
|
+
|
|
15
|
+
## What it does
|
|
16
|
+
|
|
17
|
+
- **Cue timing.** Start and end times can name other layers: `"at": "title.out+0.2"`. Lengthen one layer and
|
|
18
|
+
everything cued after it moves. Cycles and missing references are reported with the ids involved.
|
|
19
|
+
- **Animate anything.** Numbers and colours take constants, keyframes (`[[0, 0], [0.6, 1, "outBack"]]`, with
|
|
20
|
+
negative times counted from the layer's end), a tween object, or an expression such as `"=540 + sin(t*3)*40"`.
|
|
21
|
+
Colours interpolate in OKLab.
|
|
22
|
+
- **Text that moves per letter.** `"split": "chars"` with a staggered enter motion, typewriter reveal with a caret,
|
|
23
|
+
`**emphasis**` markup, per-unit expressions (`"unitY": "=sin(T*4 + i)*12"` for a wave).
|
|
24
|
+
- **Footage.** Video layers with trim, speed, loop, cover/contain fit, punch-in `zoom` around a `focus` point, and
|
|
25
|
+
rounded picture-in-picture. A `sequence` turns a cut list into clips with fade, wipe, slide, zoom or blur
|
|
26
|
+
transitions. Clip audio and music beds are mixed automatically.
|
|
27
|
+
- **Captions** from `.srt`/`.vtt` or inline cues, with karaoke and pop modes.
|
|
28
|
+
- **Depth.** Any layer takes `z`, `rotateX` and `rotateY`; a scene `camera` pans, dollies and orbits with real
|
|
29
|
+
perspective; `flip`, `flip-up`, `tumble` and `push` motions; two-sided cards with `"backface": "hidden"`.
|
|
30
|
+
- **3D models.** Lit cubes, spheres, cylinders, cones, tori and planes, or several merged as `parts`, with
|
|
31
|
+
shine, metal, rim light and toon bands; light presets; `explode` and a `build` motion. 3D text and extruded
|
|
32
|
+
SVG paths (filled or stroked) with an optional bevel. Models from `.glb`, `.gltf` and `.obj` files, and a soft
|
|
33
|
+
`ground` shadow under any model.
|
|
34
|
+
- **Shaders.** SkSL layers with `mesh`, `aurora`, `grid` and `score` presets, or your own source.
|
|
35
|
+
- **Finishing.** Per-layer blur, shadow, blend modes and colour adjustments; a scene grade with vignette and film
|
|
36
|
+
grain; optional motion blur.
|
|
37
|
+
- **Components.** `lowerThird`, `titleCard`, `callout`, `focus` (dim everything but a region), `progress`,
|
|
38
|
+
`kinetic`, plus your own with `{{param}}` placeholders.
|
|
39
|
+
- **Outputs.** H.264 `.mp4`, ProRes 4444 `.mov` and VP9 `.webm` with alpha for compositing, `.gif`, PNG sequences.
|
|
40
|
+
|
|
41
|
+
## Built for agents
|
|
42
|
+
|
|
43
|
+
An agent cannot watch a video, so Kinescript gives it things it can read:
|
|
44
|
+
|
|
45
|
+
| Command | What the agent gets |
|
|
46
|
+
|---|---|
|
|
47
|
+
| `kine docs` | the full scene reference, short enough to keep in context |
|
|
48
|
+
| `kine check scene.json` | JSON issues with layer ids and time ranges: unknown keys (with the intended name first), bad values, missing media and out-of-range trims, text off canvas or in the safe margin, overlapping text, contrast under 3:1 against what is actually behind it, tiny text, too little reading time. Every problem is listed at once. Common names from other tools (`color`, `fontSize`, `duration`, `position`) are read and reported as info notes. |
|
|
49
|
+
| `kine look scene.json --boxes` | one PNG of many labelled frames, with every layer outlined and named |
|
|
50
|
+
| `kine probe scene.json --at 3.2` | resolved in/out of every layer and each visible layer's screen box |
|
|
51
|
+
| `kine still` / `kine render` | a frame, a range (`--from/--to`), a draft (`-q draft --scale 0.5`) or the final file |
|
|
52
|
+
|
|
53
|
+
The same tools are available over MCP (`kine mcp`), and `kine_look` / `kine_still` return images inline.
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"mcpServers": {
|
|
58
|
+
"kinescript": {"command": "kine", "args": ["mcp"]}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Install
|
|
64
|
+
|
|
65
|
+
Requires Python 3.10+ and ffmpeg on `PATH`.
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install kinescript
|
|
69
|
+
kine doctor # ffmpeg path, GPU availability, default font
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
From a checkout: `pip install -e .`
|
|
73
|
+
|
|
74
|
+
Dependencies are `skia-python`, `numpy` and `glfw`. Space Grotesk and IBM Plex Mono (both SIL Open Font License)
|
|
75
|
+
ship with the package, so default text looks the same on every machine.
|
|
76
|
+
|
|
77
|
+
## Quick start
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
kine new scene.json
|
|
81
|
+
kine check scene.json
|
|
82
|
+
kine look scene.json --boxes
|
|
83
|
+
kine render scene.json -o scene.mp4
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"canvas": {"w": 1920, "h": 1080, "fps": 30, "bg": "#0a0c10"},
|
|
89
|
+
"grade": {"vignette": 0.35, "grain": 0.04},
|
|
90
|
+
"layers": [
|
|
91
|
+
{"id": "dot", "type": "circle", "x": "50%", "y": "50%", "r": 26, "fill": "$accent", "dur": 1.1,
|
|
92
|
+
"enter": {"name": "pop", "dur": 0.4}, "exit": "fade"},
|
|
93
|
+
{"id": "title", "type": "text", "text": "Motion, **written.**", "x": "50%", "y": "46%", "size": 140,
|
|
94
|
+
"weight": 700, "split": "chars", "at": "dot.out-0.1", "dur": 3.2,
|
|
95
|
+
"enter": {"name": "snap", "stagger": 0.03}, "exit": "fade"},
|
|
96
|
+
{"id": "sub", "type": "text", "text": "scenes as data", "x": "50%", "y": "62%", "size": 40,
|
|
97
|
+
"fill": "$muted", "at": "title.in+0.6", "until": "title.out", "enter": "rise"}
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
More in `examples/`: `hello.json` (title animation) and `edit.json` (a cut list with a punch-in, crossfade,
|
|
103
|
+
lower third, callout, karaoke captions and a music bed). Run `python examples/make_media.py` first to generate the
|
|
104
|
+
sample footage.
|
|
105
|
+
|
|
106
|
+
## Performance
|
|
107
|
+
|
|
108
|
+
Measured on the development machine (Intel Core Ultra 7 265, 20 threads, NVIDIA RTX 5060 Ti, Windows 11),
|
|
109
|
+
2026-10-30:
|
|
110
|
+
|
|
111
|
+
| Workload | Result |
|
|
112
|
+
|---|---|
|
|
113
|
+
| Drawing one 1080p frame of the launch video on the GPU, converted to I420 and read back as a render does | median 2.7 ms, p95 3.3 ms (all 1038 frames) |
|
|
114
|
+
| Launch video, 34.6 s at 1080p30, `-q high`, with audio | 3.5 s wall, about 300 frames/s (median of 5 runs) |
|
|
115
|
+
| `examples/edit.json`, 10.4 s with two decoded video clips | 2.05 s wall, 152 frames/s (median of 5 runs) |
|
|
116
|
+
|
|
117
|
+
`python bench/stages.py` splits the time per frame into drawing, conversion and readback, and writing to
|
|
118
|
+
ffmpeg for several workloads, and times whole renders.
|
|
119
|
+
|
|
120
|
+
Rendering uses Skia on the GPU through a hidden OpenGL context, one per worker process. Frames are split into
|
|
121
|
+
chunks, encoded in parallel and joined without re-encoding, while another ffmpeg process mixes the audio.
|
|
122
|
+
Within one process, such as the MCP server, the workers stay warm for two minutes between renders.
|
|
123
|
+
|
|
124
|
+
## Limits
|
|
125
|
+
|
|
126
|
+
- Without a usable GPU, Kinescript falls back to Skia's CPU rasteriser. With the Windows `skia-python` wheel this is
|
|
127
|
+
very slow (about 0.65 s per 1080p frame for the launch video); use `--scale 0.5` for previews on such machines.
|
|
128
|
+
`KINE_BACKEND=cpu` forces this path.
|
|
129
|
+
- 3D is drawn by Skia with a depth sort, not a GL pipeline: models have no image textures, skeletal animation or
|
|
130
|
+
shadows cast on each other, and separate model layers do not hide each other per pixel (merge touching
|
|
131
|
+
objects as `parts` of one model).
|
|
132
|
+
- Audio is mixing (trim, gain, fades, speed), not editing or effects.
|
|
133
|
+
- Video is decoded and resampled by ffmpeg to the scene frame rate. Jumping backwards or far ahead reopens the
|
|
134
|
+
decoder, which is slower than sequential playback.
|
|
135
|
+
- Text layout is single-script left-to-right with greedy wrapping. No shaping for complex scripts or bidi.
|
|
136
|
+
- Expressions are limited to arithmetic and the listed helpers; attribute access and other names are rejected.
|
|
137
|
+
|
|
138
|
+
## Project layout
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
kinescript/ engine: timing, props, presets, render, output, verify (check/look/probe), mcp, cli
|
|
142
|
+
examples/ scenes and the generator for sample media
|
|
143
|
+
marketing/ the launch video, as a scene and its builder script
|
|
144
|
+
brand/ logo files, generated art and the brand guide
|
|
145
|
+
content/ launch post and social copy
|
|
146
|
+
site/ landing page
|
|
147
|
+
tests/ pytest suite
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
MIT, see `LICENSE`. The bundled fonts are under the SIL Open Font License 1.1; their notices are in
|
|
153
|
+
`kinescript/fonts/`.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Kinescript: motion graphics and video edits written as data, checked and rendered by agents."""
|
|
2
|
+
from .output import render, still
|
|
3
|
+
from .scene import Scene, SceneError, load
|
|
4
|
+
|
|
5
|
+
__version__ = "1.1.0"
|
|
6
|
+
__all__ = ["Scene", "SceneError", "load", "render", "still", "__version__"]
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""kine: command line for Kinescript."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import json
|
|
6
|
+
import sys
|
|
7
|
+
import time
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
|
|
12
|
+
STARTER = {
|
|
13
|
+
"canvas": {"w": 1920, "h": 1080, "fps": 30, "bg": "#0a0c10"},
|
|
14
|
+
"grade": {"vignette": 0.3},
|
|
15
|
+
"layers": [
|
|
16
|
+
{"id": "bg", "type": "shader", "preset": "mesh", "opacity": 0.35},
|
|
17
|
+
{"use": "titleCard", "id": "title", "title": "Your **title**", "subtitle": "a line of context",
|
|
18
|
+
"at": 0.3, "dur": 3.5},
|
|
19
|
+
{"use": "lowerThird", "id": "who", "title": "Name Surname", "subtitle": "Role", "at": "title.out+0.2", "dur": 3},
|
|
20
|
+
],
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _emit(obj):
|
|
25
|
+
sys.stdout.write(json.dumps(obj, indent=2, ensure_ascii=False) + "\n")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def main(argv=None) -> int:
|
|
29
|
+
ap = argparse.ArgumentParser(prog="kine", description="Kinescript: motion graphics and video edits as data.")
|
|
30
|
+
ap.add_argument("--version", action="version", version=f"kinescript {__version__}")
|
|
31
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
32
|
+
|
|
33
|
+
r = sub.add_parser("render", help="render a scene to .mp4/.mov/.webm/.gif or a .png sequence")
|
|
34
|
+
r.add_argument("scene")
|
|
35
|
+
r.add_argument("-o", "--out")
|
|
36
|
+
r.add_argument("-q", "--quality", choices=["draft", "standard", "high"], default="standard")
|
|
37
|
+
r.add_argument("--scale", type=float, default=1.0, help="resolution multiplier, e.g. 0.5 for a fast preview")
|
|
38
|
+
r.add_argument("--from", dest="start", type=float)
|
|
39
|
+
r.add_argument("--to", dest="end", type=float)
|
|
40
|
+
r.add_argument("-j", "--workers", type=int)
|
|
41
|
+
r.add_argument("--transparent", action="store_true", help="drop the background (use .mov or .webm)")
|
|
42
|
+
|
|
43
|
+
s = sub.add_parser("still", help="render one frame to PNG/JPG")
|
|
44
|
+
s.add_argument("scene")
|
|
45
|
+
s.add_argument("--at", required=True, help='seconds; negative counts from the end; "end" is the last frame')
|
|
46
|
+
s.add_argument("-o", "--out")
|
|
47
|
+
s.add_argument("--scale", type=float, default=1.0)
|
|
48
|
+
|
|
49
|
+
lk = sub.add_parser("look", help="contact sheet: many frames in one image, for review")
|
|
50
|
+
lk.add_argument("scene")
|
|
51
|
+
lk.add_argument("-n", "--count", type=int, default=12)
|
|
52
|
+
lk.add_argument("--cols", type=int)
|
|
53
|
+
lk.add_argument("--width", type=int, default=480, help="width of each thumbnail")
|
|
54
|
+
lk.add_argument("--at", type=float, nargs="*", help="explicit times instead of even spacing")
|
|
55
|
+
lk.add_argument("--boxes", action="store_true", help="outline every layer with its id")
|
|
56
|
+
lk.add_argument("-o", "--out")
|
|
57
|
+
|
|
58
|
+
ck = sub.add_parser("check", help="lint layout, timing, contrast and reading time; prints JSON")
|
|
59
|
+
ck.add_argument("scene")
|
|
60
|
+
ck.add_argument("--step", type=float, default=0.25)
|
|
61
|
+
|
|
62
|
+
pr = sub.add_parser("probe", help="resolved timeline and layer boxes at --at; or, for a media file, "
|
|
63
|
+
"its duration, size, fps and audio")
|
|
64
|
+
pr.add_argument("scene")
|
|
65
|
+
pr.add_argument("--at", type=float)
|
|
66
|
+
|
|
67
|
+
sub.add_parser("docs", help="print the scene reference")
|
|
68
|
+
nw = sub.add_parser("new", help="write a starter scene")
|
|
69
|
+
nw.add_argument("path", nargs="?", default="scene.json")
|
|
70
|
+
|
|
71
|
+
w = sub.add_parser("watch", help="re-render a contact sheet whenever the scene file changes")
|
|
72
|
+
w.add_argument("scene")
|
|
73
|
+
w.add_argument("-n", "--count", type=int, default=12)
|
|
74
|
+
|
|
75
|
+
sub.add_parser("mcp", help="run the MCP server on stdio")
|
|
76
|
+
sub.add_parser("doctor", help="report ffmpeg, GPU and font availability")
|
|
77
|
+
|
|
78
|
+
a = ap.parse_args(argv)
|
|
79
|
+
try:
|
|
80
|
+
return _run(a)
|
|
81
|
+
except (ValueError, RuntimeError, FileNotFoundError) as e:
|
|
82
|
+
_emit({"ok": False, "error": str(e)})
|
|
83
|
+
return 2
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _default_out(scene: str, suffix: str) -> str:
|
|
87
|
+
p = Path(scene)
|
|
88
|
+
return str(p.with_name(p.stem + suffix))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _run(a) -> int:
|
|
92
|
+
if a.cmd == "docs":
|
|
93
|
+
from .docs import reference
|
|
94
|
+
sys.stdout.write(reference())
|
|
95
|
+
return 0
|
|
96
|
+
if a.cmd == "new":
|
|
97
|
+
p = Path(a.path)
|
|
98
|
+
if p.exists():
|
|
99
|
+
raise ValueError(f"{p} exists; pick another name")
|
|
100
|
+
p.write_text(json.dumps(STARTER, indent=2), encoding="utf-8")
|
|
101
|
+
_emit({"ok": True, "out": str(p)})
|
|
102
|
+
return 0
|
|
103
|
+
if a.cmd == "mcp":
|
|
104
|
+
from .mcp import serve
|
|
105
|
+
serve()
|
|
106
|
+
return 0
|
|
107
|
+
if a.cmd == "doctor":
|
|
108
|
+
from . import media
|
|
109
|
+
from .render import gpu_context, Renderer
|
|
110
|
+
from .scene import Scene
|
|
111
|
+
info = {"version": __version__, "ffmpeg": media.FFMPEG, "gpu": gpu_context() is not None}
|
|
112
|
+
r = Renderer(Scene({"canvas": {"w": 64, "h": 64}, "layers": [{"type": "text", "text": "kine"}]}))
|
|
113
|
+
info["font"] = r._typeface(r.s.theme["font"], 600, False).getFamilyName()
|
|
114
|
+
_emit(info)
|
|
115
|
+
return 0
|
|
116
|
+
if a.cmd == "render":
|
|
117
|
+
from . import output
|
|
118
|
+
from .output import render
|
|
119
|
+
output.WARM = 0 # one render, then the process exits: shut the workers down inside it, as timed
|
|
120
|
+
out = a.out or _default_out(a.scene, ".mp4")
|
|
121
|
+
_emit(dict(ok=True, **render(a.scene, out, a.quality, a.workers, a.scale, a.start, a.end, a.transparent)))
|
|
122
|
+
return 0
|
|
123
|
+
if a.cmd == "still":
|
|
124
|
+
from .output import still
|
|
125
|
+
at = str(a.at)
|
|
126
|
+
out = a.out or _default_out(a.scene, f"_{at.lstrip('-')}{'s' if at != 'end' else ''}.png")
|
|
127
|
+
_emit(dict(ok=True, **still(a.scene, at, out, a.scale)))
|
|
128
|
+
return 0
|
|
129
|
+
if a.cmd == "look":
|
|
130
|
+
from .verify import contact_sheet
|
|
131
|
+
out = a.out or _default_out(a.scene, "_sheet.png")
|
|
132
|
+
_emit(dict(ok=True, **contact_sheet(a.scene, out, a.count, a.cols, a.width, a.at, a.boxes)))
|
|
133
|
+
return 0
|
|
134
|
+
if a.cmd == "check":
|
|
135
|
+
from .verify import check
|
|
136
|
+
res = check(a.scene, a.step)
|
|
137
|
+
_emit(res)
|
|
138
|
+
return 0 if res["ok"] else 1
|
|
139
|
+
if a.cmd == "probe":
|
|
140
|
+
from .verify import probe
|
|
141
|
+
if Path(a.scene).suffix.lower() != ".json" and Path(a.scene).exists():
|
|
142
|
+
from . import media
|
|
143
|
+
_emit(dict(ok=True, src=a.scene, **media.probe(a.scene)))
|
|
144
|
+
return 0
|
|
145
|
+
_emit(probe(a.scene, a.at))
|
|
146
|
+
return 0
|
|
147
|
+
if a.cmd == "watch":
|
|
148
|
+
from .verify import contact_sheet
|
|
149
|
+
p = Path(a.scene)
|
|
150
|
+
last = 0.0
|
|
151
|
+
out = _default_out(a.scene, "_sheet.png")
|
|
152
|
+
print(f"watching {p} -> {out} (Ctrl+C to stop)", file=sys.stderr)
|
|
153
|
+
while True:
|
|
154
|
+
m = p.stat().st_mtime
|
|
155
|
+
if m != last:
|
|
156
|
+
last = m
|
|
157
|
+
try:
|
|
158
|
+
contact_sheet(a.scene, out, a.count)
|
|
159
|
+
print(f"{time.strftime('%H:%M:%S')} updated", file=sys.stderr)
|
|
160
|
+
except (ValueError, RuntimeError) as e:
|
|
161
|
+
print(f"{time.strftime('%H:%M:%S')} error: {e}", file=sys.stderr)
|
|
162
|
+
time.sleep(0.5)
|
|
163
|
+
return 1
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
if __name__ == "__main__":
|
|
167
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Colour parsing and perceptual (OKLab) interpolation."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
from functools import lru_cache
|
|
6
|
+
|
|
7
|
+
RGBA = tuple[float, float, float, float]
|
|
8
|
+
|
|
9
|
+
NAMED = {
|
|
10
|
+
"black": "#000000", "white": "#ffffff", "transparent": "#00000000", "red": "#ff3b30",
|
|
11
|
+
"green": "#34c759", "blue": "#0a84ff", "yellow": "#ffd60a", "orange": "#ff9f0a",
|
|
12
|
+
"gray": "#8e8e93", "grey": "#8e8e93", "purple": "#bf5af2", "pink": "#ff375f", "cyan": "#64d2ff",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def is_color(v) -> bool:
|
|
17
|
+
return isinstance(v, str) and (v.startswith("#") or v.startswith("rgb") or v in NAMED)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@lru_cache(maxsize=4096)
|
|
21
|
+
def parse(c: str) -> RGBA:
|
|
22
|
+
c = NAMED.get(c, c).strip()
|
|
23
|
+
if c.startswith("#"):
|
|
24
|
+
h = c[1:]
|
|
25
|
+
if len(h) in (3, 4):
|
|
26
|
+
h = "".join(ch * 2 for ch in h)
|
|
27
|
+
if len(h) == 6:
|
|
28
|
+
h += "ff"
|
|
29
|
+
if len(h) != 8:
|
|
30
|
+
raise ValueError(f"bad colour {c!r}")
|
|
31
|
+
return tuple(int(h[i:i + 2], 16) / 255 for i in (0, 2, 4, 6)) # type: ignore[return-value]
|
|
32
|
+
m = re.fullmatch(r"rgba?\(([^)]*)\)", c)
|
|
33
|
+
if m:
|
|
34
|
+
parts = [float(p) for p in m.group(1).replace("/", ",").split(",") if p.strip()]
|
|
35
|
+
r, g, b = (p / 255 for p in parts[:3])
|
|
36
|
+
a = parts[3] if len(parts) > 3 else 1.0
|
|
37
|
+
return (r, g, b, a)
|
|
38
|
+
raise ValueError(f"bad colour {c!r} (use #rrggbb, #rrggbbaa, rgb(), rgba() or a name)")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def to_argb_int(c: RGBA, alpha_mul: float = 1.0) -> int:
|
|
42
|
+
r, g, b, a = c
|
|
43
|
+
a = max(0.0, min(1.0, a * alpha_mul))
|
|
44
|
+
return (round(a * 255) << 24) | (round(r * 255) << 16) | (round(g * 255) << 8) | round(b * 255)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _lin(x: float) -> float:
|
|
48
|
+
return x / 12.92 if x <= 0.04045 else ((x + 0.055) / 1.055) ** 2.4
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _gam(x: float) -> float:
|
|
52
|
+
x = max(0.0, min(1.0, x))
|
|
53
|
+
return 12.92 * x if x <= 0.0031308 else 1.055 * x ** (1 / 2.4) - 0.055
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _to_oklab(c: RGBA):
|
|
57
|
+
r, g, b = (_lin(v) for v in c[:3])
|
|
58
|
+
l = (0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b) ** (1 / 3)
|
|
59
|
+
m = (0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b) ** (1 / 3)
|
|
60
|
+
s = (0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b) ** (1 / 3)
|
|
61
|
+
return (0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s,
|
|
62
|
+
1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s,
|
|
63
|
+
0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _from_oklab(L: float, A: float, B: float):
|
|
67
|
+
l = (L + 0.3963377774 * A + 0.2158037573 * B) ** 3
|
|
68
|
+
m = (L - 0.1055613458 * A - 0.0638541728 * B) ** 3
|
|
69
|
+
s = (L - 0.0894841775 * A - 1.2914855480 * B) ** 3
|
|
70
|
+
return (_gam(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
|
|
71
|
+
_gam(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
|
|
72
|
+
_gam(-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def mix(a: RGBA, b: RGBA, t: float) -> RGBA:
|
|
76
|
+
"""Interpolate in OKLab so mid-tones stay vivid instead of going muddy."""
|
|
77
|
+
la, lb = _to_oklab(a), _to_oklab(b)
|
|
78
|
+
r, g, bl = _from_oklab(*(x + (y - x) * t for x, y in zip(la, lb)))
|
|
79
|
+
return (r, g, bl, a[3] + (b[3] - a[3]) * t)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def luminance(c: RGBA) -> float:
|
|
83
|
+
r, g, b = (_lin(v) for v in c[:3])
|
|
84
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def contrast(l1: float, l2: float) -> float:
|
|
88
|
+
hi, lo = max(l1, l2), min(l1, l2)
|
|
89
|
+
return (hi + 0.05) / (lo + 0.05)
|