Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions geoh5py/data/visual_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from __future__ import annotations

import xml.etree.ElementTree as ET
from collections.abc import Sequence

import numpy as np

Expand Down Expand Up @@ -101,19 +102,24 @@ def colour(self) -> None | list:

c_string = (int(element.text)).to_bytes(4, byteorder="little").hex()

return [int(c_string[i : i + 2], 16) for i in range(0, 8, 2)][:3]
# Flip the colour order from BGR to RGB
return [int(c_string[i : i + 2], 16) for i in range(0, 8, 2)][2::-1]

@colour.setter
def colour(self, rgb: list | tuple | np.ndarray):
def colour(self, rgb: Sequence):
if (
not isinstance(rgb, (list, tuple, np.ndarray))
not isinstance(rgb, Sequence)
or len(rgb) not in [3, 4]
or not all(isinstance(val, int) for val in rgb)
):
raise TypeError("Input 'colour' values must be a list of 3 or 4 integers.")

rgb = list(rgb)
if len(rgb) == 3:
rgb = list(rgb) + [255]
rgb += [255]

# Flip the colour order from RGB to BGR
rgb = rgb[2::-1] + [rgb[3]]

byte_string = "".join(f"{val:02x}" for val in rgb)
byte_string.join(f"{255:02x}") # alpha value
Expand Down
4 changes: 2 additions & 2 deletions tests/visual_parameters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def test_visual_parameters(tmp_path, caplog):
assert copy.visual_parameters.colour == viz_params.colour

# Repeat with known color
points.visual_parameters.colour = [0, 255, 0]
points.visual_parameters.colour = [255, 0, 0] # Should be red

with Workspace(h5file_path) as workspace:
points = workspace.get_entity(name)[0]
assert points.visual_parameters.colour == [0, 255, 0]
assert points.visual_parameters.colour == [255, 0, 0]

viz_params = points.visual_parameters
viz_params_b = viz_params.copy()
Expand Down
Loading