(self)
Extract contents of ROM to a 2D image
Extract contents of ROM to a 2D image
Extract contents of ROM to a 2D image
def extract(self):
        """Extract contents of ROM to a 2D image"""
        self.open_rom('rb')
        num_tiles = os.path.getsize(self.in1)//self.multiple
        tiles_per_line = 20 if not self.args.width \
            else self.args.width//self.edge
        lines = (num_tiles+(tiles_per_line-1))//tiles_per_line
        dest_width = tiles_per_line*self.edge if not self.args.width \
            else self.args.width
        dest_height = lines*self.edge

        if self.args.verbose:
            print("input has %d tiles" % (num_tiles))
            print("destination will hold %d tiles (%dpx x %dpx)" % \
                (tiles_per_line*lines, dest_width, dest_height))

        d = pygame.Surface((dest_width, dest_height), depth=8)
        d.set_palette([(0, 0, 0)] +
                      [(randint(100, 255),
                        randint(100, 255),
                        randint(100, 255)) for i in range(1, 16)])
        dpa = pygame.PixelArray(d)

        edge = self.edge
        i = self.pos2D_iterator(dest_width)
        for n in range(num_tiles):
            (x, y) = next(i)
            t = self.read_tile_from_rom()
            tpa = pygame.PixelArray(t)
            dpa[x:x+edge, y:y+edge] = tpa

        pygame.image.save(d, self.out)
        self.close_rom()
def extract ( self ) : self . open_rom ( 'rb' ) num_tiles = os . path . getsize ( self . in1 ) // self . multiple tiles_per_line = 20 if not self . args . width else self . args . width // self . edge lines = ( num_tiles + ( tiles_per_line - 1 ) ) // tiles_per_line dest_width = tiles_per_line * self . edge if not self . args . width else self . args . width dest_height = lines * self . edge if self . args . verbose : print ( "input has %d tiles" % ( num_tiles ) ) print ( "destination will hold %d tiles (%dpx x %dpx)" % ( tiles_per_line * lines , dest_width , dest_height ) ) d = pygame . Surface ( ( dest_width , dest_height ) , depth = 8 ) d . set_palette ( [ ( 0 , 0 , 0 ) ] + [ ( randint ( 100 , 255 ) , randint ( 100 , 255 ) , randint ( 100 , 255 ) ) for i in range ( 1 , 16 ) ] ) dpa = pygame . PixelArray ( d ) edge = self . edge i = self . pos2D_iterator ( dest_width ) for n in range ( num_tiles ) : ( x , y ) = next ( i ) t = self . read_tile_from_rom ( ) tpa = pygame . PixelArray ( t ) dpa [ x : x + edge , y : y + edge ] = tpa pygame . image . save ( d , self . out ) self . close_rom ( )