Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions gimpformats/GimpIOBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self, parent: Any = None) -> None:
self.isGroup = None
self.groupItemFlags: int = 0
self.positionLocked: bool = False
self.visibilityLocked: bool = False
self.opacity: float = 1.0
self.colorTag: TagColor = TagColor.Blue
self.compositeMode: CompositeMode = CompositeMode.Union
Expand Down Expand Up @@ -320,14 +321,16 @@ def _propertyDecode(self, prop: int, data: bytearray) -> int:
self.groupItemFlags = ioBuf.u32
elif _prop_cmp(prop, AllProps.PROP_LOCK_POSITION):
self.positionLocked = ioBuf.boolean
elif _prop_cmp(prop, AllProps.PROP_LOCK_VISIBILITY):
self.visibilityLocked = ioBuf.boolean
elif _prop_cmp(prop, AllProps.PROP_FLOAT_OPACITY):
self.opacity = ioBuf.float32
elif _prop_cmp(prop, AllProps.PROP_COLOR_TAG):
self.colorTag = list(TagColor)[ioBuf.u32]
elif _prop_cmp(prop, AllProps.PROP_COMPOSITE_MODE):
self.compositeMode = list(CompositeMode)[ioBuf.i32]
self.compositeMode = list(CompositeMode)[abs(ioBuf.i32) - 1]
elif _prop_cmp(prop, AllProps.PROP_COMPOSITE_SPACE):
self.compositeSpace = list(CompositeSpace)[ioBuf.i32]
self.compositeSpace = list(CompositeSpace)[abs(ioBuf.i32) - 1]
elif _prop_cmp(prop, AllProps.PROP_BLEND_SPACE):
self.blendSpace = ioBuf.u32
elif _prop_cmp(prop, AllProps.PROP_FLOAT_COLOR):
Expand Down Expand Up @@ -479,6 +482,9 @@ def _propertyEncode(self, prop: int) -> bytearray:
elif _prop_cmp(prop, AllProps.PROP_LOCK_POSITION):
if self.positionLocked is not None and self.positionLocked:
ioBuf.boolean = self.positionLocked
elif _prop_cmp(prop, AllProps.PROP_LOCK_VISIBILITY):
if self.visibilityLocked is not None and self.visibilityLocked:
ioBuf.boolean = self.visibilityLocked
elif _prop_cmp(prop, AllProps.PROP_FLOAT_OPACITY):
if self.opacity is not None and isinstance(self.opacity, float):
ioBuf.float32 = self.opacity
Expand All @@ -487,10 +493,10 @@ def _propertyEncode(self, prop: int) -> bytearray:
ioBuf.u32 = list(TagColor).index(self.colorTag)
elif _prop_cmp(prop, AllProps.PROP_COMPOSITE_MODE):
if self.compositeMode is not None:
ioBuf.i32 = list(CompositeMode).index(self.compositeMode)
ioBuf.i32 = list(CompositeMode).index(self.compositeMode) + 1
elif _prop_cmp(prop, AllProps.PROP_COMPOSITE_SPACE):
if self.compositeSpace is not None:
ioBuf.i32 = list(CompositeSpace).index(self.compositeSpace)
ioBuf.i32 = list(CompositeSpace).index(self.compositeSpace) + 1
elif _prop_cmp(prop, AllProps.PROP_BLEND_SPACE):
if self.blendSpace is not None:
ioBuf.u32 = self.blendSpace
Expand Down
8 changes: 4 additions & 4 deletions gimpformats/GimpImageLevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,20 @@ def _decodeRLE(self, data: bytearray, pixels: int, bpp: int, index: int = 0) ->
index += 1

if 0 <= opcode <= 126: # Short run of identical bytes
val = data[index]
val = data[index:index+1] # use 1-len bytearray to avoid slow list
index += 1
ret[chan].extend([val] * (opcode + 1)) # Extend is faster than append in a loop
ret[chan].extend(val * (opcode + 1)) # Extend is faster than append in a loop
n += opcode + 1

elif opcode == 127: # Long run of identical bytes
m = data[index]
index += 1
b = data[index]
index += 1
val = data[index]
val = data[index:index+1] # use 1-len bytearray to avoid slow list
index += 1
amt = (m << 8) + b
ret[chan].extend([val] * amt)
ret[chan].extend(val * amt)
n += amt

elif opcode == 128: # Long run of different bytes
Expand Down
5 changes: 3 additions & 2 deletions gimpformats/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class CompositeMode(Enum):

class CompositeSpace(Enum):
RGB_linear = "RGB (linear)"
RGB_perceptual = "RGB (perceptual)"
RGB_profile = "RGB (from color profile)"
LAB = "LAB"
RGB_perceptual = "RGB (perceptual)"


class TagColor(Enum):
Expand Down Expand Up @@ -150,7 +151,7 @@ class GeneralProperties(Enum):
PROP_VISIBLE = 8
PROP_TATTOO = 20
# PROP_ITEM_SET_ITEM = 41
# PROP_LOCK_VISIBILITY = 42
PROP_LOCK_VISIBILITY = 42


class ImageProperties(Enum):
Expand Down
8 changes: 4 additions & 4 deletions tests/with_paths/with_paths.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Layers:
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.None_Color
Composite Mode: CompositeMode.Intersection
Composite Space: CompositeSpace.LAB
Composite Mode: CompositeMode.Union
Composite Space: CompositeSpace.RGB_linear
Blend Space: 0
Vectors Version: 0
Active Vector Index: 0
Expand Down Expand Up @@ -88,8 +88,8 @@ Layers:
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.None_Color
Composite Mode: CompositeMode.Intersection
Composite Space: CompositeSpace.LAB
Composite Mode: CompositeMode.Union
Composite Space: CompositeSpace.RGB_linear
Blend Space: 0
Vectors Version: 0
Active Vector Index: 0
Expand Down
8 changes: 4 additions & 4 deletions tests/xcf_document/dest/issue_14.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ Layers:
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.None_Color
Composite Mode: CompositeMode.Intersection
Composite Space: CompositeSpace.LAB
Composite Mode: CompositeMode.Union
Composite Space: CompositeSpace.RGB_linear
Blend Space: 0
Vectors Version: 0
Active Vector Index: 0
Expand Down Expand Up @@ -90,8 +90,8 @@ Layers:
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.None_Color
Composite Mode: CompositeMode.Intersection
Composite Space: CompositeSpace.LAB
Composite Mode: CompositeMode.Union
Composite Space: CompositeSpace.RGB_linear
Blend Space: 0
Vectors Version: 0
Active Vector Index: 0
Expand Down
158 changes: 158 additions & 0 deletions tests/xcf_document/dest/layer_comp_modes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
Version: 23
Width: 10
Height: 10
Base Color Mode: 0
Precision: <GimpPrecision bits=16-bit, gamma=gamma, format=integer>
Selected: False
Is Selection: False
Blend Mode: GimpBlendMode.ADDITION
Visible: False
Is Linked: False
Lock Alpha: False
Apply Mask: False
Editing Mask: False
Show Mask: False
Show Masked: False
X Offset: 0
Y Offset: 0
Compression: CompressionMode.RLE
Horizontal Resolution: 300.0
Vertical Resolution: 300.0
Unique Id: 00000006
Units: Units.Millimetres
Group Item Flags: 0
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.Blue
Composite Mode: CompositeMode.Union
Composite Space: CompositeSpace.RGB_linear
Vectors Version: 0
Active Vector Index: 0
Paths: []
Offset: 0 x 0
Resolution: 300.0ppi x 300.0ppi
Parasites:
<GimpParasite name='gimp-comment', flags=1, data_len=18>
<GimpParasite name='gimp-image-grid', flags=1, data_len=281>
<GimpParasite name='gimp-image-metadata', flags=1, data_len=1379>
Layers:
Name: RGB Color Profile - Intersection
Size: 10 x 10
colorMode: RGB color with alpha
Selected: True
Is Selection: False
Blend Mode: GimpBlendMode.NORMAL
Visible: True
Is Linked: False
Lock Alpha: False
Apply Mask: False
Editing Mask: False
Show Mask: False
Show Masked: False
X Offset: 0
Y Offset: 0
Compression: CompressionMode.None_Compression
Unique Id: 00000006
Units: Units.Inches
Locked: False
Group Item Flags: 0
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.None_Color
Composite Mode: CompositeMode.Intersection
Composite Space: CompositeSpace.RGB_profile
Blend Space: 0
Vectors Version: 0
Active Vector Index: 0
Paths: []
Offset: 0 x 0
Name: RGB Linear - Clip To Backdrop
Size: 10 x 10
colorMode: RGB color with alpha
Selected: False
Is Selection: False
Blend Mode: GimpBlendMode.NORMAL
Visible: True
Is Linked: False
Lock Alpha: False
Apply Mask: False
Editing Mask: False
Show Mask: False
Show Masked: False
X Offset: 0
Y Offset: 0
Compression: CompressionMode.None_Compression
Unique Id: 00000004
Units: Units.Inches
Locked: False
Group Item Flags: 0
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.None_Color
Composite Mode: CompositeMode.Clip_to_backdrop
Composite Space: CompositeSpace.RGB_linear
Blend Space: 0
Vectors Version: 0
Active Vector Index: 0
Paths: []
Offset: 0 x 0
Name: RGB Perceptual - Union
Size: 10 x 10
colorMode: RGB color with alpha
Selected: False
Is Selection: False
Blend Mode: GimpBlendMode.NORMAL
Visible: True
Is Linked: False
Lock Alpha: False
Apply Mask: False
Editing Mask: False
Show Mask: False
Show Masked: False
X Offset: 0
Y Offset: 0
Compression: CompressionMode.None_Compression
Unique Id: 00000003
Units: Units.Inches
Locked: False
Group Item Flags: 0
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.None_Color
Composite Mode: CompositeMode.Union
Composite Space: CompositeSpace.RGB_perceptual
Blend Space: 0
Vectors Version: 0
Active Vector Index: 0
Paths: []
Offset: 0 x 0
Name: Auto
Size: 10 x 10
colorMode: RGB color with alpha
Selected: False
Is Selection: False
Blend Mode: GimpBlendMode.NORMAL
Visible: True
Is Linked: False
Lock Alpha: False
Apply Mask: False
Editing Mask: False
Show Mask: False
Show Masked: False
X Offset: 0
Y Offset: 0
Compression: CompressionMode.None_Compression
Unique Id: 00000005
Units: Units.Inches
Locked: False
Group Item Flags: 0
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.None_Color
Composite Mode: CompositeMode.Union
Composite Space: CompositeSpace.RGB_linear
Blend Space: 0
Vectors Version: 0
Active Vector Index: 0
Paths: []
Offset: 0 x 0
12 changes: 6 additions & 6 deletions tests/xcf_document/dest/layer_groups.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ Layers:
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.None_Color
Composite Mode: CompositeMode.Intersection
Composite Space: CompositeSpace.LAB
Composite Mode: CompositeMode.Union
Composite Space: CompositeSpace.RGB_linear
Blend Space: 0
Vectors Version: 0
Active Vector Index: 0
Expand Down Expand Up @@ -89,8 +89,8 @@ Layers:
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.None_Color
Composite Mode: CompositeMode.Intersection
Composite Space: CompositeSpace.LAB
Composite Mode: CompositeMode.Union
Composite Space: CompositeSpace.RGB_linear
Blend Space: 0
Vectors Version: 0
Active Vector Index: 0
Expand Down Expand Up @@ -119,8 +119,8 @@ Layers:
Position Locked: False
Opacity: 1.0
Color Tag: TagColor.None_Color
Composite Mode: CompositeMode.Intersection
Composite Space: CompositeSpace.LAB
Composite Mode: CompositeMode.Union
Composite Space: CompositeSpace.RGB_linear
Blend Space: 0
Vectors Version: 0
Active Vector Index: 0
Expand Down
Loading