mirror of https://github.com/python/cpython
- VFile: moved decompression code to VideoParams (so it is also
useable via VinFile). - Vcopy: now allows decompression of 'compress' movies.
This commit is contained in:
parent
dbf71b7b4b
commit
72d73649ff
|
@ -202,6 +202,7 @@ class VideoParams:
|
||||||
self.offset = 0 # colormap index offset (XXX ???)
|
self.offset = 0 # colormap index offset (XXX ???)
|
||||||
self.chrompack = 0 # set if separate chrominance data
|
self.chrompack = 0 # set if separate chrominance data
|
||||||
self.setderived()
|
self.setderived()
|
||||||
|
self.decompressor = None
|
||||||
return self
|
return self
|
||||||
|
|
||||||
# Freeze the parameters (disallow changes)
|
# Freeze the parameters (disallow changes)
|
||||||
|
@ -333,6 +334,31 @@ class VideoParams:
|
||||||
size = (size * self.bpp + 7) / 8
|
size = (size * self.bpp + 7) / 8
|
||||||
return size
|
return size
|
||||||
|
|
||||||
|
# Decompress a possibly compressed frame. This method is here
|
||||||
|
# since you sometimes want to use it on a VFile instance and sometimes
|
||||||
|
# on a Displayer instance.
|
||||||
|
#
|
||||||
|
# XXXX This should also handle jpeg. Actually, the whole mechanism
|
||||||
|
# should be much more of 'ihave/iwant' style, also allowing you to
|
||||||
|
# read, say, greyscale images from a color movie.
|
||||||
|
|
||||||
|
def decompress(self, data):
|
||||||
|
if self.format <> 'compress':
|
||||||
|
return data
|
||||||
|
if not self.decompressor:
|
||||||
|
import cl, 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
|
||||||
|
|
||||||
|
|
||||||
# Class to display video frames in a window.
|
# Class to display video frames in a window.
|
||||||
# It is the caller's responsibility to ensure that the correct window
|
# It is the caller's responsibility to ensure that the correct window
|
||||||
|
@ -360,7 +386,6 @@ class Displayer(VideoParams):
|
||||||
self.color0 = None # magic, used by clearto()
|
self.color0 = None # magic, used by clearto()
|
||||||
self.fixcolor0 = 0 # don't need to fix color0
|
self.fixcolor0 = 0 # don't need to fix color0
|
||||||
self.mustunpack = (not support_packed_pixels())
|
self.mustunpack = (not support_packed_pixels())
|
||||||
self.decompressor = None
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
# setinfo() must reset some internal flags
|
# setinfo() must reset some internal flags
|
||||||
|
@ -390,18 +415,7 @@ class Displayer(VideoParams):
|
||||||
data, width, height, bytes = jpeg.decompress(data)
|
data, width, height, bytes = jpeg.decompress(data)
|
||||||
pmsize = bytes*8
|
pmsize = bytes*8
|
||||||
elif self.format == 'compress':
|
elif self.format == 'compress':
|
||||||
if not self.decompressor:
|
data = self.decompress(data)
|
||||||
import cl, 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)
|
|
||||||
elif self.format in ('mono', 'grey4'):
|
elif self.format in ('mono', 'grey4'):
|
||||||
if self.mustunpack:
|
if self.mustunpack:
|
||||||
if self.format == 'mono':
|
if self.format == 'mono':
|
||||||
|
|
|
@ -173,11 +173,25 @@ def process(infilename, outfilename):
|
||||||
|
|
||||||
scale = 0
|
scale = 0
|
||||||
flip = 0
|
flip = 0
|
||||||
|
decompress = 0
|
||||||
|
|
||||||
|
vinfmt = vin.format
|
||||||
|
if vinfmt == 'compress':
|
||||||
|
if not newtype or newtype == 'compress':
|
||||||
|
# compressed->compressed: copy compression header
|
||||||
|
vout.setcompressheader(vin.getcompressheader())
|
||||||
|
else:
|
||||||
|
# compressed->something else: go via rgb-24
|
||||||
|
decompress = 1
|
||||||
|
vinfmt = 'rgb'
|
||||||
|
elif newtype == 'compress':
|
||||||
|
# something else->compressed: not implemented
|
||||||
|
sys.stderr.write('Sorry, conversion to compressed not yet implemented\n')
|
||||||
|
return 1
|
||||||
if newtype:
|
if newtype:
|
||||||
vout.setformat(newtype)
|
vout.setformat(newtype)
|
||||||
try:
|
try:
|
||||||
convert = imgconv.getconverter(vin.format, vout.format)
|
convert = imgconv.getconverter(vinfmt, vout.format)
|
||||||
except imgconv.error, msg:
|
except imgconv.error, msg:
|
||||||
sys.stderr.write(str(msg) + '\n')
|
sys.stderr.write(str(msg) + '\n')
|
||||||
return 1
|
return 1
|
||||||
|
@ -236,6 +250,8 @@ def process(infilename, outfilename):
|
||||||
tin, data, cdata = vin.getnextframe()
|
tin, data, cdata = vin.getnextframe()
|
||||||
except EOFError:
|
except EOFError:
|
||||||
break
|
break
|
||||||
|
if decompress:
|
||||||
|
data = vin.decompress(data)
|
||||||
nin = nin + 1
|
nin = nin + 1
|
||||||
if regen:
|
if regen:
|
||||||
tout = nin * regen
|
tout = nin * regen
|
||||||
|
|
Loading…
Reference in New Issue