d478c77f749ef7cb6dac4942eede37e002d08502
[experiments/gstreamer.git] / shell / gst-test-jpegdec.sh
1 #!/bin/bash
2 #
3 # Test to check that jpegdec handles different chroma sub-samplings right.
4
5 set -e
6
7 command -v djpeg &> /dev/null || { echo "djpeg needed, should be in libjpeg-turbo-progs." 1>&2; exit 1; }
8 command -v cjpeg &> /dev/null || { echo "cjpeg needed, should be in libjpeg-turbo-progs." 1>&2; exit 1; }
9
10 if [ "x$1" = "x" ];
11 then
12   WIDTH=996
13   HEIGHT=784
14   gst-launch-1.0 videotestsrc num-buffers=1 ! "video/x-raw,width=${WIDTH},height=${HEIGHT}" ! jpegenc ! filesink location=videotest.jpg
15   INPUT_FILE="videotest.jpg"
16 else
17   INPUT_FILE="$1"
18 fi
19
20 declare -A SAMPLINGS
21 SAMPLINGS["NORMAL_420"]="2x2,1x1,1x1"
22 SAMPLINGS["NORMAL_422"]="2x1,1x1,1x1"
23 SAMPLINGS["NORMAL_444"]="1x1,1x1,1x1"
24 SAMPLINGS["WEIRD_422"]="2x2,1x2,1x2"
25 SAMPLINGS["WEIRDER_422"]="2x2,2x1,2x1"
26
27 for sampling in "${!SAMPLINGS[@]}";
28 do
29   BASE_NAME="${INPUT_FILE##/*}"
30   RESAMPLED_BASE_NAME="${BASE_NAME%.*}_${sampling}"
31
32   RESAMPLED_FILE="${RESAMPLED_BASE_NAME}.jpg"
33   djpeg "$INPUT_FILE" | cjpeg -sample "${SAMPLINGS[$sampling]}" > "$RESAMPLED_FILE"
34
35   DECODED_RESAMPLED_FILE="decoded_${RESAMPLED_BASE_NAME}_jpegdec.png"
36   gst-launch-1.0 filesrc location="$RESAMPLED_FILE" ! jpegparse ! jpegdec     ! videoconvert ! pngenc ! filesink location="$DECODED_RESAMPLED_FILE" || :
37
38   DECODED_RESAMPLED_FILE="decoded_${RESAMPLED_BASE_NAME}_avdec_mjpeg.png"
39   gst-launch-1.0 filesrc location="$RESAMPLED_FILE" ! jpegparse ! avdec_mjpeg ! videoconvert ! pngenc ! filesink location="$DECODED_RESAMPLED_FILE" || :
40
41   DECODED_RESAMPLED_FILE="decoded_${RESAMPLED_BASE_NAME}_djpeg.bmp"
42   djpeg -bmp "$RESAMPLED_FILE" > "$DECODED_RESAMPLED_FILE"
43 done
44