about summary refs log tree commit diff
path: root/test/pamslice-roundtrip.test
blob: f17765d1d0d0de0992d02d3b58d53d90c57d840c (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /bin/bash
# This script tests: pamslice pamdeinterlace
# Also requires: pamcut pnmtopnm pamflip

  alias pamslice="${PBM_TESTPREFIX}pamslice"
  alias pamdeinterlace="${PBM_TESTPREFIX}pamdeinterlace"
  alias pamcut="${PBM_BINPREFIX}pamcut"
  alias pnmtopnm="${PBM_BINPREFIX}pnmtopnm"
  alias pamflip="${PBM_BINPREFIX}pamflip"
  shopt -s expand_aliases

# Test 1.
# Slice rows, one by one, out of testgrid.pbm.
# Add header and reconstruct pbm image.
# Note that in pamslice output 0 is white and 1 is black: opposite of PBM
# Should print 2425386270 41

(echo "P1"
 echo "14 16"
 seq 0 15 | while read i;
     do
     pamslice -row=$i testgrid.pbm  | \
      awk '{print $2}' | sed 'y/01/10/';
     done ) |  pnmtopnm | cksum

# Test 2.
# Slice rows, one by one, out of ppm test image
# We take a part out of testimg.ppm with pamcut for processing the
# whole image takes much time.
# Add header and reconstruct ppm image.
# Should print 914327477 4864

tmpdir=${tmpdir:-/tmp}

test4933_ppm=${tmpdir}/test4933.ppm

pamcut 50 50 49 33 testimg.ppm > ${test4933_ppm}

(echo "P3"
 echo "49 33"
 echo "255"
 seq 0 32 | while read i;
     do
     pamslice -row=$i ${test4933_ppm} | awk '{print $2, $3, $4}';
     done ) | pnmtopnm | cksum

# Same as above test 2, but take cols instead of rows.
# Should print 914327477 4864

(echo "P3"
 echo "33 49"
 echo "255"
 seq 0 48 | while read i;
     do
     pamslice -col=$i ${test4933_ppm} | awk '{print $2, $3, $4}';
     done ) | pamflip -xy | cksum

# Test 4.
# Divide input image into two with pamdeinterlace and recombine.

testeven_ppm=${tmpdir}/testeven.ppm
testodd_ppm=${tmpdir}/testodd.ppm

pamdeinterlace -takeodd ${test4933_ppm} > ${testodd_ppm}
pamdeinterlace -takeeven ${test4933_ppm} > ${testeven_ppm}

(echo "P3"
 echo "49 33"
 echo "255"
 seq 0 15 | while read i;
     do
     pamslice -row=$i ${testeven_ppm} | awk '{print $2, $3, $4}';
     pamslice -row=$i ${testodd_ppm} | awk '{print $2, $3, $4}';
     done
     pamslice -row=16 ${testeven_ppm} | awk '{print $2, $3, $4}';
  ) | pnmtopnm | tee /tmp/z | cksum

rm ${test4933_ppm} ${testodd_ppm} ${testeven_ppm}