8000 Parse highlight colour · Issue #38 · ricklupton/rmscene · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Parse highlight colour #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ricklupton opened this issue Dec 2, 2024 · 7 comments
Open

Parse highlight colour #38

ricklupton opened this issue Dec 2, 2024 · 7 comments

Comments

@ricklupton
Copy link
Owner
          Another related question:

Some of the highlight color info is currently in the extra value, I have to do this to get the color code:

def get_color(
    block: SceneLineItemBlock | SceneGlyphItemBlock,
) -> tuple[int, int, int, int]:
    if block.extra_data and len(block.extra_data) >= 5:
        *_, b, g, r, a = block.extra_data
        return (r, g, b, a)

    r, g, b = remarkable_palette[block.item.value.color]
    return (r, g, b, 255)

Should I create a PR here or in rmscene?

Originally posted by @ChenghaoMou in ricklupton/rmc#18 (comment)

@ricklupton
Copy link
Owner Author

@ChenghaoMou it would be best to parse this properly in line_from_stream (

def line_from_stream(stream: TaggedBlockReader, version: int = 2) -> si.Line:
_logger.debug("Reading Line version %d", version)
tool_id = stream.read_int(1)
tool = si.Pen(tool_id)
color_id = stream.read_int(2)
color = si.PenColor(color_id)
thickness_scale = stream.read_double(3)
starting_length = stream.read_float(4)
with stream.read_subblock(5) as block_info:
data_length = block_info.size
point_size = point_serialized_size(version)
if data_length % point_size != 0:
raise ValueError(
"Point data size mismatch: %d is not multiple of point_size"
% data_length
)
num_points = data_length // point_size
points = [point_from_stream(stream, version=version) for _ in range(num_points)]
# XXX unused
timestamp = stream.read_id(6)
if stream.bytes_remaining_in_block() >= 3:
try:
move_id = stream.read_id(7)
except UnexpectedBlockError as _:
move_id = None
else:
move_id = None
return si.Line(color, tool, points, thickness_scale, starting_length, move_id)
) -- (I think)

Can you add a simple-as-possible test file to tests/data which has this highlighter colour information, and a test that shows it's read ok?

@ChenghaoMou
Copy link
Contributor

@ChenghaoMou it would be best to parse this properly in line_from_stream (

def line_from_stream(stream: TaggedBlockReader, version: int = 2) -> si.Line:
_logger.debug("Reading Line version %d", version)
tool_id = stream.read_int(1)
tool = si.Pen(tool_id)
color_id = stream.read_int(2)
color = si.PenColor(color_id)
thickness_scale = stream.read_double(3)
starting_length = stream.read_float(4)
with stream.read_subblock(5) as block_info:
data_length = block_info.size
point_size = point_serialized_size(version)
if data_length % point_size != 0:
raise ValueError(
"Point data size mismatch: %d is not multiple of point_size"
% data_length
)
num_points = data_length // point_size
points = [point_from_stream(stream, version=version) for _ in range(num_points)]
# XXX unused
timestamp = stream.read_id(6)
if stream.bytes_remaining_in_block() >= 3:
try:
move_id = stream.read_id(7)
except UnexpectedBlockError as _:
move_id = None
else:
move_id = None
return si.Line(color, tool, points, thickness_scale, starting_length, move_id)

) -- (I think)

Can you add a simple-as-possible test file to tests/data which has this highlighter colour information, and a test that shows it's read ok?

Thanks for the pointers. I will look into it!

@Utopiah
Copy link
Utopiah commented Mar 16, 2025

Hi,

sorry if already asked but is

  File "/home/fabien/.local/pipx/venvs/rmc/lib/python3.11/site-packages/rmc/exporters/writing_tools.py", line 48, in __init__
    self.base_color = RM_PALETTE[base_color_id]
                      ~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 9
/home/fabien/new.svg:117: parser error : Premature end of data in tag g line 5

from rmc 0.2.1 still related to this issue?

@ChenghaoMou
Copy link
Contributor
ChenghaoMou commented Mar 16, 2025

There is a PR #44, but it is waiting for several other PRs.

@Utopiah Meanwhile, you could try my branch to see if it solves your issue:

uv run --with git+https://github.com/ChenghaoMou/rmscene@feature/highlight_color python -m rmscene --help
# or 
pip install git+https://github.com/ChenghaoMou/rmscene@feature/highlight_color

@Utopiah
Copy link
Utopiah commented Mar 19, 2025

Thanks. It does run but how can I then use this with rmc?

PS: I feel that I install one package manager per Python program, just discovered uv ;)

@Azeirah
Copy link
Contributor
Azeirah commented Mar 19, 2025

Thanks. It does run but how can I then use this with rmc?

PS: I feel that I install one package manager per Python program, just discovered uv ;)

Python's package management situation is uh.. special

@ChenghaoMou
Copy link
Contributor

Thanks. It does run but how can I then use this with rmc?

PS: I feel that I install one package manager per Python program, just discovered uv ;)

You can run it with uv as well:

uv run --with rmc --with git+https://github.com/ChenghaoMou/rmscene@feature/highlight_color python -m rmc.cli --help

In theory, you can just install rmc first, then the modified rmscene, in two separate commands. It should override the one installed with rmc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0