Compare commits
4 Commits
362f83d4c7
...
fea6e3879c
Author | SHA1 | Date |
---|---|---|
|
fea6e3879c | |
|
2bad59515a | |
|
03351121b7 | |
|
61bf9df50c |
|
@ -1,2 +1,4 @@
|
|||
app.wasm
|
||||
app.wat
|
||||
png2c
|
||||
penger.c
|
||||
|
|
14
app.c
14
app.c
|
@ -79,17 +79,17 @@ void go(float dt)
|
|||
}
|
||||
|
||||
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 < 32; y++) {
|
||||
if (penger_img[i][y] == 0)
|
||||
for (int y = 0; y < penger_height; y++) {
|
||||
for (int i = 0; i < penger_width; i++) {
|
||||
if (penger_img[y][i] <= 0x00FFFFFF)
|
||||
continue;
|
||||
for (int s1 = 0; s1 < scale(); s1++) {
|
||||
for (int s2 = 0; s2 < scale(); s2++) {
|
||||
int idx_x = penger_origin.x + y*scale()+s1;
|
||||
int idx_y = penger_origin.y + i*scale()+s2;
|
||||
if (idx_x < 0 || idx_x > width || idx_y < 0 || idx_y > height)
|
||||
int idx_x = penger_origin.x + i*scale()+s1;
|
||||
int idx_y = penger_origin.y + y*scale()+s2;
|
||||
if (idx_x < 0 || idx_x >= width || idx_y < 0 || idx_y >= height)
|
||||
continue;
|
||||
BUFFER[idx_y*width + idx_x] = penger_img[i][y];
|
||||
BUFFER[idx_y*width + idx_x] = penger_img[y][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
13
build.sh
13
build.sh
|
@ -6,8 +6,19 @@ for e in $export_sym; do
|
|||
export_cmd="$export_cmd -Wl,--export=$e";
|
||||
done;
|
||||
|
||||
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
|
||||
|
|
46
penger.c
46
penger.c
|
@ -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,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g,B,w,w,w,w,w,w,w,w,w,w,w,B,t,t,t,t,t,t,t,
|
||||
t,t,t,t,t,t,t,B,B,g,g,g,B,w,w,w,w,w,w,w,w,w,w,w,B,t,t,t,t,t,t,t,
|
||||
t,t,t,t,t,t,t,B,B,g,g,g,B,w,w,w,w,w,w,w,w,w,w,B,y,B,B,t,t,t,t,t,
|
||||
t,t,t,t,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
|
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
|
@ -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");
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue