Skip to content

Identify similar colours

olf edited this page Nov 10, 2024 · 5 revisions

Ideas to identify similar background colours of comics

This collection of one-line shell-scripts aims at ultimately replacing hooks/pre-commit with something better.

Output web-RGB colours

grep -R '"color":' plugins/ | tr -d '",:' | tr -s ' ' | cut -f 1,3 -d ' ' | column -tO 2,1 -o ' ' | sed 's# .\+/\([[:alnum:]]\+\)/info.json$# \1#' | sort

Output R, G and B components separately as hex values

grep -R '"color":' plugins/ | tr -d '",:' | tr -s ' ' | cut -f 1,3 -d ' ' | column -tO 2,1 -o ' ' | sed 's# .\+/\([[:alnum:]]\+\)/info.json$# \1#' | sort | sed -e 's/^\(....\)\(..\)/\1 0x\2/' -e 's/^\(..\)\(..\)/\1 0x\2/' -e 's/^\(..\)/0x\1/'

Output R, G and B components separately as decimal values

printf '%d %d %d %s\n' $(grep -R '"color":' plugins/ | tr -d '",:' | tr -s ' ' | cut -f 1,3 -d ' ' | column -tO 2,1 -o ' ' | sed 's# .\+/\([[:alnum:]]\+\)/info.json$# \1#' | sort | sed -e 's/^\(....\)\(..\)/\1 0x\2/' -e 's/^\(..\)\(..\)/\1 0x\2/' -e 's/^\(..\)/0x\1/') | column -t

Generate an image to compare the colour values visually

Notes:

  • $(wc -l outfile_xxx.txt) may count a line too much (i.e. the concluding \n aka "newline" character): Use $(($(wc -l outfile_xxx.txt)-1) then.
  • If a PNG image is wanted, replace > outimage_xxx.ppm by either | pnmtopng > outimage_xxx.png or | convert - outimage_xxx.png or | ffmpeg -i - outimage_xxx.png / > outimage_xxx.ppm; ffmpeg -i outimage_xxx.ppm outimage_xxx.png.

Sorted primarily by R, secondarily by G, thirdly by B values

grep -R '"color":' plugins/ | tr -d '",:' | tr -s ' ' | cut -f 1,3 -d ' ' | column -tO 2,1 -o ' ' | sed 's# .\+/\([[:alnum:]]\+\)/info.json$# \1#' | sort | tee outfilee_rgb.txt | cut -f 1 -d ' ' | sed -e p -e p -e p -e p -e p -e p -e p | tr -d '\n' | xxd -r -ps | rawtoppm 8 $(wc -l outfile_rgb.txt) > outimage_rgb.ppm

Sorted primarily by G, secondarily by R, thirdly by B values

grep -R '"color":' plugins/ | tr -d '",:' | tr -s ' ' | cut -f 1,3 -d ' ' | column -tO 2,1 -o ' ' | sed -e 's# .\+/\([[:alnum:]]\+\)/info.json$# \1#' -e 's/^\(..\)\(..\)\(..\) /\2\1\3 /' | sort | tee outfile_grb.txt | cut -f 1 -d ' ' | sed -e p -e p -e p -e p -e p -e p -e p | tr -d '\n' | xxd -r -ps | rawtoppm -grb 8 $(wc -l outfile_grb.txt) > outimage_grb.ppm

Sorted primarily by B, secondarily by G, thirdly by R values

grep -R '"color":' plugins/ | tr -d '",:' | tr -s ' ' | cut -f 1,3 -d ' ' | column -tO 2,1 -o ' ' | sed -e 's# .\+/\([[:alnum:]]\+\)/info.json$# \1#' -e 's/^\(..\)\(..\)\(..\) /\3\2\1 /' | sort | tee outfile_bgr.txt | cut -f 1 -d ' ' | sed -e p -e p -e p -e p -e p -e p -e p | tr -d '\n' | xxd -r -ps | rawtoppm -bgr 8 $(wc -l outfile_bgr.txt) > outimage_bgr.ppm

Other RGB-permutations can be constructed accordingly.