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

lv_img_conv.py doesn't handle 8-bit pixel mode #1985

Closed
1 task done
ekirchman opened this issue Jan 19, 2024 · 3 comments · Fixed by #1989
Closed
1 task done

lv_img_conv.py doesn't handle 8-bit pixel mode #1985

ekirchman opened this issue Jan 19, 2024 · 3 comments · Fixed by #1989
Assignees
Milestone

Comments

@ekirchman
Copy link

Verification

  • I searched for similar issues (including closed issues) and found none was relevant.

Introduce the issue

Pillow supports a lot of different modes as seen here
'P' mode is an 8-bit pixel mode that not only is space efficient but also supports color and transparency. When trying save an an external resource using CF_TRUE_COLOR_ALPHA, the error TypeError: 'int' object is not subscriptable is printed because this mode does not have "channels".

Steps to reproduce:

  1. Follow the official docs for external resources.
  2. Use the following image to generate an lv compatible file:
    Enemy
  3. See error is reproduced.

A workaround for now is to use Pillow to convert the mode from 'P' to 'RGBA', but this increases the file size.

Full traceback:

Beginning conversion of /home/user/Documents/projects/pinetime/InfiniTime/src/resources/images/FEPT/Enemy.png
overwriting Enemy.bin
Traceback (most recent call last):
  File "/home/user/Documents/projects/pinetime/InfiniTime/src/resources/lv_img_conv.py", line 193, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/user/Documents/projects/pinetime/InfiniTime/src/resources/lv_img_conv.py", line 122, in main
    r_act = classify_pixel(pixel[0], 5)
                           ~~~~~^^^
TypeError: 'int' object is not subscriptable
Traceback (most recent call last):
  File "/home/user/Documents/projects/pinetime/InfiniTime/src/resources/generate-img.py", line 59, in <module>
    main()
  File "/home/user/Documents/projects/pinetime/InfiniTime/src/resources/generate-img.py", line 54, in main
    subprocess.check_call(line)
  File "/usr/lib64/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python3.11', '/home/user/Documents/projects/pinetime/InfiniTime/src/resources/lv_img_conv.py', '/home/user/Documents/projects/pinetime/InfiniTime/src/resources/images/FEPT/Enemy.png', '--force', '--output-file', 'Enemy.bin', '--color-format', 'CF_TRUE_COLOR_ALPHA', '--output-format', 'bin', '--binary-format', 'ARGB8565_RBSWAP']' returned non-zero exit status 1.

Preferred solution

Add a condition to check the mode before doing the conversion and handle accordingly

Version

No response

@FintasticMan
Copy link
Member

I recently came across a Python script by lvgl for converting images: https://github.com/lvgl/lvgl/blob/master/scripts/LVGLImage.py. Could you see if it works with that?

@ekirchman
Copy link
Author

python3 LVGLImage.py --ofmt BIN --cf TRUECOLOR_ALPHA ~/Documents/projects/pinetime/ref/FEPT_imgs/Enemy.png
It seemed to work when I made the output format TRUECOLOR_ALPHA.

But it looks like the preferred binary format output for inifiniTime is ARGB8565_RBSWAP. I don't know what binary format this script outputs.

(Uploading the bin file as a zip since Github won't let me upload it as a .bin)
Enemy.bin.zip

@ekirchman
Copy link
Author

Tagging @NeroBurner

@NeroBurner NeroBurner self-assigned this Jan 21, 2024
@NeroBurner NeroBurner added this to the 1.15.0 milestone Jan 21, 2024
NeroBurner added a commit that referenced this issue Jan 21, 2024
Support other image modes like `P`, which uses 8 bits per pixel and a
color palette to save space.

Luckily the Pillow module can do the mode conversion for us.

Fixes: #1985
NeroBurner added a commit that referenced this issue Jan 23, 2024
Support other image modes like `P`, which uses 8 bits per pixel and a
color palette to save space.

Luckily the Pillow module can do the mode conversion for us.

Fixes: #1985
lasnikr pushed a commit to lasnikr/LasnikrInfiniTime that referenced this issue Mar 5, 2024
Support other image modes like `P`, which uses 8 bits per pixel and a
color palette to save space.

Luckily the Pillow module can do the mode conversion for us.

Fixes: InfiniTimeOrg#1985
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants