Gimpformats Index / Gimpformats / Gimpxcfdocument
Auto-generated documentation for gimpformats.gimpXcfDocument module.
- Gimpxcfdocument
- GimpDocument
- GimpDocument().repr
- GimpDocument().str
- GimpDocument()._render
- GimpDocument().decode
- GimpDocument().deleteRawLayer
- GimpDocument().encode
- GimpDocument().forceFullyLoaded
- GimpDocument().full_repr
- GimpDocument().getLayer
- GimpDocument().image
- GimpDocument().insertRawLayer
- GimpDocument().iterablePointerDecoder
- GimpDocument().load
- GimpDocument().newLayer
- GimpDocument().raw_layers
- GimpDocument().render
- GimpDocument().save
- GimpDocument().saveNew
- GimpDocument().setRawLayer
- GimpDocument().walkTree
- GimpGroup
- applyMask
- blendModeLookup
- make_thumbnail
- pil2np
- 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.
class GimpDocument(GimpIOBase):
def __init__(self, fileName: BytesIO | str | None = None) -> None: ...Show source in gimpXcfDocument.py:437
Get a textual representation of this object.
def __repr__(self) -> str: ...Show source in gimpXcfDocument.py:433
Get a textual representation of this object.
def __str__(self) -> str: ...Show source in gimpXcfDocument.py:481
Perform the full project render over the current project.
Type: PIL.Image The fully composited image
def _render(self, current_group: GimpGroup) -> np.ndarray: ...Show source in gimpXcfDocument.py:176
Decode the XCF Header to a GimpDocument.
:param bytearray | bytes data: raw bytes representing the GimpDocument/XCF
indexint - 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
def decode(self, data: bytearray | bytes, index: int = 0) -> int: ...Show source in gimpXcfDocument.py:378
Delete a layer.
def deleteRawLayer(self, index: int) -> None: ...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
def encode(self) -> bytearray: ...Show source in gimpXcfDocument.py:303
Make sure everything is fully loaded from the file.
def forceFullyLoaded(self) -> None: ...Show source in gimpXcfDocument.py:445
Get a textual representation of this object.
def full_repr(self, indent: int = 0) -> str: ...Show source in gimpXcfDocument.py:335
Return a given layer.
def getLayer(self, index: int) -> GimpLayer | GimpGroup: ...Show source in gimpXcfDocument.py:405
Generates a final, compiled image by processing layers and groups.
@property
def image(self) -> Image.Image: ...Show source in gimpXcfDocument.py:370
Insert a layer object at a specific position.
layer- the new layer to insertindex- where to insert the new layer (default=top)
def insertRawLayer(self, layer: GimpLayer, index: int = -1) -> None: ...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
ioBufIO - The raw buffer representing the XCF docobjT - create instances of this type (and decode into this)
Type: tuple[list[int], list[T]] list of int pointers (representing indexes in the XCF), and a list of types representing the data.
def iterablePointerDecoder(
self, ioBuf: IO, cls: type[T]
) -> tuple[list[int], list[T]]: ...Show source in gimpXcfDocument.py:137
Load a gimp xcf and decode the file. See decode for more on this process.
fileName- can be a file name or a file-like object
def load(self, fileName: BytesIO | str) -> None: ...Show source in gimpXcfDocument.py:351
Create a new layer based on a PIL image.
namestr - a name for the new layer- GimpDocument().image Image.Image - pil image
indexint, optional - where to insert the new layer (default=top). Defaults to -1.
GimpLayer- newly created GimpLayer object
def newLayer(self, name: str, image: Image.Image, index: int = -1) -> GimpLayer: ...Show source in gimpXcfDocument.py:314
Decode the image's layers if necessary.
TODO: need to do the same thing with self.Channels
@property
def raw_layers(self) -> list[GimpLayer]: ...Show source in gimpXcfDocument.py:473
Perform the full project render over the current project.
Type: PIL.Image The fully composited image
def render(self, root_group: GimpGroup) -> Image.Image: ...Show source in gimpXcfDocument.py:414
Save this gimp image to a file.
def save(self, filename: str | BytesIO | None = None) -> NoReturn: ...Show source in gimpXcfDocument.py:424
Save a new gimp image to a file.
def saveNew(self, filename: str | None = None) -> NoReturn: ...Show source in gimpXcfDocument.py:345
Assign to a given layer.
def setRawLayer(self, index: int, layer: GimpLayer) -> None: ...Show source in gimpXcfDocument.py:382
def walkTree(self) -> GimpGroup: ...Show source in gimpXcfDocument.py:36
class GimpGroup:
def __init__(self, name: Any) -> None: ...Show source in gimpXcfDocument.py:55
Get a textual representation of this object.
def __repr__(self) -> str: ...Show source in gimpXcfDocument.py:42
def add_layer(self, layer: GimpLayer | GimpGroup) -> None: ...Show source in gimpXcfDocument.py:45
def get_group(self, idx: int) -> GimpGroup: ...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.
def applyMask(
im: np.ndarray, mask_im: Image.Image | None, offsets: tuple[int, int] = (0, 0)
) -> np.ndarray: ...Show source in gimpXcfDocument.py:591
Look up the blend mode from the lookup table.
def blendModeLookup(blend_type: GimpBlendMode) -> BlendMode: ...Show source in gimpXcfDocument.py:585
def make_thumbnail(image: Image.Image) -> None: ...Show source in gimpXcfDocument.py:579
def pil2np(image: Image.Image | None) -> np.ndarray: ...