sobel-ts
Version:
TypeScript implementation of Sobel edge detection algorithm for image processing
36 lines (35 loc) • 954 B
JavaScript
/**
* Browser-specific ImageData factory
*/
export class BrowserImageDataFactory {
create(data, width, height) {
// In browser environment, use the native ImageData constructor
if (typeof ImageData !== 'undefined') {
return new ImageData(data, width, height);
}
throw new Error('ImageData is not supported in this environment');
}
}
/**
* Node.js-specific ImageData factory
*/
export class NodeImageDataFactory {
create(data, width, height) {
// In Node.js, return a simple object that matches the interface
return {
data,
width,
height,
colorSpace: 'srgb'
};
}
}
/**
* Get the appropriate ImageData factory for the current environment
*/
export function getImageDataFactory() {
if (typeof ImageData !== 'undefined') {
return new BrowserImageDataFactory();
}
return new NodeImageDataFactory();
}