Exemple #1
0
def lin2ulaw(infile, outfile, nchannels):
    comp = cl.OpenCompressor(CL.G711_ULAW)
    if nchannels == 1:
        orig = CL.MONO
    elif nchannels == 2:
        orig = CL.STEREO_INTERLEAVED
    # The important parameters are ORIGINAL_FORMAT and the two
    # sizes.  The FRAME_RATE doesn't matter in U-law, and the
    # BITS_PER_COMPONENT is 16 by default.
    # Notice that the COMPRESSED_BUFFER_SIZE is twice the needed
    # size.
    params = [CL.ORIGINAL_FORMAT, orig, \
       CL.BITS_PER_COMPONENT, 16, \
       CL.FRAME_RATE, 8000, \
       CL.FRAME_BUFFER_SIZE, 8192, \
       CL.COMPRESSED_BUFFER_SIZE, 8192]
    comp.SetParams(params)
    dummy = comp.Compress(0, '')
    while 1:
        audio = infile.read(8192)
        if not audio:
            break
        data = comp.Compress(len(audio) / (nchannels * 2), audio)
        outfile.write(data)
    comp.CloseCompressor()
Exemple #2
0
def compress(imgdata, width, height, bytesperpixel):
    global comp
    import cl
    if comp is None: comp = cl.OpenCompressor(cl.JPEG)
    if bytesperpixel == 1:
        format = cl.GRAYSCALE
    elif bytesperpixel == 4:
        format = cl.RGBX
    if options['forcegray']:
        iformat = cl.GRAYSCALE
    else:
        iformat = cl.YUV
    # XXX How to support 'optimize'?
    params = [
        cl.IMAGE_WIDTH,
        width,
        cl.IMAGE_HEIGHT,
        height,
        cl.ORIGINAL_FORMAT,
        format,
        cl.ORIENTATION,
        cl.BOTTOM_UP,
        cl.QUALITY_FACTOR,
        options['quality'],
        cl.INTERNAL_FORMAT,
        iformat,
    ]
    comp.SetParams(params)
    jpegdata = comp.Compress(1, imgdata)
    return jpegdata
Exemple #3
0
	def _init_compression(self):
		try:
			import cl, CL
		except ImportError:
			if self._comptype == 'ULAW':
				try:
					import audioop
					self._convert = self._lin2ulaw
					return
				except ImportError:
					pass
			raise Error, 'cannot write compressed AIFF-C files'
		if self._comptype == 'ULAW':
			scheme = CL.G711_ULAW
		elif self._comptype == 'ALAW':
			scheme = CL.G711_ALAW
		else:
			raise Error, 'unsupported compression type'
		self._comp = cl.OpenCompressor(scheme)
		params = [CL.ORIGINAL_FORMAT, 0,
			  CL.BITS_PER_COMPONENT, self._sampwidth * 8,
			  CL.FRAME_RATE, self._framerate,
			  CL.FRAME_BUFFER_SIZE, 100,
			  CL.COMPRESSED_BUFFER_SIZE, 100]
		if self._nchannels == 1:
			params[1] = CL.MONO
		elif self._nchannels == 2:
			params[1] = CL.STEREO_INTERLEAVED
		else:
			raise Error, 'cannot compress more than 2 channels'
		self._comp.SetParams(params)
		# the compressor produces a header which we ignore
		dummy = self._comp.Compress(0, '')
		self._convert = self._comp_data
Exemple #4
0
	def init_compressor(self, w, h):
		self.compressor = None
		scheme = cl.QuerySchemeFromName(cl.VIDEO, self.comp_scheme)
		self.compressor = cl.OpenCompressor(scheme)
		parambuf = [cl.IMAGE_WIDTH, w, \
			  cl.IMAGE_HEIGHT, h, \
			  cl.ORIGINAL_FORMAT, cl.YUV422DC]
		self.compressor.SetParams(parambuf)
		return self.compressor.Compress(0, '')
Exemple #5
0
    def _init_compression(self):
        if self._comptype == 'G722':
            self._convert = self._lin2adpcm
            return
        try:
            import cl
        except ImportError:
            if self._comptype in ('ULAW', 'ulaw'):
                try:
                    import audioop
                    self._convert = self._lin2ulaw
                    return
                except ImportError:
                    pass

            raise Error, 'cannot write 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._comp = cl.OpenCompressor(scheme)
        params = [cl.ORIGINAL_FORMAT,
         0,
         cl.BITS_PER_COMPONENT,
         self._sampwidth * 8,
         cl.FRAME_RATE,
         self._framerate,
         cl.FRAME_BUFFER_SIZE,
         100,
         cl.COMPRESSED_BUFFER_SIZE,
         100]
        if self._nchannels == 1:
            params[1] = cl.MONO
        elif self._nchannels == 2:
            params[1] = cl.STEREO_INTERLEAVED
        else:
            raise Error, 'cannot compress more than 2 channels'
        self._comp.SetParams(params)
        dummy = self._comp.Compress(0, '')
        self._convert = self._comp_data
Exemple #6
0
def cjpeg(width, height, depth, image, quality):
	import cl, CL

	if depth == 3:
		orig = CL.RGBX
	elif depth == 1:
		orig = CL.RGB332
	elif depth == 4:
		orig = CL.RGBA
	else:
		raise Error, 'unrecognized depth'
	params = [CL.ORIGINAL_FORMAT, orig, \
		  CL.ORIENTATION, CL.BOTTOM_UP, \
		  CL.IMAGE_WIDTH, width, \
		  CL.IMAGE_HEIGHT, height, \
		  CL.QUALITY_FACTOR, quality]
	comp = cl.OpenCompressor(CL.JPEG)
	comp.SetParams(params)
	data = comp.Compress(1, image)
	comp.CloseCompressor()
	return data
Exemple #7
0
# Implement 'jpeg' interface using SGI's compression library
Exemple #8
0
#! /usr/bin/env python
Exemple #9
0
"""A module that reads JPEG files using the SGI Compression Library.
Exemple #10
0
"""Stuff to parse AIFF-C and AIFF files.