Refactoring

This commit is contained in:
Matthias Bisping 2023-01-31 14:37:46 +01:00
parent a3fece8096
commit 6dbe3b6fc9

View File

@ -43,7 +43,11 @@ random_seed = random.randint(0, 2**32 - 1)
# random_seed = 273244862 # empty large table
# random_seed = 3717442900
# random_seed = 2508340737
# random_seed = 2212357755
random_seed = 2212357755
# random_seed = 3400335399
rnd = random.Random(random_seed)
logger.info(f"Random seed: {random_seed}")
@ -318,6 +322,7 @@ def tinted_blank_page(size, color, color_intensity):
@pytest.fixture
def blank_page(size, color, color_intensity):
rnd.seed(random_seed)
page = Image.new("RGBA", size, color=(255, 255, 255, 0))
return page
@ -429,7 +434,7 @@ def compute_pasting_coordinates(smaller: Image, larger: Image.Image):
@pytest.fixture
def page_with_content(blank_page, tinted_blank_page, texture, texture_fn) -> np.ndarray:
def page_with_opaque_content(blank_page, tinted_blank_page, texture, texture_fn) -> np.ndarray:
"""Creates a page with content"""
page_partitioner = rnd.choice(
[
@ -438,17 +443,29 @@ def page_with_content(blank_page, tinted_blank_page, texture, texture_fn) -> np.
]
)
###############################
# texture = random_flip(texture)
# texture = texture_fn(texture)
#
# boxes = page_partitioner(texture)
# content_generator = ContentGenerator()
# boxes = content_generator(boxes)
# page = paste_contents(texture, boxes)
###############################
texture = random_flip(texture)
texture = texture_fn(texture)
boxes = page_partitioner(texture)
content_generator = ContentGenerator()
boxes = content_generator(boxes)
page = paste_contents(texture, boxes)
return page, boxes
@pytest.fixture
def page_with_translucent_content(
blank_page, tinted_blank_page, texture, texture_fn
) -> Tuple[np.ndarray, List[Rectangle]]:
"""Creates a page with content"""
page_partitioner = rnd.choice(
[
TwoColumnPagePartitioner(),
# RandomPagePartitioner(),
]
)
################################
boxes = page_partitioner(blank_page)
content_generator = ContentGenerator()
boxes = content_generator(boxes)
@ -459,7 +476,18 @@ def page_with_content(blank_page, tinted_blank_page, texture, texture_fn) -> np.
page_content = multiply_alpha_where_alpha_channel_is_nonzero(page_content, factor=0.6)
page = superimpose_texture_with_transparency(texture, page_content, crop_to_content=False)
################################
return page, boxes
@pytest.fixture
def page_with_content(
# page_with_translucent_content,
page_with_opaque_content,
) -> np.ndarray:
# page, boxes = page_with_translucent_content
page, boxes = page_with_opaque_content
draw_boxes(page, boxes)