Skip to content

Commit eb2ac05

Browse files
Merge pull request #3 from willstott101/master
Fix parsing of layer composite props, and add parsing of PROP_LOCK_VISIBILITY.
2 parents 26ee172 + 7aac86c commit eb2ac05

11 files changed

Lines changed: 208 additions & 43 deletions

‎gimpformats/GimpIOBase.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(self, parent: Any = None) -> None:
6767
self.isGroup = None
6868
self.groupItemFlags: int = 0
6969
self.positionLocked: bool = False
70+
self.visibilityLocked: bool = False
7071
self.opacity: float = 1.0
7172
self.colorTag: TagColor = TagColor.Blue
7273
self.compositeMode: CompositeMode = CompositeMode.Union
@@ -320,14 +321,16 @@ def _propertyDecode(self, prop: int, data: bytearray) -> int:
320321
self.groupItemFlags = ioBuf.u32
321322
elif _prop_cmp(prop, AllProps.PROP_LOCK_POSITION):
322323
self.positionLocked = ioBuf.boolean
324+
elif _prop_cmp(prop, AllProps.PROP_LOCK_VISIBILITY):
325+
self.visibilityLocked = ioBuf.boolean
323326
elif _prop_cmp(prop, AllProps.PROP_FLOAT_OPACITY):
324327
self.opacity = ioBuf.float32
325328
elif _prop_cmp(prop, AllProps.PROP_COLOR_TAG):
326329
self.colorTag = list(TagColor)[ioBuf.u32]
327330
elif _prop_cmp(prop, AllProps.PROP_COMPOSITE_MODE):
328-
self.compositeMode = list(CompositeMode)[ioBuf.i32]
331+
self.compositeMode = list(CompositeMode)[abs(ioBuf.i32) - 1]
329332
elif _prop_cmp(prop, AllProps.PROP_COMPOSITE_SPACE):
330-
self.compositeSpace = list(CompositeSpace)[ioBuf.i32]
333+
self.compositeSpace = list(CompositeSpace)[abs(ioBuf.i32) - 1]
331334
elif _prop_cmp(prop, AllProps.PROP_BLEND_SPACE):
332335
self.blendSpace = ioBuf.u32
333336
elif _prop_cmp(prop, AllProps.PROP_FLOAT_COLOR):
@@ -479,6 +482,9 @@ def _propertyEncode(self, prop: int) -> bytearray:
479482
elif _prop_cmp(prop, AllProps.PROP_LOCK_POSITION):
480483
if self.positionLocked is not None and self.positionLocked:
481484
ioBuf.boolean = self.positionLocked
485+
elif _prop_cmp(prop, AllProps.PROP_LOCK_VISIBILITY):
486+
if self.visibilityLocked is not None and self.visibilityLocked:
487+
ioBuf.boolean = self.visibilityLocked
482488
elif _prop_cmp(prop, AllProps.PROP_FLOAT_OPACITY):
483489
if self.opacity is not None and isinstance(self.opacity, float):
484490
ioBuf.float32 = self.opacity
@@ -487,10 +493,10 @@ def _propertyEncode(self, prop: int) -> bytearray:
487493
ioBuf.u32 = list(TagColor).index(self.colorTag)
488494
elif _prop_cmp(prop, AllProps.PROP_COMPOSITE_MODE):
489495
if self.compositeMode is not None:
490-
ioBuf.i32 = list(CompositeMode).index(self.compositeMode)
496+
ioBuf.i32 = list(CompositeMode).index(self.compositeMode) + 1
491497
elif _prop_cmp(prop, AllProps.PROP_COMPOSITE_SPACE):
492498
if self.compositeSpace is not None:
493-
ioBuf.i32 = list(CompositeSpace).index(self.compositeSpace)
499+
ioBuf.i32 = list(CompositeSpace).index(self.compositeSpace) + 1
494500
elif _prop_cmp(prop, AllProps.PROP_BLEND_SPACE):
495501
if self.blendSpace is not None:
496502
ioBuf.u32 = self.blendSpace

‎gimpformats/GimpImageLevel.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,20 @@ def _decodeRLE(self, data: bytearray, pixels: int, bpp: int, index: int = 0) ->
127127
index += 1
128128

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

135135
elif opcode == 127: # Long run of identical bytes
136136
m = data[index]
137137
index += 1
138138
b = data[index]
139139
index += 1
140-
val = data[index]
140+
val = data[index:index+1] # use 1-len bytearray to avoid slow list
141141
index += 1
142142
amt = (m << 8) + b
143-
ret[chan].extend([val] * amt)
143+
ret[chan].extend(val * amt)
144144
n += amt
145145

146146
elif opcode == 128: # Long run of different bytes

‎gimpformats/enums.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class CompositeMode(Enum):
2626

2727
class CompositeSpace(Enum):
2828
RGB_linear = "RGB (linear)"
29-
RGB_perceptual = "RGB (perceptual)"
29+
RGB_profile = "RGB (from color profile)"
3030
LAB = "LAB"
31+
RGB_perceptual = "RGB (perceptual)"
3132

3233

3334
class TagColor(Enum):
@@ -150,7 +151,7 @@ class GeneralProperties(Enum):
150151
PROP_VISIBLE = 8
151152
PROP_TATTOO = 20
152153
# PROP_ITEM_SET_ITEM = 41
153-
# PROP_LOCK_VISIBILITY = 42
154+
PROP_LOCK_VISIBILITY = 42
154155

155156

156157
class ImageProperties(Enum):

‎tests/with_paths/with_paths.txt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ Layers:
5858
Position Locked: False
5959
Opacity: 1.0
6060
Color Tag: TagColor.None_Color
61-
Composite Mode: CompositeMode.Intersection
62-
Composite Space: CompositeSpace.LAB
61+
Composite Mode: CompositeMode.Union
62+
Composite Space: CompositeSpace.RGB_linear
6363
Blend Space: 0
6464
Vectors Version: 0
6565
Active Vector Index: 0
@@ -88,8 +88,8 @@ Layers:
8888
Position Locked: False
8989
Opacity: 1.0
9090
Color Tag: TagColor.None_Color
91-
Composite Mode: CompositeMode.Intersection
92-
Composite Space: CompositeSpace.LAB
91+
Composite Mode: CompositeMode.Union
92+
Composite Space: CompositeSpace.RGB_linear
9393
Blend Space: 0
9494
Vectors Version: 0
9595
Active Vector Index: 0

‎tests/xcf_document/dest/issue_14.txt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ Layers:
6060
Position Locked: False
6161
Opacity: 1.0
6262
Color Tag: TagColor.None_Color
63-
Composite Mode: CompositeMode.Intersection
64-
Composite Space: CompositeSpace.LAB
63+
Composite Mode: CompositeMode.Union
64+
Composite Space: CompositeSpace.RGB_linear
6565
Blend Space: 0
6666
Vectors Version: 0
6767
Active Vector Index: 0
@@ -90,8 +90,8 @@ Layers:
9090
Position Locked: False
9191
Opacity: 1.0
9292
Color Tag: TagColor.None_Color
93-
Composite Mode: CompositeMode.Intersection
94-
Composite Space: CompositeSpace.LAB
93+
Composite Mode: CompositeMode.Union
94+
Composite Space: CompositeSpace.RGB_linear
9595
Blend Space: 0
9696
Vectors Version: 0
9797
Active Vector Index: 0
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
Version: 23
2+
Width: 10
3+
Height: 10
4+
Base Color Mode: 0
5+
Precision: <GimpPrecision bits=16-bit, gamma=gamma, format=integer>
6+
Selected: False
7+
Is Selection: False
8+
Blend Mode: GimpBlendMode.ADDITION
9+
Visible: False
10+
Is Linked: False
11+
Lock Alpha: False
12+
Apply Mask: False
13+
Editing Mask: False
14+
Show Mask: False
15+
Show Masked: False
16+
X Offset: 0
17+
Y Offset: 0
18+
Compression: CompressionMode.RLE
19+
Horizontal Resolution: 300.0
20+
Vertical Resolution: 300.0
21+
Unique Id: 00000006
22+
Units: Units.Millimetres
23+
Group Item Flags: 0
24+
Position Locked: False
25+
Opacity: 1.0
26+
Color Tag: TagColor.Blue
27+
Composite Mode: CompositeMode.Union
28+
Composite Space: CompositeSpace.RGB_linear
29+
Vectors Version: 0
30+
Active Vector Index: 0
31+
Paths: []
32+
Offset: 0 x 0
33+
Resolution: 300.0ppi x 300.0ppi
34+
Parasites:
35+
<GimpParasite name='gimp-comment', flags=1, data_len=18>
36+
<GimpParasite name='gimp-image-grid', flags=1, data_len=281>
37+
<GimpParasite name='gimp-image-metadata', flags=1, data_len=1379>
38+
Layers:
39+
Name: RGB Color Profile - Intersection
40+
Size: 10 x 10
41+
colorMode: RGB color with alpha
42+
Selected: True
43+
Is Selection: False
44+
Blend Mode: GimpBlendMode.NORMAL
45+
Visible: True
46+
Is Linked: False
47+
Lock Alpha: False
48+
Apply Mask: False
49+
Editing Mask: False
50+
Show Mask: False
51+
Show Masked: False
52+
X Offset: 0
53+
Y Offset: 0
54+
Compression: CompressionMode.None_Compression
55+
Unique Id: 00000006
56+
Units: Units.Inches
57+
Locked: False
58+
Group Item Flags: 0
59+
Position Locked: False
60+
Opacity: 1.0
61+
Color Tag: TagColor.None_Color
62+
Composite Mode: CompositeMode.Intersection
63+
Composite Space: CompositeSpace.RGB_profile
64+
Blend Space: 0
65+
Vectors Version: 0
66+
Active Vector Index: 0
67+
Paths: []
68+
Offset: 0 x 0
69+
Name: RGB Linear - Clip To Backdrop
70+
Size: 10 x 10
71+
colorMode: RGB color with alpha
72+
Selected: False
73+
Is Selection: False
74+
Blend Mode: GimpBlendMode.NORMAL
75+
Visible: True
76+
Is Linked: False
77+
Lock Alpha: False
78+
Apply Mask: False
79+
Editing Mask: False
80+
Show Mask: False
81+
Show Masked: False
82+
X Offset: 0
83+
Y Offset: 0
84+
Compression: CompressionMode.None_Compression
85+
Unique Id: 00000004
86+
Units: Units.Inches
87+
Locked: False
88+
Group Item Flags: 0
89+
Position Locked: False
90+
Opacity: 1.0
91+
Color Tag: TagColor.None_Color
92+
Composite Mode: CompositeMode.Clip_to_backdrop
93+
Composite Space: CompositeSpace.RGB_linear
94+
Blend Space: 0
95+
Vectors Version: 0
96+
Active Vector Index: 0
97+
Paths: []
98+
Offset: 0 x 0
99+
Name: RGB Perceptual - Union
100+
Size: 10 x 10
101+
colorMode: RGB color with alpha
102+
Selected: False
103+
Is Selection: False
104+
Blend Mode: GimpBlendMode.NORMAL
105+
Visible: True
106+
Is Linked: False
107+
Lock Alpha: False
108+
Apply Mask: False
109+
Editing Mask: False
110+
Show Mask: False
111+
Show Masked: False
112+
X Offset: 0
113+
Y Offset: 0
114+
Compression: CompressionMode.None_Compression
115+
Unique Id: 00000003
116+
Units: Units.Inches
117+
Locked: False
118+
Group Item Flags: 0
119+
Position Locked: False
120+
Opacity: 1.0
121+
Color Tag: TagColor.None_Color
122+
Composite Mode: CompositeMode.Union
123+
Composite Space: CompositeSpace.RGB_perceptual
124+
Blend Space: 0
125+
Vectors Version: 0
126+
Active Vector Index: 0
127+
Paths: []
128+
Offset: 0 x 0
129+
Name: Auto
130+
Size: 10 x 10
131+
colorMode: RGB color with alpha
132+
Selected: False
133+
Is Selection: False
134+
Blend Mode: GimpBlendMode.NORMAL
135+
Visible: True
136+
Is Linked: False
137+
Lock Alpha: False
138+
Apply Mask: False
139+
Editing Mask: False
140+
Show Mask: False
141+
Show Masked: False
142+
X Offset: 0
143+
Y Offset: 0
144+
Compression: CompressionMode.None_Compression
145+
Unique Id: 00000005
146+
Units: Units.Inches
147+
Locked: False
148+
Group Item Flags: 0
149+
Position Locked: False
150+
Opacity: 1.0
151+
Color Tag: TagColor.None_Color
152+
Composite Mode: CompositeMode.Union
153+
Composite Space: CompositeSpace.RGB_linear
154+
Blend Space: 0
155+
Vectors Version: 0
156+
Active Vector Index: 0
157+
Paths: []
158+
Offset: 0 x 0

‎tests/xcf_document/dest/layer_groups.txt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ Layers:
5959
Position Locked: False
6060
Opacity: 1.0
6161
Color Tag: TagColor.None_Color
62-
Composite Mode: CompositeMode.Intersection
63-
Composite Space: CompositeSpace.LAB
62+
Composite Mode: CompositeMode.Union
63+
Composite Space: CompositeSpace.RGB_linear
6464
Blend Space: 0
6565
Vectors Version: 0
6666
Active Vector Index: 0
@@ -89,8 +89,8 @@ Layers:
8989
Position Locked: False
9090
Opacity: 1.0
9191
Color Tag: TagColor.None_Color
92-
Composite Mode: CompositeMode.Intersection
93-
Composite Space: CompositeSpace.LAB
92+
Composite Mode: CompositeMode.Union
93+
Composite Space: CompositeSpace.RGB_linear
9494
Blend Space: 0
9595
Vectors Version: 0
9696
Active Vector Index: 0
@@ -119,8 +119,8 @@ Layers:
119119
Position Locked: False
120120
Opacity: 1.0
121121
Color Tag: TagColor.None_Color
122-
Composite Mode: CompositeMode.Intersection
123-
Composite Space: CompositeSpace.LAB
122+
Composite Mode: CompositeMode.Union
123+
Composite Space: CompositeSpace.RGB_linear
124124
Blend Space: 0
125125
Vectors Version: 0
126126
Active Vector Index: 0

0 commit comments

Comments
 (0)