postprocess.sh 2.2 KB

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