Пример #1
0
    def _open_file(self):
        self.np_img = self.image_opener.open_file()
        self.image_history.reset()
        self.image_history.add_new_state(self.np_img)
        self.image_saver.filename = self.image_opener.filename

        # in case of png files swap channels
        if self.np_img.shape[2] == 4:
            self.np_img = utils.bgra2rgba(self.np_img)
        self._show_np_image()

        self._enable_menu_items(True)
        self._enable_undo_redo()
        self.ui.actionSave_As.setEnabled(True)
Пример #2
0
    def mask_pixbuf(self, pb, width, height):
        """
        Mask the pixbuf so there is no offscreen garbage on multimonitor setups
        """

        geometry = self.get_geometry()
        mask = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
        mask_cr = cairo.Context(mask)

        # fill transparent
        mask_cr.set_source_rgba(0, 0, 0, 0)
        mask_cr.fill()
        mask_cr.paint()
        for geo in geometry:
            mask_cr.rectangle(geo.x, geo.y, geo.width, geo.height)
            mask_cr.set_source_rgba(1, 1, 1, 1)
            mask_cr.fill()

        img = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)

        cr = cairo.Context(img)
        gdkcr = gtk.gdk.CairoContext(cr)

        # fill with the dafault color
        gdkcr.set_source_rgba(0, 0, 0, 1)
        gdkcr.fill()
        gdkcr.paint()

        # use the mask to paint from the pixbuf
        gdkcr.set_source_pixbuf(pb, 0, 0)
        gdkcr.mask_surface(mask, 0, 0)
        gdkcr.fill()

        stride = img.get_stride()
        pixels = img.get_data()

        data = bgra2rgba(pixels, width, height)

        new_pb = gtk.gdk.pixbuf_new_from_data(data, gtk.gdk.COLORSPACE_RGB,
                                              True, 8, width, height, stride)
        return new_pb
Пример #3
0
    def mask_pixbuf(self, pb, width, height):
        """
        Mask the pixbuf so there is no offscreen garbage on multimonitor setups
        """

        geometry = self.get_geometry()
        mask = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
        mask_cr = cairo.Context(mask)

        # fill transparent
        mask_cr.set_source_rgba(0, 0, 0, 0)
        mask_cr.fill()
        mask_cr.paint()
        for geo in geometry:
            mask_cr.rectangle(geo.x, geo.y, geo.width, geo.height)
            mask_cr.set_source_rgba(1, 1, 1, 1)
            mask_cr.fill()

        img = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)

        cr = cairo.Context(img)
        gdkcr = gtk.gdk.CairoContext(cr)

        # fill with the dafault color
        gdkcr.set_source_rgba(0, 0, 0, 1)
        gdkcr.fill()
        gdkcr.paint()

        # use the mask to paint from the pixbuf
        gdkcr.set_source_pixbuf(pb, 0, 0)
        gdkcr.mask_surface(mask, 0, 0)
        gdkcr.fill()

        stride = img.get_stride()
        pixels = img.get_data()

        data = bgra2rgba(pixels, width, height)

        new_pb = gtk.gdk.pixbuf_new_from_data(data, gtk.gdk.COLORSPACE_RGB,
                                              True, 8, width, height, stride)
        return new_pb