summaryrefslogtreecommitdiff
path: root/scripts/bin2png.sh
blob: d231d192e772359e41fd07c1004b3e8aca585a86 (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
41
42
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: 2016-2017 Renesas Electronics Corporation

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