add ascii.conf and keybinds.conf for converter options and rebindable keys
ascii.conf exposes ascii-image-converter's dimension/complexity/map/ grayscale/negative/flip options (color and braille stay out since they rely on ANSI/multi-byte Unicode that txt2printr.sh's raw print path can't render). keybinds.conf lets exec-cycle.sh's capture/brightness/ exposure/reset keys be rebound instead of hardcoded, matched case-insensitively; the on-screen hint bar renders from the same config so it never drifts out of sync with the actual bindings.master
parent
ed7c0d0813
commit
7f67c5fd81
|
|
@ -0,0 +1,24 @@
|
|||
# ASCII Photobooth ascii-image-converter configuration
|
||||
# Sourced by webcam2ascii.sh. All values are optional - blank/false means
|
||||
# "use the converter's default".
|
||||
|
||||
# Output size in characters (leave both blank to size to the terminal)
|
||||
WIDTH=
|
||||
HEIGHT=
|
||||
|
||||
# Use a larger character gradient for smoother shading (true/false)
|
||||
COMPLEX=false
|
||||
|
||||
# Custom character map, darkest to lightest, e.g. " .:-=+*#%@"
|
||||
# Overrides COMPLEX if set
|
||||
CHAR_MAP=
|
||||
|
||||
GRAYSCALE=false
|
||||
NEGATIVE=false
|
||||
FLIP_X=false
|
||||
FLIP_Y=false
|
||||
|
||||
# Color and braille output are intentionally not exposed here: both rely on
|
||||
# ANSI/multi-byte Unicode that a parallel-port needle printer can't render.
|
||||
# Only add --color/--braille yourself if you don't plan to print via
|
||||
# txt2printr.sh.
|
||||
|
|
@ -4,11 +4,19 @@ trap 'stty sane; clear; exit 0' SIGINT SIGTERM
|
|||
|
||||
dir="$(dirname "$0")"
|
||||
[ -f "$dir/webcam.conf" ] && source "$dir/webcam.conf"
|
||||
[ -f "$dir/keybinds.conf" ] && source "$dir/keybinds.conf"
|
||||
|
||||
BRIGHTNESS="${DEFAULT_BRIGHTNESS:-auto}"
|
||||
EXPOSURE="${DEFAULT_EXPOSURE:-auto}"
|
||||
STEP="${STEP:-5}"
|
||||
|
||||
: "${KEY_CAPTURE:=c}"
|
||||
: "${KEY_BRIGHTNESS_UP:=+}"
|
||||
: "${KEY_BRIGHTNESS_DOWN:=-}"
|
||||
: "${KEY_EXPOSURE_UP:=.}"
|
||||
: "${KEY_EXPOSURE_DOWN:=,}"
|
||||
: "${KEY_RESET:=r}"
|
||||
|
||||
# clamps $1+$2 to 0-100, treating "auto" as a 50 starting point
|
||||
adjust() {
|
||||
local cur=$1 delta=$2 val
|
||||
|
|
@ -25,16 +33,16 @@ while true; do
|
|||
./webcam2ascii.sh
|
||||
echo
|
||||
echo "brightness: ${BRIGHTNESS} exposure: ${EXPOSURE}"
|
||||
echo "[+/-] brightness [./,] exposure [r] reset to auto [c] capture [Ctrl+C] quit"
|
||||
echo "[${KEY_BRIGHTNESS_UP}/${KEY_BRIGHTNESS_DOWN}] brightness [${KEY_EXPOSURE_UP}/${KEY_EXPOSURE_DOWN}] exposure [${KEY_RESET}] reset to auto [${KEY_CAPTURE}] capture [Ctrl+C] quit"
|
||||
|
||||
if read -n 1 -t 0.05 -s key; then
|
||||
case "$key" in
|
||||
"+") BRIGHTNESS=$(adjust "$BRIGHTNESS" "$STEP") ;;
|
||||
"-") BRIGHTNESS=$(adjust "$BRIGHTNESS" "-$STEP") ;;
|
||||
".") EXPOSURE=$(adjust "$EXPOSURE" "$STEP") ;;
|
||||
",") EXPOSURE=$(adjust "$EXPOSURE" "-$STEP") ;;
|
||||
r|R) BRIGHTNESS="${DEFAULT_BRIGHTNESS:-auto}"; EXPOSURE="${DEFAULT_EXPOSURE:-auto}" ;;
|
||||
c|C)
|
||||
"$KEY_BRIGHTNESS_UP"|"${KEY_BRIGHTNESS_UP^^}") BRIGHTNESS=$(adjust "$BRIGHTNESS" "$STEP") ;;
|
||||
"$KEY_BRIGHTNESS_DOWN"|"${KEY_BRIGHTNESS_DOWN^^}") BRIGHTNESS=$(adjust "$BRIGHTNESS" "-$STEP") ;;
|
||||
"$KEY_EXPOSURE_UP"|"${KEY_EXPOSURE_UP^^}") EXPOSURE=$(adjust "$EXPOSURE" "$STEP") ;;
|
||||
"$KEY_EXPOSURE_DOWN"|"${KEY_EXPOSURE_DOWN^^}") EXPOSURE=$(adjust "$EXPOSURE" "-$STEP") ;;
|
||||
"$KEY_RESET"|"${KEY_RESET^^}") BRIGHTNESS="${DEFAULT_BRIGHTNESS:-auto}"; EXPOSURE="${DEFAULT_EXPOSURE:-auto}" ;;
|
||||
"$KEY_CAPTURE"|"${KEY_CAPTURE^^}")
|
||||
timestamp=$(date +%Y%m%d-%H%M%S)
|
||||
cp web-cam-shot.jpg "photo-$timestamp.jpg"
|
||||
cp ascii-img.txt "ascii-img-$timestamp.txt"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
# ASCII Photobooth keybindings
|
||||
# Sourced by exec-cycle.sh. Each value must be a single character;
|
||||
# matching is case-insensitive. Ctrl+C always quits and isn't
|
||||
# configurable here.
|
||||
|
||||
KEY_CAPTURE=c
|
||||
KEY_BRIGHTNESS_UP=+
|
||||
KEY_BRIGHTNESS_DOWN=-
|
||||
KEY_EXPOSURE_UP=.
|
||||
KEY_EXPOSURE_DOWN=,
|
||||
KEY_RESET=r
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
#/bin/bash
|
||||
#
|
||||
# Captures a frame and converts it to ascii art.
|
||||
# Reads defaults from webcam.conf. BRIGHTNESS/EXPOSURE env vars (set by
|
||||
# exec-cycle.sh's live preview controls) override the config's defaults.
|
||||
# Reads defaults from webcam.conf and ascii.conf. BRIGHTNESS/EXPOSURE env
|
||||
# vars (set by exec-cycle.sh's live preview controls) override webcam.conf.
|
||||
|
||||
dir="$(dirname "$0")"
|
||||
[ -f "$dir/webcam.conf" ] && source "$dir/webcam.conf"
|
||||
[ -f "$dir/ascii.conf" ] && source "$dir/ascii.conf"
|
||||
|
||||
: "${RESOLUTION:=640x480}"
|
||||
: "${JPEG_QUALITY:=85}"
|
||||
|
|
@ -13,11 +14,29 @@ dir="$(dirname "$0")"
|
|||
: "${EXPOSURE:=${DEFAULT_EXPOSURE:-auto}}"
|
||||
: "${BRIGHTNESS_CONTROL:=Brightness}"
|
||||
: "${EXPOSURE_CONTROL:=Exposure (Absolute)}"
|
||||
: "${COMPLEX:=false}"
|
||||
: "${GRAYSCALE:=false}"
|
||||
: "${NEGATIVE:=false}"
|
||||
: "${FLIP_X:=false}"
|
||||
: "${FLIP_Y:=false}"
|
||||
|
||||
set_opts=()
|
||||
[ "$BRIGHTNESS" != "auto" ] && set_opts+=(--set "${BRIGHTNESS_CONTROL}=${BRIGHTNESS}%")
|
||||
[ "$EXPOSURE" != "auto" ] && set_opts+=(--set "${EXPOSURE_CONTROL}=${EXPOSURE}%")
|
||||
|
||||
fswebcam -q --no-banner -r "$RESOLUTION" --jpeg "$JPEG_QUALITY" "${set_opts[@]}" web-cam-shot.jpg &> /dev/null
|
||||
ascii-image-converter web-cam-shot.jpg | tee ascii-img.txt
|
||||
conv_opts=()
|
||||
[ -n "$WIDTH" ] && conv_opts+=(--width "$WIDTH")
|
||||
[ -n "$HEIGHT" ] && conv_opts+=(--height "$HEIGHT")
|
||||
if [ -n "$CHAR_MAP" ]; then
|
||||
conv_opts+=(--map "$CHAR_MAP")
|
||||
elif [ "$COMPLEX" = "true" ]; then
|
||||
conv_opts+=(--complex)
|
||||
fi
|
||||
[ "$GRAYSCALE" = "true" ] && conv_opts+=(--grayscale)
|
||||
[ "$NEGATIVE" = "true" ] && conv_opts+=(--negative)
|
||||
[ "$FLIP_X" = "true" ] && conv_opts+=(--flipX)
|
||||
[ "$FLIP_Y" = "true" ] && conv_opts+=(--flipY)
|
||||
|
||||
fswebcam -q --no-banner -r "$RESOLUTION" --jpeg "$JPEG_QUALITY" "${set_opts[@]}" web-cam-shot.jpg &> /dev/null
|
||||
ascii-image-converter web-cam-shot.jpg "${conv_opts[@]}" | tee ascii-img.txt
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue