Skip to content

Latest commit

 

History

History
580 lines (379 loc) · 13.2 KB

File metadata and controls

580 lines (379 loc) · 13.2 KB

Gimpxcfdocument

Gimpformats Index / Gimpformats / Gimpxcfdocument

Auto-generated documentation for gimpformats.gimpXcfDocument module.

GimpDocument

Show source in gimpXcfDocument.py:60

Pure python implementation of the gimp file format.

Has a series of attributes including the following: self._layers = None self._layerPtr = [] self._channels = [] self._channelPtr = [] self.version = None self.width = 0 self.height = 0 self.baseColorMode = 0 self.precision = None # Precision object self._data = None

The image structure always starts at offset 0 in the XCF file.

byte[9] "gimp xcf " File type identification byte[4] version XCF version byte 0 Zero marks the end of the version tag. uint32 width Width of canvas uint32 height Height of canvas uint32 base_type Color mode of the image; one of 0: RGB color; 1: Grayscale; 2: Indexed color uint32 precision Image precision; this field is only present for XCF 4 or over (since GIMP 2.10.0). property-list Image properties ,----------------- Repeat once for each layer, topmost layer first: | pointer lptr Pointer to the layer structure. -- pointer 0 Zero marks the end of the array of layer pointers. ,------------------ Repeat once for each channel, in no particular order: | pointer cptr Pointer to the channel structure. -- pointer 0 Zero marks the end of the array of channel pointers. ,------------------ Repeat once for each path, in no particular order: | pointer cptr Pointer to the vectors structure. `-- pointer 0 Zero marks the end of the array of vectors pointers.

Signature

class GimpDocument(GimpIOBase):
    def __init__(self, fileName: BytesIO | str | None = None) -> None: ...

See also

GimpDocument().repr

Show source in gimpXcfDocument.py:437

Get a textual representation of this object.

Signature

def __repr__(self) -> str: ...

GimpDocument().str

Show source in gimpXcfDocument.py:433

Get a textual representation of this object.

Signature

def __str__(self) -> str: ...

GimpDocument()._render

Show source in gimpXcfDocument.py:481

Perform the full project render over the current project.

Returns

Type: PIL.Image The fully composited image

Signature

def _render(self, current_group: GimpGroup) -> np.ndarray: ...

See also

GimpDocument().decode

Show source in gimpXcfDocument.py:176

Decode the XCF Header to a GimpDocument.

:param bytearray | bytes data: raw bytes representing the GimpDocument/XCF

Arguments

  • index int - An optional start index, only set this if you know what you're doing :)

Note that this decode function is somewhat lazy with what is decoded. For example, for the layers, the pointers and basic layer info is decoded, in addition to the pointers to the image_hierarchy and masks. However, the actual image data is not loaded.

Image data will be fetched when when calling descendants .image method as appropriate

byte[9] "gimp xcf " byte[4] version byte 0 uint32 width uint32 height uint32 base_type uint32 precision property-list Image properties ,----------------- | pointer lptr layer structure. -- pointer 0 ,------------------ | pointer cptr channel structure. -- pointer 0 ,------------------ | pointer cptr vectors structure. `-- pointer 0

Signature

def decode(self, data: bytearray | bytes, index: int = 0) -> int: ...

GimpDocument().deleteRawLayer

Show source in gimpXcfDocument.py:378

Delete a layer.

Signature

def deleteRawLayer(self, index: int) -> None: ...

GimpDocument().encode

Show source in gimpXcfDocument.py:241

Encode to bytearray.

Similarly to decode, we must start by constructing the XCF header, though we must then add the bytes returned when calling descendants .encode method as appropriate

byte[9] "gimp xcf " byte[4] version byte 0 uint32 width uint32 height uint32 base_type uint32 precision property-list Image properties ,----------------- | pointer lptr layer structure. -- pointer 0 ,------------------ | pointer cptr channel structure. -- pointer 0 ,------------------ | pointer cptr vectors structure. `-- pointer 0

Signature

def encode(self) -> bytearray: ...

GimpDocument().forceFullyLoaded

Show source in gimpXcfDocument.py:303

Make sure everything is fully loaded from the file.

Signature

def forceFullyLoaded(self) -> None: ...

GimpDocument().full_repr

Show source in gimpXcfDocument.py:445

Get a textual representation of this object.

Signature

def full_repr(self, indent: int = 0) -> str: ...

GimpDocument().getLayer

Show source in gimpXcfDocument.py:335

Return a given layer.

Signature

def getLayer(self, index: int) -> GimpLayer | GimpGroup: ...

GimpDocument().image

Show source in gimpXcfDocument.py:405

Generates a final, compiled image by processing layers and groups.

Signature

@property
def image(self) -> Image.Image: ...

GimpDocument().insertRawLayer

Show source in gimpXcfDocument.py:370

Insert a layer object at a specific position.

Arguments

  • layer - the new layer to insert
  • index - where to insert the new layer (default=top)

Signature

def insertRawLayer(self, layer: GimpLayer, index: int = -1) -> None: ...

See also

GimpDocument().iterablePointerDecoder

Show source in gimpXcfDocument.py:146

Iterate over a pointer as defined in the spec. This method is responsible for returning a list of int pointers (representing indexes in the XCF), and a list of types representing the data.

EG.

,----------------- | pointer lptr layer structure. `-- pointer 0

Arguments

  • ioBuf IO - The raw buffer representing the XCF doc
  • obj T - create instances of this type (and decode into this)

Returns

Type: tuple[list[int], list[T]] list of int pointers (representing indexes in the XCF), and a list of types representing the data.

Signature

def iterablePointerDecoder(
    self, ioBuf: IO, cls: type[T]
) -> tuple[list[int], list[T]]: ...

See also

GimpDocument().load

Show source in gimpXcfDocument.py:137

Load a gimp xcf and decode the file. See decode for more on this process.

Arguments

  • fileName - can be a file name or a file-like object

Signature

def load(self, fileName: BytesIO | str) -> None: ...

GimpDocument().newLayer

Show source in gimpXcfDocument.py:351

Create a new layer based on a PIL image.

Arguments


  • name str - a name for the new layer
  • GimpDocument().image Image.Image - pil image
  • index int, optional - where to insert the new layer (default=top). Defaults to -1.

Returns


  • GimpLayer - newly created GimpLayer object

Signature

def newLayer(self, name: str, image: Image.Image, index: int = -1) -> GimpLayer: ...

See also

GimpDocument().raw_layers

Show source in gimpXcfDocument.py:314

Decode the image's layers if necessary.

TODO: need to do the same thing with self.Channels

Signature

@property
def raw_layers(self) -> list[GimpLayer]: ...

See also

GimpDocument().render

Show source in gimpXcfDocument.py:473

Perform the full project render over the current project.

Returns

Type: PIL.Image The fully composited image

Signature

def render(self, root_group: GimpGroup) -> Image.Image: ...

See also

GimpDocument().save

Show source in gimpXcfDocument.py:414

Save this gimp image to a file.

Signature

def save(self, filename: str | BytesIO | None = None) -> NoReturn: ...

GimpDocument().saveNew

Show source in gimpXcfDocument.py:424

Save a new gimp image to a file.

Signature

def saveNew(self, filename: str | None = None) -> NoReturn: ...

GimpDocument().setRawLayer

Show source in gimpXcfDocument.py:345

Assign to a given layer.

Signature

def setRawLayer(self, index: int, layer: GimpLayer) -> None: ...

See also

GimpDocument().walkTree

Show source in gimpXcfDocument.py:382

Signature

def walkTree(self) -> GimpGroup: ...

See also

GimpGroup

Show source in gimpXcfDocument.py:36

Signature

class GimpGroup:
    def __init__(self, name: Any) -> None: ...

GimpGroup().repr

Show source in gimpXcfDocument.py:55

Get a textual representation of this object.

Signature

def __repr__(self) -> str: ...

GimpGroup().add_layer

Show source in gimpXcfDocument.py:42

Signature

def add_layer(self, layer: GimpLayer | GimpGroup) -> None: ...

GimpGroup().get_group

Show source in gimpXcfDocument.py:45

Signature

def get_group(self, idx: int) -> GimpGroup: ...

applyMask

Show source in gimpXcfDocument.py:596

Apply a grayscale Pillow mask to an RGBA NumPy image.

  • Black areas in the mask (0) make corresponding image areas transparent.
  • White areas (255) keep the image unchanged.
  • Gray areas (0-255) result in partial transparency.

Signature

def applyMask(
    im: np.ndarray, mask_im: Image.Image | None, offsets: tuple[int, int] = (0, 0)
) -> np.ndarray: ...

blendModeLookup

Show source in gimpXcfDocument.py:591

Look up the blend mode from the lookup table.

Signature

def blendModeLookup(blend_type: GimpBlendMode) -> BlendMode: ...

make_thumbnail

Show source in gimpXcfDocument.py:585

Signature

def make_thumbnail(image: Image.Image) -> None: ...

pil2np

Show source in gimpXcfDocument.py:579

Signature

def pil2np(image: Image.Image | None) -> np.ndarray: ...