Skip to content
Snippets Groups Projects
Commit 1da263cc authored by nick87720z's avatar nick87720z
Browse files

img-fft-resynth: Bashisms cleanup

parent 136c0f81
Branches
No related tags found
No related merge requests found
#!/bin/bash #!/bin/sh
# TODO: add resize code # TODO: add resize code
shopt -s extglob #shopt -s extglob
is_num() { is_num() {
[ -z "${1##+([0-9])}" ] for n in "$@"; do case ${n#[+-]} in
return $? ''|*[!0-9.]* | '.' | *.*.*) return 1
esac; done
} }
help() { help() {
...@@ -24,8 +25,8 @@ if ! is_num $1 ; then ...@@ -24,8 +25,8 @@ if ! is_num $1 ; then
fi' fi'
rotate_fft() { rotate_fft() {
mv -f "${tmpdir}"/fft-{proc-,}0.miff 2>/dev/null mv -f "${tmpdir}"/fft-proc-0.miff "${tmpdir}"/fft-0.miff 2>/dev/null
mv -f "${tmpdir}"/fft-{proc-,}1.miff 2>/dev/null mv -f "${tmpdir}"/fft-proc-1.miff "${tmpdir}"/fft-1.miff 2>/dev/null
} }
# Command line arguments # Command line arguments
...@@ -116,8 +117,8 @@ IM_FLAGS="-depth $depth -define quantum:format=floating-point -alpha off" ...@@ -116,8 +117,8 @@ IM_FLAGS="-depth $depth -define quantum:format=floating-point -alpha off"
# Analyzing # Analyzing
isize=$( identify "$ifile" | cut -f3 -d' ' ) isize=$( identify "$ifile" | cut -f3 -d' ' )
iw=$( cut -f1 -dx <<< $isize ) iw=$( printf "%s\n" "$isize" | cut -f1 -dx )
ih=$( cut -f2 -dx <<< $isize ) ih=$( printf "%s\n" "$isize" | cut -f2 -dx )
if [ $((ow)) -eq 0 -a $((oh)) -eq 0 ]; then if [ $((ow)) -eq 0 -a $((oh)) -eq 0 ]; then
ow=$iw ow=$iw
...@@ -154,7 +155,8 @@ ifft_size=$( identify ${tmpdir}/fft-0.miff | cut -f3 -d' ' | cut -f1 -dx ) ...@@ -154,7 +155,8 @@ ifft_size=$( identify ${tmpdir}/fft-0.miff | cut -f3 -d' ' | cut -f1 -dx )
# Find transform parameters # Find transform parameters
echo 'Find transform parameters' echo 'Find transform parameters'
rez=( $( bc <<< " { read b_incr; read offt_size; read d; } << EOF
$( printf "%s\n" "
scale=$bc_prec scale=$bc_prec
if ($ow / $oh > $iw / $ih) if ($ow / $oh > $iw / $ih)
sc = $ow / $iw else sc = $oh / $ih sc = $ow / $iw else sc = $oh / $ih
...@@ -166,17 +168,15 @@ rez=( $( bc <<< " ...@@ -166,17 +168,15 @@ rez=( $( bc <<< "
ffts + ffts % 2 /* ret 1 */ ffts + ffts % 2 /* ret 1 */
abs(ffts - $ifft_size) / 2 /* ret 2 */ abs(ffts - $ifft_size) / 2 /* ret 2 */
" ) ) " | bc )
b_incr=${rez[0]} EOF
offt_size=${rez[1]}
d=${rez[2]}
echo 'Done (Find transform parameters)' echo 'Done (Find transform parameters)'
echo isize $isize osize ${ow}x${oh} ifft_size $ifft_size offt_size $offt_size d $d echo isize $isize osize ${ow}x${oh} ifft_size $ifft_size offt_size $offt_size d $d
# Resizing # Resizing
if [ $b_incr == 1 ] if [ $b_incr -eq 1 ]
then then
# Add border for missing FFT frequencies # Add border for missing FFT frequencies
convert ${tmpdir}/fft-0.miff -bordercolor black -border $d ${tmpdir}/fft-proc-0.miff convert ${tmpdir}/fft-0.miff -bordercolor black -border $d ${tmpdir}/fft-proc-0.miff
...@@ -193,10 +193,14 @@ rotate_fft ...@@ -193,10 +193,14 @@ rotate_fft
side=$( identify ${tmpdir}/fft-0.miff | cut -f3 -d' ' | cut -f1 -dx ) side=$( identify ${tmpdir}/fft-0.miff | cut -f3 -d' ' | cut -f1 -dx )
if [ -n "$bands" ] ; then if [ -n "$bands" ] ; then
echo Preparing filter echo Preparing filter
(( r1 = bands, r2 = bands*30/40 ))
(( r = (r1+r2) / 2, blur = (r1-r2) / 2, cent = side / 2 ))
echo center $cent, r1 $r1, r2 $r2, r $r, blur $blur, reg_size ${reg_size} reg_dx ${reg_dx} echo center $cent, r1 $r1, r2 $r2, r $r, blur $blur, reg_size ${reg_size} reg_dx ${reg_dx}
r1=$(( bands ))
r2=$(( bands * 30 / 40 ))
r=$(( (r1+r2) / 2 ))
blur=$(( (r1-r2) / 2 ))
cent=$(( side / 2 ))
time convert -size ${side}x${side} xc:black \ time convert -size ${side}x${side} xc:black \
-fill white -draw "circle ${cent},${cent} $(( cent + r )),${cent}" \ -fill white -draw "circle ${cent},${cent} $(( cent + r )),${cent}" \
-blur $(( blur*1 ))x$(( blur*1 )) \ -blur $(( blur*1 ))x$(( blur*1 )) \
...@@ -204,14 +208,13 @@ if [ -n "$bands" ] ; then ...@@ -204,14 +208,13 @@ if [ -n "$bands" ] ; then
echo Applying filter echo Applying filter
convert ${tmpdir}/fft-0.miff ${tmpdir}/filter.miff -compose multiply -composite ${tmpdir}/fft-proc-0.miff convert ${tmpdir}/fft-0.miff ${tmpdir}/filter.miff -compose multiply -composite ${tmpdir}/fft-proc-0.miff
#rm ${tmpdir}/filter.miff
rotate_fft rotate_fft
fi fi
# IFT # IFT
echo Inverse transform echo Inverse transform
convert ${tmpdir}/fft-{0,1}.miff -ift -crop "$geom" -repage "$geom" ${tmpdir}/dest.miff convert ${tmpdir}/fft-0.miff ${tmpdir}/fft-1.miff -ift -crop "$geom" -repage "$geom" ${tmpdir}/dest.miff
convert ${tmpdir}/dest.miff $ofile convert ${tmpdir}/dest.miff $ofile
#rm -rf ${tmpdir}/* #rm -rf ${tmpdir}/*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment