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)
Example #2
0
    def cancel_resized_layer(self):

        # Return if no resizing flush is pending.
        if not self.fakelayer: return

        # Alias active canvas and resizing layer.
        canvas = main.documents.active.canvas
        layer = self.resizelayer

        # Set layer attributes from fake layer.
        layer.pixbuf = self.oldlayer.pixbuf
        layer.pointer = convert.pixbuf_pointer(self.oldlayer.pixbuf)
        layer.xpos = self.oldlayer.xpos
        layer.ypos = self.oldlayer.ypos
        layer.width = self.oldlayer.width
        layer.height = self.oldlayer.height

        # Reposition hud items and redraw affected area.
        self.hudflush.set_display(None)
        self.reposition_huds()
        main.documents.active.layers.update_prelower()
        main.documents.active.layers.update_preupper()
        canvas.redraw_step(layer.xpos, layer.ypos, layer.width, layer.height)

        # Disable resizing mode.
        self.oldlayer = None
        self.fakelayer = None
        self.resizelayer = None
        self.mode = None
    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)
Example #4
0
    def configure(self, width, height):

        # Create pixbuf.
        self.pixbuf = gtk.gdk.Pixbuf(
            gtk.gdk.COLORSPACE_RGB,
            True,
            8,
            width,
            height)

        # Set attributes from pixbuf.
        self.pointer = convert.pixbuf_pointer(self.pixbuf)
        self.width = width
        self.height = height
        self.alpha = 1
Example #5
0
    def flush_resized_layer(self):

        # Return if no resizing flush is pending.
        if not self.fakelayer: return

        # Alias active canvas and resizing layer.
        canvas = main.documents.active.canvas
        layer = self.resizelayer

        if self.interpolation == 0: interpolation = 0
        if self.interpolation == 1: interpolation = 2
        if self.interpolation == 2: interpolation = 3

        # Do the final scaling.
        pixbuf = self.oldlayer.pixbuf.scale_simple(
            self.fakelayer.width,
            self.fakelayer.height,
            interpolation)

        # Set layer attributes from fake layer.
        layer.pixbuf = pixbuf
        layer.pointer = convert.pixbuf_pointer(pixbuf)
        layer.xpos = self.fakelayer.xpos
        layer.ypos = self.fakelayer.ypos
        layer.width = self.fakelayer.width
        layer.height = self.fakelayer.height

        # Redraw layer.
        main.documents.active.layers.update_prelower()
        main.documents.active.layers.update_preupper()
        canvas.redraw_step(layer.xpos, layer.ypos, layer.width, layer.height)

        # Disable resizing mode.
        self.oldlayer = None
        self.fakelayer = None
        self.resizelayer = None
        self.mode = None

        # Hide flush hud item.
        self.hudflush.set_display(None)
        self.reposition_huds()

        # End resizing action.
        document = main.documents.active
        document.actions.end()
Example #6
0
    def __init__(self, name, path, width=0, height=0, fill=False):
        """Create the layer."""
        

        #declare pixData Object
        self.pixData = None

        # Allow debug tracking.
        main.log.allow_tracking(self)

        # Set attributes.
        self.name = name
        self.id = None
        self.pixbuf = None
        self.xpos = 0
        self.ypos = 0
        self.width = None
        self.height = None
        self.pointer = None
        self.alpha = 1

        # If not dimensions given exit, so the pixbuf must be created later
        # manually with some overwrite method.
        if not width or not height:
            if path: self.overwrite_from_path(path)
            return

        # Create empty pixbuf scratch.
        self.pixbuf = gtk.gdk.Pixbuf(0, True, 8, width, height)

#        # Fill pixbuf.
#        if not fill: fillcolor = 0xffffff00
#        else: fillcolor = 0xffffffff
#        self.pixbuf.fill(fillcolor)

        # Set pixbuf dimensions and memory address.
        self.width = self.pixbuf.get_width()
        self.height = self.pixbuf.get_height()
        self.pointer = convert.pixbuf_pointer(self.pixbuf)
    def unrestore(self):

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

        # Unrestore layer.
        self.layer.pixbuf = self.fpixbuf.copy()
        self.layer.pointer = convert.pixbuf_pointer(self.layer.pixbuf)
        self.layer.xpos = self.fxpos
        self.layer.ypos = self.fypos
        self.layer.width = self.fwidth
        self.layer.height = self.fheight

        # Redraw areas.
        iarea = (self.ixpos, self.iypos, self.iwidth, self.iheight)
        farea = (self.fxpos, self.fypos, self.fwidth, self.fheight)
        main.documents.active.canvas.redraw(*iarea)
        main.documents.active.canvas.redraw(*farea)

        # Notify to tool.
        tool =  main.plugins.activetool
        if tool and hasattr(tool, 'layer_changed'): tool.layer_changed()
Example #8
0
    def resize_layer(self, x, y ,ux, uy):

        # Alias active canvas and active layer.
        canvas = main.documents.active.canvas
        layer = main.documents.active.layers.active

        # Copy active layer.
        if not self.oldlayer:
            document = main.documents.active
            document.actions.begin('layer-modify')
            self.oldlayer = copy.copy(layer)
            self.fakelayer = copy.copy(layer)
            self.resizelayer = layer
            self.hudflush.set_display(True)

        # Get relative coordinates from root.
        rel_x = (x - self.xroot)
        rel_y = (y - self.yroot)

        # Alias selected hud item.
        shi = self.shi

        # Reverse relative for top and left hud items.
        if shi == 0 or shi == 3 or shi == 5: rel_x = -rel_x
        if shi == 0 or shi == 1 or shi == 2: rel_y = -rel_y

        # Disable an axis for central hud items.
        if shi == 1 or shi == 6: rel_x = 0
        if shi == 3 or shi == 4: rel_y = 0

        # Calc new dimensions.
        width = self.fakelayer.width + rel_x
        height = self.fakelayer.height + rel_y

        # Do proportional scaling for corner hud items.
        if shi == 0 or shi == 2 or shi == 5 or shi == 7:
            scale_x = float(width) / self.fakelayer.width
            scale_y = float(height) / self.fakelayer.height
            if scale_x > scale_y: width = self.fakelayer.width * scale_y
            else: height = self.fakelayer.height * scale_x

        # Calc new position.
        pos_x = self.fakelayer.xpos
        pos_y = self.fakelayer.ypos
        if shi == 0 or shi == 3 or shi == 5:
            pos_x += self.fakelayer.width - width
        if shi == 0 or shi == 1 or shi == 2:
            pos_y += self.fakelayer.height - height

        # Convert to avoid deprecations.
        pos_x = int(pos_x)
        pos_y = int(pos_y)
        width = int(width)
        height = int(height)

        # Scale to new dimensions
        pixbuf = self.oldlayer.pixbuf.scale_simple(width, height, 0)

        # Set the temporal layer attributes.
        layer.pixbuf = pixbuf
        layer.pointer = convert.pixbuf_pointer(layer.pixbuf)
        layer.xpos = pos_x
        layer.ypos = pos_y
        layer.width = width
        layer.height = height

        # Reposition hud items and redraw affected area.
        self.reposition_huds()
        canvas.redraw_step(layer.xpos, layer.ypos, layer.width, layer.height)
Example #9
0
    def update_pointer(self):
        """Update the pixbuf pointer."""

        self.pointer = convert.pixbuf_pointer(self.pixbuf)