Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72d7364

Browse files
committed
- VFile: moved decompression code to VideoParams (so it is also
useable via VinFile). - Vcopy: now allows decompression of 'compress' movies.
1 parent dbf71b7 commit 72d7364

2 files changed

Lines changed: 44 additions & 14 deletions

File tree

Demo/sgi/video/VFile.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def init(self):
202202
self.offset = 0 # colormap index offset (XXX ???)
203203
self.chrompack = 0 # set if separate chrominance data
204204
self.setderived()
205+
self.decompressor = None
205206
return self
206207

207208
# Freeze the parameters (disallow changes)
@@ -333,6 +334,31 @@ def calcframesize(self):
333334
size = (size * self.bpp + 7) / 8
334335
return size
335336

337+
# Decompress a possibly compressed frame. This method is here
338+
# since you sometimes want to use it on a VFile instance and sometimes
339+
# on a Displayer instance.
340+
#
341+
# XXXX This should also handle jpeg. Actually, the whole mechanism
342+
# should be much more of 'ihave/iwant' style, also allowing you to
343+
# read, say, greyscale images from a color movie.
344+
345+
def decompress(self, data):
346+
if self.format <> 'compress':
347+
return data
348+
if not self.decompressor:
349+
import cl, CL
350+
scheme = cl.QueryScheme(self.compressheader)
351+
self.decompressor = cl.OpenDecompressor(scheme)
352+
headersize = self.decompressor.ReadHeader(self.compressheader)
353+
width = self.decompressor.GetParam(CL.IMAGE_WIDTH)
354+
height = self.decompressor.GetParam(CL.IMAGE_HEIGHT)
355+
params = [CL.ORIGINAL_FORMAT, CL.RGBX, \
356+
CL.ORIENTATION, CL.BOTTOM_UP, \
357+
CL.FRAME_BUFFER_SIZE, width*height*CL.BytesPerPixel(CL.RGBX)]
358+
self.decompressor.SetParams(params)
359+
data = self.decompressor.Decompress(1, data)
360+
return data
361+
336362

337363
# Class to display video frames in a window.
338364
# It is the caller's responsibility to ensure that the correct window
@@ -360,7 +386,6 @@ def init(self):
360386
self.color0 = None # magic, used by clearto()
361387
self.fixcolor0 = 0 # don't need to fix color0
362388
self.mustunpack = (not support_packed_pixels())
363-
self.decompressor = None
364389
return self
365390

366391
# setinfo() must reset some internal flags
@@ -390,18 +415,7 @@ def showpartframe(self, data, chromdata, (x,y,w,h)):
390415
data, width, height, bytes = jpeg.decompress(data)
391416
pmsize = bytes*8
392417
elif self.format == 'compress':
393-
if not self.decompressor:
394-
import cl, CL
395-
scheme = cl.QueryScheme(self.compressheader)
396-
self.decompressor = cl.OpenDecompressor(scheme)
397-
headersize = self.decompressor.ReadHeader(self.compressheader)
398-
width = self.decompressor.GetParam(CL.IMAGE_WIDTH)
399-
height = self.decompressor.GetParam(CL.IMAGE_HEIGHT)
400-
params = [CL.ORIGINAL_FORMAT, CL.RGBX, \
401-
CL.ORIENTATION, CL.BOTTOM_UP, \
402-
CL.FRAME_BUFFER_SIZE, width*height*CL.BytesPerPixel(CL.RGBX)]
403-
self.decompressor.SetParams(params)
404-
data = self.decompressor.Decompress(1, data)
418+
data = self.decompress(data)
405419
elif self.format in ('mono', 'grey4'):
406420
if self.mustunpack:
407421
if self.format == 'mono':

Demo/sgi/video/Vcopy.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,25 @@ def process(infilename, outfilename):
173173

174174
scale = 0
175175
flip = 0
176+
decompress = 0
176177

178+
vinfmt = vin.format
179+
if vinfmt == 'compress':
180+
if not newtype or newtype == 'compress':
181+
# compressed->compressed: copy compression header
182+
vout.setcompressheader(vin.getcompressheader())
183+
else:
184+
# compressed->something else: go via rgb-24
185+
decompress = 1
186+
vinfmt = 'rgb'
187+
elif newtype == 'compress':
188+
# something else->compressed: not implemented
189+
sys.stderr.write('Sorry, conversion to compressed not yet implemented\n')
190+
return 1
177191
if newtype:
178192
vout.setformat(newtype)
179193
try:
180-
convert = imgconv.getconverter(vin.format, vout.format)
194+
convert = imgconv.getconverter(vinfmt, vout.format)
181195
except imgconv.error, msg:
182196
sys.stderr.write(str(msg) + '\n')
183197
return 1
@@ -236,6 +250,8 @@ def process(infilename, outfilename):
236250
tin, data, cdata = vin.getnextframe()
237251
except EOFError:
238252
break
253+
if decompress:
254+
data = vin.decompress(data)
239255
nin = nin + 1
240256
if regen:
241257
tout = nin * regen

0 commit comments

Comments
 (0)