about summary refs log tree commit diff
path: root/test/ps-roundtrip.test
blob: 1877724d9d58b852dc6820072b63dcde0c2aec84 (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
79
80
81
82
83
84
85
86
87
#! /bin/bash
# This script tests: pnmtops pstopnm
# Also requires: pnmtopnm pamtopnm gs pbmmake pnmshear pnmpad pnmcat

  alias pnmtops="${PBM_TESTPREFIX}pnmtops"
  alias pstopnm="${PBM_TESTPREFIX}pstopnm"
  alias pbmmake="${PBM_BINPREFIX}pbmmake"
  alias pnmcat="${PBM_BINPREFIX}pnmcat"
  alias pnmpad="${PBM_BINPREFIX}pnmpad"
  alias pnmshear="${PBM_BINPREFIX}pnmshear"
  alias pnmtopnm="${PBM_BINPREFIX}pnmtopnm"
  shopt -s expand_aliases

# Failure message
## This test fails when:
## (1) zlib was not linked.
## (2) ghostscript is not available.

# pstopnm does not use libnetpbm functions for output. 
# Output is filtered through pnmtopnm.

# Test 1.  Should print: 1926073387 101484 five times
# *NOTE* Fifth iteration fails if pnmtops was compiled without zlib
# (flate compression) support.
for flag in "" "-ps" "-rle" "-ps -ascii" "-ps -flate"
  do
  pnmtops -nocenter -equalpixels -dpi 72 -noturn \
    ${flag} testimg.ppm \
    > ${tmpdir}/testimg.ps
  xysize1=`awk  '/BoundingBox/ {print "-xsize="$4,"-ysize="$5}' \
    ${tmpdir}/testimg.ps` 
  pstopnm -portrait -xborder=0 -yborder=0 $xysize1 -stdout \
    -quiet ${tmpdir}/testimg.ps | \
    pnmtopnm | cksum
  done


# Test 2.  Should print: 2918318199 62 seven times
# Test image designed to detect problems with run-length compression
#
pbmmake -g 2 2 > ${tmpdir}/g.pbm
pbmmake -g 8 4 | \
  pnmshear 45 -noantialias -background=black | \
  pnmpad -right 60 | \
  pnmcat -tb -jright - ${tmpdir}/g.pbm > ${tmpdir}/t.pbm &&
for flag in "" "-rle" "-ps -rle -ascii" \
            "-bitspersample=2 -rle" "-ps -bitspersample=4 -rle" \
            "-bitspersample=8 -rle" "-ps -bitspersample=12 -rle -dict" 
  do
  pnmtops -nocenter -equalpixels -dpi 72 -noturn \
    ${flag} ${tmpdir}/t.pbm  > ${tmpdir}/testgrid.ps &&
  xysize2=`awk  '/BoundingBox/ {print "-xsize="$4,"-ysize="$5}' \
    ${tmpdir}/testgrid.ps`
  pstopnm -portrait -xborder=0 -yborder=0 $xysize2 -stdout \
    -quiet ${tmpdir}/testgrid.ps -pbm | \
    pnmtopnm | cksum
  done


#Test 3. Should print: 1386192571 507420 three times
# *NOTE* Second iteration fails if pnmtops was compiled without zlib
# (flate compression) support.
#
# Special care is needed when conducting round-trips with multiple-image
# files as input.
# (1) pnmtops: -setpage is mandatory
# (2) awk: xy values are taken from the first "BoundingBox" encountered.
#          Subsequent BoundingBox values are ignored.
# (3) pstopnm: input must be an ordinary file.  Input from stdin
#     (by pipe or input redirection: "< file" ) does not work.              
#
for flag in "" "-ps" \
            "-ps -bitspersample=12 -flate -rle -vmreclaim"
  do
cat testimg.ppm testimg.ppm testimg.ppm testgrid.pbm testgrid.pbm | \
pnmtops -nocenter -equalpixels -dpi 72 -noturn -setpage \
  ${flag}  > ${tmpdir}/testimg5.ps
xysize3=`awk  '/BoundingBox/ {print "-xsize="$4,"-ysize="$5 ; exit}' \
  ${tmpdir}/testimg5.ps`
pstopnm -portrait -xborder=0 -yborder=0 $xysize3 \
    -stdout  ${tmpdir}/testimg5.ps | \
  pnmtopnm | cksum
  done


rm ${tmpdir}/testgrid.ps  ${tmpdir}/testimg.ps  ${tmpdir}/testimg5.ps \
   ${tmpdir}/t.pbm