示例#1
0
def tex_udata_from_image( image = None ):
    if image:
        size, sy = image.get_size()
        udata = []
        for y in xrange(size):
            for x in xrange(size):
                udata += [ rgb_rgb555(image.spot(x,y)) ]
        return udata
示例#2
0
def get_rawtile_udata_from_image(image, correct_data=True):
    """
        gets the unpacked data for a maptile from an image.
        if correct_data is given, data is corrected by sizing it to 1024 entries.
    """
    udata = []
    for y in xrange(22):
        p = y + 1
        for x in range(22 - p, 22 + p):
            # FIXME: alpha unneeded. maptiles dont know transparency anyway.
            r, g, b, a = image.spot((x, y))
            color = rgb_rgb555((r, g, b))
            udata += [color]
    for y in xrange(22):
        realy = 22 + y
        p = 22 - y
        for x in range(22 - p, 22 + p):
            r, g, b, a = image.spot((x, realy))
            color = rgb_rgb555((r, g, b))
            udata += [color]
    if correct_data:
        udata += [0 for j in xrange(12)]
    return udata
示例#3
0
def get_runtile_udata_from_image(image, correct_data=True):
    """
        creates unpacked data from an image for a runtile (items in art.mul)
        if correct_data is given, it will prepend [ 1, 0 ] as FLAG to the data.
    """
    udata = []
    udata += [image.width]
    udata += [image.height]
    offsets = []
    last_offset = 0
    offset_counter = 0
    image_data = []
    for y in xrange(image.height):
        actual_data = []
        offset_counter = 0
        for x in xrange(image.width):
            # TODO: this only works for pngs right now, since bmps have no alpha channel.
            r, g, b, a = image.spot((x, y))
            if a > 0:
                # visible, since alpha > 0
                actual_data += [rgb_rgb555((r, g, b))]
            else:
                # invisible, since alpha = 0
                if len(actual_data):
                    image_data += [offset_counter, len(actual_data)] + actual_data
                    actual_data = []
                    offset_counter = 0
                offset_counter += 1
        if len(actual_data):
            image_data += [offset_counter, len(actual_data)] + actual_data
            actual_data = []
        image_data += [0, 0]
        actual_data = []
        offsets += [last_offset]
        last_offset = len(image_data)
    udata += offsets + image_data
    if correct_data:
        udata = [1, 0] + udata
    return udata