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.
8 from warnings
import warnpy3k
9 warnpy3k("the torgb module has been removed in Python 3.0", stacklevel
=2)
20 t
.append('fromppm $IN $OUT', 'ff')
24 t
.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
25 t
.append('fromppm $IN $OUT', 'ff')
31 t
.append('fromgif $IN $OUT', 'ff')
35 t
.append('tifftopnm', '--')
36 t
.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
37 t
.append('fromppm $IN $OUT', 'ff')
41 t
.append('rasttopnm', '--')
42 t
.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
43 t
.append('fromppm $IN $OUT', 'ff')
47 t
.append('djpeg', '--')
48 t
.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
49 t
.append('fromppm $IN $OUT', 'ff')
52 uncompress
= pipes
.Template()
53 uncompress
.append('uncompress', '--')
56 class error(Exception):
63 ret
= _torgb(filename
, temps
)
74 def _torgb(filename
, temps
):
75 if filename
[-2:] == '.Z':
76 (fd
, fname
) = tempfile
.mkstemp()
79 sts
= uncompress
.copy(filename
, fname
)
81 raise error
, filename
+ ': uncompress failed'
85 ftype
= imghdr
.what(fname
)
87 if type(msg
) == type(()) and len(msg
) == 2 and \
88 type(msg
[0]) == type(0) and type(msg
[1]) == type(''):
90 if type(msg
) is not type(''):
92 raise error
, filename
+ ': ' + msg
95 if ftype
is None or not table
.has_key(ftype
):
96 raise error
, '%s: unsupported image file type %r' % (filename
, ftype
)
97 (fd
, temp
) = tempfile
.mkstemp()
99 sts
= table
[ftype
].copy(fname
, temp
)
101 raise error
, filename
+ ': conversion to rgb failed'