Verified Commit 2e938603 authored by Brad Smith's avatar Brad Smith

use numpy ndarray instead of dict for color_rgb

parent f4b75c5f
......@@ -4,6 +4,7 @@ from mcatools.definitions import (
CHUNK_WIDTH_BLOCKS,
REGION_WIDTH_BLOCKS,
REGION_TOTAL_BLOCKS,
MAX_BLOCK_ID,
)
from mcatools.region import calculate_chunk_bounds, Region
......@@ -107,11 +108,10 @@ colors_hex = {
165: "ff6d3d",
166: "d8bf8d",
167: "f2b48d",
999: "ccffff", # special to use for unknown biome IDs
}
colors_rgb = dict()
colors_rgb = np.full((MAX_BLOCK_ID, 3), fill_value=255, dtype=np.uint8)
for biome_id, hexstring in colors_hex.items():
color_bytes = bytes.fromhex(hexstring)
rgb = [color_bytes[0], color_bytes[1], color_bytes[2]]
colors_rgb[biome_id] = np.array(rgb, dtype=np.uint8)
colors_rgb[biome_id] = color_bytes[0], color_bytes[1], color_bytes[2]
......@@ -8,6 +8,8 @@ REGION_WIDTH_BLOCKS = 512 # 16 * 32
REGION_WIDTH_BLOCKS_BITS = 9 # 2**9 == 515
REGION_TOTAL_BLOCKS = 262_144 # 512 * 512
MAX_BLOCK_ID = 4096 # for the Anvil file format
class BiomeType(Enum):
ocean = 0
......
......@@ -19,11 +19,7 @@ def save_biome_image_rgb(biome_data: np.ndarray, filename: str):
for index, biome_id in tqdm.tqdm(
enumerate(biome_data.flatten()), desc="coloring biome", total=biome_data.size
):
try:
color_data[index] = colors_rgb[biome_id]
except KeyError:
logging.error(f"Unknown biome id {biome_id}")
color_data[index] = colors_rgb[999] # magic value for unknown biomes
color_data[index] = colors_rgb[biome_id]
colors = color_data.reshape(biome_data.shape[0], biome_data.shape[1], 3)
im = Image.fromarray(colors, "RGB")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment