bmp.py 文件源码

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

项目:CTF 作者: calee0219 项目源码 文件源码
def _create_header(cls, width, height):
        """ Internal function used to create headers when changing them is necessary, e.g. when image dimensions change.
            This function creates both a BMP header and a V3 DIB header, with some values left as defaults (e.g. pixels/meter) """

        total_header_size = cls.bmp_header_len + 40 # V3 len = 40 bytes
        padding_size = width & 3 # Magic stuff
        bitmap_size = ((width * 3) + padding_size) * height
        file_size = total_header_size + bitmap_size

        # BMP header: Magic (2 bytes), file size, 2 ignored values, bitmap offset
        header = struct.pack('<2s I 2H I', "BM", file_size, 0, 0, total_header_size)

        # DIB V3 header: header size, px width, px height, num of color planes, bpp, compression method,
        # bitmap data size, horizontal resolution, vertical resolution, number of colors in palette, number of important colors used
        # Few of these matter, so there are a bunch of default/"magic" numbers here...
        header += struct.pack('I 2i H H I I 2i 2I', 40, width, height, 1, 24, 0, bitmap_size, 0x0B13, 0x0B13, 0, 0)

        return header
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号