image-color-grading 1.0.2 → 1.0.4

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/dist/index.d.cts CHANGED
@@ -1,3 +1,16 @@
1
+ /**
2
+ * 后端类型
3
+ */
4
+ type BackendType$1 = 'webgl' | 'webgpu';
5
+ /**
6
+ * 处理器配置选项
7
+ */
8
+ interface ProcessorOptions {
9
+ /** canvas 元素 */
10
+ canvas?: HTMLCanvasElement;
11
+ /** 后端选择:'auto' | 'webgpu' | 'webgl' */
12
+ backend?: 'auto' | BackendType$1;
13
+ }
1
14
  /**
2
15
  * 调色设置参数
3
16
  */
@@ -112,9 +125,16 @@ declare function analyzeImage(imageData: ImageData): ImageAnalysis;
112
125
  /**
113
126
  * 图像调色处理器
114
127
  *
128
+ * 支持 WebGL 和 WebGPU 双后端,自动降级
129
+ *
115
130
  * @example
116
131
  * ```ts
132
+ * // 默认自动选择后端
117
133
  * const processor = new ImageColorGrading();
134
+ *
135
+ * // 指定使用 WebGPU
136
+ * const processor = new ImageColorGrading({ backend: 'webgpu' });
137
+ *
118
138
  * await processor.loadImage('path/to/image.jpg');
119
139
  * processor.setSettings({ brightness: 20, contrast: 10 });
120
140
  * processor.render();
@@ -123,18 +143,32 @@ declare function analyzeImage(imageData: ImageData): ImageAnalysis;
123
143
  */
124
144
  declare class ImageColorGrading {
125
145
  private canvas;
126
- private resources;
146
+ private backend;
147
+ private backendType;
127
148
  private settings;
128
149
  private imageLoaded;
150
+ private initPromise;
129
151
  /**
130
152
  * 创建图像调色处理器
131
- * @param canvas - 可选的 canvas 元素,不传则自动创建
153
+ * @param options - 配置选项
132
154
  */
133
- constructor(canvas?: HTMLCanvasElement);
155
+ constructor(options?: ProcessorOptions);
134
156
  /**
135
157
  * 获取 canvas 元素
136
158
  */
137
159
  getCanvas(): HTMLCanvasElement;
160
+ /**
161
+ * 获取当前后端类型
162
+ */
163
+ getBackendType(): BackendType$1;
164
+ /**
165
+ * 检查 WebGPU 是否可用
166
+ */
167
+ static isWebGPUSupported(): boolean;
168
+ /**
169
+ * 检查 WebGL 是否可用
170
+ */
171
+ static isWebGLSupported(): boolean;
138
172
  /**
139
173
  * 获取当前设置
140
174
  */
@@ -148,6 +182,14 @@ declare class ImageColorGrading {
148
182
  * 重置所有设置为默认值
149
183
  */
150
184
  resetSettings(): void;
185
+ /**
186
+ * 初始化后端
187
+ */
188
+ private initBackend;
189
+ /**
190
+ * 确保后端已初始化
191
+ */
192
+ private ensureBackend;
151
193
  /**
152
194
  * 从 URL 加载图像
153
195
  * @param url - 图像 URL
@@ -158,7 +200,7 @@ declare class ImageColorGrading {
158
200
  * 从 HTMLImageElement 加载图像
159
201
  * @param image - 图像元素
160
202
  */
161
- loadFromImage(image: HTMLImageElement): void;
203
+ loadFromImage(image: HTMLImageElement): Promise<void>;
162
204
  /**
163
205
  * 从 File 对象加载图像
164
206
  * @param file - File 对象
@@ -169,7 +211,7 @@ declare class ImageColorGrading {
169
211
  * 从 ImageData 加载图像
170
212
  * @param imageData - ImageData 对象
171
213
  */
172
- loadFromImageData(imageData: ImageData): void;
214
+ loadFromImageData(imageData: ImageData): Promise<void>;
173
215
  /**
174
216
  * 渲染图像
175
217
  */
@@ -223,11 +265,140 @@ declare class ImageColorGrading {
223
265
  * @returns 应用的设置
224
266
  */
225
267
  applyPreset(preset: PresetType): ColorGradingSettings;
226
- private getWebGLContext;
227
- private initFromImage;
268
+ }
269
+
270
+ /**
271
+ * 后端抽象接口
272
+ * 定义 WebGL 和 WebGPU 后端的统一接口
273
+ */
274
+
275
+ /**
276
+ * 后端类型
277
+ */
278
+ type BackendType = 'webgl' | 'webgpu';
279
+ /**
280
+ * 后端初始化选项
281
+ */
282
+ interface BackendOptions {
283
+ }
284
+ /**
285
+ * 后端抽象基类
286
+ */
287
+ declare abstract class BaseBackend {
288
+ protected canvas: HTMLCanvasElement;
289
+ protected width: number;
290
+ protected height: number;
291
+ protected initialized: boolean;
292
+ protected options: BackendOptions;
293
+ constructor(canvas: HTMLCanvasElement, options?: BackendOptions);
294
+ /**
295
+ * 获取后端类型
296
+ */
297
+ abstract getType(): BackendType;
298
+ /**
299
+ * 检查后端是否可用
300
+ */
301
+ static isSupported(): boolean;
302
+ /**
303
+ * 初始化后端
304
+ */
305
+ abstract init(): Promise<void> | void;
306
+ /**
307
+ * 从图像元素加载纹理
308
+ */
309
+ abstract loadFromImage(image: HTMLImageElement): void;
310
+ /**
311
+ * 从 ImageData 加载纹理
312
+ */
313
+ abstract loadFromImageData(imageData: ImageData): void;
314
+ /**
315
+ * 渲染图像
316
+ */
317
+ abstract render(settings: ColorGradingSettings): void;
318
+ /**
319
+ * 获取渲染结果的 ImageData
320
+ */
321
+ abstract getImageData(): ImageData;
322
+ /**
323
+ * 获取图像尺寸
324
+ */
325
+ getSize(): {
326
+ width: number;
327
+ height: number;
328
+ };
329
+ /**
330
+ * 检查是否已初始化
331
+ */
332
+ isInitialized(): boolean;
333
+ /**
334
+ * 销毁后端资源
335
+ */
336
+ abstract dispose(): void;
337
+ }
338
+ /**
339
+ * 检测 WebGPU 支持
340
+ */
341
+ declare function isWebGPUSupported(): boolean;
342
+ /**
343
+ * 检测 WebGL 支持
344
+ */
345
+ declare function isWebGLSupported(): boolean;
346
+ /**
347
+ * 自动选择最佳后端
348
+ */
349
+ declare function selectBestBackend(preferred?: 'auto' | BackendType): BackendType;
350
+
351
+ /**
352
+ * WebGL 后端实现
353
+ */
354
+
355
+ declare class WebGLBackend extends BaseBackend {
356
+ private gl;
357
+ private resources;
358
+ constructor(canvas: HTMLCanvasElement, options?: BackendOptions);
359
+ getType(): BackendType;
360
+ static isSupported(): boolean;
361
+ init(): void;
362
+ loadFromImage(image: HTMLImageElement): void;
363
+ loadFromImageData(imageData: ImageData): void;
364
+ render(settings: ColorGradingSettings): void;
365
+ getImageData(): ImageData;
366
+ dispose(): void;
367
+ private getShaderSource;
368
+ private initResources;
369
+ private disposeResources;
370
+ private drawFrame;
371
+ }
372
+
373
+ /**
374
+ * WebGPU 后端实现
375
+ */
376
+
377
+ declare class WebGPUBackend extends BaseBackend {
378
+ private device;
379
+ private resources;
380
+ constructor(canvas: HTMLCanvasElement, options?: BackendOptions);
381
+ getType(): BackendType;
382
+ static isSupported(): boolean;
383
+ init(): Promise<void>;
384
+ loadFromImage(image: HTMLImageElement): void;
385
+ loadFromImageData(imageData: ImageData): void;
386
+ render(settings: ColorGradingSettings): void;
387
+ getImageData(): ImageData;
388
+ /**
389
+ * 异步获取 ImageData
390
+ */
391
+ getImageDataAsync(): Promise<ImageData>;
392
+ dispose(): void;
393
+ private getShaderSource;
394
+ private createPipeline;
395
+ private createRenderTarget;
228
396
  private initResources;
397
+ private initResourcesFromImageData;
398
+ private setupResources;
229
399
  private disposeResources;
400
+ private createUniformBuffer;
230
401
  private drawFrame;
231
402
  }
232
403
 
233
- export { type ColorGradingSettings, type ExportOptions, type ImageAnalysis, ImageColorGrading, type ImageLevels, type PartialColorGradingSettings, type PresetType, analyzeImage, analyzeImageLevels, analyzeImageVibrance, defaultSettings, presets };
404
+ export { type BackendType$1 as BackendType, BaseBackend, type ColorGradingSettings, type ExportOptions, type ImageAnalysis, ImageColorGrading, type ImageLevels, type PartialColorGradingSettings, type PresetType, type ProcessorOptions, WebGLBackend, WebGPUBackend, analyzeImage, analyzeImageLevels, analyzeImageVibrance, defaultSettings, isWebGLSupported, isWebGPUSupported, presets, selectBestBackend };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,16 @@
1
+ /**
2
+ * 后端类型
3
+ */
4
+ type BackendType$1 = 'webgl' | 'webgpu';
5
+ /**
6
+ * 处理器配置选项
7
+ */
8
+ interface ProcessorOptions {
9
+ /** canvas 元素 */
10
+ canvas?: HTMLCanvasElement;
11
+ /** 后端选择:'auto' | 'webgpu' | 'webgl' */
12
+ backend?: 'auto' | BackendType$1;
13
+ }
1
14
  /**
2
15
  * 调色设置参数
3
16
  */
@@ -112,9 +125,16 @@ declare function analyzeImage(imageData: ImageData): ImageAnalysis;
112
125
  /**
113
126
  * 图像调色处理器
114
127
  *
128
+ * 支持 WebGL 和 WebGPU 双后端,自动降级
129
+ *
115
130
  * @example
116
131
  * ```ts
132
+ * // 默认自动选择后端
117
133
  * const processor = new ImageColorGrading();
134
+ *
135
+ * // 指定使用 WebGPU
136
+ * const processor = new ImageColorGrading({ backend: 'webgpu' });
137
+ *
118
138
  * await processor.loadImage('path/to/image.jpg');
119
139
  * processor.setSettings({ brightness: 20, contrast: 10 });
120
140
  * processor.render();
@@ -123,18 +143,32 @@ declare function analyzeImage(imageData: ImageData): ImageAnalysis;
123
143
  */
124
144
  declare class ImageColorGrading {
125
145
  private canvas;
126
- private resources;
146
+ private backend;
147
+ private backendType;
127
148
  private settings;
128
149
  private imageLoaded;
150
+ private initPromise;
129
151
  /**
130
152
  * 创建图像调色处理器
131
- * @param canvas - 可选的 canvas 元素,不传则自动创建
153
+ * @param options - 配置选项
132
154
  */
133
- constructor(canvas?: HTMLCanvasElement);
155
+ constructor(options?: ProcessorOptions);
134
156
  /**
135
157
  * 获取 canvas 元素
136
158
  */
137
159
  getCanvas(): HTMLCanvasElement;
160
+ /**
161
+ * 获取当前后端类型
162
+ */
163
+ getBackendType(): BackendType$1;
164
+ /**
165
+ * 检查 WebGPU 是否可用
166
+ */
167
+ static isWebGPUSupported(): boolean;
168
+ /**
169
+ * 检查 WebGL 是否可用
170
+ */
171
+ static isWebGLSupported(): boolean;
138
172
  /**
139
173
  * 获取当前设置
140
174
  */
@@ -148,6 +182,14 @@ declare class ImageColorGrading {
148
182
  * 重置所有设置为默认值
149
183
  */
150
184
  resetSettings(): void;
185
+ /**
186
+ * 初始化后端
187
+ */
188
+ private initBackend;
189
+ /**
190
+ * 确保后端已初始化
191
+ */
192
+ private ensureBackend;
151
193
  /**
152
194
  * 从 URL 加载图像
153
195
  * @param url - 图像 URL
@@ -158,7 +200,7 @@ declare class ImageColorGrading {
158
200
  * 从 HTMLImageElement 加载图像
159
201
  * @param image - 图像元素
160
202
  */
161
- loadFromImage(image: HTMLImageElement): void;
203
+ loadFromImage(image: HTMLImageElement): Promise<void>;
162
204
  /**
163
205
  * 从 File 对象加载图像
164
206
  * @param file - File 对象
@@ -169,7 +211,7 @@ declare class ImageColorGrading {
169
211
  * 从 ImageData 加载图像
170
212
  * @param imageData - ImageData 对象
171
213
  */
172
- loadFromImageData(imageData: ImageData): void;
214
+ loadFromImageData(imageData: ImageData): Promise<void>;
173
215
  /**
174
216
  * 渲染图像
175
217
  */
@@ -223,11 +265,140 @@ declare class ImageColorGrading {
223
265
  * @returns 应用的设置
224
266
  */
225
267
  applyPreset(preset: PresetType): ColorGradingSettings;
226
- private getWebGLContext;
227
- private initFromImage;
268
+ }
269
+
270
+ /**
271
+ * 后端抽象接口
272
+ * 定义 WebGL 和 WebGPU 后端的统一接口
273
+ */
274
+
275
+ /**
276
+ * 后端类型
277
+ */
278
+ type BackendType = 'webgl' | 'webgpu';
279
+ /**
280
+ * 后端初始化选项
281
+ */
282
+ interface BackendOptions {
283
+ }
284
+ /**
285
+ * 后端抽象基类
286
+ */
287
+ declare abstract class BaseBackend {
288
+ protected canvas: HTMLCanvasElement;
289
+ protected width: number;
290
+ protected height: number;
291
+ protected initialized: boolean;
292
+ protected options: BackendOptions;
293
+ constructor(canvas: HTMLCanvasElement, options?: BackendOptions);
294
+ /**
295
+ * 获取后端类型
296
+ */
297
+ abstract getType(): BackendType;
298
+ /**
299
+ * 检查后端是否可用
300
+ */
301
+ static isSupported(): boolean;
302
+ /**
303
+ * 初始化后端
304
+ */
305
+ abstract init(): Promise<void> | void;
306
+ /**
307
+ * 从图像元素加载纹理
308
+ */
309
+ abstract loadFromImage(image: HTMLImageElement): void;
310
+ /**
311
+ * 从 ImageData 加载纹理
312
+ */
313
+ abstract loadFromImageData(imageData: ImageData): void;
314
+ /**
315
+ * 渲染图像
316
+ */
317
+ abstract render(settings: ColorGradingSettings): void;
318
+ /**
319
+ * 获取渲染结果的 ImageData
320
+ */
321
+ abstract getImageData(): ImageData;
322
+ /**
323
+ * 获取图像尺寸
324
+ */
325
+ getSize(): {
326
+ width: number;
327
+ height: number;
328
+ };
329
+ /**
330
+ * 检查是否已初始化
331
+ */
332
+ isInitialized(): boolean;
333
+ /**
334
+ * 销毁后端资源
335
+ */
336
+ abstract dispose(): void;
337
+ }
338
+ /**
339
+ * 检测 WebGPU 支持
340
+ */
341
+ declare function isWebGPUSupported(): boolean;
342
+ /**
343
+ * 检测 WebGL 支持
344
+ */
345
+ declare function isWebGLSupported(): boolean;
346
+ /**
347
+ * 自动选择最佳后端
348
+ */
349
+ declare function selectBestBackend(preferred?: 'auto' | BackendType): BackendType;
350
+
351
+ /**
352
+ * WebGL 后端实现
353
+ */
354
+
355
+ declare class WebGLBackend extends BaseBackend {
356
+ private gl;
357
+ private resources;
358
+ constructor(canvas: HTMLCanvasElement, options?: BackendOptions);
359
+ getType(): BackendType;
360
+ static isSupported(): boolean;
361
+ init(): void;
362
+ loadFromImage(image: HTMLImageElement): void;
363
+ loadFromImageData(imageData: ImageData): void;
364
+ render(settings: ColorGradingSettings): void;
365
+ getImageData(): ImageData;
366
+ dispose(): void;
367
+ private getShaderSource;
368
+ private initResources;
369
+ private disposeResources;
370
+ private drawFrame;
371
+ }
372
+
373
+ /**
374
+ * WebGPU 后端实现
375
+ */
376
+
377
+ declare class WebGPUBackend extends BaseBackend {
378
+ private device;
379
+ private resources;
380
+ constructor(canvas: HTMLCanvasElement, options?: BackendOptions);
381
+ getType(): BackendType;
382
+ static isSupported(): boolean;
383
+ init(): Promise<void>;
384
+ loadFromImage(image: HTMLImageElement): void;
385
+ loadFromImageData(imageData: ImageData): void;
386
+ render(settings: ColorGradingSettings): void;
387
+ getImageData(): ImageData;
388
+ /**
389
+ * 异步获取 ImageData
390
+ */
391
+ getImageDataAsync(): Promise<ImageData>;
392
+ dispose(): void;
393
+ private getShaderSource;
394
+ private createPipeline;
395
+ private createRenderTarget;
228
396
  private initResources;
397
+ private initResourcesFromImageData;
398
+ private setupResources;
229
399
  private disposeResources;
400
+ private createUniformBuffer;
230
401
  private drawFrame;
231
402
  }
232
403
 
233
- export { type ColorGradingSettings, type ExportOptions, type ImageAnalysis, ImageColorGrading, type ImageLevels, type PartialColorGradingSettings, type PresetType, analyzeImage, analyzeImageLevels, analyzeImageVibrance, defaultSettings, presets };
404
+ export { type BackendType$1 as BackendType, BaseBackend, type ColorGradingSettings, type ExportOptions, type ImageAnalysis, ImageColorGrading, type ImageLevels, type PartialColorGradingSettings, type PresetType, type ProcessorOptions, WebGLBackend, WebGPUBackend, analyzeImage, analyzeImageLevels, analyzeImageVibrance, defaultSettings, isWebGLSupported, isWebGPUSupported, presets, selectBestBackend };