1 # Convert "arbitrary" image files to rgb files (SGI's image format).
2 # Input may be compressed.
3 # The uncompressed file type may be PBM, PGM, PPM, GIF, TIFF, or Sun raster.
4 # An exception is raised if the file is not of a recognized type.
5 # Returned filename is either the input filename or a temporary filename;
6 # in the latter case the caller must ensure that it is removed.
7 # Other temporary files used are removed by the function.
17 t
.append('fromppm $IN $OUT', 'ff')
21 t
.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
22 t
.append('fromppm $IN $OUT', 'ff')
28 t
.append('fromgif $IN $OUT', 'ff')
32 t
.append('tifftopnm', '--')
33 t
.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
34 t
.append('fromppm $IN $OUT', 'ff')
38 t
.append('rasttopnm', '--')
39 t
.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
40 t
.append('fromppm $IN $OUT', 'ff')
44 t
.append('djpeg', '--')
45 t
.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
46 t
.append('fromppm $IN $OUT', 'ff')
49 uncompress
= pipes
.Template()
50 uncompress
.append('uncompress', '--')
53 class error(Exception):
60 ret
= _torgb(filename
, temps
)
71 def _torgb(filename
, temps
):
72 if filename
[-2:] == '.Z':
73 fname
= tempfile
.mktemp()
75 sts
= uncompress
.copy(filename
, fname
)
77 raise error
, filename
+ ': uncompress failed'
81 ftype
= imghdr
.what(fname
)
83 if type(msg
) == type(()) and len(msg
) == 2 and \
84 type(msg
[0]) == type(0) and type(msg
[1]) == type(''):
86 if type(msg
) is not type(''):
88 raise error
, filename
+ ': ' + msg
91 if ftype
is None or not table
.has_key(ftype
):
93 filename
+ ': unsupported image file type ' + `ftype`
94 temp
= tempfile
.mktemp()
95 sts
= table
[ftype
].copy(fname
, temp
)
97 raise error
, filename
+ ': conversion to rgb failed'