2020-10-01 17:25:24 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# The post-processing script gets called after taking a burst of
|
|
|
|
# pictures into a temporary directory. The first argument is the
|
|
|
|
# directory containing the raw files in the burst. The contents
|
|
|
|
# are 1.dng, 2.dng.... up to the number of photos in the burst.
|
|
|
|
#
|
|
|
|
# The second argument is the filename for the final photo without
|
|
|
|
# the extension, like "/home/user/Pictures/IMG202104031234"
|
|
|
|
#
|
|
|
|
# The post-processing script is responsible for cleaning up
|
|
|
|
# temporary directory for the burst.
|
|
|
|
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
|
|
echo "Usage: $0 [burst-dir] [target-name]"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
BURST_DIR="$1"
|
|
|
|
TARGET_NAME="$2"
|
|
|
|
|
2020-10-06 17:34:31 +02:00
|
|
|
MAIN_PICTURE="$BURST_DIR"/1
|
2020-10-05 17:46:30 +02:00
|
|
|
|
2020-10-01 17:25:24 +02:00
|
|
|
# Copy the first frame of the burst as the raw photo
|
|
|
|
cp "$BURST_DIR"/1.dng "$TARGET_NAME.dng"
|
|
|
|
|
|
|
|
# Create a .jpg if raw processing tools are installed
|
|
|
|
DCRAW=""
|
2020-10-06 17:34:31 +02:00
|
|
|
TIFF_EXT="dng.tiff"
|
2020-10-06 17:34:30 +02:00
|
|
|
if command -v "dcraw_emu" > /dev/null
|
2020-10-01 17:25:24 +02:00
|
|
|
then
|
|
|
|
DCRAW=dcraw_emu
|
2020-10-03 23:06:19 +02:00
|
|
|
# -fbdd 1 Raw denoising with FBDD
|
|
|
|
set -- -fbdd 1
|
2020-10-06 17:34:32 +02:00
|
|
|
elif [ -x "/usr/lib/libraw/dcraw_emu" ]; then
|
|
|
|
DCRAW=/usr/lib/libraw/dcraw_emu
|
|
|
|
# -fbdd 1 Raw denoising with FBDD
|
|
|
|
set -- -fbdd 1
|
|
|
|
elif command -v "dcraw" > /dev/null
|
2020-10-01 17:25:24 +02:00
|
|
|
then
|
|
|
|
DCRAW=dcraw
|
2020-10-06 17:34:31 +02:00
|
|
|
TIFF_EXT="tiff"
|
2020-10-03 23:06:19 +02:00
|
|
|
set --
|
2020-10-01 17:25:24 +02:00
|
|
|
fi
|
|
|
|
|
2021-02-21 16:19:47 +01:00
|
|
|
CONVERT=""
|
|
|
|
if command -v "convert" > /dev/null
|
|
|
|
then
|
|
|
|
CONVERT="convert"
|
|
|
|
# -fbdd 1 Raw denoising with FBDD
|
|
|
|
set -- -fbdd 1
|
|
|
|
elif command -v "gm" > /dev/null
|
|
|
|
then
|
|
|
|
CONVERT="gm"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2020-10-01 17:25:24 +02:00
|
|
|
if [ -n "$DCRAW" ]; then
|
|
|
|
# +M use embedded color matrix
|
|
|
|
# -H 4 Recover highlights by rebuilding them
|
|
|
|
# -o 1 Output in sRGB colorspace
|
|
|
|
# -q 3 Debayer with AHD algorithm
|
|
|
|
# -T Output TIFF
|
2020-10-06 17:34:31 +02:00
|
|
|
$DCRAW +M -H 4 -o 1 -q 3 -T "$@" "$MAIN_PICTURE.dng"
|
2020-10-01 17:25:24 +02:00
|
|
|
|
2020-10-02 22:20:03 +02:00
|
|
|
# If imagemagick is available, convert the tiff to jpeg and apply slight sharpening
|
2021-02-21 16:19:47 +01:00
|
|
|
if [ -n "$CONVERT" ];
|
2020-10-01 17:25:24 +02:00
|
|
|
then
|
2021-03-26 01:07:13 +01:00
|
|
|
if [ "$CONVERT" = "convert" ]; then
|
2021-02-21 16:19:47 +01:00
|
|
|
convert "$MAIN_PICTURE.$TIFF_EXT" -sharpen 0x1.0 "$TARGET_NAME.jpg"
|
|
|
|
else
|
|
|
|
gm convert "$MAIN_PICTURE.$TIFF_EXT" -sharpen 0x1.0 "$TARGET_NAME.jpg"
|
|
|
|
fi
|
2020-10-02 21:08:09 +02:00
|
|
|
|
|
|
|
# If exiftool is installed copy the exif data over from the tiff to the jpeg
|
|
|
|
# since imagemagick is stupid
|
2020-10-06 17:34:30 +02:00
|
|
|
if command -v exiftool > /dev/null
|
2020-10-02 21:08:09 +02:00
|
|
|
then
|
2020-10-06 17:34:31 +02:00
|
|
|
exiftool -tagsFromfile "$MAIN_PICTURE.$TIFF_EXT" \
|
2020-10-02 21:08:09 +02:00
|
|
|
-software="Megapixels" \
|
|
|
|
-overwrite_original "$TARGET_NAME.jpg"
|
|
|
|
fi
|
|
|
|
|
2021-01-06 09:12:11 +01:00
|
|
|
echo "$TARGET_NAME.jpg"
|
2020-10-01 17:25:24 +02:00
|
|
|
else
|
2020-10-06 17:34:31 +02:00
|
|
|
cp "$MAIN_PICTURE.$TIFF_EXT" "$TARGET_NAME.tiff"
|
2021-01-06 09:12:11 +01:00
|
|
|
|
|
|
|
echo "$TARGET_NAME.tiff"
|
2020-10-01 17:25:24 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Clean up the temp dir containing the burst
|
|
|
|
rm -rf "$BURST_DIR"
|
2021-02-21 16:19:47 +01:00
|
|
|
|