-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgenerateDCP
executable file
·213 lines (195 loc) · 8.48 KB
/
generateDCP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env bash
# This Bash4 script uses DCamProf and ArgyllCMS to generate DCP profiles.
# It uses Exiv2 or ExifTool to extract the camera model if one is not
# manually provided as a parameter (-c).
#
# Read the RawPedia article, "How to create DCP color profiles".
# Run the script from a folder which contains the DCamProf executable and the
# daylight.tif and/or tungsten.tif files.
#
# Blame DrSlony
# Version 2017-03-06
# Please report bugs or enhancements to https://github.com/Beep6581/RawTherapee
scaninCmd="argyll-scanin"
exifCmd=""
copyright="RawTherapee CC0" # For a profile to be bundled with RawTherapee it must be in the public domain (CC0).
printFormat='\n\n\n%s ----------------------------------------\n\n'
# No touching below this line ------------------------------------------------
unset exec tungsten daylight suffix
OPTIND=1
while getopts "c:t:o:g:l:r:h?-" opt; do
case "${opt}" in
c) camera="$OPTARG"
;;
t) curve="$OPTARG"
;;
o) tro="$OPTARG"
;;
g) gamut="$OPTARG"
;;
l) layout="$OPTARG"
;;
r) ref="$OPTARG"
;;
h|\?|-) printf '%s\n' "Usage:" \
"Run the script from a folder which contains the DCamProf executable and the daylight.tif and/or tungsten.tif files." \
"" \
" $0 -c \"<camera name>\" -t <tone-curve> -o <tone reproduction operator> -g <gamut compression>" \
"" \
" -c \"<camera name>\"" \
" Optional. Specify the camera name, remember to surround it in double-quotes. If not specified, exiv2 or exiftool are used." \
"" \
" -t <acr|linear|none>" \
" Optional. Specify which tone-curve to embed. If unspecified, defaults to \"acr\"." \
"" \
" -o <neutral|standard>" \
" Optional. Specify the tone reproduction operator. Only used if -t is \"acr\". If unspecified, defaults to \"neutral\"." \
"" \
" -g <none|srgb|srgb-strong|adobergb|adobergb-strong>" \
" Optional. Specify gamut compression. Only used if -t is \"linear\". If unspecified, defaults to \"none\"." \
"" \
" -l <cc|ccp|it8|/path/to/layout.cht>" \
" Optional. Select layout file." \
" cc = ColorChecker" \
" ccp = ColorCheckerPassport" \
" it8 = IT 8.7/2-1993" \
" Or custom path." \
" If unspecified, defaults to \"/usr/share/argyllcms/ref/ColorCheckerPassport.cht\"." \
"" \
" -r <cc|ccnew|/path/to/reference.cie>" \
" Optional. Select reference file." \
" cc = data-examples/cc24_ref.cie - For ColorChecker24 targets produced before November 2014." \
" ccnew = data-examples/cc24_ref-new.cie - For ColorChecker24 targets produced from Novermber 2014 onwards." \
" Or custom path." \
" If unspecified, defaults to \"data-examples/cc24_ref.cie\"." \
""
exit 0
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
# Check for dcamprof
if [[ -x ./dcamprof ]]; then
dcamprofCmd="./dcamprof"
else
printf '%s\n' "dcamprof not found, get it from" "http://www.ludd.ltu.se/~torger/dcamprof.html"
exit 0
fi
# Check for argyll-scanin
command -v "$scaninCmd" >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
command -v scanin >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
printf '%s\n' "DCamProf requires the \"scanin\" command from ArgyllCMS." "Make sure ArgyllCMS is installed." "Could not find a working \"scanin\" command. Aborting."
exit 0
else
scaninCmd="scanin"
fi
fi
# Check for Exiv2/ExifTool if camera model not provided
if [[ -z $camera ]]; then
command -v exiv2 >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
command -v exiftool >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
printf '%s\n' "Install Exiv2 or ExifTool and re-run this script." "Aborting."
exit 0
else
exifCmd="exiftool -T -Model"
fi
else
exifCmd="exiv2 -g Exif.Image.Model -Pv"
fi
if [[ -e tungsten.tif ]]; then
camera="$(${exifCmd} tungsten.tif)"
if [[ -z $camera ]]; then
printf '%s\n' "Could not find camera model in tungsten.tif's metadata." "Re-run the script and provide the camera model manually."
exit 0
fi
fi
if [[ -e daylight.tif ]]; then
camera="$(${exifCmd} daylight.tif)"
if [[ -z $camera ]]; then
printf '%s\n' "Could not find camera model in daylight.tif's metadata." "Re-run the script and provide the camera model manually."
exit 0
fi
fi
fi
# Check for input files
if [[ ! -e tungsten.tif && ! -e daylight.tif ]]; then
printf '%s\n' "Neither daylight.tif nor tungsten.tif was found in the current folder. Aborting."
exit 0
fi
# Assign defaults if parameters not provided.
case "$tro" in
s|standard) tro="standard" ;;
*) tro="neutral" ;;
esac
case "$curve" in
l|linear) curve="linear" ;;
n|none) curve="none" ;;
*) curve="acr" ;;
esac
case "$gamut" in
s|srgb) gamut="srgb" ;;
ss|srgb-strong) gamut="srgb-strong" ;;
a|adobergb) gamut="adobergb" ;;
as|adobergb-strong) gamut="adobergb-strong" ;;
*) gamut="none" ;;
esac
case "$layout" in
cc) layout="/usr/share/argyllcms/ref/ColorChecker.cht" ;;
ccp) layout="/usr/share/argyllcms/ref/ColorCheckerPassport.cht" ;;
it8) layout="/usr/share/argyllcms/ref/it8.cht" ;;
"") layout="/usr/share/argyllcms/ref/ColorChecker.cht" ;;
*) ;;
esac
case "$ref" in
cc|ccold) ref="data-examples/cc24_ref.cie" ;;
ccnew) ref="data-examples/cc24_ref-new.cie" ;;
"") ref="data-examples/cc24_ref.cie" ;;
*) ;;
esac
# Check for layout file
if [[ ! -e $layout ]]; then
printf '%s\n' "Layout file \"${layout}\" not found. Aborting."
exit 0
fi
# Check for reference file
if [[ ! -e $ref ]]; then
printf '%s\n' "Reference file \"${ref}\" not found. Aborting."
exit 0
fi
# Clean up from previous runs.
rm daylight.ti3 daylight.json daylight-diag.tif tungsten.ti3 tungsten.json tungsten-diag.tif 2>/dev/null
if [[ -e tungsten.tif ]]; then
tungsten="tungsten.tif"
printf "${printFormat}" "${scaninCmd} tungsten"
${scaninCmd} -v -G 0.454545 -p -digIcrpn tungsten.tif "${layout}" "${ref}" tungsten-diag.tif
printf "${printFormat}" "make-profile tungsten"
${dcamprofCmd} make-profile -i StdA tungsten.ti3 tungsten.json 2>&1
#${dcamprofCmd} make-profile -i StdA -w all 1.5,1,8,2,1 tungsten.ti3 tungsten1.json
#${dcamprofCmd} make-profile -i StdA -w all 1.5,1,8,2,1 -l 0.1,0.1 tungsten.ti3 tungsten2.json
#${dcamprofCmd} make-profile -i StdA -w all 1.5,1,8,2,1 -l -1,0 tungsten.ti3 tungsten3.json
fi
if [[ -e daylight.tif ]]; then
daylight="daylight.tif"
printf "${printFormat}" "${scaninCmd} daylight"
"$scaninCmd" -v -G 0.454545 -p -digIcrpn daylight.tif "${layout}" "${ref}" daylight-diag.tif
printf "${printFormat}" "make-profile daylight"
${dcamprofCmd} make-profile -i D50 -C daylight.ti3 daylight.json 2>&1
#${dcamprofCmd} make-profile -i D50 -C -w all 1.5,1,8,2,1 daylight.ti3 daylight1.json
#${dcamprofCmd} make-profile -i D50 -C -w all 1.5,1,8,2,1 -l 0.1,0.1 daylight.ti3 daylight2.json
#${dcamprofCmd} make-profile -i D50 -C -w all 1.5,1,8,2,1 -l -1,0 daylight.ti3 daylight3.json
fi
#for relax in {0..3}; do
# ${dcamprofCmd} make-dcp -n "${camera}" -d "${camera}" -c "Morgan Hardwood/RawTherapee" -t acr ${tungsten%.tif}${tungsten:+${relax}.json} ${daylight%.tif}${daylight:+${relax}.json} "${camera} ${relax}.dcp"
#done
printf "${printFormat}" "make-dcp"
printf '%s\n' "Camera: $camera" "Copyright: $copyright" "Curve: $curve" "TRO: $tro" "Gamut: $gamut" ""
read -r -p "Enter DCP filename suffix, if any: " suffix
echo
# :+ uses an alternate value. If suffix is unset or empty, it expands to nothing, else it expands to " ${suffix}" with the space before the suffix.
${dcamprofCmd} make-dcp -n "${camera}" -d "${camera}" -c "${copyright}" -t "${curve}" -o "${tro}" -g "${gamut}" ${tungsten%.tif}${tungsten:+.json} ${daylight%.tif}${daylight:+.json} "${camera}${suffix:+ ${suffix}}.dcp" 2>&1
#ls -lah *.dcp