Add gst-test-jpegdec.sh
authorAntonio Ospite <ao2@ao2.it>
Thu, 28 Dec 2017 10:57:17 +0000 (11:57 +0100)
committerAntonio Ospite <ao2@ao2.it>
Thu, 28 Dec 2017 10:57:17 +0000 (11:57 +0100)
shell/gst-test-jpegdec.sh [new file with mode: 0755]

diff --git a/shell/gst-test-jpegdec.sh b/shell/gst-test-jpegdec.sh
new file mode 100755 (executable)
index 0000000..997a629
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/bash
+#
+# Test to check that jpegdec handles different chroma sub-samplings right.
+
+set -e
+
+command -v djpeg &> /dev/null || { echo "djpeg needed, should be in libjpeg-turbo-progs." 1>&2; exit 1; }
+command -v cjpeg &> /dev/null || { echo "cjpeg needed, should be in libjpeg-turbo-progs." 1>&2; exit 1; }
+
+if [ "x$1" = "x" ];
+then
+  gst-launch-1.0 videotestsrc num-buffers=1 ! video/x-raw,width=996,height=784 ! jpegenc ! filesink location=videotest.jpg
+  INPUT_FILE="videotest.jpg"
+else
+  INPUT_FILE="$1"
+fi
+
+declare -A SAMPLINGS
+SAMPLINGS["NORMAL_420"]="2x2,1x1,1x1"
+SAMPLINGS["NORMAL_422"]="2x1,1x1,1x1"
+SAMPLINGS["NORMAL_444"]="1x1,1x1,1x1"
+SAMPLINGS["WEIRD_422"]="2x2,1x2,1x2"
+SAMPLINGS["WEIRDER_422"]="2x2,2x1,2x1"
+
+for sampling in "${!SAMPLINGS[@]}";
+do
+  BASE_NAME="${INPUT_FILE##/*}"
+  RESAMPLED_BASE_NAME="${BASE_NAME%.*}_${sampling}"
+
+  RESAMPLED_FILE="${RESAMPLED_BASE_NAME}.jpg"
+  djpeg "$INPUT_FILE" | cjpeg -sample "${SAMPLINGS[$sampling]}" > "$RESAMPLED_FILE"
+
+  DECODED_RESAMPLED_FILE="decoded_${RESAMPLED_BASE_NAME}_jpegdec.png"
+  gst-launch-1.0 filesrc location="$RESAMPLED_FILE" ! jpegparse ! jpegdec     ! videoconvert ! pngenc ! filesink location="$DECODED_RESAMPLED_FILE" || :
+
+  DECODED_RESAMPLED_FILE="decoded_${RESAMPLED_BASE_NAME}_avdec_mjpeg.png"
+  gst-launch-1.0 filesrc location="$RESAMPLED_FILE" ! jpegparse ! avdec_mjpeg ! videoconvert ! pngenc ! filesink location="$DECODED_RESAMPLED_FILE" || :
+
+  DECODED_RESAMPLED_FILE="decoded_${RESAMPLED_BASE_NAME}_djpeg.bmp"
+  djpeg -bmp "$RESAMPLED_FILE" > "$DECODED_RESAMPLED_FILE"
+done
+