https://github.com/goncalomb/sane-wasm Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} goncalomb / sane-wasm Public * Notifications * Fork 0 * Star 27 A WebAssembly port of the SANE API. webscan.goncalomb.com/ License GPL-2.0, LGPL-2.1 licenses found Licenses found GPL-2.0 LICENSE.txt LGPL-2.1 LICENSE-LGPL.txt 27 stars 0 forks Star Notifications * Code * Issues 3 * Pull requests 0 * Actions * Security * Insights More * Code * Issues * Pull requests * Actions * Security * Insights goncalomb/sane-wasm This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 1 branch 2 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/g] Use Git or checkout with SVN using the web URL. [gh repo clone goncal] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @goncalomb goncalomb Update README.md ... 3100bc9 Apr 28, 2023 Update README.md 3100bc9 Git stats * 20 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time deps Finally building all SANE backends April 25, 2023 21:51 .dockerignore Improve build script April 10, 2023 22:29 .gitignore Add support for docker build with submodules April 14, 2023 11:37 .gitmodules Add first build code April 2, 2023 22:05 Dockerfile Improve pthreads support April 22, 2023 21:13 LICENSE-LGPL.txt Add license April 26, 2023 18:41 LICENSE.txt Add license April 26, 2023 18:41 README.md Update README.md April 28, 2023 11:59 build.sh Add license April 26, 2023 18:41 glue.cpp Add license April 26, 2023 18:41 pre.js Add license April 26, 2023 18:41 shell.html Finally building all SANE backends April 25, 2023 21:51 View code [ ] SANE WebAssembly (sane-wasm) WebScan Building build.sh Using Exposed API (may not be final) Differences with the SANE API Constants Functions License README.md SANE WebAssembly (sane-wasm) A project to bring the SANE API to the web. Currently, it only supports USB scanners and is only tested on a browser environment (WebUSB). This works by compiling all SANE backends (and required dependencies) to WebAssembly using Emscripten. The other key piece is @RReverser's bridge from libusb to WebUSB (1/2) with some patching to support multi-threading. Right now, it includes all backends that have support for at least one USB device (genesys is not included due to issues). No external backends are included at the moment. WebScan Check webscan.goncalomb.com for a demo of sane-wasm. This is a React application that uses sane-wasm for document/image scanning directly in the browser. Exposes all scanning options to the user for full control. If you are interested in seeing the compiled output of sane-wasm, check: * webscan.goncalomb.com/sane-wasm/: all files * webscan.goncalomb.com/sane-wasm/libsane.html: test page Building Building requires emscripten and all the required tools to build the dependencies. The preferred way is just to use the pre-configured Docker image: git clone --recurse-submodules https://github.com/goncalomb/sane-wasm.git cd sane-wasm ./build.sh --with-docker --clean Start the test server with: ./build.sh --with-docker --no-build --emrun Check the test page at: http://localhost:6931/libsane.html. build.sh The ./build.sh script has other options for debugging: usage: build.sh [options] --with-docker run with docker (preferred) --clean clean 'deps' and 'build' directories --no-build don't actually build --debug enable debug flags --emrun run emrun development server --shell run debug shell (depends on --with-docker) Using For now, this project has only been used on a browser environment, usage with Node.js or other environments is untested/unsupported. The API may still suffer changes and no npm package is provided at the moment. The recommended way to use this project is to add it as a submodule to your application. Integrate ./build.sh with your build process. And include the main .js file: I don't recommend minifying libsane.js with your application code. It may break some things. This will be improved in the future. Exposed API (may not be final) Most of the SANE API is exposed as-is. Check the SANE Standard. Some safeguards are in place to avoid API misuse and prevent memory leaks. It's important to understand the SANE API and follow the Code Flow to avoid issues. Differences with the SANE API The most important difference with the underlying SANE API is that device handles are not exposed. This means that sane_open() does not return a device handle. A single handle is managed by the internal code. This effectively means that only one device can be accessed at a time. This was a design decision made to simplify the API and prevent other issues. Personally, I believe that this is an acceptable change, especially for WebAssembly where it may be easier to lose track of opened resources and crash the application. The SANE API is also somewhat unforgiving and building more safeguards around it (especially with multiple handles) is not worth the effort. Ultimately I don't see a use that requires more than one device open at a time. @goncalomb Constants documentation in progress, the API may still suffer changes LibSANE.SANE_WASM_COMMIT LibSANE.SANE_WASM_VERSION LibSANE.SANE_WASM_BACKENDS LibSANE.SANE_CURRENT_MAJOR (number) = SANE C macro SANE_CURRENT_MAJOR LibSANE.SANE_CURRENT_MINOR (number) = SANE C macro SANE_CURRENT_MINOR LibSANE.SANE_STATUS (object) = SANE C enum SANE_Status LibSANE.SANE_TYPE (object) = SANE C enum SANE_Value_Type LibSANE.SANE_UNIT (object) = SANE C enum SANE_Unit LibSANE.SANE_CONSTRAINT (object) = SANE C enum SANE_Constraint_Type LibSANE.SANE_FRAME (object) = SANE C enum SANE_Frame Functions documentation in progress, the API may still suffer changes LibSANE.sane_get_state (extra function, not part of the SANE API) LibSANE.sane_init LibSANE.sane_exit LibSANE.sane_get_devices LibSANE.sane_open LibSANE.sane_close LibSANE.sane_get_option_descriptor LibSANE.sane_control_option_get_value LibSANE.sane_control_option_set_value LibSANE.sane_control_option_set_auto LibSANE.sane_get_parameters LibSANE.sane_start LibSANE.sane_read LibSANE.sane_cancel LibSANE.sane_strstatus License Because of the weird state of SANE's licensing (GPL + linking exception, on some backends), see backends/LICENSE. I releasing this project with dual licensing GNU GPLv2 + GNU LGPLv2.1. IANAL, you choose. About A WebAssembly port of the SANE API. webscan.goncalomb.com/ Topics webassembly wasm libusb scanning webusb sane sane-backend Resources Readme License GPL-2.0, LGPL-2.1 licenses found Licenses found GPL-2.0 LICENSE.txt LGPL-2.1 LICENSE-LGPL.txt Stars 27 stars Watchers 1 watching Forks 0 forks Report repository Releases 2 tags Languages * C++ 37.7% * HTML 32.2% * Shell 16.5% * JavaScript 13.3% * Dockerfile 0.3% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.