-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm-indep.sh
505 lines (382 loc) · 10.3 KB
/
m-indep.sh
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
#!/bin/bash
function m.src_indep(){
source ${WGPATH}/mtool/m-indep.sh;
}
function btofslash () { echo "$1" | sed 's|\\|/|g'; }
function ftobslash () { echo "$1" | sed 's|/|\\|g'; }
function m.amon() {
local al="${JOB}/arnoldlog.txt";
touch "${al}";
tail -n 0 -f ${al};
}
function m.tonice(){
echo "$1" | sed 's/\ \ */\ /g' | sed 's/\ $//' | sed 's/\ /\_/g' | sed 's/\./\-/g';
}
function m.seqext() {
local n="${1}";
local res="";
if [[ "$n" =~ ([-_.][0-9]*[.][A-Za-z]*)[A-Za-z]*$ ]]; then
res="${BASH_REMATCH[1]}"
fi
echo "${res}";
}
function m.hasws(){
local n="${1}";
local regexp="[[:space:]]"
if [[ $n =~ $regexp ]]; then
return 1;
else
return 0;
fi
}
function m.countchar(){
echo "${2}" | awk -F"${1}" '{print NF-1}'
}
function m.isnumber(){
if [[ ! "$1" =~ ^(0|[-]?[1-9]+[0-9]*)$ ]]; then
return 1;
else
return 0;
fi
}
# handles lofasz.exr and lofasz.3.exr -> lofasz
function m.fn_base() {
local fba="${1%.*}";
echo "${fba%.*}";
}
# color.1.exr tibor.exr -> exr
function m.fn_ext(){
echo ".${1#*.}";
}
# color.1.exr -> exr
function m.fn_mext() {
local fba="${1#*.}";
echo "${fba#*.}";
}
# <root> <depth>
function m.dtree() {
m.fd_ftree "${1}" $2 'd';
}
# <root> <depth>
function m.ftree() {
# echo "e1root:${1} E2DEP:${2} ";
# echo ' ';
m.fd_ftree "${1}" $2 'f';
}
# 1 2 3 4 5
# <root> <depth> <script/line> <runmode|dry> <batch param>
function m.runftree(){
#echo "r1oot:${1} r2dept:${2} r3sh:${3} r4dry:${4} r6bextra:${5}";
m.ftree "${1}" ${2} | xargs -P 1 -r -L 1 "${MBAT}/${3}.sh" ${4} ${5};
}
# the last .ext only
function m.repext(){
if [[ -z "$1" ]]; then
echo "***ERROR no input path!"
return 0;
fi
local mext=$(m.fn_mext "${1}");
echo "${1}" | sed "s|${mext}|${2}|g";
}
function m.tmpfile(){
if [[ -z "$1" ]]; then
echo "***ERROR no input path!"
return 0;
fi
local fb=$(m.fn_base "${1}");
local outf="${fb}_";
local inext=$(m.fn_ext "${1}");
local outext="${inext}";
if [[ -n "$2" ]]; then
outext="${2}";
fi
echo "${outf}${outext}"
}
function m.side(){
if [[ -z "$1" ]]; then
echo "***ERROR no input path!"
return 0;
fi
postfix='';
if [[ ( -n "${3}" ) ]]; then
postfix="${3}";
fi
local fb=$(m.fn_base "${1}");
local outf="${fb}${postfix}";
local origext=$(m.fn_ext "${1}");
local outext="${origext}";
local res="${outf}${outext}";
if [[ ( -n "$2" ) && ( "${2}" != '_' ) ]]; then
res=$(m.repext "${res}" "${2}");
fi
echo "${res}";
}
function m.namekey(){
local fb=$(basename "${1}");
echo "${2}${fb}" | sed 's|\.||g' ;
}
function m.waituntilany() {
local wdir="${1}";
local wpat="${2}";
sleep 2;
local nofbusyfiles=$(find "${wdir}" -name "${wpat}" -type f | wc -l);
while [[ ${nofbusyfiles} -gt 0 ]]
do
sleep 2;
nofbusyfiles=$(find "${wdir}" -name "${wpat}" -type f | wc -l);
done
}
# dir nof
function m.waitfornof() {
local wdir="${1}";
local wnof=${2};
local nof=$(ls -1 "${wdir}" | wc -l);
while [[ ! ${nof} -eq ${wnof} ]]
do
sleep 1;
nof=$(ls -1 "${wdir}" | wc -l);
done;
}
# remove all new line
function m.singleline() {
echo "$(sed ':a;N;$!ba;s/\n/,/g' ${1})";
}
# max 10 char long random string
function m.rndstr(){
local yearday=`date +%j`;
local linsec=`date +%s`;
local ns=`date +%N`;
ns=${ns%%00};
sleep 0.1;
local nns=`date +%N`;
nns=${nns%%00};
echo "${yearday}${linsec:(-3)}${ns:0:2}${nns:0:2}";
}
# remove white space
function m.remws(){
echo ${1} | sed 's|\s||g';
}
# dir patFile ext
function m.noffiles(){
#echo "ls -1 "${1}/"*"${2}"*"${3}" | wc -l;";
local lista=$(ls -1d "${1}/"*"${2}"*"${3}" 2>/dev/null) ;
if [[ $? -ne 0 ]]; then
echo '0';
fi
local szavak=$(echo "${lista}" | wc -w);
if [[ ${szavak} -eq 0 ]]; then
# nincsenek szavak - ures sor / sorok
echo '0';
else
echo "${lista}" | wc -l ;
fi
}
# sec -> Xmin Ysec
function m.sec2min(){
local em=$((${1} / 60));
local rs=$((${1} % 60));
if [[ ( -z "${em}" ) || ( ${em} -eq 0 )]]; then
echo "${1}s";
else
echo "${em}min ${rs}s";
fi
}
# remove ws
function m.rwspace(){
echo "${1}" | sed -e 's/\s\+//g';
}
function m.allchannels(){
local srci="${1}";
local ach=$(oiiotool.exe --info -v "${srci}" | grep -e "channel list:" | sed 's|channel list:||g' );
echo "${ach}";
}
function m.allch_except(){
local aexc=$(echo $(m.allchannels "${1}") | sed 's|'"${2}"'||g' );
m.rwspace "${aexc}";
}
# ----------- up: truely independent, down: dependent only from above -----
m.txnext(){
local res=$(m.repext "$1" 'tx');
echo "${res}";
}
m.float2graytx() {
local pin="$1";
local tx=$(m.txnext "${pin}");
local gray=$(m.tmpfile "${pin}" 'exr');
oiiotool.exe -i "${pin}" --iscolorspace linear --chsum:weight=.2126,.7152,.0722 --ch 0,0,0 -o ${gray}
maketx --hicomp --oiio --fixnan box3 -d float -u --stats --filter radial-lanczos3 --format exr -o "${tx}" "${gray}" >/dev/null;
rm -f "${gray}";
echo "${tx}";
}
# arnold magatol:
# .hdr -v -u --unpremult --oiio --colorconvert "linear" "linear"
# .exr -v -u --unpremult --oiio --colorconvert "linear" "linear"
# ez lossy
# .jpg -v -u --unpremult --oiio --format exr -d half --compression dwaa --colorconvert "sRGB" "linear"
# oiiotool resize .hdri
# oiiotool.exe '/q/Work/royal/In/vhdri_sky/dlight/173-hdri-skies-com.hdr' -v --unpremult --colorconvert "linear" "linear" -resize 2048x2048 -o '/q/Work/royal/In/vhdri_sky/dlight/173-hsky_2k.hdr'
# in [width]x[height] out
m.rszhdri(){
oiiotool.exe "$1" -v --unpremult --colorconvert "linear" "linear" -resize "$2" -o "${3}"
}
m.float2tx() {
local tx=$(m.txnext "${1}");
maketx -u --oiio --fixnan box3 --colorconvert "linear" "linear" -o "${tx}" "$1" >/dev/null;
echo "${tx}";
}
m.srgbtotx() {
local pin="$1";
#if [[ ! -e "${1}" ]]; then
# echo "file not found:[${pin}]";
# exit 1;
#fi
local ext="${pin##*.}";
local fn="${pin%.${ext}}";
local outf="${fn}.tx";
maketx -v -u --unpremult --oiio --format tiff --colorconvert "sRGB" "linear" -o "${outf}" "$1" ; # >/dev/null;
echo "${outf}";
}
m.8bit2tx(){
local pin="$1";
if [[ ! -e "${1}" ]]; then
echo "file not found:[${pin}]";
exit 1;
fi
pin=$(realpath "${pin}");
# any sRGB -> 8bit linear png
local lin=$(m.side "${pin}" 'png' '_linear' );
local tx=$(m.side "${pin}" 'tx' '' );
#echo "lin:[${lin}]";
#echo "tx: [${tx}";
oiiotool.exe -i "${pin}" --colorconvert sRGB linear -o "${lin}" >/dev/null;
maketx --oiio -d uint8 -u --format tiff -o "${tx}" "${lin}" >/dev/null;
rm -f "${lin}";
echo "${tx}";
}
# 1 2 3
# <path> <depth> <f|d>
m.fd_ftree(){
#echo "f1Root:${1} f2dept:${2} f3mode:${3}";
local t='f';
if [[ "${3}" == 'd' ]]; then
#echo 'dirmode!';
t='d';
fi
local level=1;
m.isnumber "${2}";
if [[ $? -eq 0 ]]; then
if [[ $2 -le 0 ]]; then
level=1;
else
level=$2;
fi
else
if [[ "${2}" = 'c' ]]; then
level=1;
fi
if [[ "${2}" = 'r' ]]; then
level=10000;
fi
fi
#echo "f1Root:${1}-f2dept:${level}-f3type:${t}";
# echo ' '
find "${1}" -maxdepth ${level} -type "${t}" ! -wholename "*/.*";
}
m.dotcount(){
local r=$( m.countchar '.' "${1}" );
echo $r;
}
m.isseq() {
local sext=$(m.seqext "${1}");
if [[ ${#sext} == 0 ]]; then
return 1;
fi
return 0;
}
m.vfxext() {
local n="${1}";
local res="";
m.isseq "${n}";
if [[ $? == 0 ]]; then
res=$(m.seqext "${n}");
else
res=".${n#*.}";
fi
echo "${res}";
}
m.linpath(){
local pin="$1";
local drive_part="";
local path_part="";
local wp="";
if [[ ${pin:1:1} == ":" ]]; then
drive_part="${pin:0:1}";
path_part="${pin:2}";
wp="\\${drive_part}${path_part}";
else
wp=${pin};
fi
local linp=$(btofslash "${wp}");
echo "${linp}";
}
m.winpath(){
local drive_part="";
local path_part="";
local pin="$1";
local pin="$1";
if [[ ${pin:1:3} == ":\\\\" ]]; then
local wp=$(m.rem_backslash "$pin");
echo "${wp}";
return 0;
fi
if [[ ! ${pin:1:1} == ":" ]]; then
if [[ ${pin:2:1} == "/" ]]; then
drive_part="${pin:1:1}:";
path_part="${pin:2}";
else
if [[ ${pin:0:2} == "\\\\" ]]; then
drive_part="";
path_part="$pin";
fi
fi
else
drive_part="";
path_part="${pin}";
fi
if [[ -z ${path_part} ]]; then
echo '***ERROR:illegal path ' "${pin}";
return 0;
fi
local raw="${drive_part}${path_part}";
local sles=$(ftobslash "${raw}");
echo "${sles}";
}
export -f m.srgbtotx m.rwspace m.allchannels m.allch_except m.side m.fn_base m.fn_ext m.fn_mext m.namekey m.waituntilany m.singleline m.rndstr m.remws m.waitfornof m.noffiles m.sec2min m.repext;
# -----------------------------------------
# runs when the file gets sourced
#silent mode
export MVRB=0;
# mtool root
mtool=$(m.linpath "${WGPATH}/mtool");
# echo "mtool root: [${mtool}]";
# temp files
#[ ! -e "${mtool}/_tmp" ] && mkdir -p "${mtool}/_tmp";
#export MTRASH="${mtool}/_tmp";
# fusion comp templates
#export MTEMPLATE="${mtool}/template";
# linux path to bat utilities folder
# use m.fgbat() and m.bgbat() to run them
# export MBAT="${mtool}/bat"
# windows path to bat utilities
# use this variable in any .bat file
# to access this collection.
#export BBAT=$(m.winpath "${MBAT}");
export PATH="${mtool}/bin:${mtool}/bat:${PATH}";
if [[ ${JOB##*/} == 'snap' ]]; then
export PATH="${JOB}/bin:${PATH}";
export PATH="${JOB}/bat:${PATH}";
# echo 'snap bin bat is on path';
#else
# echo 'not a snap project';
fi
source snaplog.sh;