Support jobs argument

This commit is contained in:
mmcwilliams 2023-11-30 08:09:53 -05:00
parent 8ac70d5a08
commit 328d538824
1 changed files with 5 additions and 23 deletions

View File

@ -25,6 +25,7 @@ class Posterize:
previews = []
svgs = []
headless = False
jobs = 1
pallete = None
pallete_space = 'BGR'
@ -43,13 +44,14 @@ class Posterize:
output = None
def __init__ (self, image, pallete, n_colors, output, headless) :
def __init__ (self, image, pallete, n_colors, output, headless, jobs) :
self.image = cv2.imread(image)
(self.h, self.w) = self.image.shape[:2]
self.pallete = pallete
self.n_colors = n_colors + 1
self.output = output
self.headless = headless
self.jobs = jobs
if not os.path.exists(self.output) :
print(f'Output directory {self.output} does not exist, creating...')
@ -92,34 +94,14 @@ class Posterize:
layer_name = f'WHITE.png'
output_layer = os.path.join(self.output, layer_name)
cv2.imwrite(output_layer, mask)
self.layers.append({
'layer' : output_layer,
'color' : white,
'space' : self.pallete_space
})
for i in range(self.n_colors) :
if list_match(self.original_colors[i], white) :
continue
original = self.original_colors[i]
mask = self.extract_color_mask(self.image, original)
original_normalized = convert_color(original, 'BGR', self.pallete_space)
if self.pallete_space == 'RGB' or self.pallete_space == 'BGR' :
closest, dist = closest_color_weighted_euclidean(self.colors, original_normalized, self.pallete_space)
else :
closest, dist = closest_color_euclidean(self.colors, original_normalized)
self.colors = remove_from_list(self.colors, closest)
name = self.match_color_name(closest)
layer_name = f'{name}.png'
output_layer = os.path.join(self.output, layer_name)
cv2.imwrite(output_layer, mask)
self.layers.append({
'layer' : output_layer,
'color' : closest,
'space' : self.pallete_space
})
mask = cv2.bitwise_not(mask)
composite[mask > 0] = np.array(convert_color(closest, self.pallete_space, 'BGR'))
composite_name = f'posterized.png'
composite_path = os.path.join(self.output, composite_name)