@@ -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' :
0 commit comments