Skip to content
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

uncompressed bitmap length error #8

Closed
fbalobanov opened this issue Nov 10, 2021 · 7 comments
Closed

uncompressed bitmap length error #8

fbalobanov opened this issue Nov 10, 2021 · 7 comments

Comments

@fbalobanov
Copy link

Hi, thanks for the library, but it doesn't work for all files. I've tried to convert several notes and some of them are failing with the mistakes like this:


DecoderException Traceback (most recent call last)
d:\Dropbox#PY\supernote-tool-master\supernote-tool.py in
25 for i in range(0, total_pages):
26 converter = sn.converter.ImageConverter(notebook)
---> 27 img = converter.convert(i)
28
29 html += '
'

d:\Dropbox#PY\supernote-tool-master\supernotelib\converter.py in convert(self, page_number, visibility_overlay)
62 page = self.note.get_page(page_number)
63 if page.is_layer_supported():
---> 64 return self._convert_layered_page(page, self.palette, visibility_overlay)
65 else:
66 return self._convert_nonlayered_page(page, self.palette, visibility_overlay)

d:\Dropbox#PY\supernote-tool-master\supernotelib\converter.py in _convert_layered_page(self, page, palette, visibility_overlay)
88 if custom_bg:
89 decoder = Decoder.PngDecoder()
---> 90 img = self._create_image_from_decoder(decoder, binary, palette=palette, blank_hint=all_blank)
91 imgs[layer_name] = img
92 return self._flatten_layers(page, imgs, visibility_overlay)

d:\Dropbox#PY\supernote-tool-master\supernotelib\converter.py in _create_image_from_decoder(self, decoder, binary, palette, blank_hint)
116
117 def _create_image_from_decoder(self, decoder, binary, palette=None, blank_hint=False):
--> 118 bitmap, size, bpp = decoder.decode(binary, palette=palette, all_blank=blank_hint)
119 if bpp == 32:
120 img = Image.frombytes('RGBA', size, bitmap)

d:\Dropbox#PY\supernote-tool-master\supernotelib\decoder.py in decode(self, data, palette, all_blank)
184 expected_length = fileformat.PAGE_HEIGHT * fileformat.PAGE_WIDTH * int(bit_per_pixel / 8)
185 if len(uncompressed) != expected_length:
--> 186 raise exceptions.DecoderException(f'uncompressed bitmap length = {len(uncompressed)}, expected = {expected_length}')
187
188 return bytes(uncompressed), (fileformat.PAGE_WIDTH, fileformat.PAGE_HEIGHT), bit_per_pixel

DecoderException: uncompressed bitmap length = 2618568, expected = 2628288

@jya-dev
Copy link
Owner

jya-dev commented Nov 11, 2021

Hi,
There may be a problem with the handling of custom templates.
I will check the details so could you please send me the note file that causes the error?

@fbalobanov
Copy link
Author

Hi, I think you are right, the other notes with the plain template are working.

I've created a new note with the custom template, which the converter fails to convert. Here it is:
https://www.dropbox.com/s/gppj54q61ssvwvh/test.note?dl=0

and here is the template:
https://www.dropbox.com/s/2mn2qjslolas756/byjo.png?dl=0

@jya-dev
Copy link
Owner

jya-dev commented Nov 12, 2021

Hi,
I found a strange metadata in your test.note and Work.note (received from email).
The metadata of a page generally has MAINLAYER and BGLAYER (and optionally LAYER1, 2, 3),
but the files that cause the error have two MAINLAYERs and no BGLAYER. I don't know why.

$ python3 ./supernote-tool.py analyze test.note | jq .__pages__[0].__layers__
[
  {
    "LAYERTYPE": "NOTE",
    "LAYERPROTOCOL": "RATTA_RLE",
    "LAYERNAME": "MAINLAYER",
    "LAYERPATH": "0",
    "LAYERBITMAP": "16472",
    "LAYERVECTORGRAPH": "0",
    "LAYERRECOGN": "0"
  },
  {},
  {},
  {},
  {
    "LAYERTYPE": "NOTE",
    "LAYERPROTOCOL": "RATTA_RLE",
    "LAYERNAME": "MAINLAYER",       <--------- duplicated layer name; normally "BGLAYER"
    "LAYERPATH": "0",
    "LAYERBITMAP": "293",
    "LAYERVECTORGRAPH": "0",
    "LAYERRECOGN": "0"
  }
]

I added a workaround to treat 2nd MAINLAYER as BGLAYER and now I can convert them.
Please check latest code (commit d860016) helps you to convert your note files. Thanks.

@jya-dev
Copy link
Owner

jya-dev commented Nov 13, 2021

I submitted a new commit 566b29c that fix bitmap length problem.
This fix solves conversion error you encountered with Trades.note (received from email).

This is the error message on trying to convert Trades.note with the tool before applying the patch:

supernotelib.exceptions.DecoderException: uncompressed bitmap length = 2613528, expected = 2628288

It is similar to your first report, so perhaps the first report was also due to this issue.

@jya-dev jya-dev closed this as completed Nov 22, 2021
@fbalobanov
Copy link
Author

fbalobanov commented Nov 22, 2021 via email

@fbalobanov
Copy link
Author

fbalobanov commented Dec 2, 2021 via email

@jya-dev
Copy link
Owner

jya-dev commented Dec 3, 2021

Thank you for the notice.
Could you create a new issue on github?
Please also attach a test.note file as I am not beta program user.

Thanks.

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

2 participants