降采样宽高备注

Signed-off-by: tsm <tianshuangming@h-partners.com>
This commit is contained in:
tsm 2024-09-13 14:31:38 +08:00
parent b44ad4dba1
commit b2af4e1958
1 changed files with 7 additions and 7 deletions

View File

@ -37,8 +37,8 @@ export class Downsampler {
downsampType: DownsampleStrategy | undefined, downsampType: DownsampleStrategy | undefined,
): calculateScaleType { ): calculateScaleType {
const fileType = typeValue //获取图片类型 const fileType = typeValue //获取图片类型
let targetWidth: number | null = null; let targetWidth: number | null = null;//降采样之后的宽
let targetHeight: number | null = null; let targetHeight: number | null = null;//降采样之后的高
if (sourceHeight <= 0 || sourceWidth == undefined || sourceWidth == null || sourceWidth <= 0) { if (sourceHeight <= 0 || sourceWidth == undefined || sourceWidth == null || sourceWidth <= 0) {
throw new Error("Cannot found width or height") throw new Error("Cannot found width or height")
} }
@ -47,14 +47,14 @@ export class Downsampler {
} }
let downsampler = this.getDownsampler(downsampType); let downsampler = this.getDownsampler(downsampType);
let exactScaleFactor : number = downsampler.getScaleFactor(sourceWidth, sourceHeight, requestWidth, requestHeight, downsampType); let exactScaleFactor : number = downsampler.getScaleFactor(sourceWidth, sourceHeight, requestWidth, requestHeight, downsampType);
let rounding: SampleSizeRounding= downsampler.getSampleSizeRounding(sourceWidth, sourceHeight, requestWidth, requestHeight, downsampType); let rounding: SampleSizeRounding= downsampler.getSampleSizeRounding(sourceWidth, sourceHeight, requestWidth, requestHeight, downsampType);//采样类型
if (exactScaleFactor==undefined|| exactScaleFactor <= 0 ) { if (exactScaleFactor==undefined|| exactScaleFactor <= 0 ) {
throw new Error("Cannot round with exactScaleFactor"); throw new Error("Cannot round with exactScaleFactor");
} }
let outWidth: number = this.round(exactScaleFactor * sourceWidth); let outWidth: number = this.round(exactScaleFactor * sourceWidth);//原始宽和缩放系数的乘积
let outHeight: number = this.round(exactScaleFactor * sourceHeight); let outHeight: number = this.round(exactScaleFactor * sourceHeight);//原始高和缩放系数的乘积
let widthScaleFactor = sourceWidth / outWidth; let widthScaleFactor = sourceWidth / outWidth;//计算的缩放因子
let heightScaleFactor = sourceHeight / outHeight; let heightScaleFactor = sourceHeight / outHeight;//计算的缩放因子
let scaleFactor = rounding ==SampleSizeRounding.QUALITY ? Math.max(widthScaleFactor, heightScaleFactor) : let scaleFactor = rounding ==SampleSizeRounding.QUALITY ? Math.max(widthScaleFactor, heightScaleFactor) :
Math.min(widthScaleFactor, heightScaleFactor) //将整型的缩放因子转换为2的次幂采样大小 Math.min(widthScaleFactor, heightScaleFactor) //将整型的缩放因子转换为2的次幂采样大小
let powerOfTwoSampleSize: number = scaleFactor; let powerOfTwoSampleSize: number = scaleFactor;