update library/src/main/ets/downsampling/Downsampler.ets.

Signed-off-by: 田双明 <tianshuangming@h-partners.com>
This commit is contained in:
田双明 2024-09-26 03:11:39 +00:00 committed by Gitee
parent fe9235d8b1
commit 48c92b5fe7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 13 additions and 7 deletions

View File

@ -27,9 +27,10 @@ export interface calculateScaleType {
targetHeight: number
}
export class Downsampler {
calculateScaling(
typeValue: string,
typeValue: string |null,
sourceWidth: number, //原始宽高
sourceHeight: number, //原始宽高
requestWidth: number, //请求宽高
@ -38,7 +39,7 @@ export class Downsampler {
): calculateScaleType {
if (sourceHeight <= 0 || sourceWidth <= 0) {
throw new Error("非法宽高 sourceHeight sourceWidth")
throw new Error(`Invalid width and height, sourceHeight:${sourceHeight}+ sourceWidth:${sourceWidth}`)
}
let downsampler = this.getDownsampler(downsampType);
let exactScaleFactor: number =
@ -46,7 +47,7 @@ export class Downsampler {
let rounding: SampleSizeRounding =
downsampler.getSampleSizeRounding(sourceWidth, sourceHeight, requestWidth, requestHeight, downsampType); //采样类型
//原始宽高和缩放系数的乘积
let outSize = {
let outSize:Size = {
width: this.round(exactScaleFactor * sourceWidth),
height: this.round(exactScaleFactor * sourceHeight)
}
@ -64,11 +65,16 @@ export class Downsampler {
targetHeight: Math.floor(sourceHeight / scaleFactor)
}
} else if (typeValue === "webp") {
targetWidth = Math.round(sourceWidth / scaleFactor);
targetHeight = Math.round(sourceHeight / scaleFactor);
return {
targetWidth: Math.round(sourceWidth / scaleFactor),
targetHeight: Math.round(sourceHeight / scaleFactor)
}
} else {
targetWidth = sourceWidth / scaleFactor;
targetHeight = sourceHeight / scaleFactor;
return {
targetWidth: sourceWidth / scaleFactor,
targetHeight: sourceHeight / scaleFactor
}
}
}