mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[ion] linux: enable to use key layouts jpg files in C/C++ code
This commit is contained in:
committed by
EmilieNumworks
parent
a27122802d
commit
22250b4234
@@ -3,7 +3,7 @@
|
||||
$(eval $(call rule_for, \
|
||||
AS, %.o, %.s, \
|
||||
$$(CC) $$(SFLAGS) -c $$< -o $$@, \
|
||||
global \
|
||||
global local \
|
||||
))
|
||||
|
||||
$(eval $(call rule_for, \
|
||||
|
||||
@@ -10,7 +10,7 @@ SFLAGS += -Iion/src/simulator/linux/include
|
||||
ion_src += $(addprefix ion/src/simulator/linux/, \
|
||||
images.cpp \
|
||||
language.cpp \
|
||||
background.s \
|
||||
assets.s \
|
||||
)
|
||||
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
@@ -26,3 +26,21 @@ ion_src += ion/src/shared/telemetry_console.cpp
|
||||
endif
|
||||
|
||||
LDFLAGS += -ljpeg
|
||||
|
||||
jpg_assets = background horizontal_arrow vertical_arrow round small_squircle large_squircle
|
||||
|
||||
jpg_images = $(foreach i,$(jpg_assets),ion/src/simulator/assets/$(i).jpg)
|
||||
|
||||
$(eval $(call rule_for, \
|
||||
LINUX_ASSETS, \
|
||||
ion/src/simulator/linux/assets.s, \
|
||||
$(jpg_images), \
|
||||
$$(PYTHON) ion/src/simulator/linux/assets.py --files $(jpg_assets) --implementation $$@, \
|
||||
global \
|
||||
))
|
||||
|
||||
assets_address_ranges_declaration = $(foreach i,$(jpg_assets),extern unsigned char _ion_simulator_$(i)_start;)
|
||||
assets_address_ranges_declaration += $(foreach i,$(jpg_assets),extern unsigned char _ion_simulator_$(i)_end;)
|
||||
assets_address_ranges_definition = $(foreach i,$(jpg_assets), {"$(i).jpg", _ion_simulator_$(i)_start, _ion_simulator_$(i)_end},)
|
||||
|
||||
$(call object_for,ion/src/simulator/linux/images.cpp): CXXFLAGS += -DASSETS_ADDRESS_RANGES_DECLARATION='$(assets_address_ranges_declaration)' -DASSETS_ADDRESS_RANGES_DEFINITION='$(assets_address_ranges_definition)'
|
||||
|
||||
29
ion/src/simulator/linux/assets.py
Normal file
29
ion/src/simulator/linux/assets.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# This script generates a .s file representing jpg assets in order to access
|
||||
# them from C code
|
||||
|
||||
import sys
|
||||
import re
|
||||
import argparse
|
||||
import io
|
||||
|
||||
parser = argparse.ArgumentParser(description="Process some jpg files.")
|
||||
parser.add_argument('--files', nargs='+', help='a list of jpg file names')
|
||||
parser.add_argument('--implementation', help='the .s file to generate')
|
||||
args = parser.parse_args()
|
||||
|
||||
def print_jpg(f, jpg):
|
||||
f.write(".global _ion_simulator_" + jpg + "_start\n")
|
||||
f.write(".global _ion_simulator_" + jpg + "_end\n")
|
||||
f.write("_ion_simulator_" + jpg + "_start:\n")
|
||||
f.write(" .incbin \"ion/src/simulator/assets/" + jpg + ".jpg\"\n")
|
||||
f.write("_ion_simulator_" + jpg + "_end:\n\n")
|
||||
|
||||
def print(files, path):
|
||||
f = open(path, "w")
|
||||
for jpg in files:
|
||||
print_jpg(f, jpg)
|
||||
|
||||
f.close()
|
||||
|
||||
print(args.files, args.implementation)
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
.global _ion_simulator_background_start
|
||||
.global _ion_simulator_background_end
|
||||
_ion_simulator_background_start:
|
||||
.incbin "ion/src/simulator/assets/background.jpg"
|
||||
_ion_simulator_background_end:
|
||||
@@ -4,8 +4,18 @@
|
||||
#include <jpeglib.h>
|
||||
#include <assert.h>
|
||||
|
||||
extern unsigned char _ion_simulator_background_start;
|
||||
extern unsigned char _ion_simulator_background_end;
|
||||
#ifndef ASSETS_ADDRESS_RANGES_DECLARATION
|
||||
#error Missing assets adress range declarations
|
||||
#endif
|
||||
|
||||
ASSETS_ADDRESS_RANGES_DECLARATION
|
||||
static struct {
|
||||
const char * identifier;
|
||||
unsigned char start;
|
||||
unsigned char end;
|
||||
} resources_addresses[] = {
|
||||
ASSETS_ADDRESS_RANGES_DEFINITION
|
||||
};
|
||||
|
||||
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) {
|
||||
struct jpeg_decompress_struct info;
|
||||
@@ -14,8 +24,17 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
|
||||
|
||||
jpeg_create_decompress(&info);
|
||||
|
||||
unsigned char * jpegStart = &_ion_simulator_background_start;
|
||||
unsigned long jpegSize = &_ion_simulator_background_end - &_ion_simulator_background_start;
|
||||
unsigned char * jpegStart = nullptr;
|
||||
unsigned long jpegSize = 0;
|
||||
|
||||
for (size_t i = 0; i < sizeof(resources_addresses)/sizeof(resources_addresses[0]); i++) {
|
||||
if (strcmp(identifier, resources_addresses[i].identifier) == 0) {
|
||||
jpegStart = &resources_addresses[i].start;
|
||||
jpegSize = &resources_addresses[i].end - &resources_addresses[i].start;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(jpegStart);
|
||||
jpeg_mem_src(&info, jpegStart, jpegSize);
|
||||
|
||||
if (jpeg_read_header(&info, TRUE) != 1) {
|
||||
|
||||
Reference in New Issue
Block a user