postprocess.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. # Copy the first frame of the burst as the raw photo
  19. cp "$BURST_DIR"/1.dng "$TARGET_NAME.dng"
  20. # Create a .jpg if raw processing tools are installed
  21. DCRAW=""
  22. if command -v "dcraw_emu" &> /dev/null
  23. then
  24. DCRAW=dcraw_emu
  25. fi
  26. if command -v "dcraw" &> /dev/null
  27. then
  28. DCRAW=dcraw
  29. fi
  30. if [ -n "$DCRAW" ]; then
  31. # +M use embedded color matrix
  32. # -H 4 Recover highlights by rebuilding them
  33. # -o 1 Output in sRGB colorspace
  34. # -q 3 Debayer with AHD algorithm
  35. # -T Output TIFF
  36. # -fbdd 1 Raw denoising with FBDD
  37. $DCRAW +M -H 4 -o 1 -q 3 -T -fbdd 1 $BURST_DIR/1.dng
  38. # If imagemagick is available, convert the tiff to jpeg and apply slight sharpening
  39. if command -v convert &> /dev/null
  40. then
  41. convert "$BURST_DIR"/1.dng.tiff -sharpen 0x1.0 "$TARGET_NAME.jpg"
  42. # If exiftool is installed copy the exif data over from the tiff to the jpeg
  43. # since imagemagick is stupid
  44. if command -v exiftool &> /dev/null
  45. then
  46. exiftool -tagsFromfile "$BURST_DIR"/1.dng.tiff \
  47. -software="Megapixels" \
  48. -overwrite_original "$TARGET_NAME.jpg"
  49. fi
  50. else
  51. cp "$BURST_DIR"/1.dng.tiff "$TARGET_NAME.tiff"
  52. fi
  53. fi
  54. # Clean up the temp dir containing the burst
  55. rm -rf "$BURST_DIR"