postprocess.sh 2.1 KB

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