Exemplo n.º 1
0
    def restore(self):

        # Set the target layer as active.
        main.documents.active.layers.set_active(self.layer, False)
        main.gui.sidebar.layers.dump()

        # Get diff and modified subpixbufs.
        diffbuf = self.decompress(self.diff)
        pixbuf = self.copy_area(self.layer.pixbuf)

        # Calc original subpixbuf.
        core.diff(
            convert.pixbuf_pointer(pixbuf),
            convert.pixbuf_pointer(diffbuf),
            self.zone[2],
            self.zone[3],
            True)

        # Copy original subpixbuf to layer.
        pixbuf.copy_area(
            0,
            0,
            self.zone[2],
            self.zone[3],
            self.layer.pixbuf,
            self.zone[0],
            self.zone[1])

        # Redraw zone (at document offset level).
        zone = copy.copy(self.zone)
        zone[0] += self.layer.xpos
        zone[1] += self.layer.ypos
        main.documents.active.canvas.redraw(*zone)
Exemplo n.º 2
0
    def final(self, zone=None):

        # If not zone given, zone is the entire layer.
        if not zone: zone = [0, 0, self.layer.width, self.layer.height]

        # Adjust zone to layer limits.
        if zone[0] < 0:
            zone[2] += zone[0]
            zone[0] = 0
        if zone[1] < 0:
            zone[3] += zone[1]
            zone[1] = 0
        zone[2] = min(zone[2], self.layer.width - zone[0])
        zone[3] = min(zone[3], self.layer.height - zone[1])
        self.zone = zone

        # Get original and modified subpixbufs.
        pixbuf = self.copy_area(self.pixbuf)
        pixbufmod = self.copy_area(self.layer.pixbuf)

        # Calc diff subpixbuf.
        core.diff(
            convert.pixbuf_pointer(pixbuf),
            convert.pixbuf_pointer(pixbufmod),
            zone[2],
            zone[3],
            False)

        # Compress diff subpixbuf.
        self.diff = zlib.compress(pixbuf.get_pixels())

        # Set propierties.
        self.rowstride = pixbuf.get_rowstride()
        self.bytes = len(self.diff)

        # Free memory.
        del(pixbuf)
        del(pixbufmod)
        del(self.pixbuf)