<s> from warnings import warnpy3k <EOL> warnpy3k ( "<STR_LIT>" , stacklevel = <NUM_LIT:2> ) <EOL> del warnpy3k <EOL> class error ( Exception ) : <EOL> pass <EOL> options = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> comp = None <EOL> decomp = None <EOL> def compress ( imgdata , width , height , bytesperpixel ) : <EOL> global comp <EOL> import cl <EOL> if comp is None : comp = cl . OpenCompressor ( cl . JPEG ) <EOL> if bytesperpixel == <NUM_LIT:1> : <EOL> format = cl . GRAYSCALE <EOL> elif bytesperpixel == <NUM_LIT:4> : <EOL> format = cl . RGBX <EOL> if options [ '<STR_LIT>' ] : <EOL> iformat = cl . GRAYSCALE <EOL> else : <EOL> iformat = cl . YUV <EOL> params = [ cl . IMAGE_WIDTH , width , cl . IMAGE_HEIGHT , height , cl . ORIGINAL_FORMAT , format , cl . ORIENTATION , cl . BOTTOM_UP , cl . QUALITY_FACTOR , options [ '<STR_LIT>' ] , cl . INTERNAL_FORMAT , iformat , ] <EOL> comp . SetParams ( params ) <EOL> jpegdata = comp . Compress ( <NUM_LIT:1> , imgdata ) <EOL> return jpegdata <EOL> def decompress ( jpegdata ) : <EOL> global decomp <EOL> import cl <EOL> if decomp is None : decomp = cl . OpenDecompressor ( cl . JPEG ) <EOL> headersize = decomp . ReadHeader ( jpegdata ) <EOL> params = [ cl . IMAGE_WIDTH , <NUM_LIT:0> , cl . IMAGE_HEIGHT , <NUM_LIT:0> , cl . INTERNAL_FORMAT , <NUM_LIT:0> ] <EOL> decomp . GetParams ( params ) <EOL> width , height , format = params [ <NUM_LIT:1> ] , params [ <NUM_LIT:3> ] , params [ <NUM_LIT:5> ] <EOL> if format == cl . GRAYSCALE or options [ '<STR_LIT>' ] : <EOL> format = cl . GRAYSCALE <EOL> bytesperpixel = <NUM_LIT:1> <EOL> else : <EOL> format = cl . RGBX <EOL> bytesperpixel = <NUM_LIT:4> <EOL> params = [ cl . ORIGINAL_FORMAT , format , cl . ORIENTATION , cl . BOTTOM_UP , cl . FRAME_BUFFER_SIZE , width * height * bytesperpixel ] <EOL> decomp . SetParams ( params ) <EOL> imgdata = decomp . Decompress ( <NUM_LIT:1> , jpegdata ) <EOL> return imgdata , width , height , bytesperpixel <EOL> def setoption ( name , value ) : <EOL> if type ( value ) is not type ( <NUM_LIT:0> ) : <EOL> raise TypeError , '<STR_LIT>' <EOL> if name == '<STR_LIT>' : <EOL> name = '<STR_LIT>' <EOL> if not options . has_key ( name ) : <EOL> raise KeyError , '<STR_LIT>' <EOL> options [ name ] = int ( value ) <EOL> def test ( ) : <EOL> import sys <EOL> if sys . argv [ <NUM_LIT:1> : <NUM_LIT:2> ] == [ '<STR_LIT>' ] : <EOL> del sys . argv [ <NUM_LIT:1> ] <EOL> setoption ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> if not sys . argv [ <NUM_LIT:1> : ] : <EOL> sys . argv . append ( '<STR_LIT>' ) <EOL> for file in sys . argv [ <NUM_LIT:1> : ] : <EOL> show ( file ) <EOL> def show ( file ) : <EOL> import gl , GL , DEVICE <EOL> jpegdata = open ( file , '<STR_LIT:r>' ) . read ( ) <EOL> imgdata , width , height , bytesperpixel = decompress ( jpegdata ) <EOL> gl . foreground ( ) <EOL> gl . prefsize ( width , height ) <EOL> win = gl . winopen ( file ) <EOL> if bytesperpixel == <NUM_LIT:1> : <EOL> gl . cmode ( ) <EOL> gl . pixmode ( GL . PM_SIZE , <NUM_LIT:8> ) <EOL> gl . gconfig ( ) <EOL> for i in range ( <NUM_LIT> ) : <EOL> gl . mapcolor ( i , i , i , i ) <EOL> else : <EOL> gl . RGBmode ( ) <EOL> gl . pixmode ( GL . PM_SIZE , <NUM_LIT:32> ) <EOL> gl . gconfig ( ) <EOL> gl . qdevice ( DEVICE . REDRAW ) <EOL> gl . qdevice ( DEVICE . ESCKEY ) <EOL> gl . qdevice ( DEVICE . WINQUIT ) <EOL> gl . qdevice ( DEVICE . WINSHUT ) <EOL> gl . lrectwrite ( <NUM_LIT:0> , <NUM_LIT:0> , width - <NUM_LIT:1> , height - <NUM_LIT:1> , imgdata ) <EOL> while <NUM_LIT:1> : <EOL> dev , val = gl . qread ( ) <EOL> if dev in ( DEVICE . ESCKEY , DEVICE . WINSHUT , DEVICE . WINQUIT ) : <EOL> break <EOL> if dev == DEVICE . REDRAW : <EOL> gl . lrectwrite ( <NUM_LIT:0> , <NUM_LIT:0> , width - <NUM_LIT:1> , height - <NUM_LIT:1> , imgdata ) <EOL> gl . winclose ( win ) <EOL> newjpegdata = compress ( imgdata , width , height , bytesperpixel ) <EOL> open ( '<STR_LIT>' , '<STR_LIT:w>' ) . write ( newjpegdata ) </s>
