当前位置: 首页>>代码示例>>Python>>正文


Python ByteReader.readByte方法代码示例

本文整理汇总了Python中mmfparser.bytereader.ByteReader.readByte方法的典型用法代码示例。如果您正苦于以下问题:Python ByteReader.readByte方法的具体用法?Python ByteReader.readByte怎么用?Python ByteReader.readByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mmfparser.bytereader.ByteReader的用法示例。


在下文中一共展示了ByteReader.readByte方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_runinfo

# 需要导入模块: from mmfparser.bytereader import ByteReader [as 别名]
# 或者: from mmfparser.bytereader.ByteReader import readByte [as 别名]
def read_runinfo(data):
    info = {}
    reader = ByteReader(data)
    count = reader.readInt(True)
    for _ in xrange(count):
        name = reader.read(reader.readInt(True))
        alts = {}
        for i in xrange(26):
            alts[i] = reader.readByte(True)
        info[name] = alts
    return info
开发者ID:joaormatos,项目名称:anaconda,代码行数:13,代码来源:runinfo.py

示例2: Tiler

# 需要导入模块: from mmfparser.bytereader import ByteReader [as 别名]
# 或者: from mmfparser.bytereader.ByteReader import readByte [as 别名]
class Tiler(object):
    def __init__(self, filename):
        filename = os.path.join(DATA_DIR, filename)
        self.filename = filename

        self.tiles = os.stat(filename).st_size != 0

        name = os.path.basename(filename).encode('utf-8')
        self.name = os.path.splitext(name)[0]

        self.outdir = os.path.join(DATA_DIR, 'mfas')# + self.name
        try:
            os.makedirs(self.outdir)
        except OSError:
            pass

        self.objects = {}

        self.x_size = 16
        self.y_size = 16

        template_path = os.path.join(DATA_DIR, 'template.mfa')
        self.mfa = MFA(ByteReader(open(template_path, 'rb')))

        self.object_id = 32
        self.image_id = 0
        self.icon_id = max(self.mfa.icons.itemDict) + 1

    def run(self, cmd):
        self.room = ByteReader(open(self.filename, 'rb'))
        self.file_ver = self.room.readByte(True)
        self.x_size = self.room.readByte(True)
        self.y_size = self.room.readByte(True)
        tileset_len = self.room.readByte(True)
        self.tileset = self.room.readString(tileset_len)
        self.tile_count = self.room.readInt(True)

        image_path = os.path.join(SETS_PATH, '%s.png' % self.tileset)
        image = Image.open(image_path).convert('RGBA')

        col = image.getpixel((0, 0))
        self.tileset_transparent = col[:3]
        if col[3] == 255:
            print 'Filtering image with transparent color', col
            buf = image.load()
            for y in xrange(image.size[1]):
                for x in xrange(image.size[0]):
                    test_col = buf[(x, y)]
                    if test_col != col:
                        continue
                    buf[(x, y)] = (0, 0, 0, 0)

        frame = self.mfa.frames[0]

        if cmd == 'extract_tiles':
            self.run_extract_tiles(image)
            return
        elif cmd == 'build':
            self.run_build(image)

        frame.folders = []
        for item in frame.items:
            folder = frame.new(ItemFolder)
            folder.items = [item.handle]
            frame.folders.append(folder)

        basename = os.path.basename(self.filename)
        out_name = os.path.splitext(basename)[0] + '.mfa'
        out_path = os.path.join(self.outdir, out_name)

        if os.path.isfile(out_path):
            os.remove(out_path)
        self.mfa.write(ByteReader(open(out_path, 'wb')))
        print 'Created %s' % out_name

    def run_build(self, image):
        mask_path = os.path.join(SETS_PATH, '%s_mask.png' % self.tileset)
        mask = Image.open(mask_path)

        if mask.mode != 'P':
            raise ValueError('The mask has to be palette image')

        #mask = mask.convert('P')
        colors = mask.getcolors()
        transparent = mask.getpixel((0, 0))

        if transparent != 0:
            raise ValueError('The transparent color should be the first color '
                             'in the palette')

        buf = image.load()

        for (_, color) in colors:
            if color == transparent or color == 255:
                continue
            color_image = mask.point(lambda x: 1 if x == color else 0)
            box = color_image.getbbox()
            tile_x = box[0] / self.x_size
            tile_y = box[1] / self.y_size
            height = box[3] - box[1]
#.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:anaconda,代码行数:103,代码来源:roombuilder.py


注:本文中的mmfparser.bytereader.ByteReader.readByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。