Skip to content

Commit f810700

Browse files
authored
Merge pull request #63 from Kittl/CU-86c42m6a9-Fix-Transparency
Fix transparency CU-86c42m6a9
2 parents 91032f2 + 860d892 commit f810700

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

vectorizing/solvers/color/ColorSolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def solve(self):
3535
self.timer.end_timer()
3636

3737
self.timer.start_timer("Polygon Clipping")
38-
compound_paths = remove_layering(traced_bitmaps, self.img)
38+
compound_paths = remove_layering(traced_bitmaps, self.img, has_background)
3939
self.timer.end_timer()
4040

4141
return [compound_paths, colors, self.img.size[0], self.img.size[1]]

vectorizing/solvers/color/clip.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def create_background_rect(img, padding):
2020
rect.close()
2121
return rect
2222

23-
def remove_layering(traced_bitmaps, img):
23+
def remove_layering(traced_bitmaps, img, has_background):
2424
"""
2525
Performs boolean operations on a list of traced bitmaps
2626
to ensure that they are all disjoint.
@@ -35,6 +35,7 @@ def remove_layering(traced_bitmaps, img):
3535
Parameters:
3636
traced_bitmaps: The list of traced bitmaps (potrace paths).
3737
img: A Pillow image.
38+
has_background: Whether the image has a transparent background
3839
3940
Returns:
4041
The processed list of compound paths.
@@ -43,6 +44,19 @@ def remove_layering(traced_bitmaps, img):
4344
potrace_path_to_compound_path(traced) for traced in traced_bitmaps
4445
]
4546

47+
if has_background:
48+
# If there's a transparent background, the boolean trick
49+
# can't be used because the top path (the one who contains all
50+
# the subsequent ones before they are separated) does not cover
51+
# the total area of the image
52+
for x in range(len(compound_paths) - 1):
53+
next = compound_paths[x + 1]
54+
try:
55+
compound_paths[x] = op(compound_paths[x], next, PathOp.DIFFERENCE)
56+
except:
57+
break
58+
return compound_paths
59+
4660
disjoint_paths = []
4761
for x in range(len(compound_paths) - 1):
4862
# Each base path has bigger padding to reduce

0 commit comments

Comments
 (0)