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

Small refactoring

Fix case when either width or height only is specified.
More consistent names for some variables.
parent 146f2d6a
No related branches found
No related tags found
No related merge requests found
...@@ -36,8 +36,8 @@ tmpdir= ...@@ -36,8 +36,8 @@ tmpdir=
ifile= ifile=
ofile= ofile=
depth=32 depth=32
width= ow=
height= oh=
bands= bands=
if [ -n "$*" ]; then if [ -n "$*" ]; then
while true; do while true; do
...@@ -51,13 +51,13 @@ if [ -n "$*" ]; then ...@@ -51,13 +51,13 @@ if [ -n "$*" ]; then
--width ) --width )
eval "${check_arg_missing}; ${check_arg_num}" eval "${check_arg_missing}; ${check_arg_num}"
if [ $1 -gt 0 ] ; then if [ $1 -gt 0 ] ; then
width=$1 ow=$1
fi;; fi;;
--height ) --height )
eval "${check_arg_missing}; ${check_arg_num}" eval "${check_arg_missing}; ${check_arg_num}"
if [ $1 -gt 0 ] ; then if [ $1 -gt 0 ] ; then
height=$1 oh=$1
fi;; fi;;
--depth ) --depth )
...@@ -99,6 +99,8 @@ else ...@@ -99,6 +99,8 @@ else
exit exit
fi fi
# Pick actual tmpdir
for d in "$tmpdir" "${XDG_RUNTIME_DIR}" "/tmp" "~" ; do for d in "$tmpdir" "${XDG_RUNTIME_DIR}" "/tmp" "~" ; do
d=$( realpath "$d" 2>/dev/null ) || continue d=$( realpath "$d" 2>/dev/null ) || continue
[ -d "$d" ] || continue [ -d "$d" ] || continue
...@@ -106,61 +108,69 @@ for d in "$tmpdir" "${XDG_RUNTIME_DIR}" "/tmp" "~" ; do ...@@ -106,61 +108,69 @@ for d in "$tmpdir" "${XDG_RUNTIME_DIR}" "/tmp" "~" ; do
tmpdir="$( realpath "$d/$self" )" tmpdir="$( realpath "$d/$self" )"
break break
done done
rm -rf "${tmpdir}"/*
IM_FLAGS="-depth $depth -define quantum:format=floating-point -alpha off"
IM_FLAGS="-depth ${depth} -define quantum:format=floating-point -alpha off" # Analyzing
echo New width: $width isize=$( identify "$ifile" | cut -f3 -d' ' )
echo New height: $height iw=$( cut -f1 -dx <<< $isize )
ih=$( cut -f2 -dx <<< $isize )
if [ $((ow)) -eq 0 -a $((oh)) -eq 0 ]; then
ow=$iw
oh=$ih
elif [ $((ow)) -eq 0 ]; then
ow=$(( oh * iw / ih ))
elif [ $((oh)) -eq 0 ]; then
oh=$(( ow * ih / iw ))
fi
geom="${ow}x${oh}+0+0"
echo New width: $ow
echo New height: $oh
echo Bands: $bands echo Bands: $bands
echo Color depth: $depth echo Color depth: $depth
echo Input: $ifile echo Input: $ifile
echo Output: $ofile echo Output: $ofile
echo Tmpdir: $tmpdir echo Tmpdir: $tmpdir
# Analyzing # Prepare source
if [ -n "${width}" ] && [ -n "${height}" ]; then
geom="${width}x${height}+0+0"
else
geom=$( identify "${ifile}" | cut -f4 -d' ' )
fi
# FFT
echo Processing ${ifile} echo Processing ${ifile}
if [ "${ifile%.miff}" != "${ifile}" ] || [ "${ifile%.mif}" != "${ifile}" ] ; then if [ "${ifile%.miff}" != "${ifile}" ] || [ "${ifile%.mif}" != "${ifile}" ] ; then
cp "${ifile}" ${tmpdir}/src.miff cp "${ifile}" ${tmpdir}/src.miff
else else
convert ${ifile} ${IM_FLAGS} ${tmpdir}/src.miff convert ${ifile} ${IM_FLAGS} ${tmpdir}/src.miff
fi fi
convert ${tmpdir}/src.miff -fft +adjoin ${tmpdir}/fft.miff
# Extract source size # FFT
isize=$( identify ${tmpdir}/src.miff | cut -f3 -d' ' )
iw=$( cut -f1 -dx <<< ${isize} ) convert ${tmpdir}/src.miff -fft +adjoin ${tmpdir}/fft.miff
ih=$( cut -f2 -dx <<< ${isize} )
ifft_size=$( identify ${tmpdir}/fft-0.miff | cut -f3 -d' ' | cut -f1 -dx ) ifft_size=$( identify ${tmpdir}/fft-0.miff | cut -f3 -d' ' | cut -f1 -dx )
#rm ${tmpdir}/src.miff
# Find transform parameters # Find transform parameters
echo 'Find transform parameters' echo 'Find transform parameters'
rez=( $( bc <<< " rez=( $( bc <<< "
scale=${bc_prec} scale=$bc_prec
if (${width} / ${height} > ${iw} / ${ih}) if ($ow / $oh > $iw / $ih)
sc = ${width} / ${iw} else sc = ${height} / ${ih} sc = $ow / $iw else sc = $oh / $ih
scale=0
scale=0 (b_incr = (sc > 1)) /* ret 0 */
ffts = max ($ow, $oh)
(b_incr = (sc > 1)) /* ret 0 */ ffts + ffts % 2 /* ret 1 */
ffts = max (${width}, ${height}) abs(ffts - $ifft_size) / 2 /* ret 2 */
ffts + ffts % 2 /* ret 1 */
abs(ffts - ${ifft_size}) / 2 /* ret 2 */
" ) ) " ) )
b_incr=${rez[0]} b_incr=${rez[0]}
offt_size=${rez[1]} offt_size=${rez[1]}
d=${rez[2]} d=${rez[2]}
echo 'Done (Find transform parameters)' echo 'Done (Find transform parameters)'
echo isize $isize osize ${width}x${height} 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
#exit #DEBUG
# Resizing # Resizing
if [ $b_incr == 1 ] if [ $b_incr == 1 ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment