@bb-studio/ocio 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ import OcioWasmModule from '#ocio-wasm';
2
+ import DEFAULT_WASM_URL from './wasm-url.js';
3
+
1
4
  export const ACES_CG_V2_CONFIG = 'ocio://cg-config-v2.2.0_aces-v1.3_ocio-v2.4';
2
5
  export const ACES_STUDIO_V2_CONFIG = 'ocio://studio-config-v2.2.0_aces-v1.3_ocio-v2.4';
3
6
  export const ACES_CG_V4_CONFIG = 'ocio://cg-config-v4.0.0_aces-v2.0_ocio-v2.5';
@@ -17,7 +20,6 @@ export const OptimizationFlags = Object.freeze({
17
20
  DRAFT: -1
18
21
  });
19
22
 
20
- const DEFAULT_WASM_URL = new URL('../dist/ocio-wasm.wasm', import.meta.url).href;
21
23
  const DEFAULT_GPU_SHADER_FUNCTION = 'OCIODisplay';
22
24
  const DEFAULT_GPU_RESOURCE_PREFIX = 'ocio';
23
25
  const GPU_UNIFORM_TYPES = Object.freeze([
@@ -82,8 +84,9 @@ function toPositiveInteger(value, name) {
82
84
  }
83
85
 
84
86
  export async function createOCIO(options = {}) {
85
- const moduleFactory = options.moduleFactory ?? (await import('#ocio-wasm')).default;
87
+ const moduleFactory = options.moduleFactory ?? OcioWasmModule;
86
88
  const userLocateFile = options.locateFile;
89
+ const wasmUrl = options.wasmUrl == null ? DEFAULT_WASM_URL : String(options.wasmUrl);
87
90
  const moduleOptions = {
88
91
  ...options.moduleOptions,
89
92
  locateFile(path, prefix) {
@@ -91,7 +94,7 @@ export async function createOCIO(options = {}) {
91
94
  return userLocateFile(path, prefix);
92
95
  }
93
96
  if (path === 'ocio-wasm.wasm') {
94
- return DEFAULT_WASM_URL;
97
+ return wasmUrl;
95
98
  }
96
99
  return prefix + path;
97
100
  }
@@ -297,6 +300,79 @@ export class Config {
297
300
  });
298
301
  }
299
302
 
303
+ getFileRule(index) {
304
+ const ruleIndex = Number(index);
305
+ if (!Number.isInteger(ruleIndex) || ruleIndex < 0) {
306
+ throw new RangeError('OCIO file rule index must be a non-negative integer');
307
+ }
308
+
309
+ const customKeyCount = this.ocio.module._ocio_config_get_file_rule_custom_key_count(
310
+ this.handle,
311
+ ruleIndex
312
+ );
313
+ const custom = {};
314
+ for (let keyIndex = 0; keyIndex < customKeyCount; keyIndex += 1) {
315
+ const name = this.ocio._string(
316
+ 'ocio_config_get_file_rule_custom_key_name',
317
+ this.handle,
318
+ ruleIndex,
319
+ keyIndex
320
+ );
321
+ custom[name] = this.ocio._string(
322
+ 'ocio_config_get_file_rule_custom_key_value',
323
+ this.handle,
324
+ ruleIndex,
325
+ keyIndex
326
+ );
327
+ }
328
+
329
+ return {
330
+ index: ruleIndex,
331
+ name: this.ocio._string('ocio_config_get_file_rule_name', this.handle, ruleIndex),
332
+ colorSpace: this.ocio._string('ocio_config_get_file_rule_color_space', this.handle, ruleIndex),
333
+ pattern: this.ocio._string('ocio_config_get_file_rule_pattern', this.handle, ruleIndex),
334
+ extension: this.ocio._string('ocio_config_get_file_rule_extension', this.handle, ruleIndex),
335
+ regex: this.ocio._string('ocio_config_get_file_rule_regex', this.handle, ruleIndex),
336
+ custom
337
+ };
338
+ }
339
+
340
+ listFileRules() {
341
+ const count = this.ocio.module._ocio_config_get_num_file_rules(this.handle);
342
+ return Array.from({ length: count }, (_, index) => this.getFileRule(index));
343
+ }
344
+
345
+ matchFileRule(filePath) {
346
+ return this.ocio._withCString(filePath, (filePathPtr) => {
347
+ const colorSpace = this.ocio._string(
348
+ 'ocio_config_get_color_space_from_filepath',
349
+ this.handle,
350
+ filePathPtr
351
+ );
352
+ if (!colorSpace) {
353
+ return null;
354
+ }
355
+
356
+ const ruleIndex = this.ocio.module._ocio_config_get_file_rule_index_from_filepath(
357
+ this.handle,
358
+ filePathPtr
359
+ );
360
+ const rule = this.getFileRule(ruleIndex);
361
+ const isDefaultRule =
362
+ this.ocio.module._ocio_config_filepath_only_matches_default_rule(
363
+ this.handle,
364
+ filePathPtr
365
+ ) === 1;
366
+ return {
367
+ colorSpace,
368
+ ruleIndex,
369
+ ruleName: rule.name,
370
+ isDefaultRule,
371
+ custom: rule.custom
372
+ };
373
+ });
374
+ }
375
+
300
376
  listDisplays() {
301
377
  const count = this.ocio.module._ocio_config_get_num_displays(this.handle);
302
378
  return Array.from({ length: count }, (_, index) => this.ocio._string('ocio_config_get_display', this.handle, index));
@@ -0,0 +1,11 @@
1
+ import { createOCIO as createDefaultOCIO } from './index.js';
2
+ import wasmUrl from './wasm-url.vite.js';
3
+
4
+ export * from './index.js';
5
+
6
+ export function createOCIO(options = {}) {
7
+ if (options.locateFile || options.wasmUrl != null) {
8
+ return createDefaultOCIO(options);
9
+ }
10
+ return createDefaultOCIO({ ...options, wasmUrl });
11
+ }
package/src/ocio-js.d.ts CHANGED
@@ -20,6 +20,7 @@ export const OptimizationFlags: Readonly<{
20
20
  export interface CreateOCIOOptions {
21
21
  moduleFactory?: (options?: unknown) => Promise<unknown>;
22
22
  moduleOptions?: Record<string, unknown>;
23
+ wasmUrl?: string;
23
24
  locateFile?: (path: string, prefix: string) => string;
24
25
  }
25
26
 
@@ -54,6 +55,24 @@ export interface ViewInfo {
54
55
  description: string;
55
56
  }
56
57
 
58
+ export interface FileRuleInfo {
59
+ index: number;
60
+ name: string;
61
+ colorSpace: string;
62
+ pattern: string;
63
+ extension: string;
64
+ regex: string;
65
+ custom: Record<string, string>;
66
+ }
67
+
68
+ export interface FileRuleMatch {
69
+ colorSpace: string;
70
+ ruleIndex: number;
71
+ ruleName: string;
72
+ isDefaultRule: boolean;
73
+ custom: Record<string, string>;
74
+ }
75
+
57
76
  export interface DisplayViewProcessorOptions {
58
77
  source: string;
59
78
  display: string;
@@ -136,6 +155,9 @@ export class Config {
136
155
  listRoles(): RoleInfo[];
137
156
  listColorSpaces(): ColorSpaceInfo[];
138
157
  getColorSpace(name: string): ColorSpaceInfo;
158
+ getFileRule(index: number): FileRuleInfo;
159
+ listFileRules(): FileRuleInfo[];
160
+ matchFileRule(filePath: string): FileRuleMatch | null;
139
161
  listDisplays(): string[];
140
162
  getDefaultDisplay(): string;
141
163
  listViews(display: string): ViewInfo[];
@@ -0,0 +1 @@
1
+ export default new URL('../dist/ocio-wasm.wasm', import.meta.url).href;
@@ -0,0 +1,3 @@
1
+ import wasmUrl from '../dist/ocio-wasm.wasm?url';
2
+
3
+ export default wasmUrl;