-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adf81f8
commit 60c8c03
Showing
13 changed files
with
452 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 William Silversmith | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {decompressPng} from 'neuroglancer/sliceview/png'; | ||
import {decodePng} from 'neuroglancer/async_computation/decode_png_request'; | ||
import {registerAsyncComputation} from 'neuroglancer/async_computation/handler'; | ||
|
||
registerAsyncComputation( | ||
decodePng, | ||
async function( | ||
data: Uint8Array, width: number, height: number, | ||
numComponents: number, bytesPerPixel:number, | ||
convertToGrayscale: boolean | ||
) { | ||
const result = await decompressPng( | ||
data, width, height, numComponents, | ||
bytesPerPixel, convertToGrayscale | ||
); | ||
return { value: result, transfer: [result.buffer] }; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 William Silversmith | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import {asyncComputation} from 'neuroglancer/async_computation'; | ||
|
||
export const decodePng = asyncComputation<( | ||
data: Uint8Array, width: number, height: number, | ||
numComponents: number, bytesPerPixel:number, | ||
convertToGrayscale: boolean | ||
) => Uint8Array>('decodePng'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 William Silvermsith. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {TypedArray} from 'neuroglancer/util/array'; | ||
import {DATA_TYPE_BYTES} from 'neuroglancer/util/data_type'; | ||
import {decodeRawChunk} from 'neuroglancer/sliceview/backend_chunk_decoders/raw'; | ||
import {VolumeChunk} from 'neuroglancer/sliceview/volume/backend'; | ||
import {CancellationToken} from 'neuroglancer/util/cancellation'; | ||
import {decodePng} from 'neuroglancer/async_computation/decode_png_request'; | ||
import {requestAsyncComputation} from 'neuroglancer/async_computation/request'; | ||
|
||
export async function decodePngChunk( | ||
chunk: VolumeChunk, cancellationToken: CancellationToken, response: ArrayBuffer) { | ||
|
||
const chunkDataSize = chunk.chunkDataSize!; | ||
const dataType = chunk.source!.spec.dataType; | ||
let image : TypedArray = await requestAsyncComputation( | ||
decodePng, cancellationToken, [response], | ||
/*buffer=*/(new Uint8Array(response)), | ||
/*width=*/chunkDataSize[0], | ||
/*height=*/chunkDataSize[1] * chunkDataSize[2], | ||
/*numComponents=*/chunkDataSize[3] || 1, | ||
/*bytesPerPixel=*/DATA_TYPE_BYTES[dataType], | ||
/*convertToGrayscale=*/false | ||
); | ||
|
||
await decodeRawChunk(chunk, cancellationToken, image.buffer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 2.0.24 (2021-06-10) | ||
FROM emscripten/emsdk@sha256:81ec54b7a096d28f24d906955dbf98ff336cca47658d980c243baa36f6484f9f | ||
|
||
ENV SPNG_0_7_1_SHA256 0726a4914ad7155028f3baa94027244d439cd2a2fbe8daf780c2150c4c951d8e | ||
ENV MINIZ_2_2_0_SHA256 bd1136d0a1554520dcb527a239655777148d90fd2d51cf02c36540afc552e6ec | ||
|
||
RUN mkdir -p /usr/src/spng \ | ||
&& curl -SL -o /usr/src/spng.tar.gz https://github.com/randy408/libspng/archive/refs/tags/v0.7.1.tar.gz | ||
|
||
RUN echo "${SPNG_0_7_1_SHA256} /usr/src/spng.tar.gz" | sha256sum --check --status | ||
RUN tar -xzC /usr/src/spng -f /usr/src/spng.tar.gz --strip-components=1 \ | ||
&& rm /usr/src/spng.tar.gz | ||
|
||
RUN mkdir -p /usr/src/miniz \ | ||
&& curl -SL -o /usr/src/miniz.tar.gz https://github.com/richgel999/miniz/archive/refs/tags/2.2.0.tar.gz | ||
RUN echo "${MINIZ_2_2_0_SHA256} /usr/src/miniz.tar.gz" | sha256sum --check --status | ||
RUN tar -xzC /usr/src/miniz -f /usr/src/miniz.tar.gz --strip-components=1 \ | ||
&& rm /usr/src/miniz.tar.gz | ||
|
||
RUN mkdir -p /usr/src/miniz/build && cd /usr/src/miniz/build && cmake .. | ||
RUN cp /usr/src/miniz/build/miniz_export.h /usr/src/miniz/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash -xve | ||
|
||
# This script builds `libpng.wasm` using emsdk in a docker container. | ||
|
||
cd "$(dirname "$0")" | ||
|
||
docker build . | ||
docker run \ | ||
--rm \ | ||
-v ${PWD}:/src \ | ||
-u $(id -u):$(id -g) \ | ||
$(docker build -q .) \ | ||
./build_wasm.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash -xve | ||
|
||
SPNG=/usr/src/spng/spng | ||
MINIZ=/usr/src/miniz | ||
|
||
compile_options=( | ||
-O2 | ||
-I$MINIZ -DMINIZ_NO_STDIO=1 | ||
$MINIZ/miniz_zip.c $MINIZ/miniz_tinfl.c $MINIZ/miniz_tdef.c $MINIZ/miniz.c | ||
# spng defaults to zlib if we don't force miniz | ||
# it also prints a warning about SIMD if we don't disable SIMD | ||
# using the SPNG_DISABLE_OPT flag. | ||
# As of this writng, WASM doesn't support SIMD by default anyway. | ||
-I$SPNG -DSPNG_USE_MINIZ=1 -DSPNG_DISABLE_OPT=1 $SPNG/spng.c | ||
png_wasm.c | ||
-DNDEBUG | ||
--no-entry | ||
-s FILESYSTEM=0 | ||
-s ALLOW_MEMORY_GROWTH=1 | ||
-s TOTAL_STACK=32768 | ||
-s TOTAL_MEMORY=64kb | ||
-s EXPORTED_FUNCTIONS='["_png_decompress","_malloc","_free"]' | ||
-s MALLOC=emmalloc | ||
-s ENVIRONMENT=worker | ||
-s STANDALONE_WASM=1 | ||
# -s ASSERTIONS=1 | ||
# -s SAFE_HEAP=1 | ||
-o libpng.wasm | ||
) | ||
emcc ${compile_options[@]} |
Oops, something went wrong.