postprocess.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/sh
  2. # The post-processing script gets called after taking a burst of
  3. # pictures into a temporary directory. The first argument is the
  4. # directory containing the raw files in the burst. The contents
  5. # are 1.dng, 2.dng.... up to the number of photos in the burst.
  6. #
  7. # The second argument is the filename for the final photo without
  8. # the extension, like "/home/user/Pictures/IMG202104031234"
  9. #
  10. # The post-processing script is responsible for cleaning up
  11. # temporary directory for the burst.
  12. if [ "$#" -ne 2 ]; then
  13. echo "Usage: $0 [burst-dir] [target-name]"
  14. exit 2
  15. fi
  16. BURST_DIR="$1"
  17. TARGET_NAME="$2"
  18. MAIN_PICTURE="$BURST_DIR"/1
  19. # Copy the first frame of the burst as the raw photo
  20. cp "$BURST_DIR"/1.dng "$TARGET_NAME.dng"
  21. # Create a .jpg if raw processing tools are installed
  22. DCRAW=""
  23. TIFF_EXT="dng.tiff"
  24. if command -v "dcraw_emu" > /dev/null
  25. then
  26. DCRAW=dcraw_emu
  27. # -fbdd 1 Raw denoising with FBDD
  28. set -- -fbdd 1
  29. elif [ -x "/usr/lib/libraw/dcraw_emu" ]; then
  30. DCRAW=/usr/lib/libraw/dcraw_emu
  31. # -fbdd 1 Raw denoising with FBDD
  32. set -- -fbdd 1
  33. elif command -v "dcraw" > /dev/null
  34. then
  35. DCRAW=dcraw
  36. TIFF_EXT="tiff"
  37. set --
  38. fi
  39. if [ -n "$DCRAW" ]; then
  40. # +M use embedded color matrix
  41. # -H 4 Recover highlights by rebuilding them
  42. # -o 1 Output in sRGB colorspace
  43. # -q 3 Debayer with AHD algorithm
  44. # -T Output TIFF
  45. $DCRAW +M -H 4 -o 1 -q 3 -T "$@" "$MAIN_PICTURE.dng"
  46. # If imagemagick is available, convert the tiff to jpeg and apply slight sharpening
  47. if command -v convert > /dev/null
  48. then
  49. convert "$MAIN_PICTURE.$TIFF_EXT" -sharpen 0x1.0 "$TARGET_NAME.jpg"
  50. # If exiftool is installed copy the exif data over from the tiff to the jpeg
  51. # since imagemagick is stupid
  52. if command -v exiftool > /dev/null
  53. then
  54. exiftool -tagsFromfile "$MAIN_PICTURE.$TIFF_EXT" \
  55. -software="Megapixels" \
  56. -overwrite_original "$TARGET_NAME.jpg"
  57. fi
  58. else
  59. cp "$MAIN_PICTURE.$TIFF_EXT" "$TARGET_NAME.tiff"
  60. fi
  61. fi
  62. # Clean up the temp dir containing the burst
  63. rm -rf "$BURST_DIR"