regionhelpers.py 文件源码

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

项目:htmlDE 作者: freundTech 项目源码 文件源码
def cairo_region_create_from_surface(surface, mask_accuracy):
    rect = cairo.RectangleInt()
    extents = _cairo_surface_extents(surface)
    if extents != False:
        if surface.get_content() == cairo.CONTENT_COLOR:
            return cairo.Region(extents)
        if type(surface) != cairo.ImageSurface or surface.get_format != cairo.FORMAT_A1:
            image = cairo.ImageSurface(cairo.FORMAT_A1, extents.width, extents.height)

            cr = cairo.Context(image)
            cr.set_source_surface(surface, -extents.x, -extents.y)
            cr.paint()
        else:
            image = surface

        image.flush()
        data = image.get_data()
        stride = image.get_stride()

        region = cairo.Region()
        for y in range(0, extents.height, mask_accuracy):
            for x in range(0, extents.width, mask_accuracy):
                x0 = x;
                while x < extents.width: 
                    if sys.byteorder == 'little':
                        if ((data[y*stride+x//8] >> (x%8)) & 1) == 0:
                            break
                    if sys.byteorder == 'big':
                        if ((data[y*stride+x//8] >> (7-(x%8))) & 1) == 0:
                            break
                    x += mask_accuracy

                if x > x0:
                    rect.x = x0
                    rect.width = x - x0
                    rect.y = y
                    rect.height = mask_accuracy
                    region.union(rect)

    region.translate(extents.x, extents.y)
    return region
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号