Skip to content

Commit d437c3e

Browse files
committed
Refactor first image processing
1 parent d882e26 commit d437c3e

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

lfgen/image_processor.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,23 @@ def set_dims_and_get_array(self, x, y, extension):
8787
self.buffer_width = (self.max_x+1)*self.output_width
8888

8989
return self._get_array(image)
90-
91-
def set_shared_array(self, x, y, extension, array):
92-
np_img = np.ndarray((self.buffer_height, self.buffer_width, 3), dtype=np.uint8, buffer=array.buf)
93-
90+
91+
def set_shared_array_from_image(self, x, y, np_img, image):
9492
array_x_start = x*self.output_width
9593
array_y_start = (self.max_y-y)*self.output_height
9694

9795
np_img[
9896
array_y_start:array_y_start+self.output_height,
9997
array_x_start:array_x_start+self.output_width,
10098
:
101-
] = self._get_array(self._get_image(x, y, extension))
99+
] = image
100+
101+
102+
def set_shared_array(self, x, y, extension, array):
103+
self.set_shared_array_from_image(
104+
x,
105+
y,
106+
np.ndarray((self.buffer_height, self.buffer_width, 3), dtype=np.uint8, buffer=array.buf),
107+
self._get_array(self._get_image(x, y, extension))
108+
)
102109

lfgen/main.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ def main():
110110

111111
with multiprocessing.managers.SharedMemoryManager() as smm:
112112
with concurrent.futures.ProcessPoolExecutor(
113-
min(arguments.jobs, total_images-1),
114-
mp_context=multiprocessing.get_context('spawn')
115-
) as pool:
113+
min(arguments.jobs, total_images-1),
114+
mp_context=multiprocessing.get_context('spawn')
115+
) as pool:
116116
future_to_coord = {}
117117
for x in range(max_x+1):
118118
for y in range(max_y+1):
@@ -131,13 +131,8 @@ def main():
131131
(max_x+1)*img_processor.output_width,
132132
3
133133
), buffer=shared_array.buf, dtype=np.uint8)
134-
start_y = (max_y-y)*img_processor.output_height
135-
start_x = x*img_processor.output_width
136-
shared_np_array[
137-
start_y:start_y+img_processor.output_height,
138-
start_x:start_x+img_processor.output_width,
139-
:
140-
] = subimage
134+
135+
img_processor.set_shared_array_from_image(x, y, shared_np_array, subimage)
141136

142137
extra_config["displayFOV"] = [img_processor.fov_x, img_processor.fov_y]
143138
progress.set_postfix_str(f'Completed: ({x}, {y})')

0 commit comments

Comments
 (0)