<s> import argparse <EOL> import sys <EOL> import os <EOL> import numpy as np <EOL> from PIL import Image <EOL> import urllib , urllib2 <EOL> import cStringIO <EOL> import collections <EOL> import zlib <EOL> """<STR_LIT>""" <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , type = int ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , type = int ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , type = int ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , type = int , default = <NUM_LIT> ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , default = '<STR_LIT:R>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , type = int , default = <NUM_LIT> ) <EOL> result = parser . parse_args ( ) <EOL> ximgsz = result . ximagesize <EOL> yimgsz = result . yimagesize <EOL> tilesz = result . tilesize <EOL> zoomlevels = result . zoomlevels <EOL> slices = result . slices <EOL> if not os . path . exists ( os . path . abspath ( result . outputpath ) ) : <EOL> try : <EOL> os . mkdir ( os . path . abspath ( result . outputpath ) ) <EOL> except : <EOL> print "<STR_LIT>" <EOL> elif not os . path . isdir ( os . path . abspath ( result . outputpath ) ) : <EOL> print "<STR_LIT>" <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> for l in range ( zoomlevels ) : <EOL> if not os . path . exists ( os . path . abspath ( '<STR_LIT>' % ( result . outputpath , l ) ) ) : <EOL> try : <EOL> os . mkdir ( os . path . abspath ( '<STR_LIT>' % ( result . outputpath , l ) ) ) <EOL> except : <EOL> print "<STR_LIT>" <EOL> for sl in range ( slices ) : <EOL> for l in range ( zoomlevels ) : <EOL> if not os . path . exists ( os . path . abspath ( '<STR_LIT>' % ( result . outputpath , l , sl ) ) ) : <EOL> try : <EOL> os . mkdir ( os . path . abspath ( '<STR_LIT>' % ( result . outputpath , l , sl ) ) ) <EOL> except : <EOL> print "<STR_LIT>" <EOL> filenm = result . inputpath + '<STR_LIT:/>' + '<STR_LIT>' . format ( sl ) + '<STR_LIT>' <EOL> print "<STR_LIT>" + filenm <EOL> xtiles = ( ximgsz - <NUM_LIT:1> ) / ( tilesz * ( <NUM_LIT:2> ** l ) ) + <NUM_LIT:1> <EOL> ytiles = ( yimgsz - <NUM_LIT:1> ) / ( tilesz * ( <NUM_LIT:2> ** l ) ) + <NUM_LIT:1> <EOL> xdim = xtiles * tilesz * ( <NUM_LIT:2> ** l ) <EOL> ydim = ytiles * tilesz * ( <NUM_LIT:2> ** l ) <EOL> tiledata = np . zeros ( [ ydim , xdim ] , dtype = np . uint32 ) <EOL> imgdata = np . uint32 ( np . fromfile ( filenm , dtype = np . uint8 ) . reshape ( [ yimgsz , ximgsz ] ) ) <EOL> if result . color == '<STR_LIT:R>' : <EOL> tiledata [ <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:0> ] , <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:1> ] ] = imgdata + <NUM_LIT> <EOL> elif result . color == '<STR_LIT>' : <EOL> tiledata [ <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:0> ] , <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:1> ] ] = np . left_shift ( imgdata , <NUM_LIT:8> ) + <NUM_LIT> <EOL> elif result . color == '<STR_LIT:B>' : <EOL> tiledata [ <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:0> ] , <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:1> ] ] = np . left_shift ( imgdata , <NUM_LIT:16> ) + <NUM_LIT> <EOL> elif result . color == '<STR_LIT:C>' : <EOL> tiledata [ <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:0> ] , <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:1> ] ] = np . left_shift ( imgdata , <NUM_LIT:16> ) + np . left_shift ( imgdata , <NUM_LIT:8> ) + <NUM_LIT> <EOL> elif result . color == '<STR_LIT:M>' : <EOL> tiledata [ <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:0> ] , <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:1> ] ] = imgdata + np . left_shift ( imgdata , <NUM_LIT:16> ) + <NUM_LIT> <EOL> elif result . color == '<STR_LIT:Y>' : <EOL> tiledata [ <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:0> ] , <NUM_LIT:0> : imgdata . shape [ <NUM_LIT:1> ] ] = imgdata + np . left_shift ( imgdata , <NUM_LIT:8> ) + <NUM_LIT> <EOL> else : <EOL> print "<STR_LIT>" <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> for y in range ( ytiles ) : <EOL> for x in range ( xtiles ) : <EOL> outimg = Image . frombuffer ( '<STR_LIT>' , ( tilesz * ( <NUM_LIT:2> ** l ) , tilesz * ( <NUM_LIT:2> ** l ) ) , tiledata [ y * tilesz * ( <NUM_LIT:2> ** l ) : ( y + <NUM_LIT:1> ) * tilesz * ( <NUM_LIT:2> ** l ) , x * tilesz * ( <NUM_LIT:2> ** l ) : ( x + <NUM_LIT:1> ) * tilesz * ( <NUM_LIT:2> ** l ) ] . flatten ( ) , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> outimg = outimg . resize ( [ tilesz , tilesz ] ) <EOL> outimg . save ( os . path . abspath ( '<STR_LIT>' % ( result . outputpath , l , sl , y , x ) ) ) <EOL> print '<STR_LIT>' % ( result . outputpath , l , sl , y , x ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
