postprocess.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 command -v convert &> /dev/null
  39. then
  40. convert "$BURST_DIR"/1.dng.tiff "$TARGET_NAME.jpg"
  41. # If exiftool is installed copy the exif data over from the tiff to the jpeg
  42. # since imagemagick is stupid
  43. if command -v exiftool &> /dev/null
  44. then
  45. exiftool -tagsFromfile "$BURST_DIR"/1.dng.tiff \
  46. -software="Megapixels" \
  47. -overwrite_original "$TARGET_NAME.jpg"
  48. fi
  49. else
  50. cp "$BURST_DIR"/1.dng.tiff "$TARGET_NAME.tiff"
  51. fi
  52. fi
  53. # Clean up the temp dir containing the burst
  54. rm -rf "$BURST_DIR"