Skip to content

Commit

Permalink
optimized build
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianpls committed Jul 24, 2024
1 parent 3ca3b1d commit 6068cc8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions build
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
rm lerc1dec.* *.o
emcc -O3 -c lerc1Image.cpp
emcc -O3 -c lerc1api.cpp
emcc -O3 -c rasterfunk.cpp
OPTS="-O3 -flto"
emcc $OPTS -c lerc1Image.cpp
emcc $OPTS -c lerc1api.cpp
emcc $OPTS -ffast-math -c rasterfunk.cpp

# Build the test app
# emcc -O3 -o lercapp.html app.cpp lerc1api.o lerc1Image.o --preload-file 0 -sUSE_SDL=2
# emcc $OPTS -o lercapp.html app.cpp lerc1api.o lerc1Image.o --preload-file 0 -sUSE_SDL=2

# Build a lerc1.wasm library, with just the lerc1api exported
EXPORTS=_malloc,_free
emcc -O3 -o lerc1dec.js lerc1api.o lerc1Image.o rasterfunk.o -sNO_EXIT_RUNTIME=1 -sEXPORTED_FUNCTIONS=$EXPORTS --no-entry -sEXPORTED_RUNTIME_METHODS=[cwrap,writeArrayToMemory,UTF8ToString]
emcc $OPTS -o lerc1dec.js lerc1api.o lerc1Image.o rasterfunk.o -sNO_EXIT_RUNTIME=1 -sEXPORTED_FUNCTIONS=$EXPORTS --no-entry -sEXPORTED_RUNTIME_METHODS=[cwrap,writeArrayToMemory,UTF8ToString]
Binary file modified docs/lerc1dec.wasm
Binary file not shown.
7 changes: 4 additions & 3 deletions rasterfunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int hillshade(float *data, size_t sz, double pixel_size, double sun_angle, uint3

constexpr int TILESIZE(256);
constexpr int DATATILESIZE(257);
constexpr uint32_t ALPHA(0xff000000);
constexpr uint32_t OPAQUE(0xff000000);
constexpr auto base(32.0); // baseline brightness
constexpr auto rescale((256 - base) / 256); // brightness rescale factor
for (int y = 0; y < TILESIZE; y++)
Expand All @@ -75,12 +75,13 @@ int hillshade(float *data, size_t sz, double pixel_size, double sun_angle, uint3
uint32_t red = val & 0xff;
uint32_t green = (val >> 8) & 0xff;
uint32_t blue = (val >> 16) & 0xff;
uint32_t alpha = (val >> 24) & 0xff;
red = (base + rescale * red) * factor;
green = (base + rescale * green) * factor;
blue = (base + rescale * blue) * factor;
// alpha is unaffected by hillshade
uint32_t alpha = val & OPAQUE;

pixels[TILESIZE * y + x] = ALPHA | (blue << 16) | (green << 8) | red;
pixels[TILESIZE * y + x] = alpha | (blue << 16) | (green << 8) | red;
}
}
return 1;
Expand Down

0 comments on commit 6068cc8

Please sign in to comment.