Exemple #1
0
 def _insert_layer(self, image, layer_elems, inserted_layer_copy, insert_index=0):
   if not layer_elems:
     return None, None
   
   if inserted_layer_copy is None:
     layer_group = pdb.gimp_layer_group_new(image)
     pdb.gimp_image_insert_layer(image, layer_group, None, insert_index)
     
     for i, layer_elem in enumerate(list(layer_elems)):
       layer_copy = pdb.gimp_layer_new_from_drawable(layer_elem.item, image)
       pdb.gimp_image_insert_layer(image, layer_copy, layer_group, i)
       pdb.gimp_item_set_visible(layer_copy, True)
       
       if pdb.gimp_item_is_group(layer_copy):
         layer_copy = pgpdb.merge_layer_group(layer_copy)
       
       self._on_after_insert_layer_func(layer_copy)
       
       if self.export_settings['more_operations/ignore_layer_modes'].value:
         layer_copy.mode = gimpenums.NORMAL_MODE
     
     layer = pgpdb.merge_layer_group(layer_group)
     
     inserted_layer_copy = pdb.gimp_layer_copy(layer, True)
     return layer, inserted_layer_copy
   else:
     layer_copy = pdb.gimp_layer_copy(inserted_layer_copy, True)
     pdb.gimp_image_insert_layer(image, layer_copy, None, insert_index)
     return layer_copy, inserted_layer_copy
 def _process_layer(self, image, layer):
   background_layer, self._tagged_layer_copies['background'] = self._insert_layer(
     image, self._tagged_layer_elems['background'], self._tagged_layer_copies['background'], insert_index=0)
   
   layer_copy = pdb.gimp_layer_new_from_drawable(layer, image)
   pdb.gimp_image_insert_layer(image, layer_copy, None, 0)
   # This is necessary for file formats which flatten the image (such as JPG).
   pdb.gimp_item_set_visible(layer_copy, True)
   
   if pdb.gimp_item_is_group(layer_copy):
     layer_copy = pgpdb.merge_layer_group(layer_copy)
   
   if self.export_settings['ignore_layer_modes'].value:
     layer_copy.mode = gimpenums.NORMAL_MODE
   
   image.active_layer = layer_copy
   
   foreground_layer, self._tagged_layer_copies['foreground'] = self._insert_layer(
     image, self._tagged_layer_elems['foreground'], self._tagged_layer_copies['foreground'], insert_index=0)
   
   layer_copy = self._crop_and_merge(image, layer_copy, background_layer, foreground_layer)
   
   # Remove the " copy" suffix from the layer name, which is preserved in
   # formats supporting layers (XCF, PSD, ...).
   layer_copy.name = layer.name
   
   return layer_copy
 def _insert_layer(self, image, layer_elems, inserted_layer_copy, insert_index=0):
   if not layer_elems:
     return None, None
   
   if inserted_layer_copy is None:
     if self.export_settings['use_image_size'].value:
       # Remove layers outside the image canvas since they won't be visible in
       # the exported layer and because we need to avoid `RuntimeError`
       # when `pdb.gimp_image_merge_visible_layers` with `CLIP_TO_IMAGE`
       # argument tries to merge layers that are all outside the image canvas.
       for i in range(len(layer_elems)):
         if not pgpdb.is_layer_inside_image(image, layer_elems[i].item):
           layer_elems.pop(i)
       
       if not layer_elems:
         return None, None
     
     layer_group = pdb.gimp_layer_group_new(image)
     pdb.gimp_image_insert_layer(image, layer_group, None, insert_index)
     
     for i, layer_elem in enumerate(layer_elems):
       layer_copy = pdb.gimp_layer_new_from_drawable(layer_elem.item, image)
       pdb.gimp_image_insert_layer(image, layer_copy, layer_group, i)
       pdb.gimp_item_set_visible(layer_copy, True)
       if self.export_settings['ignore_layer_modes'].value:
         layer_copy.mode = gimpenums.NORMAL_MODE
       if pdb.gimp_item_is_group(layer_copy):
         layer_copy = pgpdb.merge_layer_group(layer_copy)
     
     layer = pgpdb.merge_layer_group(layer_group)
     
     if self.export_settings['use_image_size'].value:
       pdb.gimp_layer_resize_to_image_size(layer)
     
     inserted_layer_copy = pdb.gimp_layer_copy(layer, True)
     return layer, inserted_layer_copy
   else:
     layer_copy = pdb.gimp_layer_copy(inserted_layer_copy, True)
     pdb.gimp_image_insert_layer(image, layer_copy, None, insert_index)
     return layer_copy, inserted_layer_copy
Exemple #4
0
    def _insert_background(self):
        if self._background_layer_elems:
            if self._background_layer is None:
                if self.main_settings['use_image_size'].value:
                    # Remove background layers outside the image canvas, since they wouldn't
                    # be visible anyway and because we need to avoid `RuntimeError`
                    # when `pdb.gimp_image_merge_visible_layers` with the `CLIP_TO_IMAGE`
                    # option tries to merge layers that are all outside the image canvas.
                    self._background_layer_elems = [
                        bg_elem for bg_elem in self._background_layer_elems
                        if pgpdb.is_layer_inside_image(self._image_copy,
                                                       bg_elem.item)
                    ]

                    if not self._background_layer_elems:
                        return

                for i, bg_elem in enumerate(self._background_layer_elems):
                    bg_layer_copy = pdb.gimp_layer_new_from_drawable(
                        bg_elem.item, self._image_copy)
                    pdb.gimp_image_insert_layer(self._image_copy,
                                                bg_layer_copy, None, i)
                    pdb.gimp_item_set_visible(bg_layer_copy, True)
                    if self.main_settings['ignore_layer_modes'].value:
                        bg_layer_copy.mode = gimpenums.NORMAL_MODE
                    if pdb.gimp_item_is_group(bg_layer_copy):
                        bg_layer_copy = pgpdb.merge_layer_group(
                            self._image_copy, bg_layer_copy)

                if self.main_settings['use_image_size'].value:
                    background_layer = pdb.gimp_image_merge_visible_layers(
                        self._image_copy, gimpenums.CLIP_TO_IMAGE)
                else:
                    background_layer = pdb.gimp_image_merge_visible_layers(
                        self._image_copy, gimpenums.EXPAND_AS_NECESSARY)

                self._background_layer = pdb.gimp_layer_copy(
                    background_layer, True)
                return background_layer
            else:
                background_layer_copy = pdb.gimp_layer_copy(
                    self._background_layer, True)
                pdb.gimp_image_insert_layer(self._image_copy,
                                            background_layer_copy, None, 0)
                return background_layer_copy

        return None
    def _process_layer(self, layer):
        background_layer = self._insert_background()

        layer_copy = pdb.gimp_layer_new_from_drawable(layer, self._image_copy)
        pdb.gimp_image_insert_layer(self._image_copy, layer_copy, None, 0)
        # This is necessary for file formats which flatten the image (such as JPG).
        pdb.gimp_item_set_visible(layer_copy, True)
        if pdb.gimp_item_is_group(layer_copy):
            layer_copy = pgpdb.merge_layer_group(layer_copy)

        if self.export_settings["ignore_layer_modes"].value:
            layer_copy.mode = gimpenums.NORMAL_MODE

        self._image_copy.active_layer = layer_copy

        layer_copy = self._crop_and_merge(layer_copy, background_layer)

        return layer_copy
Exemple #6
0
    def _process_layer(self, layer):
        background_layer = self._insert_background()

        layer_copy = pdb.gimp_layer_new_from_drawable(layer, self._image_copy)
        pdb.gimp_image_insert_layer(self._image_copy, layer_copy, None, 0)
        # This is necessary for file formats which flatten the image (such as JPG).
        pdb.gimp_item_set_visible(layer_copy, True)
        if pdb.gimp_item_is_group(layer_copy):
            layer_copy = pgpdb.merge_layer_group(self._image_copy, layer_copy)

        if self.main_settings['ignore_layer_modes'].value:
            layer_copy.mode = gimpenums.NORMAL_MODE

        self._image_copy.active_layer = layer_copy

        layer_copy = self._crop_and_merge(layer_copy, background_layer)

        return layer_copy
    def _insert_background(self):
        if not self._background_layer_elems:
            return None

        if self._background_layer is None:
            if self.export_settings["use_image_size"].value:
                # Remove background layers outside the image canvas, since they wouldn't
                # be visible anyway and because we need to avoid `RuntimeError`
                # when `pdb.gimp_image_merge_visible_layers` with the `CLIP_TO_IMAGE`
                # option tries to merge layers that are all outside the image canvas.
                self._background_layer_elems = [
                    bg_elem
                    for bg_elem in self._background_layer_elems
                    if pgpdb.is_layer_inside_image(self._image_copy, bg_elem.item)
                ]
                if not self._background_layer_elems:
                    return None

            for i, bg_elem in enumerate(self._background_layer_elems):
                bg_layer_copy = pdb.gimp_layer_new_from_drawable(bg_elem.item, self._image_copy)
                pdb.gimp_image_insert_layer(self._image_copy, bg_layer_copy, None, i)
                pdb.gimp_item_set_visible(bg_layer_copy, True)
                if self.export_settings["ignore_layer_modes"].value:
                    bg_layer_copy.mode = gimpenums.NORMAL_MODE
                if pdb.gimp_item_is_group(bg_layer_copy):
                    bg_layer_copy = pgpdb.merge_layer_group(bg_layer_copy)

            if self.export_settings["use_image_size"].value:
                merge_type = gimpenums.CLIP_TO_IMAGE
            else:
                merge_type = gimpenums.EXPAND_AS_NECESSARY

            background_layer = pdb.gimp_image_merge_visible_layers(self._image_copy, merge_type)
            self._background_layer = pdb.gimp_layer_copy(background_layer, True)
            return background_layer
        else:
            # Optimization: copy the already created background layer.
            background_layer_copy = pdb.gimp_layer_copy(self._background_layer, True)
            pdb.gimp_image_insert_layer(self._image_copy, background_layer_copy, None, 0)
            return background_layer_copy
Exemple #8
0
 def _process_layer(self, layer_elem, image, layer):
   background_layer, self._tagged_layer_copies['background'] = self._insert_layer(
     image, self._tagged_layer_elems['background'], self._tagged_layer_copies['background'], insert_index=0)
   
   layer_copy = pdb.gimp_layer_new_from_drawable(layer, image)
   pdb.gimp_image_insert_layer(image, layer_copy, None, 0)
   pdb.gimp_item_set_visible(layer_copy, True)
   
   if pdb.gimp_item_is_group(layer_copy):
     layer_copy = pgpdb.merge_layer_group(layer_copy)
   
   self._on_after_insert_layer_func(layer_copy)
   
   if self.export_settings['more_operations/ignore_layer_modes'].value:
     layer_copy.mode = gimpenums.NORMAL_MODE
   
   if self.export_settings['more_operations/inherit_transparency_from_groups'].value:
     layer_copy.opacity = 100.0 * functools.reduce(
       lambda layer1_opacity, layer2_opacity: layer1_opacity * layer2_opacity,
       [parent.item.opacity / 100.0 for parent in layer_elem.parents] + [layer_elem.item.opacity / 100.0])
   
   image.active_layer = layer_copy
   
   foreground_layer, self._tagged_layer_copies['foreground'] = self._insert_layer(
     image, self._tagged_layer_elems['foreground'], self._tagged_layer_copies['foreground'], insert_index=0)
   
   image.active_layer = layer_copy
   
   layer_copy = self._crop_layer(image, layer_copy, background_layer, foreground_layer)
   layer_copy = self._merge_and_resize_layer(image, layer_copy)
   
   image.active_layer = layer_copy
   
   # Remove the " copy" suffix from the layer name, which is preserved in
   # formats supporting layers (XCF, PSD, ...).
   layer_copy.name = layer.name
   
   return layer_copy