forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB03dc6e9Tahinli3 months ago178 commits

gen-still-fixtures.sh104 lines, 6.4 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# Still-image fixtures for ec-image's differential tests: every PNG colour
3# type and bit depth, both JPEG processes at each chroma layout, and both WebP
4# bitstreams with and without alpha.
5#
6# The corpus is generated rather than committed, so the repository stays free
7# of binaries and every machine can rebuild it: ImageMagick writes the PNG and
8# JPEG variants, ffmpeg the WebP ones.
9set -euo pipefail
10
11root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
12out="$root/fixtures/stills"
13mkdir -p "$out"
14
15need() {
16 command -v "$1" >/dev/null || { echo "missing: $1" >&2; exit 1; }
17}
18need magick
19need ffmpeg
20
21# Source pictures: one with smooth and hard content at even dimensions, one at
22# odd dimensions (chroma subsampling and Adam7 both round there), and one with
23# a real alpha channel.
24# Seeded, so the corpus is byte-identical on every machine and a differential
25# bar measured today still means the same thing tomorrow.
26magick -seed 1234 -size 320x240 plasma:fractal -blur 0x1 \
27 -fill white -stroke black -draw "rectangle 20,20 80,60" \
28 -draw "line 0,239 319,0" "$out/source.png"
29magick "$out/source.png" -resize 61x47! "$out/source-odd.png"
30magick "$out/source.png" -alpha set -channel A \
31 -fx "i/w" +channel "$out/source-alpha.png"
32
33# --- PNG: every colour type, every bit depth, both interlace methods --------
34magick "$out/source.png" -define png:color-type=2 -depth 8 "$out/rgb8.png"
35magick "$out/source-alpha.png" -define png:color-type=6 -depth 8 "$out/rgba8.png"
36magick "$out/source.png" -colorspace Gray -define png:color-type=0 -depth 8 "$out/gray8.png"
37magick "$out/source-alpha.png" -colorspace Gray -define png:color-type=4 -depth 8 "$out/graya8.png"
38magick "$out/source.png" -define png:color-type=2 -depth 16 "$out/rgb16.png"
39magick "$out/source-alpha.png" -define png:color-type=6 -depth 16 "$out/rgba16.png"
40magick "$out/source.png" -colorspace Gray -define png:color-type=0 -depth 16 "$out/gray16.png"
41magick "$out/source.png" -colors 256 -define png:color-type=3 "$out/palette8.png"
42magick "$out/source.png" -colors 16 -define png:color-type=3 -define png:bit-depth=4 "$out/palette4.png"
43magick "$out/source.png" -colors 3 -define png:color-type=3 -define png:bit-depth=2 "$out/palette2.png"
44magick "$out/source.png" -monochrome -define png:color-type=3 -define png:bit-depth=1 "$out/palette1.png"
45magick "$out/source.png" -colorspace Gray -depth 4 -define png:color-type=0 -define png:bit-depth=4 "$out/gray4.png"
46magick "$out/source.png" -colorspace Gray -depth 2 -define png:color-type=0 -define png:bit-depth=2 "$out/gray2.png"
47magick "$out/source.png" -colorspace Gray -threshold 50% -define png:color-type=0 -define png:bit-depth=1 "$out/gray1.png"
48magick "$out/source.png" -interlace PNG -define png:color-type=2 "$out/interlaced-rgb8.png"
49magick "$out/source-alpha.png" -interlace PNG -define png:color-type=6 -depth 16 "$out/interlaced-rgba16.png"
50magick "$out/source.png" -colors 64 -interlace PNG -define png:color-type=3 "$out/interlaced-palette.png"
51magick "$out/source-odd.png" -define png:color-type=2 "$out/odd-rgb8.png"
52magick "$out/source-odd.png" -interlace PNG -define png:color-type=2 "$out/odd-interlaced.png"
53# Palette with a transparent entry, and a colour-keyed truecolour image.
54magick "$out/source-alpha.png" -colors 32 PNG8:"$out/trns-palette.png"
55magick "$out/source.png" -define png:color-type=2 -transparent white "$out/trns-rgb.png" || true
56magick "$out/source.png" -colorspace Gray -depth 8 -transparent black \
57 -define png:color-type=0 "$out/trns-gray.png" || true
58
59# --- JPEG: both processes, every chroma layout, restarts, EXIF -------------
60magick "$out/source.png" -quality 90 -sampling-factor 1x1 "$out/baseline-444.jpg"
61magick "$out/source.png" -quality 90 -sampling-factor 2x1 "$out/baseline-422.jpg"
62magick "$out/source.png" -quality 90 -sampling-factor 2x2 "$out/baseline-420.jpg"
63magick "$out/source.png" -quality 50 -sampling-factor 2x2 "$out/baseline-420-q50.jpg"
64magick "$out/source.png" -quality 90 -sampling-factor 2x2 -interlace JPEG "$out/progressive-420.jpg"
65magick "$out/source.png" -quality 90 -sampling-factor 1x1 -interlace JPEG "$out/progressive-444.jpg"
66magick "$out/source.png" -colorspace Gray -quality 90 "$out/gray.jpg"
67magick "$out/source.png" -quality 90 -sampling-factor 2x2 \
68 -define jpeg:restart-interval=4 "$out/restart-420.jpg"
69magick "$out/source-odd.png" -quality 90 -sampling-factor 2x2 "$out/odd-420.jpg"
70magick "$out/source-odd.png" -quality 90 -sampling-factor 2x1 "$out/odd-422.jpg"
71
72# --- WebP: lossy and lossless, with and without alpha ----------------------
73ffmpeg -loglevel error -y -i "$out/source.png" -c:v libwebp -lossless 0 -quality 80 \
74 "$out/lossy.webp"
75ffmpeg -loglevel error -y -i "$out/source.png" -c:v libwebp -lossless 0 -quality 40 \
76 "$out/lossy-q40.webp"
77ffmpeg -loglevel error -y -i "$out/source.png" -c:v libwebp -lossless 1 "$out/lossless.webp"
78ffmpeg -loglevel error -y -i "$out/source-alpha.png" -c:v libwebp -lossless 1 \
79 "$out/lossless-alpha.webp"
80ffmpeg -loglevel error -y -i "$out/source-alpha.png" -c:v libwebp -lossless 0 -quality 80 \
81 "$out/lossy-alpha.webp"
82ffmpeg -loglevel error -y -i "$out/source-odd.png" -c:v libwebp -lossless 0 -quality 80 \
83 "$out/odd-lossy.webp"
84ffmpeg -loglevel error -y -i "$out/source-odd.png" -c:v libwebp -lossless 1 "$out/odd-lossless.webp"
85# A palette-friendly picture, so the lossless colour-indexing transform is
86# exercised rather than only the predictor one.
87magick "$out/source.png" -colors 8 "$out/source-flat.png"
88ffmpeg -loglevel error -y -i "$out/source-flat.png" -c:v libwebp -lossless 1 \
89 "$out/lossless-palette.webp"
90# An animation, which the decoder must refuse by name rather than decode.
91# ffmpeg's libwebp_anim silently writes a single still here, so ImageMagick
92# writes this one: its output really does carry ANIM/ANMF chunks.
93magick -delay 10 "$out/source.png" "$out/source-flat.png" "$out/source-odd.png" \
94 -loop 0 "$out/animated.webp"
95
96# Small versions of each format, for the fuzz sweep: ten thousand mutations
97# per format is only affordable on a picture that decodes in microseconds.
98magick "$out/source.png" -resize 32x24! "$out/tiny.png"
99magick "$out/tiny.png" -quality 80 -sampling-factor 2x2 "$out/tiny.jpg"
100ffmpeg -loglevel error -y -i "$out/tiny.png" -c:v libwebp -lossless 0 -quality 75 \
101 "$out/tiny-lossy.webp"
102ffmpeg -loglevel error -y -i "$out/tiny.png" -c:v libwebp -lossless 1 "$out/tiny-lossless.webp"
103
104echo "wrote $(ls "$out" | wc -l) files to $out"