Compare commits

..

4 Commits

Author SHA1 Message Date
nemo fea6e3879c fix bug overflow pixel scale 2024-11-13 10:13:16 +01:00
nemo 2bad59515a fix inv x y 2024-11-13 10:10:20 +01:00
nemo 03351121b7 rm penger.c 2024-11-13 10:06:52 +01:00
nemo 61bf9df50c auto penger 2024-11-13 10:05:35 +01:00
7 changed files with 8046 additions and 55 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
app.wasm app.wasm
app.wat app.wat
png2c
penger.c

14
app.c
View File

@ -79,17 +79,17 @@ void go(float dt)
} }
v2 penger_origin = {(float) width/2 - 32*scale()/2, (float) height/2 - 32*scale()/2}; v2 penger_origin = {(float) width/2 - 32*scale()/2, (float) height/2 - 32*scale()/2};
for (int i = 0; i < 32; i++) { for (int y = 0; y < penger_height; y++) {
for (int y = 0; y < 32; y++) { for (int i = 0; i < penger_width; i++) {
if (penger_img[i][y] == 0) if (penger_img[y][i] <= 0x00FFFFFF)
continue; continue;
for (int s1 = 0; s1 < scale(); s1++) { for (int s1 = 0; s1 < scale(); s1++) {
for (int s2 = 0; s2 < scale(); s2++) { for (int s2 = 0; s2 < scale(); s2++) {
int idx_x = penger_origin.x + y*scale()+s1; int idx_x = penger_origin.x + i*scale()+s1;
int idx_y = penger_origin.y + i*scale()+s2; int idx_y = penger_origin.y + y*scale()+s2;
if (idx_x < 0 || idx_x > width || idx_y < 0 || idx_y > height) if (idx_x < 0 || idx_x >= width || idx_y < 0 || idx_y >= height)
continue; continue;
BUFFER[idx_y*width + idx_x] = penger_img[i][y]; BUFFER[idx_y*width + idx_x] = penger_img[y][i];
} }
} }
} }

View File

@ -6,8 +6,19 @@ for e in $export_sym; do
export_cmd="$export_cmd -Wl,--export=$e"; export_cmd="$export_cmd -Wl,--export=$e";
done; done;
f=$(echo $1 | sed "s/\..*$//g") if [[ "$1" == "" ]]; then
f='app'
e='app.c'
else
f=$(echo $1 | sed "s/\..*$//g")
e=$1
fi
clang -O2 --target=wasm32 -fno-builtin -nostdlib --no-standard-libraries -Wl,--no-entry $export_cmd -Wl,--allow-undefined -o $f.wasm $1 set -xe
clang png2c.c -o png2c -lm
./png2c "penger.png" > penger.c
clang -O2 --target=wasm32 -fno-builtin -nostdlib --no-standard-libraries -Wl,--no-entry $export_cmd -Wl,--allow-undefined -o $f.wasm $e
wasm2wat $f.wasm > $f.wat wasm2wat $f.wasm > $f.wat

View File

@ -1,46 +0,0 @@
#define t 0x00000000
#define B 0xff000000
#define g 0xff383838
#define w 0xffc0c0c0
#define y 0xff36c7fb
unsigned int penger_img[32][32] = {
t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,
t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,B,B,t,t,t,t,t,t,t,t,t,t,t,t,t,
t,t,t,t,t,t,t,t,t,t,t,t,t,B,B,B,B,g,B,B,B,t,t,t,t,t,t,t,t,t,t,t,
t,t,t,t,t,t,t,t,t,t,t,t,B,B,g,g,g,g,g,g,B,B,t,t,t,t,t,t,t,t,t,t,
t,t,t,t,t,t,t,t,t,t,t,B,B,g,g,g,g,g,g,g,g,B,t,t,t,t,t,t,t,t,t,t,
t,t,t,t,t,t,t,t,t,t,B,B,g,g,g,g,g,g,g,g,g,B,t,t,t,t,t,t,t,t,t,t,
t,t,t,t,t,t,t,t,t,t,B,g,g,g,g,g,g,g,g,g,g,B,t,t,t,t,t,t,t,t,t,t,
t,t,t,t,t,t,t,t,t,B,B,g,g,g,g,g,g,g,g,g,g,g,B,t,t,t,t,t,t,t,t,t,
t,t,t,t,t,t,t,t,t,B,g,g,g,g,g,B,B,B,g,g,g,g,B,t,t,t,t,t,t,t,t,t,
t,t,t,t,t,t,t,t,t,B,g,g,g,g,g,g,B,B,g,g,g,g,B,t,t,t,t,t,t,t,t,t,
t,t,t,t,t,t,t,t,B,B,g,g,g,g,g,g,g,g,g,g,g,g,B,B,t,t,t,t,t,t,t,t,
t,t,t,t,t,t,t,t,B,g,g,g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,t,B,B,B,y,B,g,g,B,w,w,w,w,w,w,w,w,B,B,B,y,y,B,B,t,t,t,t,
t,t,t,t,B,B,y,y,y,y,B,B,B,B,B,B,B,B,B,B,B,y,y,y,y,y,y,B,B,t,t,t,
t,t,t,t,B,B,y,y,y,y,y,y,B,t,t,t,t,t,t,t,t,B,B,y,y,y,y,y,B,t,t,t,
t,t,t,t,t,B,B,B,y,y,B,B,B,t,t,t,t,t,t,t,t,t,B,B,B,y,y,B,B,t,t,t,
t,t,t,t,t,t,t,B,B,B,B,t,t,t,t,t,t,t,t,t,t,t,t,t,B,B,B,B,t,t,t,t,
};
#undef t
#undef B
#undef g
#undef w
#undef y

BIN
penger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

36
png2c.c Normal file
View File

@ -0,0 +1,36 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
int main(int argc, const char *argv[])
{
if (argc < 2) {
fprintf(stdout, "usage: %s <image path>\n", argv[0]);
fprintf(stderr, "ERROR: no image provided\n");
return 1;
}
const char *img_path = argv[1];
int width, height, n;
unsigned int *data = (unsigned int*)stbi_load(img_path, &width, &height, &n, 4);
if (n != 4) {
fprintf(stderr, "ERROR: n components is not 4\n");
return 1;
}
printf("int penger_height = %d;\n", height);
printf("int penger_width = %d;\n", width);
printf("unsigned int penger_img[%d][%d] = {\n", height, width);
for (int y = 0; y < height; y++) {
printf(" ");
for (int i = 0; i < width; i++) {
printf("0x%08X,", data[y*height + i]);
}
printf("\n");
}
printf("};\n");
}

7988
stb_image.h Normal file

File diff suppressed because it is too large Load Diff