postprocess.sh 2.0 KB

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