ricklupton / rmscene

Read v6 .rm files from the reMarkable tablet
MIT License
87 stars 16 forks source link

Parse paperSize in SceneInfo #39

Open ricklupton opened 15 hours ago

ricklupton commented 15 hours ago

This commit (https://github.com/Seb-sti1/rmscene/pull/1/commits/9505d1db55c48890953acfe65f22fabc26e823a2) is the addition of paperSize in the SceneInfo class

On the files that had excess bytes, they were 92, 8, 0, 0, 0, 124, 5, 0, 0, 80, 7, 0, 0 which seems to correspond to :

The first implementation I tried was with the code below as it seemed to be closer to a simple value but given the existence of what appears to be a size I changed it and used TaggedBlockReader.read_subblock. Btw I don't know if it would be better to read size/4 uint32 instead of the hardcoded two.

def read_two_int(self, index: int) -> tuple[int, int]:
    """Read a tagged two 4-byte int."""
    self.data.read_tag(index, TagType.Length4)
    first = self.data.read_uint32()
    second = self.data.read_uint32()
    return first, second

def read_two_int_optional(
        self, index: int, default: tp.Optional[float] = None
) -> tp.Optional[tuple[int, int]]:
    """Read a tagged two 4-byte int."""
    return self._read_optional(self.read_two_int, index, default)

Originally posted by @Seb-sti1 in https://github.com/ricklupton/rmscene/issues/34#issuecomment-2486829797

ricklupton commented 15 hours ago

@Seb-sti1 yes please for opening a pull request to add this.

Based on your version here: https://github.com/Seb-sti1/rmscene/commit/9505d1db55c48890953acfe65f22fabc26e823a2

I think the check for bytes_remaining_in_block should be in SceneInfo.from_stream rather than in read_two_int for consistency with the other methods.

And maybe read_int_pair would be a better name but I don't really mind.

Seb-sti1 commented 1 hour ago

Got it, I'll do that as soon as possible (most likely by the week)