postprocess.sh 2.3 KB

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