Browse Source

remove lanczos and convert to perl, add scripts to find unused strings, better optimised assets script

Signed-off-by: lizzie <lizzie@eden-emu.dev>
pull/2749/head
lizzie 5 months ago
parent
commit
afc85c0787
No known key found for this signature in database GPG Key ID: 287378CADCAB13
  1. 7
      tools/README.md
  2. 7
      tools/find-unused-strings.sh
  3. 40
      tools/lanczos-gen.pl
  4. 48
      tools/lanczos_gen.c
  5. 6
      tools/optimize-assets.sh

7
tools/README.md

@ -11,15 +11,16 @@ Tools for Eden and other subprojects.
- `find-unused-strings.pl`: Find unused strings (for Android XML files).
- `shellcheck.sh`: Ensure POSIX compliance (and syntax sanity) for all tools in this directory and subdirectories.
- `llvmpipe-run.sh`: Sets environment variables needed to run any command (or Eden) with llvmpipe.
- `optimize-assets.sh`: Optimize PNG assets with OptiPng.
- `optimize-assets.sh`: Optimizes PNG assets with OptiPng.
- `update-cpm.sh`: Updates CPM.cmake to the latest version.
- `update-icons.sh`: Rebuild all icons (macOS, Windows, bitmaps) based on the master SVG file (`dist/dev.eden_emu.eden.svg`)
* Also optimizes the master SVG
* Requires: `png2icns` (libicns), ImageMagick, [`svgo`](https://github.com/svg/svgo)
- `dtrace-tool.sh`
- `lanczos_gen.c`
- `lanczos-gen.pl`: Generates constants for the Lanczos filter.
- `clang-format.sh`: Runs `clang-format` on the entire codebase.
* Requires: clang
- `find-unused-strings.sh`: Find any unused strings in the Android app (XML -> Kotlin).
## Android
It's recommended to run these scritps after almost any Android change, as they are relatively fast and important both for APK bloat and CI.
@ -29,4 +30,4 @@ It's recommended to run these scritps after almost any Android change, as they a
## Translations
- [Translation Scripts](./translations)
- [Translation Scripts](./translations)

7
tools/find-unused-strings.sh

@ -0,0 +1,7 @@
#!/bin/sh -e
# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
# SPDX-License-Identifier: GPL-3.0-or-later
cat src/android/app/src/main/res/values/strings.xml \
| grep 'string name="' | awk -F'"' '$0=$2' \
| xargs -I {} sh -c 'grep -qirnw R.string.'{}' src/android/app/src || echo '{}

40
tools/lanczos-gen.pl

@ -0,0 +1,40 @@
#!/usr/bin/perl
# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
# SPDX-License-Identifier: GPL-3.0-or-later
use strict;
use warnings;
sub generate_lanczos {
my $pi = 3.14159265358979;
sub sinc {
if ($_[0] eq 0.0) {
return 1.0;
} else {
return sin($pi * $_[0]) / ($pi * $_[0]);
}
}
sub lanczos {
my $d = sqrt($_[0] * $_[0] + $_[1] * $_[1]);
return sinc($d) / sinc($d / $_[2]);
}
my $r = 3.0; #radius (1 = 3 steps)
my $k_size = ($r * 2.0 + 1.0) * ($r * 2.0 + 1.0);
my $w_sum = \0.0;
my $factor = 1.0 / ($r + 1.0);
#kernel size = (r * 2 + 1) ^ 2
printf("const float w_kernel[%i] = float[] (\n ", $k_size);
for (my $x = -$r; $x <= $r; $x++) {
for (my $y = -$r; $y <= $r; $y++) {
my $w = lanczos($x, $y, $r);
printf("%f, ", $w);
$w_sum += $w;
}
}
printf("\n);\nconst vec2 w_pos[%i] = vec[](\n ", $k_size);
for (my $x = -$r; $x <= $r; $x++) {
for (my $y = -$r; $y <= $r; $y++) {
printf("vec2(%f, %f), ", $x * $factor, $y * $factor);
}
}
printf("\n);\nconst float w_sum = %f;\n", $w_sum);
}
generate_lanczos;

48
tools/lanczos_gen.c

@ -1,48 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// clang -lm tools/lanczos_gen.c -o tools/lanczos_gen && ./tools/lanczos_gen
#include <stdio.h>
#include <math.h>
double sinc(double x) {
return x == 0.0f ? 1.0f : sin(M_PI * x) / (M_PI * x);
}
typedef struct vec2 {
double x;
double y;
} vec2;
double lanczos(vec2 v, float a) {
double d = sqrt(v.x * v.x + v.y * v.y);
return sinc(d) / sinc(d / a);
}
int main(int argc, char* argv[]) {
const int r = 3; //radius (1 = 3 steps)
const int k_size = (r * 2 + 1) * (r * 2 + 1);
double w_sum = 0.0f;
// kernel size = (r * 2 + 1) ^ 2
printf("const float w_kernel[%i] = float[] (\n ", k_size);
double factor = 1.0f / ((double)r + 1.0f);
for (int x = -r; x <= r; x++)
for (int y = -r; y <= r; y++) {
double w = lanczos((vec2){ .x = x, .y = y }, (double)r);
printf("%lff, ", w);
w_sum += w;
}
printf("\n);\n");
printf("const vec2 w_pos[%i] = vec2[] (\n ", k_size);
for (int x = -r; x <= r; x++)
for (int y = -r; y <= r; y++) {
vec2 kp = (vec2){
.x = x * factor,
.y = y * factor
};
printf("vec2(%lff, %lff), ", kp.x, kp.y);
}
printf("\n);\n");
printf("const float w_sum = %lff;\n", w_sum);
return 0;
}

6
tools/optimize-assets.sh

@ -1,9 +1,5 @@
#!/bin/sh -e
# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
# SPDX-License-Identifier: GPL-3.0-or-later
# Optimizes assets of Eden (requires OptiPng)
which optipng || exit
find . -type f -name "*.png" -exec optipng -o7 {} \;
find . -type f -iname '*.png' -print0 | xargs -0 -P 16 -I {} optipng -o7 {}
Loading…
Cancel
Save