コード例 #1
0
	def _read_comm_chunk(self, chunk):
		self._nchannels = _read_short(chunk)
		self._nframes = _read_long(chunk)
		self._sampwidth = (_read_short(chunk) + 7) / 8
		self._framerate = int(_read_float(chunk))
		self._framesize = self._nchannels * self._sampwidth
		if self._aifc:
			#DEBUG: SGI's soundeditor produces a bad size :-(
			kludge = 0
			if chunk.chunksize == 18:
				kludge = 1
				print 'Warning: bad COMM chunk size'
				chunk.chunksize = 23
			#DEBUG end
			self._comptype = chunk.read(4)
			#DEBUG start
			if kludge:
				length = ord(chunk.file.read(1))
				if length & 1 == 0:
					length = length + 1
				chunk.chunksize = chunk.chunksize + length
				chunk.file.seek(-1, 1)
			#DEBUG end
			self._compname = _read_string(chunk)
			if self._comptype != 'NONE':
				if self._comptype == 'G722':
					try:
						import audioop
					except ImportError:
						pass
					else:
						self._convert = self._adpcm2lin
						self._framesize = self._framesize / 4
						return
				# for ULAW and ALAW try Compression Library
				try:
					import cl, CL
				except ImportError:
					if self._comptype == 'ULAW':
						try:
							import audioop
							self._convert = self._ulaw2lin
							self._framesize = self._framesize / 2
							return
						except ImportError:
							pass
					raise Error, 'cannot read compressed AIFF-C files'
				if self._comptype == 'ULAW':
					scheme = CL.G711_ULAW
					self._framesize = self._framesize / 2
				elif self._comptype == 'ALAW':
					scheme = CL.G711_ALAW
					self._framesize = self._framesize / 2
				else:
					raise Error, 'unsupported compression type'
				self._decomp = cl.OpenDecompressor(scheme)
				self._convert = self._decomp_data
		else:
			self._comptype = 'NONE'
			self._compname = 'not compressed'
コード例 #2
0
ファイル: jpeg.py プロジェクト: webiumsk/WOT-0.9.17-CT
def decompress(jpegdata):
    global decomp
    import cl
    if decomp is None:
        decomp = cl.OpenDecompressor(cl.JPEG)
    headersize = decomp.ReadHeader(jpegdata)
    params = [cl.IMAGE_WIDTH,
     0,
     cl.IMAGE_HEIGHT,
     0,
     cl.INTERNAL_FORMAT,
     0]
    decomp.GetParams(params)
    width, height, format = params[1], params[3], params[5]
    if format == cl.GRAYSCALE or options['forcegray']:
        format = cl.GRAYSCALE
        bytesperpixel = 1
    else:
        format = cl.RGBX
        bytesperpixel = 4
    params = [cl.ORIGINAL_FORMAT,
     format,
     cl.ORIENTATION,
     cl.BOTTOM_UP,
     cl.FRAME_BUFFER_SIZE,
     width * height * bytesperpixel]
    decomp.SetParams(params)
    imgdata = decomp.Decompress(1, jpegdata)
    return (imgdata,
     width,
     height,
     bytesperpixel)
コード例 #3
0
ファイル: aifc.py プロジェクト: webiumsk/WOT-0.9.17-CT
    def _read_comm_chunk(self, chunk):
        self._nchannels = _read_short(chunk)
        self._nframes = _read_long(chunk)
        self._sampwidth = (_read_short(chunk) + 7) // 8
        self._framerate = int(_read_float(chunk))
        self._framesize = self._nchannels * self._sampwidth
        if self._aifc:
            kludge = 0
            if chunk.chunksize == 18:
                kludge = 1
                print 'Warning: bad COMM chunk size'
                chunk.chunksize = 23
            self._comptype = chunk.read(4)
            if kludge:
                length = ord(chunk.file.read(1))
                if length & 1 == 0:
                    length = length + 1
                chunk.chunksize = chunk.chunksize + length
                chunk.file.seek(-1, 1)
            self._compname = _read_string(chunk)
            if self._comptype != 'NONE':
                if self._comptype == 'G722':
                    try:
                        import audioop
                    except ImportError:
                        pass
                    else:
                        self._convert = self._adpcm2lin
                        self._sampwidth = 2
                        return

                try:
                    import cl
                except ImportError:
                    if self._comptype in ('ULAW', 'ulaw'):
                        try:
                            import audioop
                            self._convert = self._ulaw2lin
                            self._sampwidth = 2
                            return
                        except ImportError:
                            pass

                    raise Error, 'cannot read compressed AIFF-C files'

                if self._comptype in ('ULAW', 'ulaw'):
                    scheme = cl.G711_ULAW
                elif self._comptype in ('ALAW', 'alaw'):
                    scheme = cl.G711_ALAW
                else:
                    raise Error, 'unsupported compression type'
                self._decomp = cl.OpenDecompressor(scheme)
                self._convert = self._decomp_data
                self._sampwidth = 2
        else:
            self._comptype = 'NONE'
            self._compname = 'not compressed'
コード例 #4
0
 def decompress(self, data):
     if self.format <> 'compress':
         return data
     if not self.decompressor:
         import cl
         scheme = cl.QueryScheme(self.compressheader)
         self.decompressor = cl.OpenDecompressor(scheme)
         headersize = self.decompressor.ReadHeader(self.compressheader)
         width = self.decompressor.GetParam(cl.IMAGE_WIDTH)
         height = self.decompressor.GetParam(cl.IMAGE_HEIGHT)
         params = [cl.ORIGINAL_FORMAT, cl.RGBX, \
            cl.ORIENTATION, cl.BOTTOM_UP, \
            cl.FRAME_BUFFER_SIZE, width*height*cl.BytesPerPixel(cl.RGBX)]
         self.decompressor.SetParams(params)
     data = self.decompressor.Decompress(1, data)
     return data
コード例 #5
0
ファイル: imageview.py プロジェクト: 8Banana/py1.0
def imageview(file):
	import cl, CL, gl, GL, DEVICE

	filep = open(file, 'r')
	header = filep.read(16)
	filep.seek(0)
	scheme = cl.QueryScheme(header)
	decomp = cl.OpenDecompressor(scheme)
	headersize = cl.QueryMaxHeaderSize(scheme)
	header = filep.read(headersize)
	filep.seek(0)
	headersize = decomp.ReadHeader(header)
	width = decomp.GetParam(CL.IMAGE_WIDTH)
	height = decomp.GetParam(CL.IMAGE_HEIGHT)
	params = [CL.ORIGINAL_FORMAT, CL.RGBX, \
		  CL.ORIENTATION, CL.BOTTOM_UP, \
		  CL.FRAME_BUFFER_SIZE, width*height*CL.BytesPerPixel(CL.RGBX)]
	decomp.SetParams(params)

	image = decomp.Decompress(1, filep.read())
	filep.close()
	decomp.CloseDecompressor()

	gl.foreground()
	gl.prefsize(width, height)
	win = gl.winopen(file)
	gl.RGBmode()
	gl.pixmode(GL.PM_SIZE, 32)
	gl.gconfig()
	gl.qdevice(DEVICE.REDRAW)
	gl.qdevice(DEVICE.ESCKEY)
	gl.qdevice(DEVICE.WINQUIT)
	gl.qdevice(DEVICE.WINSHUT)
	gl.lrectwrite(0, 0, width-1, height-1, image)
	while 1:
		dev, val = gl.qread()
		if dev in (DEVICE.ESCKEY, DEVICE.WINSHUT, DEVICE.WINQUIT):
			break
		if dev == DEVICE.REDRAW:
			gl.lrectwrite(0, 0, width-1, height-1, image)
	gl.winclose(win)
コード例 #6
0
ファイル: jpeg.py プロジェクト: mcyril/ravel-ftn
# Implement 'jpeg' interface using SGI's compression library
コード例 #7
0
ファイル: imgjpeg.py プロジェクト: mcyril/ravel-ftn
"""A module that reads JPEG files using the SGI Compression Library.
コード例 #8
0
ファイル: aifc.py プロジェクト: mcyril/ravel-ftn
"""Stuff to parse AIFF-C and AIFF files.
コード例 #9
0
ファイル: VFile.py プロジェクト: mcyril/ravel-ftn
# Classes to read and write CMIF video files.