Browse Source

Update & clean up scripts a bit

master
Pekka Helenius 1 year ago
parent
commit
ad598c5f33
11 changed files with 1728 additions and 1380 deletions
  1. +43
    -28
      4_scripts/PKGBUILD
  2. +1017
    -739
      4_scripts/imagetools_01_exif_statistics.sh
  3. +91
    -96
      4_scripts/imagetools_02_dualiso.sh
  4. +384
    -383
      4_scripts/imagetools_03_raw_resolution-baseline.sh
  5. +16
    -11
      4_scripts/imagetools_04_mlvdump.sh
  6. +5
    -3
      4_scripts/imagetools_05_mlvinfo.sh
  7. +25
    -16
      4_scripts/imagetools_06_exif_deletedata.sh
  8. +58
    -13
      4_scripts/imagetools_06_exif_deletedata_critical.sh
  9. +11
    -9
      4_scripts/imagetools_07_ale_stack.sh
  10. +70
    -52
      4_scripts/imagetools_08_geotag.sh
  11. +8
    -30
      4_scripts/imagetools_09_mtime.sh

+ 43
- 28
4_scripts/PKGBUILD View File

@ -1,49 +1,64 @@
# Maintainer: Pekka Helenius <fincer89 at hotmail DOT com>
pkgname=kde-servicemenus-imagetools
pkgver=1
pkgrel=1
pkgdesc="Useful combination of tools for processing various images (KDE5 Dolphin action)"
url=()
arch=('any')
license=('GPL')
install=''
source=(imagetools_01_exif_statistics.sh
imagetools_02_dualiso.sh
imagetools_03_raw_resolution-baseline.sh
imagetools_04_mlvdump.sh
imagetools_05_mlvinfo.sh
imagetools_06_exif_deletedata.sh
imagetools_06_exif_deletedata_critical.sh
imagetools_07_ale_stack.sh
01_imagetools-statistics.desktop
02_imagetools-dng-cr2.desktop
03_imagetools-mlv.desktop
04_imagetools-jpg-png.desktop
05_imagetools-imagestack.desktop)
source=(
imagetools_01_exif_statistics.sh
imagetools_02_dualiso.sh
imagetools_03_raw_resolution-baseline.sh
imagetools_04_mlvdump.sh
imagetools_05_mlvinfo.sh
imagetools_06_exif_deletedata.sh
imagetools_06_exif_deletedata_critical.sh
imagetools_07_ale_stack.sh
imagetools_09_mtime.sh
01_imagetools-statistics.desktop
02_imagetools-dng-cr2.desktop
03_imagetools-mlv.desktop
04_imagetools-jpg-png.desktop
05_imagetools-imagestack.desktop
)
#xwinkill) #Workaround for bug: https://sourceforge.net/p/gnuplot/bugs/1659/
depends=('magiclantern-tools' 'perl-image-exiftool' 'ale' 'dcraw' 'netpbm' 'gnuplot' 'coreutils' 'dolphin')
optdepends=()
conflicts=()
makedepends=()
md5sums=('b4c1f2f5906a56c5cd5404415b26ad5b'
'a84bf74fb67a5f6f2289ebee2ce4452e'
'6e81d48727e7fc6922a2aed0ce7810c1'
depends=(
magiclantern-tools
perl-image-exiftool
ale
dcraw
netpbm
gnuplot
coreutils
dolphin
)
md5sums=('a4e9c260727723ebfecf986586c34880'
'758c9cc2ecc858350e041504f7d7ea12'
'cdc5c555acb2b96411e16cfa9ea2f25d'
'a7e0c36553ff59d182460a2108163798'
'01756513818969a07ff61a1ee648106b'
'75588a9f375ac5c6f6f245d12cc315d5'
'c294e69b9f6e714a307306fd4301fd61'
'88cbadd0f290c737f7f0660a7029029d'
'2b239ca3efac3713004635d29798b44d'
'93bb82eec8ead83b5b5369822d44d780'
'940848e05d6c6400eac97a998fb0f26b'
'a3e7650c1cbfd8d113f57f60d8699c6b'
'be883bb11a24c4f7ac6452f3cab6cf66'
'9170a5e116fc2eede5325d0a985931dc'
'b42063458ada3002666280a5b06b1e92'
'531f2b73b8514430a772a61a10de097f')
package() {
mkdir -p $pkgdir/usr/share/kservices5/ServiceMenus/
cp $srcdir/{imagetools_01_exif_statistics.sh,imagetools_02_dualiso.sh,imagetools_03_raw_resolution-baseline.sh,imagetools_04_mlvdump.sh,imagetools_05_mlvinfo.sh,imagetools_06_exif_deletedata.sh,imagetools_06_exif_deletedata_critical.sh,imagetools_07_ale_stack.sh,01_imagetools-statistics.desktop,02_imagetools-dng-cr2.desktop,03_imagetools-mlv.desktop,04_imagetools-jpg-png.desktop,05_imagetools-imagestack.desktop} $pkgdir/usr/share/kservices5/ServiceMenus/
chmod 755 $pkgdir/usr/share/kservices5/ServiceMenus/{imagetools_01_exif_statistics.sh,imagetools_02_dualiso.sh,imagetools_03_raw_resolution-baseline.sh,imagetools_04_mlvdump.sh,imagetools_05_mlvinfo.sh,imagetools_06_exif_deletedata.sh,imagetools_06_exif_deletedata_critical.sh,imagetools_07_ale_stack.sh,01_imagetools-statistics.desktop,02_imagetools-dng-cr2.desktop,03_imagetools-mlv.desktop,04_imagetools-jpg-png.desktop,05_imagetools-imagestack.desktop}
for t in sh desktop; do
for f in ${srcdir}/*.${t}; do
cp ${f} $pkgdir/usr/share/kservices5/ServiceMenus/
done
done
find $pkgdir/usr/share/kservices5/ServiceMenus/ -type f -iname "*.sh" -exec chmod 755 {} \;
#chmod +x $pkgdir/usr/share/kservices5/ServiceMenus/xwinkill
}

+ 1017
- 739
4_scripts/imagetools_01_exif_statistics.sh
File diff suppressed because it is too large
View File


+ 91
- 96
4_scripts/imagetools_02_dualiso.sh View File

@ -1,7 +1,7 @@
#!/bin/bash
#!/bin/env bash
# Batch convert multiple Magic Lantern dual ISO image files on Linux
# Copyright (C) 2017 Pekka Helenius
# Copyright (C) 2017,2023 Pekka Helenius
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -19,155 +19,150 @@
#
###############################################
# NOTE: This script REQUIRES a patched cr2hdr tool with '--dry-run' parameter support!!
# Required patch file is provided in the same repository with this script
#Brackets and quotation marks in variables prevent errors occuring if file paths with spaces is used.
################################################################################################
# File system check
# We don't allow writing to SD card.
#Sed is here to remove any trailing spaces and crap like blank lines
INPUT_FILESYSTEM=$(df -h "${1}" | awk -F ' ' 'FNR> 1 {print $1}' | grep -i -E "/dev/sd?|/dev/hd?|?rewritefs|?tmpfs|/dev/nvme?" | sed '/^\s*$/d' | wc -l)
if [[ "${INPUT_FILESYSTEM}" -eq 0 ]]; then #if input file (first file printed in bash) filesystem does not start with /dev/sdX
kdialog --error "Image(s) are in a SD Card. Please move them your local or external storage and try again."
exit
fi
################################################################################################
#We get the directory just from the first filename. Pwd should be easier, but bugged, so...
# We get the directory just from the first filename.
INPUT_DIR=$(dirname "${1}")
DIR_BASENAME=$(echo "${INPUT_DIR}" | rev | cut -d/ -f 1 | rev)
echo "DEBUG: Input dir is $INPUT_DIR"
mkdir -p "${INPUT_DIR}"/converted_dual_iso
echo "DEBUG: 'converted_dual_iso' directory created"
mkdir -p "${INPUT_DIR}/converted_dual_iso"
############################################################################################
####PROGRESSBAR STUFF - BEGIN
LABELTEXT='Processing RAW images...'
# PROGRESSBAR CODE - BEGIN
LABELTEXT="Processing RAW images..."
numargs=$# # Number of all files
tics=100 # Percentage tics
inc=0 # Current file number
mltp=1000 # Percentage multiplier for bash
tics=100 # Percentage tics
inc=0 # Current file number
mltp=1000 # Percentage multiplier for bash
dbusRef=$(kdialog --title "Dual ISO (folder: ${DIR_BASENAME})" --progressbar "$LABELTEXT" $tics)
dbusRef=$(kdialog --title "Dual ISO (folder: ${DIR_BASENAME})" --progressbar "${LABELTEXT}" "${tics}")
qdbus $dbusRef showCancelButton true
####PROGRESSBAR STUFF - END
# PROGRESSBAR CODE - END
while [[ $# -gt 0 ]] && [[ $(qdbus $dbusRef wasCancelled) == "false" ]]; do
while \
[[ $# -gt 0 ]] && \
[[ $(qdbus $dbusRef wasCancelled) == "false" ]]
do
INPUT="${1}" #Input file path, full path like: /home/myhome/IMG_4021.CR2
OLDFILE_CR2=$(basename "${INPUT}") #Output as IMG_4021.CR2 (for example)
INPUT="${1}"
OLDFILE_CR2=$(basename "${INPUT}")
# Once we do this, it's very clear which kind of CR2 file we're talking about here.
NEWFILE_CR2=$(basename "${INPUT}" | sed 's/\.\w*$/_dualiso.CR2/')
# Once we do this, it's very clear which kind of CR2 file we're talking about here.
NEWFILE_CR2=$(basename "${INPUT}" | sed 's/\.\w*$/_dualiso.CR2/')
# Converted Dual ISO file.
NEWFILE_DNG=$(basename "${INPUT}" | sed 's/\.\w*$/_dualiso.DNG/')
# Converted Dual ISO file.
NEWFILE_DNG=$(basename "${INPUT}" | sed 's/\.\w*$/_dualiso.DNG/')
#If converted Dual ISO exists already, we skip the conversion process. This passes only if the file doesn't exist.
if [[ ! -e "${INPUT_DIR}"/converted_dual_iso/"${NEWFILE_DNG}" ]]; then
# If converted Dual ISO exists already, we skip the conversion process.
# This test passes only if the file doesn't exist.
if [[ ! -e "${INPUT_DIR}/converted_dual_iso/${NEWFILE_DNG}" ]]
then
if [[ $(cr2hdr --dry-run "${INPUT}" | grep "Interlaced ISO detected" | wc -l) == 1 ]]; then # Test an input file for Dual ISO.
# Test an input file for Dual ISO.
if [[ $(cr2hdr --dry-run "${INPUT}" | grep "Interlaced ISO detected" | wc -l) -eq 1 ]]
then
echo "Interlaced ISO detected: ${OLDFILE_CR2}"
echo "Interlaced ISO detected: ${OLDFILE_CR2}"
#Rename detected dual ISO CR2 file with a proper prefix (so that we can distinguish Dual ISO images from "normal" CR2 files)
mv "${INPUT_DIR}"/"${OLDFILE_CR2}" "${INPUT_DIR}"/"${NEWFILE_CR2}"
# Rename detected dual ISO CR2 file with a proper prefix
# (so that we can distinguish Dual ISO images from "normal" CR2 files)
mv "${INPUT_DIR}/${OLDFILE_CR2}" "${INPUT_DIR}/${NEWFILE_CR2}"
#Input we will use from this point is the renamed file, so we set INPUT variable to point to the renamed file.
INPUT="${INPUT_DIR}"/"${NEWFILE_CR2}"
# Input we will use from this point is the renamed file,
# so we set INPUT variable to point to the renamed file.
INPUT="${INPUT_DIR}/${NEWFILE_CR2}"
cr2hdr --process "${INPUT}" # Process a valid input file.
# Process a valid input file.
cr2hdr --process "${INPUT}"
mv "${INPUT_DIR}"/"${NEWFILE_DNG}" "${INPUT_DIR}"/converted_dual_iso/ # Move converted Dual ISO.
# Move converted dual iso file.
mv "${INPUT_DIR}/${NEWFILE_DNG}" "${INPUT_DIR}/converted_dual_iso/"
# Add Subject=Dual-ISO tag for every Dual ISO CR2 file.
echo "Writing new EXIF/XMP tag Subject: Dual ISO CR2"
exiftool -xmp:subject='Dual ISO CR2' "${INPUT_DIR}"/"${NEWFILE_CR2}" -overwrite_original
# Add Subject=Dual-ISO tag for every Dual ISO CR2 file.
echo "Writing new EXIF/XMP tag Subject: Dual ISO CR2"
exiftool -xmp:subject="Dual ISO CR2" "${INPUT_DIR}/${NEWFILE_CR2}" -overwrite_original
fi
fi
fi
##############################################
####PROGRESSBAR STUFF - BEGIN
# PROGRESSBAR CODE - BEGIN
let inc++
#Percentage needs to be calculated like this due to bash rounding limitations...
PERCENT_VALUE=$((($mltp*$tics)/(200*$numargs/$inc % 2 + $mltp*$numargs/$inc)))
#Output: 20, 40, 59, 80, 100 etc.
# Percentage needs to be calculated like this due to bash rounding limitations.
PERCENT_VALUE=$(((${mltp}*${tics})/(200*${numargs}/${inc} % 2 + ${mltp}*${numargs}/${inc})))
# Output: 20, 40, 59, 80, 100 etc.
qdbus $dbusRef Set "" "value" "${PERCENT_VALUE}";
qdbus $dbusRef setLabelText "$LABELTEXT (${inc}/${numargs})";
qdbus $dbusRef Set "" "value" $PERCENT_VALUE;
qdbus $dbusRef setLabelText "$LABELTEXT ($inc/$numargs)";
####PROGRESSBAR STUFF - END
# PROGRESSBAR CODE - END
shift #Process next CR2/DNG file...
# Move to the next file.
shift
done
##############################################
#Close processing window if cancelled event has been triggered.
# Close processing window if cancelled event has been triggered.
# PROGRESSBAR CODE - BEGIN
####PROGRESSBAR STUFF - BEGIN
# If the process was cancelled, remove tmp file and exit the script.
if [[ ! $(qdbus $dbusRef wasCancelled) == "false" ]]; then
exit
if [[ ! $(qdbus $dbusRef wasCancelled) == "false" ]]
then
exit 0
fi
##############################################
#Close processing window if not cancelled and processing finished.
# Close processing window if not cancelled and processing finished.
qdbus $dbusRef close
####PROGRESSBAR STUFF - END
# PROGRESSBAR CODE - END
##############################################
if [ $(pgrep -x 'cr2hdr' | wc -l) == 0 ]; then
notify-send 'Dual ISO' -i image-x-krita 'Conversion done!'
if [[ $(pgrep -x 'cr2hdr' | wc -l) == 0 ]]
then
notify-send 'Dual ISO' -i image-x-krita 'Conversion done!'
fi
############################################################################################
QUESTCOUNT=0 #Ask this question only once
#Dual ISO (Subject only defined in converted Dual ISO DNG images)
for i in $(find "${INPUT_DIR}" -maxdepth 1 -type f -iname "*.DNG"); do
if [[ ! -z $(echo -n $i) ]] && [[ $(exiftool $i |grep --max-count=1 "Subject" | sed -e 's/.*: //g') == *"Dual-ISO"* ]] ; then
if [[ $QUESTCOUNT == 0 ]]; then
QUESTION=$(kdialog --yesno "More Dual ISO files detected in '$(echo ${INPUT_DIR} | rev | cut -d/ -f1 | rev)' main folder. Do you want to move these files into 'converted_dual_iso' folder?";)
echo $QUESTION
MOVEALL=true
let QUESTCOUNT++
else
MOVEALL=false
fi
if [[ $MOVEALL == true ]]; then
mv $i "${INPUT_DIR}"/converted_dual_iso/
echo "DEBUG: all detected Dual ISO images moved to 'converted_dual_iso' folder"
fi
# Dual ISO (Subject only defined in converted Dual ISO DNG images)
for i in $(find "${INPUT_DIR}" -maxdepth 1 -type f -iname "*.DNG")
do
if \
[[ ! -z $(echo -n "${i}") ]] && \
[[ $(exiftool "${i}" |grep --max-count=1 "Subject" | sed -e 's/.*: //g') == *"Dual-ISO"* ]]
then
if [[ "${QUESTCOUNT}" -eq 0 ]]; then
QUESTION=$(kdialog --yesno "More Dual ISO files detected in '$(echo ${INPUT_DIR} | rev | cut -d/ -f1 | rev)' main folder. Do you want to move these files into 'converted_dual_iso' folder?";)
echo "${QUESTION}"
MOVEALL=true
let QUESTCOUNT++
else
MOVEALL=false
fi
if [[ "${MOVEALL}" == true ]]; then
mv "${i}" "${INPUT_DIR}/converted_dual_iso/"
echo "DEBUG: all detected Dual ISO images moved to 'converted_dual_iso' folder"
fi
fi
done
############################################################################################
#If there are no files converted, we delete converted_dual_iso folder
if [[ $(ls "${INPUT_DIR}"/converted_dual_iso | wc -l) == 0 ]]; then
rm -Rf "${INPUT_DIR}"/converted_dual_iso
echo "DEBUG: 'converted_dual_iso' empty, so deleted"
# If there are no files converted, we delete converted_dual_iso folder
if [[ $(ls "${INPUT_DIR}/converted_dual_iso" | wc -l) -eq 0 ]]
then
rm -Rf "${INPUT_DIR}/converted_dual_iso"
fi
exit
exit 0

+ 384
- 383
4_scripts/imagetools_03_raw_resolution-baseline.sh View File

@ -1,7 +1,7 @@
#!/bin/bash
#!/bin/env bash
# Add CR2 tags: Baseline, Subject (to distinguish Single & Dual ISOs)
# Copyright (C) 2017 Pekka Helenius
# Copyright (C) 2017,2023 Pekka Helenius
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -19,501 +19,502 @@
#
###############################################
# File system check
# We don't allow writing to SD card.
#Sed is here to remove any trailing spaces and crap like blank lines
INPUT_FILESYSTEM=$(df -h "${1}" | awk -F ' ' 'FNR> 1 {print $1}' | grep -i -E "/dev/sd?|/dev/hd?|?rewritefs|?tmpfs|/dev/nvme?" | sed '/^\s*$/d' | wc -l)
if [[ "${INPUT_FILESYSTEM}" -eq 0 ]]; then #if input file (first file printed in bash) filesystem does not start with /dev/sdX
kdialog --error "Image(s) are in a SD Card. Please move them your local or external storage and try again."
exit
fi
################################################################################################
#We get the directory just from the first filename. Pwd should be easier, but bugged, so...
# We get the directory just from the first filename.
INPUT_DIR=$(dirname "${1}")
DIR_BASENAME=$(echo "${INPUT_DIR}" | rev | cut -d/ -f 1 | rev)
#Camera resolution in pixels (absolute limit, we can't exceed these pixel values!)
# Camera resolution in pixels (absolute limit, we can't exceed these pixel values!)
C5DMK3_WIDTH=5796
C5DMK3_HEIGHT=3870
# In a case or emergency (can't open a picture etc), revert this values to 5760 x 3840
# In a case or emergency (can't open a picture etc), revert these values to 5760 x 3840.
################################################################################################
####PROGRESSBAR STUFF - BEGIN
LABELTEXT='Processing RAW images...'
# PROGRESSBAR CODE - BEGIN
LABELTEXT="Processing RAW images..."
numargs=$# # Number of all files
tics=100 # Percentage tics
inc=0 # Current file number
mltp=1000 # Percentage multiplier for bash
tics=100 # Percentage tics
inc=0 # Current file number
mltp=1000 # Percentage multiplier for bash
dbusRef=$(
kdialog \
--title "EXIF Tags (folder: ${DIR_BASENAME})" \
--progressbar "$LABELTEXT" "${tics}"
)
dbusRef=$(kdialog --title "EXIF Tags (folder: ${DIR_BASENAME})" --progressbar "$LABELTEXT" $tics)
qdbus $dbusRef showCancelButton true
####PROGRESSBAR STUFF - END
# PROGRESSBAR CODE - END
while [[ $# -gt 0 ]] && [[ $(qdbus $dbusRef wasCancelled) == "false" ]]; do
while \
[[ $# -gt 0 ]] && \
[[ $(qdbus $dbusRef wasCancelled) == "false" ]]
do
################################################################
# Values that change during the while loop (differ from file to file)
INPUT="${1}"
# Values that change during the while loop (differ from file to file)
INPUT_BASENAME=$(basename "${INPUT}" | cut -f 1 -d '.')
INPUT_EXTENSION=$(echo $(basename "${INPUT}" | cut -f 2 -d '.' | sed '/^\s*$/d')) #Get the correct file extension for an input file (so the new one will use the same)
INPUT="${1}"
SUBJECT=$(exiftool "${INPUT}" | grep "Subject")
SUBJECT_SINGLEISO=$(exiftool "${INPUT}" | grep "Subject" | grep "Single ISO")
SUBJECT_DUALISO=$(exiftool "${INPUT}" | grep "Subject" | grep "Dual ISO")
INPUT_BASENAME=$(basename "${INPUT}" | cut -f 1 -d '.')
#This is just for compatibility
SUBJECT_DUALISO_OLD=$(exiftool "${INPUT}" | grep "Subject" | grep "Dual-ISO")
# Get the correct file extension for an input file, to be used for the new file.
INPUT_EXTENSION=$(echo $(basename "${INPUT}" | cut -f 2 -d '.' | sed -e '/^\s*$/d' -e 's/\(.*\)/\U\1/'))
BASELINES=$(exiftool "${INPUT}" | grep "Baseline Exposure")
SUBJECT=$(exiftool "${INPUT}" | grep "Subject")
SUBJECT_SINGLEISO=$(exiftool "${INPUT}" | grep "Subject" | grep "Single ISO")
SUBJECT_DUALISO=$(exiftool "${INPUT}" | grep "Subject" | grep "Dual ISO")
C5DMK3_CHECK=$(exiftool "${INPUT}" |grep -i "5D Mark III" |wc -l)
CROPHEIGHT_CHECK_VALUE=$(echo -n $(exiftool "${INPUT}" |grep -i "Cropped Image Height" | sed 's/[^0-9]*//g'))
# This is just for compatibility.
SUBJECT_DUALISO_OLD=$(exiftool "${INPUT}" | grep "Subject" | grep "Dual-ISO")
ISO_VALUE=$(echo -n $(exiftool "${INPUT}" | grep "Recommended Exposure Index" | grep -v "Sensitivity Type" | sed 's/[^0-9]*//g'))
BASELINES=$(exiftool "${INPUT}" | grep "Baseline Exposure")
################################################################
# FIRST CHECK FOR INDIVIDUAL FILE
################################
# CR2 FILES
#
# Input file is CR2 or cr2
if [[ "${INPUT_EXTENSION}" == "CR2" ]] || [[ "${INPUT_EXTENSION}" == "cr2" ]]; then
C5DMK3_CHECK=$(exiftool "${INPUT}" |grep -i "5D Mark III" |wc -l)
CROPHEIGHT_CHECK_VALUE=$(echo -n $(exiftool "${INPUT}" |grep -i "Cropped Image Height" | sed 's/[^0-9]*//g'))
###########
# Dual ISO - unprocessed CR2 (NOTE: THIS CHECK IS SLOW)
if [[ $(cr2hdr --dry-run "${INPUT}" | grep "Interlaced ISO detected" | wc -l) == 1 ]]; then # Test an input file for Dual ISO.
echo "${INPUT_BASENAME}: Dual ISO CR2 image. Skipping."
IS_SINGLE_CR2=false
ISO_VALUE=$(echo -n $(exiftool "${INPUT}" | grep "Recommended Exposure Index" | grep -v "Sensitivity Type" | sed 's/[^0-9]*//g'))
else
IS_SINGLE_CR2=true
fi
if [[ $IS_SINGLE_CR2 == true ]]; then
###########
# Single ISO - CR2
# Subject Tag
#
if [[ $(echo "${SUBJECT}" | sed '/^\s*$/d' | wc -l) == 0 ]]; then
echo "${INPUT_BASENAME}: Add a new Subject tag."
SUBJECT_TAG='Single ISO CR2'
PROCESS_SUBJECT=true
else
echo "${INPUT_BASENAME} is a Single ISO image and has a Subject tag already."
PROCESS_SUBJECT=false
fi
# Baseline Tags
#
if [[ $(echo "${BASELINES}" | sed '/^\s*$/d' | wc -l) == 0 ]]; then
echo "${INPUT_BASENAME}: Add new Baseline tags."
PROCESS_BASELINE=true
else
echo "${INPUT_BASENAME}: Baseline tags exist. Skipping."
PROCESS_BASELINE=false
################################################################
fi
# FIRST CHECK FOR INDIVIDUAL FILE
if [[ $CROPHEIGHT_CHECK_VALUE != $C5DMK3_HEIGHT ]]; then
################################
# CR2 FILES
#
# Input file is CR2 or cr2
echo "${INPUT_BASENAME}: New resolution, $C5DMK3_WIDTH x $C5DMK3_HEIGHT."
PROCESS_SIZE=true
if [[ "${INPUT_EXTENSION}" == "CR2" ]]
then
else
# Dual ISO - unprocessed CR2 (NOTE: THIS CHECK IS SLOW)
# Test an input file for Dual ISO.
if [[ $(cr2hdr --dry-run "${INPUT}" | grep "Interlaced ISO detected" | wc -l) -eq 1 ]]
then
echo "${INPUT_BASENAME}: Dual ISO CR2 image. Skipping."
IS_SINGLE_CR2=false
else
IS_SINGLE_CR2=true
fi
echo "${INPUT_BASENAME}: Has correct resolution already."
PROCESS_SIZE=false
# Single ISO - CR2
if [[ "${IS_SINGLE_CR2}" == true ]]
then
# Subject Tag
if [[ $(echo "${SUBJECT}" | sed '/^\s*$/d' | wc -l) -eq 0 ]]
then
echo "${INPUT_BASENAME}: Add a new Subject tag."
SUBJECT_TAG="Single ISO CR2"
PROCESS_SUBJECT=true
else
echo "${INPUT_BASENAME} is a Single ISO image and has a Subject tag already."
PROCESS_SUBJECT=false
fi
# Baseline Tags
if [[ $(echo "${BASELINES}" | sed '/^\s*$/d' | wc -l) -eq 0 ]]
then
echo "${INPUT_BASENAME}: Add new Baseline tags."
PROCESS_BASELINE=true
else
echo "${INPUT_BASENAME}: Baseline tags exist. Skipping."
PROCESS_BASELINE=false
fi
# Image size
if [[ "${CROPHEIGHT_CHECK_VALUE}" -ne "${C5DMK3_HEIGHT}" ]]
then
echo "${INPUT_BASENAME}: New resolution, ${C5DMK3_WIDTH} x ${C5DMK3_HEIGHT}."
PROCESS_SIZE=true
else
echo "${INPUT_BASENAME}: Has correct resolution already."
PROCESS_SIZE=false
fi
fi
fi
fi
################################
# DNG FILES
#
# Input file is DNG or dng
################################
# DNG FILES
#
# Input file is DNG or dng
elif [[ "${INPUT_EXTENSION}" == "DNG" ]] || [[ "${INPUT_EXTENSION}" == "dng" ]]; then
elif [[ "${INPUT_EXTENSION}" == "DNG" ]]
then
###########
# DNG with missing Subject Tag
# DNG with missing Subject Tag
if [[ $(echo "${SUBJECT}" | sed '/^\s*$/d' | wc -l) == 0 ]]; then
if [[ $(echo "${SUBJECT}" | sed '/^\s*$/d' | wc -l) -eq 0 ]]
then
echo "${INPUT_BASENAME}: Add a new Subject tag."
SUBJECT_TAG='Single ISO CR2'
PROCESS_SUBJECT=true
echo "${INPUT_BASENAME}: Add a new Subject tag."
SUBJECT_TAG="Single ISO CR2"
PROCESS_SUBJECT=true
#We don't update size tags. See reason below.
#Baseline tags have already been written by Adobe converter.
PROCESS_SIZE=false
PROCESS_BASELINE=false
# We don't update size tags. See reason below.
# Baseline tags have already been written by Adobe converter.
PROCESS_SIZE=false
PROCESS_BASELINE=false
###########
# DNG with updated Subject Tag
# DNG with updated Subject Tag
elif [[ $(echo "${SUBJECT_SINGLEISO}" | sed '/^\s*$/d' | wc -l) != 0 ]]; then
elif [[ $(echo "${SUBJECT_SINGLEISO}" | sed '/^\s*$/d' | wc -l) -ne 0 ]]
then
echo "${INPUT_BASENAME}: Subject tag exists. Skipping."
PROCESS_SUBJECT=false
echo "${INPUT_BASENAME}: Subject tag exists. Skipping."
PROCESS_SUBJECT=false
#We don't update size tags. See reason below.
#Baseline tags have already been written by Adobe converter.
PROCESS_SIZE=false
PROCESS_BASELINE=false
# We don't update size tags. See reason below.
# Baseline tags have already been written by Adobe converter.
PROCESS_SIZE=false
PROCESS_BASELINE=false
###########
# New Dual ISO - DNG
# New Dual ISO - DNG
elif [[ $(echo "${SUBJECT_DUALISO}" | sed '/^\s*$/d' | wc -l) != 0 ]]; then
elif [[ $(echo "${SUBJECT_DUALISO}" | sed '/^\s*$/d' | wc -l) -ne 0 ]]
then
echo "${INPUT_BASENAME}: Dual ISO image with proper tags. Skipping."
echo "${INPUT_BASENAME}: Dual ISO image with proper tags. Skipping."
# Tags have already be written by updated cr2hdr.
PROCESS_SUBJECT=false
PROCESS_SIZE=false
PROCESS_BASELINE=false
# Tags have already be written by updated cr2hdr.
PROCESS_SUBJECT=false
PROCESS_SIZE=false
PROCESS_BASELINE=false
###########
# Old Dual ISO - DNG
elif [[ $(echo "${SUBJECT_DUALISO_OLD}" | sed '/^\s*$/d' | wc -l) != 0 ]]; then
# Old Dual ISO - DNG
echo "${INPUT_BASENAME}: old Dual ISO image. Update Subject & Baseline tags."
exiftool -xmp:subject= "${INPUT}" -overwrite_original #Clear old tag
elif [[ $(echo "${SUBJECT_DUALISO_OLD}" | sed '/^\s*$/d' | wc -l) -ne 0 ]]
then
PROCESS_SUBJECT=true
SUBJECT_TAG='Dual ISO DNG'
echo "${INPUT_BASENAME}: old Dual ISO image. Update Subject & Baseline tags."
exiftool -xmp:subject= "${INPUT}" -overwrite_original #Clear old tag
PROCESS_SIZE=false
PROCESS_BASELINE=true #Old dual ISOs don't have this one.
PROCESS_SUBJECT=true
SUBJECT_TAG="Dual ISO DNG"
################################
PROCESS_SIZE=false
fi
# Old dual ISOs don't have this one.
PROCESS_BASELINE=true
fi
fi
################################################################
# Suffix for the new file name
# U = Uncropped (PROCESS_SIZE)
# S = Subject Tag (PROCESS_SUBJECT)
# B = Baseline Tags (PROCESS_BASELINE)
# false, false, false
if [[ $PROCESS_SUBJECT == false ]] && [[ $PROCESS_BASELINE == false ]] && [[ $PROCESS_SIZE == false ]]; then
#WRITENEWFILE=false
SUFFIX=
# true, true, true
elif [[ $PROCESS_SUBJECT == true ]] && [[ $PROCESS_BASELINE == true ]] && [[ $PROCESS_SIZE == true ]]; then
#WRITENEWFILE=true
SUFFIX=_USB
# Suffix for the new file name
# U = Uncropped (PROCESS_SIZE)
# S = Subject Tag (PROCESS_SUBJECT)
# B = Baseline Tags (PROCESS_BASELINE)
# false, false, false
if \
[[ "${PROCESS_SUBJECT}" == false ]] && \
[[ "${PROCESS_BASELINE}" == false ]] && \
[[ "${PROCESS_SIZE}" == false ]]
then
SUFFIX=
# true, true, true
elif \
[[ "${PROCESS_SUBJECT}" == true ]] && \
[[ "${PROCESS_BASELINE}" == true ]] && \
[[ "${PROCESS_SIZE}" == true ]]
then
SUFFIX=_USB
# true, true, false
elif \
[[ "${PROCESS_SUBJECT}" == true ]] && \
[[ "${PROCESS_BASELINE}" == true ]] && \
[[ "${PROCESS_SIZE}" == false ]]
then
SUFFIX=_SB
# false, true, true
elif \
[[ "${PROCESS_SUBJECT}" == false ]] && \
[[ "${PROCESS_BASELINE}" == true ]] && \
[[ "${PROCESS_SIZE}" == true ]]
then
SUFFIX=_UB
# true, false, true
elif \
[[ "${PROCESS_SUBJECT}" == true ]] && \
[[ "${PROCESS_BASELINE}" == false ]] && \
[[ "${PROCESS_SIZE}" == true ]]
then
SUFFIX=_US
# false, true, false
elif \
[[ "${PROCESS_SUBJECT}" == false ]] && \
[[ "${PROCESS_BASELINE}" == true ]] && \
[[ "${PROCESS_SIZE}" == false ]]
then
SUFFIX=_B
# true, false, false
elif \
[[ "${PROCESS_SUBJECT}" == true ]] && \
[[ "${PROCESS_BASELINE}" == false ]] && \
[[ "${PROCESS_SIZE}" == false ]]
then
SUFFIX=_S
# false, false, true
elif \
[[ "${PROCESS_SUBJECT}" == false ]] && \
[[ "${PROCESS_BASELINE}" == false ]] && \
[[ "${PROCESS_SIZE}" == true ]]
then
SUFFIX=_U
fi
# true, true, false
elif [[ $PROCESS_SUBJECT == true ]] && [[ $PROCESS_BASELINE == true ]] && [[ $PROCESS_SIZE == false ]]; then
#WRITENEWFILE=true
SUFFIX=_SB
################################################################
# false, true, true
elif [[ $PROCESS_SUBJECT == false ]] && [[ $PROCESS_BASELINE == true ]] && [[ $PROCESS_SIZE == true ]]; then
# RESOLUTION TAGS MANIPULATION - non-Dual ISO CR2 only
#WRITENEWFILE=true
SUFFIX=_UB
# 1) Check if Size process variable is true
# 2) If question "Do we have a 5D Mark string in the file?" does not
# return 0, E.G. the camera model is 5D Mark 3.
# true, false, true
elif [[ $PROCESS_SUBJECT == true ]] && [[ $PROCESS_BASELINE == false ]] && [[ $PROCESS_SIZE == true ]]; then
if \
[[ "${PROCESS_SIZE}" == true ]] && \
[[ "${C5DMK3_CHECK}" -ne 0 ]]
then
#WRITENEWFILE=true
SUFFIX=_US
# According to file analysis done with CR2 and DNG files,
# Cropped & Exif Width/Height tags should be written into CR2 files.
# CR2 files require only Cropped Image Height/Width values,
# but if we convert an uncropped CR2 file into DNG, we get wrong picture size.
# To correct this for DNG files, Exif Height/Witdh values are required, too.
# false, true, false
elif [[ $PROCESS_SUBJECT == false ]] && [[ $PROCESS_BASELINE == true ]] && [[ $PROCESS_SIZE == false ]]; then
# WHY WE DON'T CHANGE EXIF TAGS FOR DNG FILES HERE?
# We can't uncrop DNG file procuded by Adobe algorithms (Adobe DNG Converter or raw2dng).
# This is because Adobe's method writes a tag name "Default Crop Size" which can't be
# changed afterwards without rendering the image unusable in Adobe Camera Raw software.
#
# My hypothesis about the issue is as follows:
# Camera Raw may do some comparison check between dimensions defined in "Default Crop Size"
# and some of the exif-unwritable Width/Height values. If there's a mismatch, the file can't
# be opened in Adobe Camera Raw software. An image that can't be opened in ACR, is still
# usable in some other RAW processing software (because their check for EXIF value tags differ).
#
# Every time I edited "Default Crop Size" value in DNG file, ACR gave me an error about
# unsupported or corrupted file.
#WRITENEWFILE=true
SUFFIX=_B
exiftool \
-CroppedImageWidth="${C5DMK3_WIDTH}" \
-CroppedImageHeight="${C5DMK3_HEIGHT}" \
-ExifImageWidth="${C5DMK3_WIDTH}" \
-ExifImageHeight="${C5DMK3_HEIGHT}" \
"${INPUT}" \
-overwrite_original
# true, false, false
elif [[ $PROCESS_SUBJECT == true ]] && [[ $PROCESS_BASELINE == false ]] && [[ $PROCESS_SIZE == false ]]; then
echo -e "${INPUT_BASENAME}: Image dimensions updated to ${C5DMK3_WIDTH} x ${C5DMK3_HEIGHT}.\n"
#WRITENEWFILE=true
SUFFIX=_S
# Other useful Height/Width tags are as follows:
# false, false, true
elif [[ $PROCESS_SUBJECT == false ]] && [[ $PROCESS_BASELINE == false ]] && [[ $PROCESS_SIZE == true ]]; then
# -OriginalImageWidth
# -OriginalImageHeight
#WRITENEWFILE=true
SUFFIX=_U
# -RelatedImageWidth
# -RelatedImageHeight
fi
fi
################################################################
# RESOLUTION TAGS MANIPULATION - non-Dual ISO CR2 only
# 1) Check if Size process variable is true
# 2) If question "Do we have a 5D Mark string in the file?" does not return 0, E.G. the camera model is 5D Mark 3...
# And if all previous checks pass, then we do our tricks here.
if [[ $PROCESS_SIZE == true ]] && [[ $C5DMK3_CHECK != 0 ]]; then
# BASELINE TAGS ADDITION - non-Dual ISO CR2 only
# According to file analysis done with CR2 and DNG files, Cropped & Exif Width/Height tags should be written in a CR2 files.
# CR2 files require only Cropped Image Height/Width values, but if we convert an uncropped CR2 file into DNG, we get wrong picture size.
# To correct this for DNG files, Exif Height/Witdh values are required, too.
# 1) We can request that PROCESS variable returns true though it's set to
# false in Dual ISO CR2 images too. These CR2 images have Baseline values
# already added into EXIF metadata since 01/07/2017 (cr2hdr code patched).
# WHY WE DON'T CHANGE EXIF TAGS FOR DNG FILES HERE?
# We can't uncrop DNG file procuded by Adobe algorithms (Adobe DNG Converter or raw2dng). This is because Adobe's method writes a tag named
#"Default Crop Size" which can't be changed afterwards without rendering the image unusable in Adobe Camera Raw software. I assume Camera Raw
# does some comparison check between dimensions defined in "Default Crop Size" and some of the exif-unwritable Width/Height values, and if
# there's a mismatch, the file can't be opened in Adobe Camera Raw software. I tested it so an image that can't be opened in ACR, is still
# usable in some other RAW processing software (because their check for EXIF value tags differ).
# 2) We check for Canon 5D Mark 3 here
# Every time I edited "Default Crop Size" value in DNG, ACR gave me an error claiming the file is unsupported or corrupted.
# NOTE: We don't care about the image resolution here.
exiftool -CroppedImageWidth=$C5DMK3_WIDTH -CroppedImageHeight=$C5DMK3_HEIGHT -ExifImageWidth=$C5DMK3_WIDTH -ExifImageHeight=$C5DMK3_HEIGHT "${INPUT}" -overwrite_original
echo -e "${INPUT_BASENAME}: Image dimensions updated to $C5DMK3_WIDTH x $C5DMK3_HEIGHT.\n"
# Other useful Height/Width tags are as follows:
if \
[[ "${PROCESS_BASELINE}" == true ]] && \
[[ "${C5DMK3_CHECK}" -ne 0 ]]
then
# -OriginalImageWidth
# -OriginalImageHeight
# The following tags (with their respective values) are being used in DNG files
# converted from CR2 files of Canon 5D Mark 3. Because CR2 files are mostly
# equal to DNG files but these tags don't exist inside CR2 files, we can add them
# as shown in the following section.
# -RelatedImageWidth
# -RelatedImageHeight
fi
################################################################
# BASELINE TAGS ADDITION - non-Dual ISO CR2 only
# 1) We can request that PROCESS variable returns true though it's set to false in Dual ISO CR2 images too. These CR2 images have Baseline values
# already added into EXIF metadata since 01/07/2017 (cr2hdr code patched).
# 2) We check for Canon 5D Mark 3 here
# NOTE: We don't care about the image resolution here.
if [[ $PROCESS_BASELINE == true ]] && [[ $C5DMK3_CHECK != 0 ]]; then
# The following tags (with their respective values) are being used in DNG files converted from CR2 files of Canon 5D Mark 3 camera. Because CR2 files are mostly equal to
# DNG files but these tags don't exist inside CR2 files, we can add them as done in the following lines.
# ######################################################
#
# Camera Model: Canon EOS 5D Mark III
# ISO Value Baseline Exposure Value
#
# 100 0.25
# 125 0.25
# 200 0.25
# 250 0.25
# 400 0.25
# 500 0.25
# 800 0.25
# 1000 0.25
# 1600 0.25
# 2000 0.25
# 3200 0.25
# 4000 0.25
# 6400 0.25
# 8000 0.25
# 12800 0.25
# 16000 0.25
# 25600 0.25
#
# 50 -0.75
# 160 0.02
# 320 0.01
# 640 0.01
# 1250 0.01
# 2500 0.01
# 5000 0.01
# 10000 0.01
# 20000 0.01
# 51200 0.36
# 102400 0.36
#
# ######################################################
#
# Same values for all ISOs:
#
# Baseline Noise 0.8
# Baseline Sharpness 1.2
# Bayer Green Split 100
#
# ######################################################
#
# Camera Profiles in Adobe Camera RAW - Baseline Exposure Offsets:
#
# All Canon EOS 5D Mark 3 profiles (Standard, Neutral, Landscape etc.): -0.25
# Adobe Standard Profile: 0.00
#
# ######################################################
# We Do ISO check with Exposure Index value (It returns the same value than used ISO, and works with ISO 102400, too)
if [[ $ISO_VALUE == 50 ]]; then
BL_EXP=-0.75
elif [[ $ISO_VALUE == 160 ]]; then
BL_EXP=0.02
elif [[ $ISO_VALUE == 51200 ]] || [[ $ISO_VALUE == 102400 ]]; then
BL_EXP=0.36
elif [[ $ISO_VALUE == 320 ]] || [[ $ISO_VALUE == 640 ]] || [[ $ISO_VALUE == 1250 ]] || [[ $ISO_VALUE == 2500 ]] || [[ $ISO_VALUE == 5000 ]] || [[ $ISO_VALUE == 10000 ]] || [[ $ISO_VALUE == 20000 ]]; then
BL_EXP=0.01
else
BL_EXP=0.25
fi
exiftool -BaselineExposure=$BL_EXP -BaselineNoise=0.8 -BaselineSharpness=1.2 -BayerGreenSplit=100 "${INPUT}" -overwrite_original
echo -e "${INPUT_BASENAME}: Baseline tags added.\n"
# ######################################################
#
# Camera Model: Canon EOS 5D Mark III
# ISO Value Baseline Exposure Value
#
# 100 0.25
# 125 0.25
# 200 0.25
# 250 0.25
# 400 0.25
# 500 0.25
# 800 0.25
# 1000 0.25
# 1600 0.25
# 2000 0.25
# 3200 0.25
# 4000 0.25
# 6400 0.25
# 8000 0.25
# 12800 0.25
# 16000 0.25
# 25600 0.25
#
# 50 -0.75
# 160 0.02
# 320 0.01
# 640 0.01
# 1250 0.01
# 2500 0.01
# 5000 0.01
# 10000 0.01
# 20000 0.01
# 51200 0.36
# 102400 0.36
#
# ######################################################
#
# Same values for all ISOs:
#
# Baseline Noise 0.8
# Baseline Sharpness 1.2
# Bayer Green Split 100
#
# ######################################################
#
# Camera Profiles in Adobe Camera RAW - Baseline Exposure Offsets:
#
# All Canon EOS 5D Mark 3 profiles (Standard, Neutral, Landscape etc.): -0.25
# Adobe Standard Profile: 0.00
#
# ######################################################
# We Do ISO check with Exposure Index value (It returns the same
# value than used ISO, and works with ISO 102400, too).
if [[ "${ISO_VALUE}" -eq 50 ]]
then
BL_EXP=-0.75
elif [[ "${ISO_VALUE}" -eq 160 ]]
then
BL_EXP=0.02
elif \
[[ "$ISO_VALUE}" -eq 51200 ]] || \
[[ "$ISO_VALUE}" -eq 102400 ]]
then
BL_EXP=0.36
elif \
[[ "${ISO_VALUE}" -eq 320 ]] || \
[[ "${ISO_VALUE}" -eq 640 ]] || \
[[ "${ISO_VALUE}" -eq 1250 ]] || \
[[ "${ISO_VALUE}" -eq 2500 ]] || \
[[ "${ISO_VALUE}" -eq 5000 ]] || \
[[ "${ISO_VALUE}" -eq 10000 ]] || \
[[ "${ISO_VALUE}" -eq 20000 ]]
then
BL_EXP=0.01
else
BL_EXP=0.25
fi
# ######################################################
exiftool \
-BaselineExposure="${BL_EXP}" \
-BaselineNoise=0.8 \
-BaselineSharpness=1.2 \
-BayerGreenSplit=100 \
"${INPUT}" \
-overwrite_original
################################################################
echo -e "${INPUT_BASENAME}: Baseline tags added.\n"
# SUBJECT TAG ADDITION
fi
if [[ $PROCESS_SUBJECT == true ]] && [[ $C5DMK3_CHECK != 0 ]]; then
################################################################
exiftool -xmp:subject="$SUBJECT_TAG" "${INPUT}" -overwrite_original
# SUBJECT TAG ADDITION
echo -e "${INPUT_BASENAME}: New Subject tag added: $SUBJECT_TAG\n"
if \
[[ "${PROCESS_SUBJECT}" == true ]] && \
[[ "${C5DMK3_CHECK}" -ne 0 ]]
then
exiftool -xmp:subject="${SUBJECT_TAG}" "${INPUT}" -overwrite_original
echo -e "${INPUT_BASENAME}: New Subject tag added: $SUBJECT_TAG\n"
fi
fi
################################################################
################################################################
# FILE SUFFIX ADDITION
# FILE SUFFIX ADDITION
exiftool "-FileModifyDate<EXIF:DateTimeOriginal" "${INPUT}"
#if [[ $WRITENEWFILE == true ]]; then
NEWFILE="${INPUT_DIR}"/"${INPUT_BASENAME}${SUFFIX}"."${INPUT_EXTENSION}"
exiftool "-FileModifyDate<EXIF:DateTimeOriginal" "${INPUT}" #For individual images and commands, use -P parameter
mv "${INPUT}" "${NEWFILE}"
NEWFILE="${INPUT_DIR}"/"${INPUT_BASENAME}"$SUFFIX."${INPUT_EXTENSION}"
exiftool '-FileName<DateTimeOriginal' -d '%Y%m%d-%f%%-c.%%e' "${NEWFILE}"
mv "${INPUT}" "${NEWFILE}"
if [[ "${2}" != "" ]]; then
echo "Moving to the next file."
fi
exiftool '-FileName<DateTimeOriginal' -d '%Y%m%d-%f%%-c.%%e' "${NEWFILE}"
################################################################
#fi
# PROGRESSBAR CODE - BEGIN
if [[ "${2}" != "" ]]; then
echo "Moving to the next file."
fi
let inc++
################################################################
# Percentage needs to be calculated like this due to bash rounding limitations.
PERCENT_VALUE=$(((${mltp}*${tics})/(200*${numargs}/${inc} % 2 + ${mltp}*${numargs}/${inc})))
# Output: 20, 40, 59, 80, 100 etc.
####PROGRESSBAR STUFF - BEGIN
let inc++
qdbus $dbusRef Set "" "value" "${PERCENT_VALUE}";
qdbus $dbusRef setLabelText "${LABELTEXT} (${inc}/${numargs})";
#Percentage needs to be calculated like this due to bash rounding limitations...
PERCENT_VALUE=$((($mltp*$tics)/(200*$numargs/$inc % 2 + $mltp*$numargs/$inc)))
#Output: 20, 40, 59, 80, 100 etc.
# PROGRESSBAR CODE - END
qdbus $dbusRef Set "" "value" $PERCENT_VALUE;
qdbus $dbusRef setLabelText "$LABELTEXT ($inc/$numargs)";
####PROGRESSBAR STUFF - END
shift # Move to the next file
# Move to the next file.
shift
done
##############################################
#Close processing window if cancelled event has been triggered.
# Close processing window if cancelled event has been triggered.
# PROGRESSBAR CODE - BEGIN
####PROGRESSBAR STUFF - BEGIN
# If the process was cancelled, remove tmp file and exit the script.
if [[ ! $(qdbus $dbusRef wasCancelled) == "false" ]]; then
exit
exit 0
fi
##############################################
#Close processing window if not cancelled and processing finished.
qdbus $dbusRef close
####PROGRESSBAR STUFF - END
exit
##############################################
################################################################################################
# PROGRESSBAR CODE - END
# DEPRECATED
#
# ##while [ $# -gt 0 ]; do
# CROPPED=$1
# EXTENSION=$(echo $1 | rev | cut -f 1 -d '.' | rev) #Get the correct file extension for an input file (so the new one will use the same)
# UNCROPPED=$(echo "$CROPPED" | sed "s/\.\w*$/_uncropped.$EXTENSION/")
#
# #Is the uncropping already done for a file? If yes, we skip this step. This passes only if file doesn't exist.
# if [[ ! -e $INPUT_DIR/uncropped/$UNCROPPED ]]; then
#
# if [[ $(cr2hdr --dry-run $CROPPED | grep "Interlaced ISO detected" | wc -l) == 1 ]] || [[ $(exiftool $CROPPED |grep "Dual-ISO" | wc -l) != 0 ]] ; then # Test an input file for Dual ISO.
# return 1; #Do not edit Exif data of a Dual ISO file.
# else
# exifres_5dmk3
# mv $UNCROPPED $INPUT_DIR/uncropped/
# fi
# fi
#
# ####PROGRESSBAR STUFF - BEGIN
# let inc++
#
# #Percentage needs to be calculated like this due to bash rounding limitations...
# PERCENT_VALUE=$((($mltp*$tics)/(200*$numargs/$inc % 2 + $mltp*$numargs/$inc)))
# #Output: 20, 40, 59, 80, 100 etc.
#
# qdbus $dbusRef Set "" "value" $PERCENT_VALUE;
# qdbus $dbusRef setLabelText "$LABELTEXT ($inc/$numargs)";
# ####PROGRESSBAR STUFF - END
#
# shift
# done
#
####PROGRESSBAR STUFF - BEGIN
#$(qdbus $dbusRef wasCancelled) = "true"
#qdbus $dbusRef close
#done
####PROGRESSBAR STUFF - END
#
#Delete empty dir, if no files have been generated
#if [[ $(ls $INPUT_DIR/uncropped/ | wc -l) == 0 ]]; then
# rm -Rf $INPUT_DIR/uncropped/
#fi
#
# DEPRECATED
exit 0

+ 16
- 11
4_scripts/imagetools_04_mlvdump.sh View File

@ -1,7 +1,7 @@
#!/bin/bash
#!/bin/env bash
# Extract DNG frames from Magic Lantern MLV files (KDE/Plasma DE)
# Copyright (C) 2017 Pekka Helenius
# Copyright (C) 2017,2023 Pekka Helenius
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -19,16 +19,21 @@
#
###############################################
#We get the directory just from the first filename. Pwd should be easier, but bugged, so...
INPUT_DIR=$(dirname $1)
# We get the directory just from the first filename.
INPUT_DIR=$(dirname "${1}")
mkdir -p $INPUT_DIR/mlv_export
mkdir -p "${INPUT_DIR}/mlv_export"
while [ $# -gt 0 ]; do
MLV=$1
mlv_dump --dng $MLV -o ${MLV}_
mv ????????.MLV_??????.dng $INPUT_DIR/mlv_export
shift
while [[ $# -gt 0 ]]
do
MLV_FILE="${1}"
mlv_dump --dng "${MLV_FILE}" -o "${MLV_FILE}_"
mv ????????.MLV_??????.dng "${INPUT_DIR}/mlv_export"
# Move to the next file.
shift
done
kdialog --msgbox "MLV extracted successfully" --title "MLV Extraction";
kdialog \
--msgbox "MLV extracted successfully" \
--title "MLV Extraction";

+ 5
- 3
4_scripts/imagetools_05_mlvinfo.sh View File

@ -1,7 +1,7 @@
#!/bin/bash
#!/bin/env bash
# Show MLV file info in kdialog window (KDE/Plasma DE)
# Copyright (C) 2017 Pekka Helenius
# Copyright (C) 2017,2023 Pekka Helenius
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -19,4 +19,6 @@
#
###############################################
kdialog --msgbox "$(mlv_dump $1 2>&1 | grep -E 'opened|frames' | awk '{print $2}' | sed 's/.*\///' | sed -e '1 i\Files:' -e '4 i\\nDNG Frames:' )" --title "MLV Information";
kdialog \
--msgbox "$(mlv_dump $1 2>&1 | grep -E 'opened|frames' | awk '{print $2}' | sed 's/.*\///' | sed -e '1 i\Files:' -e '4 i\\nDNG Frames:' )" \
--title "MLV Information";

+ 25
- 16
4_scripts/imagetools_06_exif_deletedata.sh View File

@ -1,7 +1,7 @@
#!/bin/bash
#!/bin/env bash
# Delete all exif metadata from selected images with Exiftool
# Copyright (C) 2017 Pekka Helenius
# Copyright (C) 2017,2023 Pekka Helenius
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -19,26 +19,35 @@
#
###############################################
#We get the directory just from the first filename. Pwd should be easier, but bugged, so...
INPUT_DIR=$(dirname $1)
# We get the directory just from the first filename.
INPUT_DIR=$(dirname "${1}")
mkdir -p $INPUT_DIR/nometadata
mkdir -p "${INPUT_DIR}"/nometadata
#kdialog --yesnocancel "Do you really want to delete EXIF data for the selection?";
#if [ "$?" = 0 ]; then
while [ $# -gt 0 ]; do
#if [[ "$?" = 0 ]]
#then
while [[ $# -gt 0 ]]
do
EXTENSION=$(echo $1 | rev | cut -f 1 -d '.' | rev) #Get the correct file extension for an input file (so the new one will use the same)
# Get the correct file extension for an input file, to be used for the new file.
EXTENSION=$(echo "${1}" | rev | cut -f 1 -d '.' | rev)
OLDFILE=$(basename $1 | sed "s/\.\w*$/.$EXTENSION/")
NEWFILE=$(basename "$OLDFILE" | sed "s/\.\w*$/_nometadata.$EXTENSION/")
OLDFILE=$(basename "${1}" | sed "s/\.\w*$/.$EXTENSION/")
NEWFILE=$(basename "$OLDFILE" | sed "s/\.\w*$/_nometadata.$EXTENSION/")
exiftool -all= $INPUT_DIR/$OLDFILE -o $INPUT_DIR/nometadata/$NEWFILE
shift
done
exiftool -all= "${INPUT_DIR}/${OLDFILE}" -o "${INPUT_DIR}/nometadata/${NEWFILE}"
#Delete empty metadata folder (if it is)
if [[ $(ls $INPUT_DIR/nometadata/ | wc -l) == 0 ]]; then
rm -Rf $INPUT_DIR/nometadata/
# Move to the next file.
shift
done
# else
# exit 0
# fi
# Delete empty metadata folder.
if [[ $(ls "${INPUT_DIR}/nometadata/" | wc -l) == 0 ]]
then
rm -Rf "${INPUT_DIR}/nometadata/"
fi

+ 58
- 13
4_scripts/imagetools_06_exif_deletedata_critical.sh View File

@ -1,7 +1,7 @@
#!/bin/bash
#!/bin/env bash
# Delete critical metadata from an image or images using Exiftool
# Copyright (C) 2017 Pekka Helenius
# Copyright (C) 2017,2023 Pekka Helenius
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -19,22 +19,67 @@
#
###############################################
#We get the directory just from the first filename. Pwd should be easier, but bugged, so...
INPUT_DIR=$(dirname $1)
# We get the directory just from the first filename.
INPUT_DIR=$(dirname "${1}")
#kdialog --yesnocancel "Do you really want to delete EXIF data for the selection?";
#if [ "$?" = 0 ]; then
while [ $# -gt 0 ]; do
#if [[ "$?" = 0 ]]
#then
while [[ $# -gt 0 ]]
do
EXTENSION=$(echo $1 | rev | cut -f 1 -d '.' | rev) #Get the correct file extension for an input file (so the new one will use the same)
# Get the correct file extension for an input file, to be used for the new file.
EXTENSION=$(echo "${1}" | rev | cut -f 1 -d '.' | rev)
FILE=$(basename "${1}" | sed "s/\.\w*$/.$EXTENSION/")
FILE=$(basename $1 | sed "s/\.\w*$/.$EXTENSION/")
exiftool \
-ApertureValue= \
-ColorSpace= \
-ExposureCompensation= \
-ExposureMode= \
-ExposureProgram= \
-ExposureTime= \
-FNumber= \
-Flash= \
-FocalLength= \
-FocalPlaneResolutionUnit= \
-FocalPlaneXResolution= \
-FocalPlaneYResolution= \
-Lens= \
-LensInfo= \
-LensModel= \
-LensSerialNumber= \
-Make= \
-MaxApertureValue= \
-MeteringMode= \
-Model= \
-PhotoshopThumbnail= \
-RecommendedExposureIndex= \
-ResolutionUnit= \
-SensitivityType= \
-SerialNumber= \
-ShutterSpeedValue= \
-Software= \
-Version= \
-WhiteBalance= \
-XResolution= \
-YResolution= \
-creatortool= \
-historysoftwareagent= \
-iso= \
-adobe:all= \
-xmp:subject= \
-xmp:all= \
-photoshop:all= \
"${INPUT_DIR}/${FILE}" \
-overwrite_original
exiftool -xmp:subject= -Software= -Version= -creatortool= -historysoftwareagent= -PhotoshopThumbnail= -FocalLength= -Lens= -FNumber= -ApertureValue= -LensInfo= -LensModel= -ExposureTime= -MaxApertureValue= -SerialNumber= -Make= -ExposureMode= -WhiteBalance= -Flash= -MeteringMode= -ExposureCompensation= -ShutterSpeedValue= -RecommendedExposureIndex= -SensitivityType= -LensSerialNumber= -FocalPlaneYResolution= -FocalPlaneXResolution= -FocalPlaneResolutionUnit= -XResolution= -YResolution= -ResolutionUnit= -iso= -ColorSpace= -Model= -ExposureProgram= -adobe:all= -xmp:all= -photoshop:all= $INPUT_DIR/$FILE -overwrite_original
shift
done
# kdialog --msgbox "Exif metadata deleted!"
# Move to the next file.
shift
done
# kdialog --msgbox "Exif metadata deleted!"
#else
# exit 0
# exit 0
#fi

+ 11
- 9
4_scripts/imagetools_07_ale_stack.sh View File

@ -1,7 +1,7 @@
#!/bin/bash
#!/bin/env bash
# Stack TIFF images with Anti-Lamenessing Engine (ALE)
# Copyright (C) 2017 Pekka Helenius
# Copyright (C) 2017,2023 Pekka Helenius
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -19,15 +19,17 @@
#
###############################################
#We get the directory just from the first filename. Pwd should be easier, but bugged, so...
INPUT_DIR=$(dirname $1)
# We get the directory just from the first filename.
INPUT_DIR=$(dirname "${1}")
#First & Last file names (without suffixes)
for last; do true; done
FIRST=$(basename $1 | cut -f 1 -d '.' | sed 's/IMG_//g') #Name of the first file passed into the script
LAST=$(basename $last | cut -f 1 -d '.' | sed 's/IMG_//g') #Name of the last file passed into the script
# First & Last file names (without suffixes)
for _LAST; do true; done
# Name of the first file passed into the script.
FIRST=$(basename "${1}" | cut -f 1 -d '.' | sed 's/IMG_//g')
# Name of the last file passed into the script.
LAST=$(basename "${_LAST}" | cut -f 1 -d '.' | sed 's/IMG_//g')
echo 'Starting image stacking process using temporary TIFF files.' && \
echo "Starting image stacking process using temporary TIFF files."
ale ./temp_tiff/*.tiff output.tif

+ 70
- 52
4_scripts/imagetools_08_geotag.sh View File

@ -1,7 +1,7 @@
#!/bin/bash
#!/bin/env bash
# Geotag images
# Copyright (C) 2017 Pekka Helenius
# Copyright (C) 2017,2023 Pekka Helenius
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -20,65 +20,83 @@
###############################################
# TODO Coordinate threshold = Grid size is 30x30m?
# TODO Find API for ASTER DEM v2 (better data)
# TODO Find API for ASTER DEM v2 (provides better data)
USERNAME=Fincer #For API (data request)
# Username for REST API data request
USERNAME=<PUT_YOUR_USERNAME_HERE>
############################
INTERNET_TEST=$(ping -c 3 nominatim.openstreetmap.org 2>&1 | grep -c "unknown host") #Ping Github three times and look for string 'unknown host'
# Ping openstreetmap.org three times.
PING_ADDRESS="nominatim.openstreetmap.org"
INTERNET_TEST=$(ping -c 3 "${PING_ADDRESS}" 2>&1 | grep -c "unknown host")
if [[ ! $INTERNET_TEST -eq 0 ]]; then #If 'unknown host' string is found, then
echo -e "\nCan't connect to geoservice provider (Nominatim). Please check your internet connection and try again.\n"
exit 1
if [[ ! "${INTERNET_TEST}" -eq 0 ]]
then
echo -e "\nCan't connect to the Geo Service provider '${PING_ADDRESS}'. Please check your internet connection and try again.\n"
exit 1
fi
############################
for IMAGE in $(echo "${@}"); do
for IMAGE in $(echo "${@}")
do
IMAGE_BASENAME=$(basename "${IMAGE}" | cut -f 1 -d '.')
IMAGE_EXTENSION=$(echo $(basename "${IMAGE}" | cut -f 2 -d '.' | sed '/^\s*$/d'))
if [[ $(exiftool -n -p '$GPSLatitude,$GPSLongitude' "${IMAGE}" | awk -F ',' '{print NF}') != 2 ]]
then
echo -e "$IMAGE_BASENAME: Missing coordinates. Are you sure you have geotagged the photo?\n"
exit 0
else
LATITUDE=$(exiftool -n -p '$GPSLatitude' "${IMAGE}")
LONGITUDE=$(exiftool -n -p '$GPSLongitude' "${IMAGE}")
# Clear previous geonames information.
exiftool \
-Location= \
-LocationShownCity= \
-LocationShownCountryName= \
-LocationShownProvinceState= \
-LocationShownSublocation= \
-Country-PrimaryLocationName= \
-Sub-location= \
-Country= \
-City= \
-State= \
-Province-State= \
-GPSAltitude= \
"${IMAGE}" \
-overwrite_original
echo -e "$IMAGE_BASENAME: retrieving country information.\n"
reversegeo "${IMAGE}"
# Reference: http://www.geonames.org/export/web-services.html
# Get elevation by retrieving a ASTER DEM value from GeoNames API server, grid size 30x30m
# There are several error factors:
# DEM Grid size
# General inaccurancies in DEM model
# Geoid model & projection errors
# Coordinate errors
# Variations in (estimated) height values
# So the retrieved elevation value is just a rough estimation here.
ALTITUDE=$(curl -s "http://api.geonames.org/astergdem?lat=$LATITUDE&lng=$LONGITUDE&username=$USERNAME")
# If we have a successful answer, then
if [[ "${ALTITUDE}" =~ '^[0-9]+$' ]]
then
exiftool -GPSAltitude="${ALTITUDE}" "${IMAGE}" -overwrite_original
echo -e "${IMAGE_BASENAME}: Altitude value updated.\n"
IMAGE_BASENAME=$(basename "${IMAGE}" | cut -f 1 -d '.')
IMAGE_EXTENSION=$(echo $(basename "${IMAGE}" | cut -f 2 -d '.' | sed '/^\s*$/d'))
if [[ $(exiftool -n -p '$GPSLatitude,$GPSLongitude' "${IMAGE}" | awk -F ',' '{print NF}') != 2 ]]; then
echo -e "$IMAGE_BASENAME: Missing coordinates. Are you sure you have geotagged the photo?\n"
exit
else
LATITUDE=$(exiftool -n -p '$GPSLatitude' "${IMAGE}")
LONGITUDE=$(exiftool -n -p '$GPSLongitude' "${IMAGE}")
# Clear previous geonames information
exiftool -Location= -LocationShownCity= -LocationShownCountryName= -LocationShownProvinceState= -LocationShownSublocation= -Country-PrimaryLocationName= -Sub-location= -Country= -City= -State= -Province-State= -GPSAltitude= "${IMAGE}" -overwrite_original
#if [[ $(exiftool -p '$Country-PrimaryLocationName' "${IMAGE}" | awk '{print NF}') != 1 ]]; then
echo -e "$IMAGE_BASENAME: retrieving country information.\n"
reversegeo "${IMAGE}"
#fi
# Reference: http://www.geonames.org/export/web-services.html
# Get elevation by retrieving a ASTER DEM value from GeoNames API server, grid size 30x30m
# There are several error factors:
# DEM Grid size
# General inaccurancies in DEM model
# Geoid model & projection errors
# Coordinate errors
# Variations in (estimated) height values
# So the retrieved elevation value is just a rough estimation here
ALTITUDE=$(curl -s "http://api.geonames.org/astergdem?lat=$LATITUDE&lng=$LONGITUDE&username=$USERNAME")
# IF successful answer, then
if [[ $ALTITUDE =~ '^[0-9]+$' ]]; then
exiftool -GPSAltitude=$ALTITUDE "${IMAGE}" -overwrite_original
echo -e "$IMAGE_BASENAME: Altitude value updated.\n"
else
# TODO IF NOT successful, try again for 2 times, then abort
echo -e "$IMAGE_BASENAME: Couldn't retrieve altitude value.\n"
# TODO: If not successful, try again for 2 times, then abort.
echo -e "${IMAGE_BASENAME}: Couldn't retrieve altitude value.\n"
fi
fi
done

+ 8
- 30
4_scripts/imagetools_09_mtime.sh View File

@ -1,35 +1,13 @@
#!/bin/bash
################################################################################################
# File system check
# We don't allow writing to SD card.
#Sed is here to remove any trailing spaces and crap like blank lines
INPUT_FILESYSTEM=$(df -h "${1}" | awk -F ' ' 'FNR> 1 {print $1}' | grep -i -E "/dev/sd?|/dev/hd?|?rewritefs|?tmpfs|/dev/nvme?" | sed '/^\s*$/d' | wc -l)
if [[ "${INPUT_FILESYSTEM}" -eq 0 ]]; then #if input file (first file printed in bash) filesystem does not start with /dev/sdX
kdialog --error "Image(s) are in a SD Card. Please move them your local or external storage and try again."
exit
fi
################################################################################################
#We get the directory just from the first filename. Pwd should be easier, but bugged, so...
INPUT_DIR=$(dirname "${1}")
DIR_BASENAME=$(echo "${INPUT_DIR}" | rev | cut -d/ -f 1 | rev)
while [[ $# -gt 0 ]]; do
################################################################
# Values that change during the while loop (differ from file to file)
#!/bin/env bash
while [[ $# -gt 0 ]]
do
INPUT="${1}"
MTIME=$(exiftool -d "%s" -DateTimeOriginal -s -S "${INPUT}")
touch --date=@${MTIME} "${INPUT}"
if [[ ! -z "${MTIME}" ]]; then
touch --date=@${MTIME} "${INPUT}"
fi
shift # Move to the next file
# Move to the next file.
shift
done

Loading…
Cancel
Save