Skip to content

Commit 3bb24be

Browse files
committed
Load font only once, not once per task
1 parent 4aaccee commit 3bb24be

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

rawtools/qualitycontrol.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ def get_side_projection(args, fp):
224224
buffer_size = x * y * np.dtype('uint16').itemsize
225225
logging.debug(f'Allocated memory for a slice (i.e., buffer_size): {buffer_size} bytes')
226226

227+
# Load font
228+
font_fp = '/'.join([os.path.dirname(os.path.realpath(__file__)), 'assets', 'OpenSans-Regular.ttf'])
229+
logging.debug(f"Font filepath: '{font_fp}'")
230+
font = ImageFont.truetype(font_fp, args.font_size)
231+
227232
pbar = tqdm(total = z, desc="Generating side-view projection") # progress bar
228233
with open(fp, mode='rb', buffering=buffer_size) as ifp:
229234
# Load in the first slice
@@ -267,9 +272,6 @@ def get_side_projection(args, fp):
267272
img = ImageMath.eval('im/256', {'im': img }).convert('L').convert('RGBA')
268273
draw = ImageDraw.Draw(img)
269274

270-
font_fp = '/'.join([os.path.dirname(os.path.realpath(__file__)), 'assets', 'OpenSans-Regular.ttf'])
271-
logging.debug(f"Font filepath: '{font_fp}'")
272-
font = ImageFont.truetype(font_fp, args.font_size)
273275
ascent, descent = font.getmetrics()
274276
offset = (ascent + descent) // 2
275277

0 commit comments

Comments
 (0)