FBT: Optimize icons blob -4KB DFU, scrub unused icons (#291)

* Unused icons to check later

* Exclude disabled icons from firmware

* Format

* Also report free flash in gh comment

* Fix free flash calc

* Fix?

* Fix??

* Split to next line

* Remove dead icons

* Some spring cleaning of icons cooker

* Improve unused icons script

* Disable icons that cant be used in asset packs

* These will need a workaround for external

* Revert "These will need a workaround for external"

This reverts commit fb23d97952.

* Here's the workaround: split assets lib

now there is "assets" and "fwassets"

firmware links with fwassets and includes all icons
however not all of them are exposed to api

if an app needs a firmware icon not in api, it can use fap_libs=["assets"]
this will link against this dummy assets lib
it only contains the icons that arent exposed to api

this way, an app using assets lib will still benefit from asset packs
but at same time, we can remove pointless icons from dfu blob

* Update changelog
This commit is contained in:
WillyJL
2024-11-05 07:32:24 +00:00
committed by GitHub
parent 78f517b294
commit 3ef283824d
24 changed files with 183 additions and 77 deletions
+57 -35
View File
@@ -11,11 +11,20 @@ ICONS_SUPPORTED_FORMATS = ["png"]
ICONS_TEMPLATE_H_HEADER = """#pragma once
#include <furi.h>
#include <stddef.h>
#include <gui/icon.h>
"""
ICONS_TEMPLATE_H_ICON_NAME = "extern const Icon {name};\n"
ICONS_TEMPLATE_H_ICON_PATHS = """
typedef struct {
const Icon* icon;
const char* path;
} IconPath;
extern const IconPath ICON_PATHS[];
extern const size_t ICON_PATHS_COUNT;
"""
ICONS_TEMPLATE_C_HEADER = """#include "{assets_filename}.h"
@@ -25,6 +34,15 @@ ICONS_TEMPLATE_C_HEADER = """#include "{assets_filename}.h"
ICONS_TEMPLATE_C_FRAME = "const uint8_t {name}[] = {data};\n"
ICONS_TEMPLATE_C_DATA = "const uint8_t* const {name}[] = {data};\n"
ICONS_TEMPLATE_C_ICONS = "const Icon {name} = {{.width={width},.height={height},.frame_count={frame_count},.frame_rate={frame_rate},.frames=_{name}}};\n"
ICONS_TEMPLATE_C_ICON_PATH = ' {{&{name}, "{path}"}},\n'
ICONS_TEMPLATE_C_ICON_PATHS = """
const IconPath ICON_PATHS[] = {{
#ifndef FURI_RAM_EXEC
{icon_paths}
#endif
}};
const size_t ICON_PATHS_COUNT = COUNT_OF(ICON_PATHS);
"""
MAX_IMAGE_WIDTH = 2**16 - 1
MAX_IMAGE_HEIGHT = 2**16 - 1
@@ -45,6 +63,22 @@ class Main(App):
required=False,
default="assets_icons",
)
self.parser_icons.add_argument(
"--fw-bundle",
dest="fw_bundle",
help="Bundle all icons and path info, only for use in firmware blob",
default=0,
type=int,
required=False,
)
self.parser_icons.add_argument(
"--add-include",
dest="add_include",
help="Add assets_icons.h include drop-in for apps",
default=0,
type=int,
required=False,
)
self.parser_icons.set_defaults(func=self.icons)
@@ -138,7 +172,6 @@ class Main(App):
)
icons = []
paths = []
is_main_assets = self.args.filename == "assets_icons"
symbols = pathlib.Path(__file__).parent.parent
if "UFBT_HOME" in os.environ:
symbols /= "sdk_headers/f7_sdk"
@@ -154,7 +187,8 @@ class Main(App):
if "frame_rate" in filenames:
self.logger.debug("Folder contains animation")
icon_name = "A_" + os.path.split(dirpath)[1].replace("-", "_")
if not is_main_assets and api_has_icon(icon_name):
icon_in_api = api_has_icon(icon_name)
if not self.args.fw_bundle and icon_in_api:
self.logger.info(
f"{self.args.filename}: ignoring duplicate icon {icon_name}"
)
@@ -193,8 +227,9 @@ class Main(App):
)
icons_c.write("\n")
icons.append((icon_name, width, height, frame_rate, frame_count))
p = dirpath.removeprefix(self.args.input_directory)[1:]
paths.append((icon_name, p.replace("\\", "/")))
if self.args.fw_bundle and icon_in_api:
path = dirpath.removeprefix(self.args.input_directory)[1:]
paths.append((icon_name, path.replace("\\", "/")))
else:
# process icons
for filename in filenames:
@@ -204,7 +239,8 @@ class Main(App):
icon_name = "I_" + "_".join(filename.split(".")[:-1]).replace(
"-", "_"
)
if not is_main_assets and api_has_icon(icon_name):
icon_in_api = api_has_icon(icon_name)
if not self.args.fw_bundle and icon_in_api:
self.logger.info(
f"{self.args.filename}: ignoring duplicate icon {icon_name}"
)
@@ -222,8 +258,11 @@ class Main(App):
)
icons_c.write("\n")
icons.append((icon_name, width, height, 0, 1))
p = fullfilename.removeprefix(self.args.input_directory)[1:]
paths.append((icon_name, p.replace("\\", "/").rsplit(".", 1)[0]))
if self.args.fw_bundle and icon_in_api:
path = fullfilename.removeprefix(self.args.input_directory)[1:]
paths.append(
(icon_name, path.replace("\\", "/").rsplit(".", 1)[0])
)
# Create array of images:
self.logger.debug("Finalizing source file")
for name, width, height, frame_rate, frame_count in icons:
@@ -236,21 +275,14 @@ class Main(App):
frame_count=frame_count,
)
)
if is_main_assets:
icons_c.write(
"""
const IconPath ICON_PATHS[] = {
#ifndef FURI_RAM_EXEC
"""
)
for name, path in paths:
icons_c.write(f' {{&{name}, "{path}"}},\n')
icons_c.write(
"""#endif
};
const size_t ICON_PATHS_COUNT = COUNT_OF(ICON_PATHS);
"""
if not self.args.fw_bundle:
icons_c.write("\n")
else:
icon_paths = "\n".join(
ICONS_TEMPLATE_C_ICON_PATH.format(name=name, path=path)
for name, path in paths
)
icons_c.write(ICONS_TEMPLATE_C_ICON_PATHS.format(icon_paths=icon_paths))
icons_c.close()
# Create Public Header
@@ -263,19 +295,9 @@ const size_t ICON_PATHS_COUNT = COUNT_OF(ICON_PATHS);
icons_h.write(ICONS_TEMPLATE_H_HEADER)
for name, width, height, frame_rate, frame_count in icons:
icons_h.write(ICONS_TEMPLATE_H_ICON_NAME.format(name=name))
if is_main_assets:
icons_h.write(
"""
typedef struct {
const Icon* icon;
const char* path;
} IconPath;
extern const IconPath ICON_PATHS[];
extern const size_t ICON_PATHS_COUNT;
"""
)
else:
if self.args.fw_bundle:
icons_h.write(ICONS_TEMPLATE_H_ICON_PATHS)
if self.args.add_include:
icons_h.write("#include <assets_icons.h>\n")
icons_h.close()
self.logger.debug("Done")