diff --git a/build b/build index edfa6fc..477c328 100644 --- a/build +++ b/build @@ -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] diff --git a/docs/lerc1dec.wasm b/docs/lerc1dec.wasm index d7e1ba9..879be9a 100644 Binary files a/docs/lerc1dec.wasm and b/docs/lerc1dec.wasm differ diff --git a/rasterfunk.cpp b/rasterfunk.cpp index 7592833..c07da1c 100644 --- a/rasterfunk.cpp +++ b/rasterfunk.cpp @@ -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++) @@ -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;