about summary refs log tree commit diff
path: root/test/rgb3-roundtrip.test
blob: 5edb1f19e617a94397f9a05bd0e0b5074d77980d (plain) (blame)
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
43
44
45
46
47
48
49
50
51
52
53
54
#! /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
echo "Test 1.  Should print 1926073387 101484"
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

# Simple cat of three planes
echo "Test 2.  Should print 3744829044 101514"
cat ${testimg_red} ${testimg_grn} ${testimg_blu} | cksum

rm ${testimg_ppm} ${testimg_red} ${testimg_grn} ${testimg_blu}

# Test 3.  PBM (monochrome) input
echo "Test 3.  Should print 281226646 481 twice"
maze_pbm=${tmpdir}/maze.pbm
maze_red=${tmpdir}/maze.red
maze_grn=${tmpdir}/maze.grn
maze_blu=${tmpdir}/maze.blu

cp maze.pbm ${tmpdir} &&
ppmtorgb3 ${maze_pbm} &&
rgb3toppm ${maze_red} ${maze_grn} ${maze_blu} | \
  ppmtopgm | pgmtopbm -th -val=0.5 | cksum
pgmtopbm -th -val=0.5 ${maze_red} | cksum

# Test 4.
# With PGM or PBM input, the three monochrome planes should be
# identical.  Test for this.

echo "Test 4.  Should print 0 twice"
cmp -s ${maze_red} ${maze_grn} ; echo $?
cmp -s ${maze_grn} ${maze_blu} ; echo $?

echo "Test 5.  Should print 0 0 : 0"
pgmtopgm < maze.pbm | cmp -s - ${maze_red}
  echo ${PIPESTATUS[@]} ":" $?

rm ${maze_pbm} ${maze_red} ${maze_grn} ${maze_blu}