Skip to content

Commit 5201826

Browse files
committed
fix: make some method static
1 parent 3a2ffef commit 5201826

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

packages/libraw.wasm/src/index.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class LibRaw implements Disposable {
4040
LibRaw.modulePromise = mod;
4141
LibRaw.module = await mod;
4242
}
43+
return await LibRaw.modulePromise;
4344
}
4445
async waitUntilReady() {
4546
await LibRaw.modulePromise;
@@ -170,18 +171,25 @@ export class LibRaw implements Disposable {
170171
setFbddNoiserd(value: Int) {
171172
LibRaw.module._libraw_set_fbdd_noiserd(this.lr, value);
172173
}
173-
version(): string {
174-
return this.readString(LibRaw.module._libraw_version(this.lr));
174+
static version(): string {
175+
if (LibRaw.module === undefined) throw new Error("Not initialized");
176+
const ptr = LibRaw.module._libraw_version();
177+
return typ
178+
.sizedCharArrayAsString(Number.POSITIVE_INFINITY)
179+
.read({ buf: LibRaw.module.HEAPU8, offset: ptr }, {});
175180
}
176-
versionNumber(): number {
177-
return LibRaw.module._libraw_versionNumber(this.lr);
181+
static versionNumber(): number {
182+
if (LibRaw.module === undefined) throw new Error("Not initialized");
183+
return LibRaw.module._libraw_versionNumber();
178184
}
179-
cameraCount(): number {
180-
return LibRaw.module._libraw_cameraCount(this.lr);
185+
static cameraCount(): number {
186+
if (LibRaw.module === undefined) throw new Error("Not initialized");
187+
return LibRaw.module._libraw_cameraCount();
181188
}
182-
cameraList(): string[] {
183-
const ptr = LibRaw.module._libraw_cameraList(this.lr);
184-
const length = this.cameraCount();
189+
static cameraList(): string[] {
190+
if (LibRaw.module === undefined) throw new Error("Not initialized");
191+
const ptr = LibRaw.module._libraw_cameraList();
192+
const length = LibRaw.cameraCount();
185193
return typ
186194
.sizedArray(typ.charPointerAsString(), length)
187195
.read({ buf: LibRaw.module.HEAPU8, offset: ptr }, {});

packages/libraw.wasm/src/types/c-api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ export interface LibRawWasmModule {
6969
): LibRawProcessedImageT;
7070
_libraw_dcraw_clear_mem(lr: LibRawProcessedImageT): void;
7171
_libraw_strerror(error: ErrorCode): CharPtr;
72-
_libraw_version(lr: LibRawDataT): CharPtr;
73-
_libraw_versionNumber(lr: LibRawDataT): number;
74-
_libraw_capabilities(lr: LibRawDataT): void;
75-
_libraw_cameraCount(lr: LibRawDataT): number;
76-
_libraw_cameraList(lr: LibRawDataT): CharPtrPtr;
72+
_libraw_version(): CharPtr;
73+
_libraw_versionNumber(): number;
74+
_libraw_capabilities(): void;
75+
_libraw_cameraCount(): number;
76+
_libraw_cameraList(): CharPtrPtr;
7777
_libraw_get_decoder_info(info: LibRawDecoderInfo): ErrorCode;
7878
_libraw_unpack_function_name(lr: LibRawDataT): CharPtr;
7979
_libraw_COLOR(lr: LibRawDataT, row: Int, col: Int): Int;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { LibRaw } from 'libraw.wasm';
22
import * as Comlink from 'comlink';
33

4+
LibRaw.initialize().then(() => {
5+
console.log('LibRaw version:', LibRaw.version());
6+
console.log('Supported cameras:', LibRaw.cameraList());
7+
});
8+
49
Comlink.expose(new LibRaw());

playground/src/routes/+page.svelte

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
type LibRawReturn<T extends keyof LibRaw> = LibRaw[T] extends (...args: unknown[]) => infer R
1010
? R
1111
: never;
12-
let version = $state<string | undefined>();
1312
let iparams = $state<ResolvablePromise<LibRawReturn<'getIParams'>> | undefined>();
1413
let thumb = $state<ResolvablePromise<Uint8Array> | undefined>();
1514
let raw = $state<ResolvablePromise<LibRawReturn<'dcrawMakeMemImage'>> | undefined>();
@@ -22,8 +21,6 @@
2221
raw = resolvable();
2322
const libraw = createLibRaw();
2423
await libraw.waitUntilReady();
25-
libraw.cameraList().then(console.log, console.error);
26-
version = await libraw.version();
2724
try {
2825
const arrayBuffer = await readFile(file);
2926
await libraw.open(arrayBuffer);
@@ -49,9 +46,6 @@
4946
};
5047
</script>
5148

52-
{#if version}
53-
<p>libraw version: {version}</p>
54-
{/if}
5549
<input type="file" onchange={onFileChange} />
5650
{#if iparams}
5751
{#await iparams}

tests/__snapshots__/index.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`supported cameras 1`] = `
3+
exports[`meta 3`] = `
44
[
55
"Adobe Digital Negative (DNG)",
66
"AgfaPhoto DC-833m",

tests/index.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const __dirname = path.dirname(__filename);
88
const repoRoot = path.join(__dirname, "..");
99
const samplesDir = path.join(repoRoot, "raw-samples");
1010

11-
it("supported cameras", async () => {
12-
using libraw = new LibRaw();
13-
await libraw.waitUntilReady();
14-
const cameras = libraw.cameraList();
15-
expect(cameras).toMatchSnapshot();
11+
it("meta", async () => {
12+
await LibRaw.initialize();
13+
expect(LibRaw.version()).toMatchInlineSnapshot(`"0.22.0-Devel202403"`);
14+
expect(LibRaw.versionNumber()).toMatchInlineSnapshot("5632");
15+
expect(LibRaw.cameraList()).toMatchSnapshot();
1616
});
1717

1818
it("ARW", async () => {

0 commit comments

Comments
 (0)