Language: English | 简体中文 | 日本語
Compile Lensfun into WebAssembly and expose a frontend-friendly JavaScript API.
lensfun-wasm ships:
- Upstream
lensfunsource as a pinned git submodule - Full official lens database (
data/db) packaged into.data - A C bridge layer for stable wasm exports
- A high-level TypeScript API for browser applications
- ESM and UMD bundles for npm and CDN usage
- Initialize Lensfun database in browser
- Search lenses and cameras
- Build correction maps for:
- Geometry/distortion
- TCA (transverse chromatic aberration)
- Vignetting
The output maps are designed for WebGL/WebGPU/canvas remap pipelines.
third_party/lensfun: upstream source (submodule)native/: wasm bridge, GLib compatibility, native CMake buildsrc/: public TypeScript APIscripts/build-wasm.sh: wasm build entrydist/assets/: generatedlensfun-core.js/.wasm/.data
- Modern browser with WebAssembly support
- Node.js 22+
- npm 10+
- CMake 3.20+
- Emscripten (
emcc,emcmakein PATH)
npm install @neoanaloglabkk/lensfun-wasmimport { createLensfun } from '@neoanaloglabkk/lensfun-wasm';
import createLensfunCoreModule from '@neoanaloglabkk/lensfun-wasm/core';
import wasmUrl from '@neoanaloglabkk/lensfun-wasm/core-wasm?url';
import dataUrl from '@neoanaloglabkk/lensfun-wasm/core-data?url';
const client = await createLensfun({
moduleFactory: createLensfunCoreModule,
wasmUrl,
dataUrl
});
const lenses = client.searchLenses({
lensModel: 'pEntax 50-200 ED'
});
console.log(lenses[0]);<script src="https://cdn.jsdelivr.net/npm/@neoanaloglabkk/lensfun-wasm@0.1.2/dist/assets/lensfun-core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@neoanaloglabkk/lensfun-wasm@0.1.2/dist/umd/index.iife.js"></script>
<script>
(async () => {
const client = await LensfunWasm.createLensfun();
const lenses = client.searchLenses({ lensModel: 'pEntax 50-200 ED' });
console.log(lenses[0]);
})();
</script>options (LensfunInitOptions):
moduleFactory?: (opts) => Promise<LensfunModule>- Recommended in bundlers. Usually from
import createLensfunCoreModule from '@neoanaloglabkk/lensfun-wasm/core'.
- Recommended in bundlers. Usually from
moduleJsUrl?: string- Optional fallback URL for loading
lensfun-core.jsdynamically.
- Optional fallback URL for loading
wasmUrl?: string- Explicit URL for
lensfun-core.wasm.
- Explicit URL for
dataUrl?: string- Explicit URL for
lensfun-core.data.
- Explicit URL for
locateFile?: (path, prefix) => string- Full override for Emscripten file resolution.
dbPath?: string- Database path in Emscripten FS. Default
/lensfun-db.
- Database path in Emscripten FS. Default
autoInitDb?: boolean- Default
true. If false, db init is skipped.
- Default
SearchLensesInput:
lensModel(required)lensMaker?cameraMaker?cameraModel?searchFlags?(defaultLF_SEARCH_SORT_AND_UNIQUIFY)
Returns LensMatch[]:
handle(native lens handle for map generation)maker,model,scoreminFocal,maxFocal,minAperture,maxAperture,cropFactor
SearchCamerasInput:
maker?model?searchFlags?
Returns CameraMatch[] with maker/model/variant/mount/cropFactor/score.
Returns bit flags from Lensfun (LF_MODIFY_*).
CorrectionInput:
lensHandle(required)width,height(required, positive integers)focal,crop(required)step?(default1)reverse?(defaultfalse)includeTca?(defaultfalse)includeVignetting?(defaultfalse)aperture?(required whenincludeVignetting = true)distance?(default1000)
CorrectionMaps:
gridWidth,gridHeight,stepgeometry: Float32Arraylength =gridW * gridH * 2- Layout:
[x0, y0, x1, y1, ...]
- Layout:
tca?: Float32Arraylength =gridW * gridH * 6- Layout:
[rx, ry, gx, gy, bx, by, ...]
- Layout:
vignetting?: Float32Arraylength =gridW * gridH * 3- Layout:
[rGain, gGain, bGain, ...]
- Layout:
Releases native database memory. Call this when finished.
Search:
LF_SEARCH_LOOSE = 1LF_SEARCH_SORT_AND_UNIQUIFY = 2
Modification flags:
LF_MODIFY_TCA = 0x00000001LF_MODIFY_VIGNETTING = 0x00000002LF_MODIFY_DISTORTION = 0x00000008LF_MODIFY_GEOMETRY = 0x00000010LF_MODIFY_SCALE = 0x00000020LF_MODIFY_PERSPECTIVE = 0x00000040
# 1) install dependencies
npm install
# 2) make sure emcc/emcmake are in PATH
# (example)
# source /path/to/emsdk/emsdk_env.sh
# 3) build wasm + js + d.ts
npm run buildnpm run build steps:
npm run build:wasmnpm run build:jsnpm run build:types
Output:
dist/assets/lensfun-core.jsdist/assets/lensfun-core.wasmdist/assets/lensfun-core.datadist/esm/index.jsdist/umd/index.iife.jsdist/types/index.d.ts
npm run checkIncludes:
- JS bundle build
- Type declaration build
- Vitest unit tests
- Lensfun is tracked by pinned submodule commit.
- Upgrade manually (no auto tracking).
Sync helper:
scripts/sync-upstream.sh origin/masterAfter bumping upstream:
- Rebuild wasm
- Run tests
- Update
UPSTREAM.md
Install and activate emsdk, then re-run build in the same shell session.
Provide moduleFactory or pre-load dist/assets/lensfun-core.js so createLensfunCoreModule exists.
Database path or .data load is wrong.
- Ensure
dataUrlpoints tolensfun-core.data - Ensure
dbPathmatches preloaded path (/lensfun-dbby default)
Input validation or Lensfun calibration mismatch.
- Check
lensHandlecomes from latestsearchLenses - Verify
width/height/stepare valid - Provide
aperturewhen requesting vignetting
- Lensfun core library: LGPL-3.0-or-later
- Lensfun database: CC BY-SA 3.0
- tinyxml2: zlib license
- utf8proc: MIT license
See: