forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

gen.py35 lines, 1.6 KiBHistoryRawDownload
1#!/usr/bin/env python3
2"""Regenerates the synthetic JPEG fixtures next to this file (Pillow, libjpeg-turbo).
3
4The pictures are computed gradients plus seeded noise; nothing here is personal media.
5The expected pixels are never stored: the tests ask ffmpeg's mjpeg decoder at run time."""
6import numpy as np
7from PIL import Image
8
9def picture(w, h, seed):
10 rng = np.random.default_rng(seed)
11 y, x = np.mgrid[0:h, 0:w]
12 r = (x * 255 // max(w - 1, 1)) % 256
13 g = (y * 255 // max(h - 1, 1)) % 256
14 b = ((x ^ y) * 5) % 256
15 img = np.stack([r, g, b], -1).astype(np.int32)
16 img += rng.integers(-24, 25, img.shape)
17 img[h // 3: h // 3 + 6, w // 4: w // 4 + 9] = [250, 10, 20]
18 return Image.fromarray(np.clip(img, 0, 255).astype(np.uint8), "RGB")
19
20SUB = {"420": 2, "422": 1, "444": 0}
21jobs = []
22for name, sub in SUB.items():
23 jobs.append((f"prog{name}", dict(progressive=True, subsampling=sub, quality=85), (64, 48)))
24 jobs.append((f"rst{name}", dict(restart_marker_blocks=2, subsampling=sub, quality=80), (64, 48)))
25 jobs.append((f"progrst{name}", dict(progressive=True, restart_marker_blocks=3, subsampling=sub, quality=70), (53, 37)))
26 jobs.append((f"odd{name}", dict(subsampling=sub, quality=90, optimize=True), (51, 35)))
27jobs.append(("basegray", dict(quality=75), (40, 24), "L"))
28jobs.append(("proggray", dict(progressive=True, quality=85), (64, 48), "L"))
29jobs.append(("rstgray", dict(restart_marker_blocks=2, quality=80), (61, 45), "L"))
30for i, job in enumerate(jobs):
31 name, kw, (w, h) = job[:3]
32 img = picture(w, h, i + 1)
33 if len(job) > 3:
34 img = img.convert(job[3])
35 img.save(f"{name}.jpg", "JPEG", **kw)