Created
July 8, 2018 01:47
-
-
Save zellski/d226590aae1d4e47d1d17290c0412b67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
HOME="/Users/zell/TextureWork" | |
(( BASH_VERSINFO[0] >= 4 )) || { | |
echo "This script requires Bash 4.*" | |
exit 1 | |
} | |
INPUT="$1" | |
[[ "${#}" == 3 ]] || { | |
echo "Usage: run_benchmark.sh <input.png> <colorspace> <perceptual|linear>" | |
exit 1 | |
} | |
BASE="`basename "${INPUT}" .png | cut -c1-20`" | |
IM_IDENTIFY="/usr/local/bin/identify" | |
IM_COMPARE="/usr/local/bin/compare" | |
IM_COLORSPACE="$2" | |
"${IM_IDENTIFY}" -list colorspace | grep -iq "^${IM_COLORSPACE}$" || { | |
echo "ERROR: Unknown colorspace '${IM_COLORSPACE}'. Please use one of:" | |
echo "----------------------------------------------------------------" | |
"${IM_IDENTIFY}" -list colorspace | |
exit 1 | |
} | |
case "$3" in | |
'perceptual') | |
PERCEPTUAL="yes" | |
;; | |
'linear') | |
PERCEPTUAL="" | |
;; | |
*) | |
echo "The third argument should be one of perceptual or linear." | |
exit 1 | |
;; | |
esac | |
CSV_RESULT_FILE="bench_${BASE}.csv" | |
printf "%s,%s,%s,%s,%s,%s\n" "Image" "ID" "CPU(s)" "SSIM" "PSNR(dB)" "Size(kB)" > "${CSV_RESULT_FILE}" | |
OUTDIR="${HOME}/bench_out" | |
mkdir -p "${OUTDIR}" | |
CRUNCH="/Users/zell/crunch/repos/zellski/release_build/crunch" | |
CRUNCH_QUALITIES=(superfast fast normal better uber) | |
# this is the best ktx -> png extraction tool I found in 5 minutes of searching... | |
# hilariously it compresses to .pvr as a side effect. | |
PVRTEXTOOLCLI="${HOME}/bin/PVRTexToolCLI" | |
[[ "${PERCEPTUAL}" ]] && \ | |
PTT_QUALITIES=(etcfastperceptual etcslowperceptual) || \ | |
PTT_QUALITIES=(etcfast etcslow) | |
ZSTD="/usr/local/bin/zstd" | |
ZSTD_LEVEL="19" | |
ETC2COMP="${HOME}/etc2comp/release_build/EtcTool/EtcTool" | |
ETC2COMP_EFFORTS=(0 10 20 40 60) | |
function runCrunch() { | |
[[ "${PERCEPTUAL}" ]] && crunchMetricsArg="-mipMode None" || crunchMetricsArg="-uniformMetrics" | |
"${CRUNCH}" \ | |
"${crunchMetricsArg}" \ | |
-mipMode None \ | |
-dxtQuality "${argEffort}" \ | |
-ETC1 \ | |
"${INPUT}" \ | |
-out "${argOutBase}.ktx" | |
} | |
function runEtc2Comp() { | |
[[ "${PERCEPTUAL}" ]] && compMetric="rec709" || compMetric="numeric" | |
"${ETC2COMP}" \ | |
-errormetric "${compMetric}" \ | |
-j 8 \ | |
-format ETC1 \ | |
-effort "${argEffort}" \ | |
"${INPUT}" \ | |
-output "${argOutBase}.ktx" | |
} | |
function runPTT() { | |
"${PVRTEXTOOLCLI}" -i "${INPUT}" -o "${argOutBase}.ktx" -f ETC1 -q "${argEffort}" | |
} | |
function process() { | |
printf "%-60s" "[Compressor=${argCompressor}, Effort=${argEffort}]" | |
argOutBase="${OUTDIR}/${BASE}-etc1.${argCompressor}-${argEffort}" | |
printf "%-12s" "(COMPRESSING)" | |
TIME=`( time -p "run${argCompressor}" 2>&1 >&/tmp/error ) 2>&1` || { | |
echo | |
echo "----------------------------------------------------------------------------------------------------" | |
echo "Error in callback: `cat /tmp/error`" | |
exit 1 | |
} | |
printf "\b\b\b\b\b\b\b\b\b\b\b\b\b" | |
REAL_TIME=`echo "${TIME}" | sed '1q;d' | cut -d' ' -f2` | |
CPU_TIME=`echo "${TIME}" | sed '2q;d' | cut -d' ' -f2` | |
printf "%-12s" "(ZSTD SIZE)" | |
"${ZSTD}" -f -"${ZSTD_LEVEL}" "${argOutBase}.ktx" >/dev/null 2>&1 | |
SIZE=`stat -f"%z" "${argOutBase}.ktx.zst"` | |
SIZE=$(( SIZE / 1024 )) | |
printf "\b\b\b\b\b\b\b\b\b\b\b\b" | |
printf "%-12s" "(TO PNG)" | |
( "${PVRTEXTOOLCLI}" -i "${argOutBase}.ktx" -f R8G8B8 -d "${argOutBase}.png" >/dev/null 2>&1) | |
printf "\b\b\b\b\b\b\b\b\b\b\b\b" | |
printf "%-12s" "(PSNR)" | |
PSNR=`"${IM_COMPARE}" -metric PSNR -colorspace "${IM_COLORSPACE}" "${INPUT}" "${argOutBase}.png" NULL: 2>&1` | |
printf "\b\b\b\b\b\b\b\b\b\b\b\b" | |
printf "%-12s" "(SSIM)" | |
SSIM=`"${IM_COMPARE}" -metric SSIM -colorspace "${IM_COLORSPACE}" "${INPUT}" "${argOutBase}.png" NULL: 2>&1` | |
printf "\b\b\b\b\b\b\b\b\b\b\b\b" | |
printf "CPU(s): %-8.2f SSIM: %-10.6f PSNR(dB): %-8.2f Size(kB): %d\n" "${CPU_TIME}" "${SSIM}" "${PSNR}" "${SIZE}" | |
argId="${argCompressor}_${argEffort}" | |
printf "%s,%s,%.2f,%.6f,%.2f,%d\n" "${BASE}" "${argId}" "${CPU_TIME}" "${SSIM}" "${PSNR}" "${SIZE}" \ | |
>> "${CSV_RESULT_FILE}" | |
} | |
argCompressor="Crunch" | |
for argEffort in "${CRUNCH_QUALITIES[@]}"; do | |
process | |
done | |
argCompressor="PTT" | |
for argEffort in "${PTT_QUALITIES[@]}"; do | |
process | |
done | |
argCompressor="Etc2Comp" | |
for argEffort in "${ETC2COMP_EFFORTS[@]}"; do | |
process | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment