bmp.py 文件源码

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

项目:CTF 作者: calee0219 项目源码 文件源码
def grayscale(self):
        """ Convert the image into a (24-bit) grayscale one, using the Y'UV method. """

        # http://en.wikipedia.org/wiki/YUV
        Wr = 0.299
        Wb = 0.114
        Wg = 0.587

        mod_bitmap = ""

        f = StringIO(self.bitmap_data)
        for row_num in xrange(0, self.height):
            for pix in xrange(0, self.width):
                pixel = struct.unpack("3B", f.read(3))
                out_pix = chr(int(Wr * pixel[2] + Wg * pixel[1] + Wb * pixel[0]))
                mod_bitmap += out_pix * 3

            mod_bitmap += chr(0x00) * self.padding_size
            f.seek(self.padding_size, 1)

        self.bitmap_data = mod_bitmap

        return self
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号