-#!/bin/bash
+#!/usr/bin/env bash
-# Pass .NEF files as $@.
-# This makes many variants of each one at different exposure levels.
+# Pass .NEF and .jpeg files as $@.
+# This makes many variants of each .NEF file at different exposure levels
+# and makes reduced-size versions for faster browsing.
-GREEN=1.105
-TEMPERATURE=5500
-JPEGCOMPRESSION=95
+MINFREESPACE=$((10 * 1024 * 1024)) # 10GiB in KiB
+SMALLHEIGHT=700
+
+renice -n 19 $$
+ionice -c 3 -p $$
for f;do
- for level in {10..30};do
- mkdir -p "$level"
- base="$(basename "$f")"
- out="$level/${base%.NEF}.jpeg"
- exposure=$(dc <<< "2k $level 4 / 3.5-p") # 10 to 30 -> -1 to 4 in .25 steps
- ufraw-batch --out-type=jpeg \
- --green="$GREEN" \
- --temperature="$TEMPERATURE" \
- --compression="$JPEGCOMPRESSION" \
- --exposure="$exposure" \
- --output="$out" \
- "$f"
- done
+ if (( "$(df -k . | awk 'NR == 2 { print $4 }')" < $MINFREESPACE ));then
+ echo "Out of disk space"
+ break
+ fi
+ if [[ "$f" == *.NEF ]];then
+ for level in {10..30};do
+ mkdir -p {,sm/}"$level"
+ base="$(basename "$f")"
+ out="$level/${base%.NEF}.jpeg"
+ if [[ -s "$out" ]];then
+ echo "Skipping $out"
+ else
+ exposure=$(dc <<< "2k $level 4 / 3.5-p") # 10 to 30 -> -1 to 4 in .25 steps
+ pics-run-ufraw "$exposure" "$f" "$out"
+ fi
+ if [[ -s "sm/$out" ]];then
+ echo "Skipping sm/$out"
+ else
+ convert "$out" -geometry "x$SMALLHEIGHT" "sm/$out"
+ fi
+ done
+ else
+ if [[ -s "sm/$f" ]];then
+ echo "Skipping sm/$f"
+ else
+ mkdir -p sm
+ convert "$f" -geometry "x$SMALLHEIGHT" "sm/$f"
+ fi
+ fi
done