summaryrefslogtreecommitdiff
path: root/scripts/bin2png.sh
blob: 6422ee51bc33818083e6521b3c778e51f55a0d50 (plain)
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
#!/bin/sh

FILE=${1:-.}

convert_image() {
	local file=$1
	local pnm=${file%bin}pnm
	local png=${file%bin}png

	local format=$(echo $file | sed -e 's|.*-\([[:alnum:]]*\)-\([0-9]*x[0-9]*\).*.bin|\1|' | tr '[:lower:]' '[:upper:]')
	local size=$(echo $file   | sed -e 's|.*-\([[:alnum:]]*\)-\([0-9]*x[0-9]*\).*.bin|\2|')

	case $format in
	YUV*|YVU*)
		format=$(echo $format | tr 'M' 'P')
		;;
	NV*)
		format=$(echo $format | tr -d 'M')
		;;
	*RGB*)
		format=$(echo $format | tr -d 'AX')
		;;
	esac

	raw2rgbpnm -f $format -s $size $file $pnm && \
		convert $pnm $png
	rm $pnm
}

if [ -d $FILE ] ; then
	if [ $(ls $FILE/vsp-unit-test-00*-*frame*.bin 2>/dev/null | wc -l) != 0 ] ; then
		for f in $FILE/vsp-unit-test-00*-*frame*.bin ; do
			convert_image $f
		done
	fi
elif [ -f $FILE ] ; then
	convert_image $FILE
else
	echo "Usage: $0 <file or directory>"
fi