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

Move Navigation font to external memory #1838

Merged
merged 4 commits into from
Sep 2, 2023

Conversation

JF002
Copy link
Collaborator

@JF002 JF002 commented Aug 20, 2023

The TTF font used by the navigation app is ~20KB and is stored in internal flash memory. To free this space, the TTF font is now converted in 2 "atlas pictures" (pictures that contain multiple concatenated images) stored in the external flash memory. The navigation app now accesses one of those 2 files and apply an offset to display the desired picture.

The corresponding documentation has also been updated.

The final binary file is now 19380B lighter.

Here is a quick video I made while testing the implementation :

20230820_204038.mp4

The TTF font used by the navigation app is ~20KB and is stored in internal flash memory.
To free this space, the TTF font is now converted in 2 "atlas pictures" (pictures that contain multiple concatenated images) stored in the external flash memory. The navigation app now accesses one of those 2 files and apply an offset to display the desired picture.

The corresponding documentation has also been updated.
@JF002 JF002 added enhancement Enhancement to an existing app/feature external flash labels Aug 20, 2023
@github-actions
Copy link

github-actions bot commented Aug 20, 2023

Build size and comparison to main:

Section Size Difference
text 376560B -19396B
data 940B -56B
bss 63420B 0B

Copy link
Member

@FintasticMan FintasticMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this! It doesn't look to me like you're checking that the image files exist in the filesystem before using them. That would be good to add so that if people haven't updated their resources yet, it doesn't cause issues. Other than that, this code looks good to me.

src/displayapp/screens/Navigation.cpp Show resolved Hide resolved
Copy link
Member

@mark9064 mark9064 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builds with -DBUILD_RESOURCES=1 fail for me with this PR. Could totally be a problem with my dependency setup if it works for you.

/home/laptop/Local/pinetime/InfiniTime/node_modules/lv_img_conv/lib/image-q/utils/point.ts:85
    this.r = point.r;
                   ^
TypeError: Cannot read properties of undefined (reading 'r')
    at Point.from (/home/laptop/Local/pinetime/InfiniTime/node_modules/lv_img_conv/lib/image-q/utils/point.ts:85:20)
    at ErrorDiffusionArray.<anonymous> (/home/laptop/Local/pinetime/InfiniTime/node_modules/lv_img_conv/lib/image-q/image/array.ts:128:15)
    at step (/home/laptop/Local/pinetime/InfiniTime/node_modules/lv_img_conv/lib/image-q/image/array.ts:205:23)
    at Object.next (/home/laptop/Local/pinetime/InfiniTime/node_modules/lv_img_conv/lib/image-q/image/array.ts:146:20)
    at Immediate.next (/home/laptop/Local/pinetime/InfiniTime/node_modules/lv_img_conv/lib/image-q/basicAPI.ts:163:33)
    at processImmediate (node:internal/timers:476:21)
Traceback (most recent call last):
  File "/home/laptop/Local/pinetime/InfiniTime/src/resources/generate-img.py", line 56, in <module>
    main()
  File "/home/laptop/Local/pinetime/InfiniTime/src/resources/generate-img.py", line 51, in main
    subprocess.check_call(line)
  File "/usr/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/laptop/Local/pinetime/InfiniTime/node_modules/.bin/lv_img_conv', '/home/laptop/Local/pinetime/InfiniTime/src/resources/images/navigation0.png', '--force', '--output-file', 'navigation0.bin', '--color-format', 'CF_INDEXED_1_BIT', '--output-format', 'bin', '--binary-format', 'ARGB8565_RBSWAP']' returned non-zero exit status 1.

Using "lv_font_conv": "^1.5.2","lv_img_conv": "^0.3.0" (npm chose the versions for me)

doc/buildAndProgram.md Show resolved Hide resolved
JF002 added 2 commits August 27, 2023 20:42
Add comments about the layout of the pictures that contain the icon and about the indexing of those icons.
In documentation (buildAndProgram.md), edit the section about the debug compilation mode. Remove the part about removing the Navigation app to free some memory (since it's not relevant anymore) and explain how to selectively build parts of the firmware in Debug mode.
Copy link
Member

@FintasticMan FintasticMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now! Shall we merge the PR that prevents starting the navigation app if the files aren't present after this one?

@JF002
Copy link
Collaborator Author

JF002 commented Sep 2, 2023

@FintasticMan
I've just pushed #1847 which disables the Navigation app if the resource files are not available. We'll be able to use this implementation for other applications when needed as well.

If you're OK with this, we can merge #1847 after we merge this one.

@JF002
Copy link
Collaborator Author

JF002 commented Sep 2, 2023

Builds with -DBUILD_RESOURCES=1 fail for me with this PR. Could totally be a problem with my dependency setup if it works for you.
[...]
Using "lv_font_conv": "^1.5.2","lv_img_conv": "^0.3.0" (npm chose the versions for me)

This is probably not related to this PR since it doesn't to any change on how the images and fonts are converted. Does it work fine on the main branch ?

These are the versions I'm using on my dev setup:

$ lv_font_conv -v
1.5.2
$lv_img_conv --version
0.3.0

@FintasticMan FintasticMan merged commit 44d1798 into main Sep 2, 2023
@FintasticMan FintasticMan deleted the move-navigation-font-to-external-memory branch September 2, 2023 17:42
@mark9064
Copy link
Member

mark9064 commented Sep 5, 2023

Builds with -DBUILD_RESOURCES=1 fail for me with this PR. Could totally be a problem with my dependency setup if it works for you.
[...]
Using "lv_font_conv": "^1.5.2","lv_img_conv": "^0.3.0" (npm chose the versions for me)

This is probably not related to this PR since it doesn't to any change on how the images and fonts are converted. Does it work fine on the main branch ?

These are the versions I'm using on my dev setup:

$ lv_font_conv -v
1.5.2
$lv_img_conv --version
0.3.0
  • Built fine before this commit
  • I've tried nodejs 16,18,20 with the dependency versions you use, no dice
  • Creates the pine_logo image without problem, only breaks on the navigation atlases
  • Broken on both my laptop and desktop (though they run pretty much the same software)

But it works on your machine and CI, so I have no clue. I've basically never used node before so I guess I will have to find out how to debug it... strange behaviour all round

@FintasticMan
Copy link
Member

Maybe try using the node lockfile from #1764.

@jackwilsdon
Copy link

jackwilsdon commented Sep 5, 2023

I experienced this issue in #1819, try pinning @swc/core to 1.2.160 (see my changes on that PR). It probably needs adding to the Dockerfile (and anywhere else we install @swc/core).

@mark9064
Copy link
Member

mark9064 commented Sep 5, 2023

Maybe try using the node lockfile from #1764.

Good idea, I gave this a go. After installing from the package(-lock), the build failed with error message asking for swc/core, which I then installed. Unfortunately the original error then returned :(

I've been digging through lv_img_conv and it looks like it's trying to create a palette with no colours in it. Still working on figuring out the root problem

@mark9064
Copy link
Member

mark9064 commented Sep 5, 2023

I experienced this issue in #1819, try pinning @swc/core to 1.2.160 (see my changes on that PR). It probably needs adding to the Dockerfile (and anywhere else we install @swc/core).

Spot on, this resolved the issue. Cheers!

Now I'm wondering: why do newer versions of swc/core break? Is there a regression we can track upstream (or should we report one)

@JF002
Copy link
Collaborator Author

JF002 commented Sep 9, 2023

Spot on, this resolved the issue. Cheers!

Great! I honestly don't know why it doesn't work with more recent version of swc (in fact, I don't know what it is... I don't know Node either, but that's what the LVGL tools are based on).
The only think I can think of is that it's the 1st time we use CF_INDEXED_1_BIT as output format. Maybe there was a breaking change in lv_img_conv in recent versions?

@JF002
Copy link
Collaborator Author

JF002 commented Sep 9, 2023

I experienced this issue in #1819, try pinning @swc/core to 1.2.160 (see my changes on that PR). It probably needs adding to the Dockerfile (and anywhere else we install @swc/core).

If I understand correctly, this change is needed to ensure that the correct version will be installed? If so, I guess we would appreciate a PR for this :)

@FintasticMan FintasticMan added this to the 1.14.0 milestone Sep 18, 2023
Zetabite pushed a commit to Zetabite/InfiniTime that referenced this pull request Nov 12, 2023
The TTF font used by the navigation app is ~20KB and is stored in internal flash memory.
To free this space, the TTF font is now converted in 2 "atlas pictures" (pictures that contain multiple concatenated images) stored in the external flash memory. The navigation app now accesses one of those 2 files and apply an offset to display the desired picture.

The corresponding documentation has also been updated.

Add comments about the layout of the pictures that contain the icon and about the indexing of those icons.

In documentation (buildAndProgram.md), edit the section about the debug compilation mode. Remove the part about removing the Navigation app to free some memory (since it's not relevant anymore) and explain how to selectively build parts of the firmware in Debug mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to an existing app/feature external flash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants