-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprofilescan
executable file
·143 lines (123 loc) · 2.81 KB
/
profilescan
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
#!/bin/bash
#
# Licensing:
#
# Copyright © Laurence Lumi 2017
# Licensed GNU General Public License v3
# which can be found here https://www.gnu.org/licenses/gpl-3.0.en.html
#
progname=`basename $0`
usage()
{
echo >&2 ""
echo >&2 "$progname:" "$@"
cat << MESSAGE1
USAGE: $progname [-d] [-dd] [-l] [-s name] [-fb] [-p name] [-crop XxY+x+y] infile
USAGE: $progname [-h] [-help]
OPTIONS:
MESSAGE1
exit 1
}
help()
{
echo >&2 ""
echo >&2 "$progname:" "$@"
cat >&2 << MESSAGE2
NAME: $progname
PURPOSE: creates profile information for later use.
Arguments:
MESSAGE2
exit 1
}
function DEBUG()
{
[ ! "$debug" -eq 0 ] && $@
}
tmpdir="./"
debug=0
tmpprefix=$tmpdir"_ps_"
comment="Processed with profilescan"
DEBUG echo -set comment "$comment"
prof_dir=$HOME/.scantools
mkdir -p "$prof_dir"
while [ $# -gt 0 ]
do
# get parameters
case "$1" in
-h|-help) # help information
echo ""
help
;;
-d) debug=1
;;
-dd) debug=2
;;
-l) # list profile
ls $prof_dir
exit 0
;;
-s) # show profile
shift
profile_name="$1"
cat $prof_dir/$profile_name
exit 0
;;
-fb) mode=filmbase
;;
-p) # profile name
shift
profile_name="$1"
;;
-crop) # crop value
shift
crop="-crop $1"
;;
-) # STDIN and end of arguments
break
;;
-*) # any other - argument
echo "--- UNKNOWN OPTION ---" $1
usage
;;
*) # end of arguments
break
;;
esac
shift # next option
done
infile=$1
if [ -z $infile ]; then
echo "must provide a filename"
usage
fi
if [ ! -f "$infile" -o ! -r "$infile" ]; then
echo "Cannot open: $infile"
exit 1
fi
if [[ $infile =~ .*.tif$ ]]; then
DEBUG echo assuming the input file being tif is saved in a linear colorspace, even though the metadata says otherwise
CSPACE="-set colorspace RGB"
fi
DEBUG set -x;
if [ "$mode" = "filmbase" ]; then
DEBUG echo mode = $filmbase
# calculate the filmbase values
eval set -- `convert "$infile[0]" $CSPACE -strip \
$crop\
-format\
"%[fx: mean.r ] %[fx: mean.g ] %[fx: mean.b ]"\
info:`
echo "Red: " $1 $4
echo "Green:" $2 $5
echo "Blue: " $3 $6
r_base=$1
g_base=$2
b_base=$3
if [ ! -z $profile_name ]; then
echo append data to profile $profile_name
DATE=`date '+%Y-%m-%d>%H:%M:%S'`
echo "Date FB_red GB_green FB_blue" >> "$prof_dir/$profile_name"
echo "$DATE $r_base $g_base $b_base" >> "$prof_dir/$profile_name"
fi
fi
exit 0