about summary refs log tree commit diff
path: root/test/rgb3-roundtrip.test
diff options
context:
space:
mode:
Diffstat (limited to 'test/rgb3-roundtrip.test')
-rwxr-xr-xtest/rgb3-roundtrip.test46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/rgb3-roundtrip.test b/test/rgb3-roundtrip.test
new file mode 100755
index 00000000..cac52220
--- /dev/null
+++ b/test/rgb3-roundtrip.test
@@ -0,0 +1,46 @@
+#! /bin/bash
+# This script tests: ppmtorgb3 rgb3toppm
+# Also requires: pgmtopbm pgmtopgm ppmtopgm
+
+
+# Break an image into three monochrome planes, reassemble the
+# image from them and check whether the resulting output is
+# identical to the original input.
+
+tmpdir=${tmpdir:-/tmp}
+
+# Test 1.  PPM (color) input
+testimg_ppm=${tmpdir}/testimg.ppm
+testimg_red=${tmpdir}/testimg.red
+testimg_grn=${tmpdir}/testimg.grn
+testimg_blu=${tmpdir}/testimg.blu
+
+cp testimg.ppm ${tmpdir} &&
+ppmtorgb3 ${testimg_ppm} &&
+rgb3toppm ${testimg_red} ${testimg_grn} ${testimg_blu} | cksum
+
+cat ${testimg_red} ${testimg_grn} ${testimg_blu} | cksum
+
+rm ${testimg_ppm} ${testimg_red} ${testimg_grn} ${testimg_blu}
+
+# Test 2.  PBM (monochrome) input
+testgrid_pbm=${tmpdir}/testgrid.pbm
+testgrid_red=${tmpdir}/testgrid.red
+testgrid_grn=${tmpdir}/testgrid.grn
+testgrid_blu=${tmpdir}/testgrid.blu
+
+cp testgrid.pbm ${tmpdir} &&
+ppmtorgb3 ${testgrid_pbm} &&
+rgb3toppm ${testgrid_red} ${testgrid_grn} ${testgrid_blu} | \
+  ppmtopgm | pgmtopbm -th -val=0.5 | cksum
+
+# Test 3.
+# With PGM or PBM input, the three monochrome planes should be
+# identical.  Test for this.
+
+cmp -s ${testgrid_red} ${testgrid_grn} ; echo $?
+cmp -s ${testgrid_grn} ${testgrid_blu} ; echo $?
+pgmtopgm < testgrid.pbm | cmp -s - ${testgrid_red}
+  echo $?
+
+rm ${testgrid_pbm} ${testgrid_red} ${testgrid_grn} ${testgrid_blu}