Exemplo n.º 1
0
def image_from_tex_udata( udata = None ):
    if udata:
        size = 0
        if len(udata) == 0x4000: # 0x8000 bytes! 
            size = 128
        elif len(udata) == 0x1000:
            size = 64
        if not size:
            raise Exception( "Unknown Size!" + str(len(udata)))
        image = StandardSurface()
        image.new((size, size))
        for y in xrange(size):
            for x in xrange(size):
                image.dot( (x, y), rgb555_rgb(udata[ y * size + x ]) )
        return image
Exemplo n.º 2
0
 def rawtile_data_rot(self, udata):
     """Alazane's Method of rotating the Maptile to a 44x44 bitmap
     a bit buggy d'oh."""
     image = StandardSurface()
     image.new((44, 44))
     xstart = 0
     ystart = 1
     i = 0
     while xstart <= 44:
         x = xstart
         y = ystart
         while (x <= 44) and (y >= 0):
             image.dot((x, y), rgb555_rgb(udata[i]))
             image.dot((x + 1, y), rgb555_rgb(udata[i]))
             image.dot((x, y + 1), rgb555_rgb(udata[i]))
             i += 1
             x += 1
             y -= 1
         if ystart < 43:
             ystart += 2
         elif ystart == 43:
             ystart += 1
             xstart += 1
         else:
             xstart += 2
     return image
Exemplo n.º 3
0
def get_image_from_runtile_udata(udata, surface=None):
    """generates image object from unpacked data."""
    if udata:
        # prepare header data
        width = udata[0]
        height = udata[1]
        if (width >= 1024) or (width <= 0) or (height <= 0) or (height >= 1024):
            return None
        if surface:
            image = surface
        else:
            image = StandardSurface()
            image.new((width, height))
        lstart = udata[2 : 2 + height]
        udata = udata[2 + height :]
        x = 0
        y = 0
        o = y
        while y < height:
            xoffset = udata[lstart[y] + o]
            xrun = udata[lstart[y] + o + 1]
            # print "xrun %s xoffset %s" % (xrun, xoffset)
            o += 2
            if (xoffset + xrun) >= 2048:
                pass
            elif (xoffset + xrun) != 0:
                x += xoffset
                for i in xrange(xrun):
                    if (x + i) < width:
                        try:
                            image.dot((x + i, y), rgb555_rgb(udata[lstart[y] + o + i]))
                        except:
                            print "Ooops"
                x += xrun
                o += xrun
            else:
                x = 0
                y += 1
                o = 0
        return image
Exemplo n.º 4
0
def get_image_from_rawtile_udata(udata, surface=None):
    """generates a map image from unpacked data"""
    image = surface
    # print len(udata)
    if not surface:
        image = StandardSurface()
        image.new((44, 44))
    o = 0
    for y in xrange(22):
        p = y + 1
        pixels = udata[o : o + p * 2]
        # spiegels = whole_data[ len(whole_data) / 2 + o: o + p * 2 - 1 ]
        for x in xrange(len(pixels)):
            image.dot((21 - y + x, y), rgb555_rgb(pixels[x]))
        o += len(pixels)
    for y in xrange(22):
        realy = 22 + y
        numx = 44 - y * 2
        pixels = udata[o : o + numx]
        for x in xrange(len(pixels)):
            image.dot((x + y, realy), rgb555_rgb(pixels[x]))
        o += len(pixels)
    return image
Exemplo n.º 5
0
 def get_radar_map(self, map = None, statics = None, scale = 1, upper_left = (0,0), lower_right = None, image = None, height_map = False, tile_map = True ):
     scale = int(scale)
     if not scale:
         # stupid?
         scale = 1
     if not lower_right:
         if map:
             lower_right = ( map.map_x * 8, map.map_y * 8 )
         else:
             lower_right = ( Map.map_x * 8, Map.map_y * 8 )
     if not image:
         image = StandardSurface()
         image.new( (lower_right[0] / scale, lower_right[1] / scale) )
     block_x = 0
     block_y = 0
     block = None
     static = None
     old_block_y = None
     old_block_x = None
     for x in range( upper_left[0] / scale, lower_right[0] / scale ):
         block_x = x * scale / 8
         if block_x != old_block_x:
             if map:
                 block = map.get_blockx_raw(block_x)
             old_block_x = block_x
         cell_x = x * scale % 8
         for y in range( upper_left[1] / scale, lower_right[1] / scale ):
             block_y = y * scale / 8
             cell_y = y * scale % 8
             if statics:
                 s = statics.get_statics( (x * scale, y * scale) )
                 if len(s) > 0:
                     s = s[0] # normally we would search the highest.
                     image.dot( (x - upper_left[0], y - upper_left[1]), self.get_rgb( s[0] + 16384 ))
                     continue
             if block_y != old_block_y:
                 if block:
                     b = block[ block_y * 196 : block_y * 196 + 196 ]
                 old_block_y = block_y
             if block:
                 # calculate the point we want to get information from in the block:
                 start = (cell_y * 8 + cell_x) * 3 + 4
                 if height_map and not tile_map:
                     a = unpack("<b", b[ start+2:start+3 ])[0]
                     a += 127
                     rgb = ( a, a, a )
                     image.dot( (x - upper_left[0], y - upper_left[1]), rgb )
                 elif not height_map and tile_map:
                     c = unpack("<H", b[ start: start + 2 ])[0]
                     image.dot( (x - upper_left[0], y - upper_left[1]), self.get_rgb(c))
                 else:
                     c, a = unpack("<Hb", b[ start: start + 3 ])
                     rgb = self.get_rgb(c)                        
                     rgb = (rgb[0] + a,rgb[1] + a, rgb[2] + a, ) 
                     image.dot( (x - upper_left[0], y - upper_left[1]), rgb)
     return image