mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 01:37:26 +00:00
Two workers & worker termination (#198)
* Refactoring codecs * Plugging in new processor * Fixing decorator * MozJPEG free issue * Better worker aborting, and terminate workers that aren't used for 10 seconds * Better comment * Ooops, half-typed comment * Uncommenting problematic line * Surma fixed it! * Abstracting WASM initialisation * Better comment * Don't need this. * Adding ticket * noInitalRun * Reverting MozJPEG issue demo * Making a const for worker timeout * Inline docs * Bail early rather than nesting * Addressing nits
This commit is contained in:
@@ -2,7 +2,7 @@ import { h, Component } from 'preact';
|
||||
import linkState from 'linkstate';
|
||||
import { bind } from '../../lib/initial-util';
|
||||
import { inputFieldValueAsNumber } from '../../lib/util';
|
||||
import { ResizeOptions } from './resize';
|
||||
import { ResizeOptions } from './processor-meta';
|
||||
|
||||
interface Props {
|
||||
isVector: Boolean;
|
||||
|
||||
26
src/codecs/resize/processor-meta.ts
Normal file
26
src/codecs/resize/processor-meta.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
type BitmapResizeMethods = 'browser-pixelated' | 'browser-low' | 'browser-medium' | 'browser-high';
|
||||
|
||||
export interface ResizeOptions {
|
||||
width: number;
|
||||
height: number;
|
||||
method: 'vector' | BitmapResizeMethods;
|
||||
fitMethod: 'stretch' | 'cover';
|
||||
}
|
||||
|
||||
export interface BitmapResizeOptions extends ResizeOptions {
|
||||
method: BitmapResizeMethods;
|
||||
}
|
||||
|
||||
export interface VectorResizeOptions extends ResizeOptions {
|
||||
method: 'vector';
|
||||
}
|
||||
|
||||
export const defaultOptions: ResizeOptions = {
|
||||
// Width and height will always default to the image size.
|
||||
// This is set elsewhere.
|
||||
width: 1,
|
||||
height: 1,
|
||||
// This will be set to 'vector' if the input is SVG.
|
||||
method: 'browser-high',
|
||||
fitMethod: 'stretch',
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import { nativeResize, NativeResizeMethod, drawableToImageData } from '../../lib/util';
|
||||
import { BitmapResizeOptions, VectorResizeOptions } from './processor-meta';
|
||||
|
||||
function getCoverOffsets(sw: number, sh: number, dw: number, dh: number) {
|
||||
const currentAspect = sw / sh;
|
||||
@@ -46,30 +47,3 @@ export function vectorResize(data: HTMLImageElement, opts: VectorResizeOptions):
|
||||
width: opts.width, height: opts.height,
|
||||
});
|
||||
}
|
||||
|
||||
type BitmapResizeMethods = 'browser-pixelated' | 'browser-low' | 'browser-medium' | 'browser-high';
|
||||
|
||||
export interface ResizeOptions {
|
||||
width: number;
|
||||
height: number;
|
||||
method: 'vector' | BitmapResizeMethods;
|
||||
fitMethod: 'stretch' | 'cover';
|
||||
}
|
||||
|
||||
export interface BitmapResizeOptions extends ResizeOptions {
|
||||
method: BitmapResizeMethods;
|
||||
}
|
||||
|
||||
export interface VectorResizeOptions extends ResizeOptions {
|
||||
method: 'vector';
|
||||
}
|
||||
|
||||
export const defaultOptions: ResizeOptions = {
|
||||
// Width and height will always default to the image size.
|
||||
// This is set elsewhere.
|
||||
width: 1,
|
||||
height: 1,
|
||||
// This will be set to 'vector' if the input is SVG.
|
||||
method: 'browser-high',
|
||||
fitMethod: 'stretch',
|
||||
};
|
||||
Reference in New Issue
Block a user