WalImageFile.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:InstagramPosting 作者: LeviParadis 项目源码 文件源码
def open(filename):
    # FIXME: modify to return a WalImageFile instance instead of
    # plain Image object ?

    if hasattr(filename, "read"):
        fp = filename
    else:
        import __builtin__
        fp = __builtin__.open(filename, "rb")

    # read header fields
    header = fp.read(32+24+32+12)
    size = i32(header, 32), i32(header, 36)
    offset = i32(header, 40)

    # load pixel data
    fp.seek(offset)

    im = Image.fromstring("P", size, fp.read(size[0] * size[1]))
    im.putpalette(quake2palette)

    im.format = "WAL"
    im.format_description = "Quake2 Texture"

    # strings are null-terminated
    im.info["name"] = header[:32].split("\0", 1)[0]
    next_name = header[56:56+32].split("\0", 1)[0]
    if next_name:
        im.info["next_name"] = next_name

    return im
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号