예제 #1
0
    def _do_paint_rgb(self, cairo_format, has_alpha, img_data, x, y, width,
                      height, rowstride, options):
        """ must be called from UI thread """
        log(
            "cairo._do_paint_rgb(%s, %s, %s %s, %s, %s, %s, %s, %s, %s) set_image_surface_data=%s, use pixbuf=%s",
            FORMATS.get(cairo_format, cairo_format), has_alpha, len(img_data),
            type(img_data), x, y, width, height, rowstride, options,
            set_image_surface_data, CAIRO_USE_PIXBUF)
        rgb_format = options.strget(b"rgb_format", "RGB")
        if set_image_surface_data and not CAIRO_USE_PIXBUF:
            if (cairo_format==cairo.FORMAT_RGB24 and rgb_format in ("RGB", "BGR")) or \
                (cairo_format==cairo.FORMAT_ARGB32 and rgb_format in ("BGRX", "BGRA")):
                img_surface = cairo.ImageSurface(cairo_format, width, height)
                set_image_surface_data(img_surface, rgb_format, img_data,
                                       width, height, rowstride)
                self.cairo_paint_surface(img_surface, x, y, options)
                return True

        if rgb_format in ("RGB", "RGBA", "RGBX"):
            data = GLib.Bytes(img_data)
            pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(data,
                                                     GdkPixbuf.Colorspace.RGB,
                                                     has_alpha, 8, width,
                                                     height, rowstride)
            self.cairo_paint_pixbuf(pixbuf, x, y, options)
            return True

        img_data = memoryview(img_data)
        self.nasty_rgb_via_png_paint(cairo_format, has_alpha, img_data, x, y,
                                     width, height, rowstride, rgb_format)
        return True
예제 #2
0
    def _do_paint_rgb(self, cairo_format, has_alpha, img_data, x, y, width, height, rowstride, options):
        """ must be called from UI thread """
        log("cairo._do_paint_rgb(%s, %s, %s %s,%s,%s,%s,%s,%s,%s) set_image_surface_data=%s", FORMATS.get(cairo_format, cairo_format), has_alpha, len(img_data), type(img_data), x, y, width, height, rowstride, options, set_image_surface_data)
        rgb_format = options.strget("rgb_format", "RGB")
        #this format we can handle with the workaround:
        if cairo_format==cairo.FORMAT_RGB24 and rgb_format=="RGB" and set_image_surface_data:
            img_surface = cairo.ImageSurface(cairo_format, width, height)
            set_image_surface_data(img_surface, rgb_format, img_data, width, height, rowstride)
            return self.cairo_paint_surface(img_surface, x, y)

        self.nasty_rgb_via_png_paint(cairo_format, has_alpha, img_data, x, y, width, height, rowstride, rgb_format)
        return True
예제 #3
0
파일: cairo_backing.py 프로젝트: chewi/xpra
    def _do_paint_rgb(self, cairo_format, has_alpha, img_data, x: int, y: int,
                      width: int, height: int, render_width: int,
                      render_height: int, rowstride: int, options):
        """ must be called from UI thread """
        log(
            "cairo._do_paint_rgb(%s, %s, %s %s, %s, %s, %s, %s, %s, %s, %s, %s) set_image_surface_data=%s, use pixbuf=%s",
            FORMATS.get(cairo_format, cairo_format), has_alpha, len(img_data),
            type(img_data), x, y, width, height, render_width, render_height,
            rowstride, options, set_image_surface_data, CAIRO_USE_PIXBUF)
        rgb_format = options.strget("rgb_format", "RGB")
        if set_image_surface_data and not CAIRO_USE_PIXBUF:
            rgb_formats = CAIRO_FORMATS.get(cairo_format)
            if rgb_format in rgb_formats:
                img_surface = ImageSurface(cairo_format, width, height)
                set_image_surface_data(img_surface, rgb_format, img_data,
                                       width, height, rowstride)
                self.cairo_paint_surface(img_surface, x, y, render_width,
                                         render_height, options)
                return True
            log(
                "cannot set image surface data for cairo format %s and rgb_format %s (rgb formats supported: %s)",
                cairo_format, rgb_format, rgb_formats)

        if rgb_format in ("RGB", "RGBA", "RGBX"):
            data = GLib.Bytes(img_data)
            pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(data,
                                                     GdkPixbuf.Colorspace.RGB,
                                                     has_alpha, 8, width,
                                                     height, rowstride)
            if render_width != width or render_height != height:
                resample = options.strget("resample")
                if resample == "NEAREST":
                    interp_type = GdkPixbuf.InterpType.NEAREST
                elif resample in ("BICUBIC", "LANCZOS"):
                    interp_type = GdkPixbuf.InterpType.HYPER
                else:
                    interp_type = GdkPixbuf.InterpType.BILINEAR
                pixbuf = pixbuf.scale_simple(render_width, render_height,
                                             interp_type)
            self.cairo_paint_pixbuf(pixbuf, x, y, options)
            return True

        img_data = memoryview(img_data)
        self.nasty_rgb_via_png_paint(cairo_format, has_alpha, img_data, x, y,
                                     width, height, rowstride, rgb_format)
        return True
예제 #4
0
    def _do_paint_rgb(self, cairo_format, has_alpha, img_data, x, y, width,
                      height, rowstride, options):
        """ must be called from UI thread """
        log(
            "cairo._do_paint_rgb(%s, %s, %s %s,%s,%s,%s,%s,%s,%s) set_image_surface_data=%s",
            FORMATS.get(cairo_format, cairo_format), has_alpha, len(img_data),
            type(img_data), x, y, width, height, rowstride, options,
            set_image_surface_data)
        rgb_format = options.strget("rgb_format", "RGB")
        #this format we can handle with the workaround:
        if cairo_format == cairo.FORMAT_RGB24 and rgb_format == "RGB" and set_image_surface_data:
            img_surface = cairo.ImageSurface(cairo_format, width, height)
            set_image_surface_data(img_surface, rgb_format, img_data, width,
                                   height, rowstride)
            return self.cairo_paint_surface(img_surface, x, y)

        self.nasty_rgb_via_png_paint(cairo_format, has_alpha, img_data, x, y,
                                     width, height, rowstride, rgb_format)
        return True
예제 #5
0
파일: cairo_backing.py 프로젝트: chewi/xpra
 def update_fps_buffer(self, width, height, pixels):
     self.fps_image = ImageSurface(FORMAT_ARGB32, width, height)
     set_image_surface_data(self.fps_image, "RGBA", pixels, width, height,
                            width * 4)