Improve preprocess parameter type

This commit is contained in:
ergunsh
2021-09-03 11:53:52 +03:00
parent 00cfdafdf3
commit 27f103fee5
2 changed files with 29 additions and 14 deletions

View File

@@ -29,14 +29,23 @@ interface ResizeWithAspectParams {
target_height: number;
}
interface ResizeInstantiateOptions {
export interface ResizeOptions {
width: number;
height: number;
method: string;
method: 'triange' | 'catrom' | 'mitchell' | 'lanczos3';
premultiply: boolean;
linearRGB: boolean;
}
export interface QuantOptions {
numColors: number;
dither: number;
}
export interface RotateOptions {
numRotations: number;
}
declare global {
// Needed for being able to use ImageData as type in codec types
type ImageData = import('./image_data.js').default;
@@ -171,13 +180,7 @@ export const preprocessors = {
buffer: Uint8Array,
input_width: number,
input_height: number,
{
width,
height,
method,
premultiply,
linearRGB,
}: ResizeInstantiateOptions,
{ width, height, method, premultiply, linearRGB }: ResizeOptions,
) => {
({ width, height } = resizeWithAspect({
input_width,
@@ -218,7 +221,7 @@ export const preprocessors = {
buffer: Uint8Array,
width: number,
height: number,
{ numColors, dither }: { numColors: number; dither: number },
{ numColors, dither }: QuantOptions,
) =>
new ImageData(
imageQuant.quantize(buffer, width, height, numColors, dither),
@@ -239,7 +242,7 @@ export const preprocessors = {
buffer: Uint8Array,
width: number,
height: number,
{ numRotations }: { numRotations: number },
{ numRotations }: RotateOptions,
) => {
const degrees = (numRotations * 90) % 360;
const sameDimensions = degrees == 0 || degrees == 180;