Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: jpeg xl encoding and decoding #44

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM emscripten/emsdk:3.1.53
FROM emscripten/emsdk:3.1.54

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "packages/charls/extern/charls"]
path = packages/charls/extern/charls
url = https://github.com/cornerstonejs/charls.git
[submodule "packages/libjxl/extern/libjxl"]
path = packages/libjxl/extern/libjxl
url = https://github.com/libjxl/libjxl.git
108 changes: 108 additions & 0 deletions packages/libjxl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
build/
build-native/

.DS_Store

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
3 changes: 3 additions & 0 deletions packages/libjxl/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "extern/libjxl"]
path = extern/libjxl
url = https://github.com/libjxl/libjxl.git
30 changes: 30 additions & 0 deletions packages/libjxl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.16)

project (libjxl-js
LANGUAGES CXX)

# set the build type if not specified
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}")
endif()

if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/libjxl/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()

option(BUILD_SHARED_LIBS "" OFF)

# add the external library
add_subdirectory(extern/libjxl EXCLUDE_FROM_ALL)

# add the js wrapper
if(EMSCRIPTEN)
add_subdirectory(src)
endif()

# c++ native test case
if(NOT EMSCRIPTEN)
add_subdirectory(test/cpp)
endif()
45 changes: 45 additions & 0 deletions packages/libjxl/Docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

#FROM mcr.microsoft.com/vscode/devcontainers/base:0-debian-9
FROM emscripten/emsdk:3.1.54

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# This Dockerfile's base image has a non-root user with sudo access. Use the "remoteUser"
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
# will be updated to match your local UID/GID (when using the dockerFile property).
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Configure apt and install packages
RUN apt-get update \
#
# Install C++ tools
#&& apt-get -y install build-essential cmake cppcheck valgrind \
&& apt-get -y install build-essential cppcheck valgrind pkg-config libbrotli-dev clang \
# libjxl deps
&& apt-get -y install pkg-config libbrotli-dev libgflags-dev \
# version 3.17 of cmake
#& wget -qO- "https://cmake.org/files/v3.17/cmake-3.17.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local\
#& wget -qO- "https://cmake.org/files/v3.17/cmake-3.17.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local\
#
# [Optional] Update UID/GID if needed
&& if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \
groupmod --gid $USER_GID $USERNAME \
&& usermod --uid $USER_UID --gid $USER_GID $USERNAME \
&& chown -R $USER_UID:$USER_GID /home/$USERNAME; \
fi \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog
1 change: 1 addition & 0 deletions packages/libjxl/Docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -t jxlbuild .
4 changes: 4 additions & 0 deletions packages/libjxl/Docker/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
docker run -it --rm \
--user $(id -u):$(id -g) \
-v $HOME/src/github/chafey/libjxl-js:/libjxl-js -w /libjxl-js \
jxlbuild bash
3 changes: 3 additions & 0 deletions packages/libjxl/Docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docker run -it --rm \
-v $HOME/src/github/chafey/libjxl-js:/libjxl-js -w /libjxl-js \
emscripten/emsdk:3.1.54 bash
37 changes: 37 additions & 0 deletions packages/libjxl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM emscripten/emsdk:3.1.54

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# default username, userid and group id to use in the container.
# NOTE - scripts/docker-build.sh overrides these using current user info via command line args
ARG USERNAME=dev
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# delete emscripten user and create user with sudo privelege that matches current user
RUN userdel emscripten \
# && groupadd -g $USER_GID $USERNAME \
&& useradd -ms /bin/bash -u $USER_UID -g $USER_GID $USERNAME \
&& usermod -aG sudo $USERNAME \
&& printf "\n$USERNAME ALL=(ALL) NOPASSWD: ALL\n" >> /etc/sudoers

# Configure apt and install packages
RUN apt-get update \
#
# Install nvm
&& su - $USERNAME -c "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash" \
#
# Install C++ tools
&& apt-get -y install build-essential cppcheck valgrind pkg-config libbrotli-dev clang \
#
# version 3.17 of cmake
#& wget -qO- "https://cmake.org/files/v3.17/cmake-3.17.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local\
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog
21 changes: 21 additions & 0 deletions packages/libjxl/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Chris Hafey

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 54 additions & 0 deletions packages/libjxl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# libjxl-js
JS/WASM build of libjxl (JPEG-XL)

## Try It Out!

Try it in your browser [here](https://chafey.github.io/libjxl-js/test/browser/index.html)

## Building

This project uses git submodules to pull in libjxl. If developing, initialize the git submodules first:

```
> git submodule update --init --recursive
```

This project uses Docker to provide a consistent developer environment.

Create docker container 'libjxljsbuild'

```
> scripts/docker-build.sh
```

Create shell inside libjxljsbuild container:

```
> scripts/docker-sh.sh
```

Install node 16 (inside docker shell):
```
> nvm install 16
```

To build WASM (inside docker shell):
```
> scripts/wasm-build.sh
```

To build native C/C++ version (inside docker shell):
```
> scripts/native-build.sh
```

Run performance test (inside docker shell):
```
> scripts/performance.sh
```

## NOTES

Luca's suggestions for cjxl parameters to use for progressive lossless encoding

* ./tools/cjxl -P 0 -R 1 -I 0 -s 4 -g 0 in.png out.jxl
7 changes: 7 additions & 0 deletions packages/libjxl/build-native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
rm -rf build-native
mkdir -p build-native
(cd build-native && CC=clang CXX=clang++ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DJPEGXL_ENABLE_TOOLS=false ..)
#(cd build && cmake ..)
(cd build-native && CC=clang CXX=clang++ make VERBOSE=1 -j 8)
(build-native/test/cpp/cpptest)
11 changes: 11 additions & 0 deletions packages/libjxl/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
mkdir -p build
mkdir -p dist
#(cd build && CXXFLAGS=-msimd128 emcmake cmake -DCMAKE_BUILD_TYPE=Debug ..)
(./extern/libjxl/deps.sh)
(cd build && CXXFLAGS=-msimd128 emcmake cmake -DCMAKE_BUILD_TYPE=Debug ..)
(cd build && emmake make VERBOSE=1 -j ${nprocs})
cp ./build/src/libjxl.js ./dist
cp ./build/src/libjxl.wasm ./dist
# disable tests for now since CI doesn't like to run with SIMD
# (cd test/node; npm run test)
1 change: 1 addition & 0 deletions packages/libjxl/extern/libjxl
Submodule libjxl added at fb8b6f
28 changes: 28 additions & 0 deletions packages/libjxl/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@cornerstonejs/codec-libjxl",
"version": "0.0.1",
"description": "JS/WASM Build of [libjxl](https://github.com/libjxl/libjxl)",
"main": "dist/libjxljs.js",
"publishConfig": {
"access": "public"
},
"directories": {
"test": "test"
},
"engines": {
"node": ">=0.16"
},
"files": [
"package.json",
"README.md",
"dist"
],
"scripts": {
"build": "bash build.sh",
"build:ci": "yarn run build",
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "yarn run build"
},
"author": "",
"license": "ISC"
}
Loading