Pre Merge pull request !381 from 田双明/master

This commit is contained in:
田双明 2024-09-05 10:35:53 +00:00 committed by Gitee
commit d04b3ee407
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 84 additions and 127 deletions

View File

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { DownsampleStrategy } from '@ohos/imageknife';
import { IEngineKey, ImageKnifeOption, PixelMapTransformation,SparkMD5 ,ImageKnifeRequestSource} from '@ohos/libraryimageknife'; import { IEngineKey, ImageKnifeOption, PixelMapTransformation,SparkMD5 ,ImageKnifeRequestSource} from '@ohos/libraryimageknife';
//全局自定义key demo //全局自定义key demo
@ -35,6 +36,10 @@ export class CustomEngineKeyImpl implements IEngineKey {
if (imageKnifeOption.transformation) { if (imageKnifeOption.transformation) {
key += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";" key += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";"
} }
if ((imageKnifeOption.downsampleOf !== DownsampleStrategy.NONE && imageKnifeOption.downsampleOf !== undefined)) {
key += "downsampleOf" + imageKnifeOption.downsampleOf +"width="+width+"height="+ height
}
} }
return key return key
} }

View File

@ -45,24 +45,24 @@ struct DownSamplePage {
updateImageKnifeOption(value: string) { updateImageKnifeOption(value: string) {
if (value === 'NONE') { if (value === 'NONE') {
this.imageKnifeOption =new ImageKnifeOption( { this.imageKnifeOption =new ImageKnifeOption( {
loadSrc: $r('app.media.jpgSample'), loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain, objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.NONE downsampleOf: DownsampleStrategy.NONE
}) })
this.originalPixMap($r('app.media.jpgSample')) this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.jpgSample')) this.afterSamplingFunc($r('app.media.pngSample'))
} else if (value === 'AT_MOST') { } else if (value === 'AT_MOST') {
this.imageKnifeOption =new ImageKnifeOption( { this.imageKnifeOption =new ImageKnifeOption( {
loadSrc: $r('app.media.svgSample'), loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain, objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.AT_MOST downsampleOf: DownsampleStrategy.AT_MOST
}) })
this.originalPixMap($r('app.media.svgSample')) this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.svgSample')) this.afterSamplingFunc($r('app.media.pngSample'))
} else if (value === 'FIT_CENTER_MEMORY') { } else if (value === 'FIT_CENTER_MEMORY') {
this.imageKnifeOption =new ImageKnifeOption( { this.imageKnifeOption =new ImageKnifeOption( {
loadSrc: $r('app.media.pngSample'), loadSrc: $r('app.media.pngSample'),
@ -87,35 +87,35 @@ struct DownSamplePage {
} }
else if (value === 'CENTER_INSIDE_MEMORY') { else if (value === 'CENTER_INSIDE_MEMORY') {
this.imageKnifeOption = new ImageKnifeOption({ this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.jpgSample1'), loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain, objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.CENTER_INSIDE_MEMORY downsampleOf: DownsampleStrategy.CENTER_INSIDE_MEMORY
}) })
this.originalPixMap($r('app.media.jpgSample1')) this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.jpgSample1')) this.afterSamplingFunc($r('app.media.pngSample'))
} else if (value === 'CENTER_INSIDE_QUALITY') { } else if (value === 'CENTER_INSIDE_QUALITY') {
this.imageKnifeOption = new ImageKnifeOption({ this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.jpgSample1'), loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain, objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.CENTER_INSIDE_QUALITY downsampleOf: DownsampleStrategy.CENTER_INSIDE_QUALITY
}) })
this.originalPixMap($r('app.media.jpgSample1')) this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.jpgSample1')) this.afterSamplingFunc($r('app.media.pngSample'))
} }
else { else {
this.imageKnifeOption = new ImageKnifeOption({ this.imageKnifeOption = new ImageKnifeOption({
loadSrc: $r('app.media.jpgSample2'), loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"), placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"), errorholderSrc: $r("app.media.app_icon"),
objectFit: ImageFit.Contain, objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.CENTER_OUTSIDE downsampleOf: DownsampleStrategy.CENTER_OUTSIDE
}) })
this.originalPixMap($r('app.media.jpgSample2')) this.originalPixMap($r('app.media.pngSample'))
this.afterSamplingFunc($r('app.media.jpgSample2')) this.afterSamplingFunc($r('app.media.pngSample'))
} }
} }

View File

@ -656,11 +656,11 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
editable: true, editable: true,
desiredSize: defaultSize desiredSize: defaultSize
}; };
let imageInfo = await imageSource.getImageInfo() // let imageInfo = await imageSource.getImageInfo()
if ((request.downsampType !== DownsampleStrategy.NONE && request.downsampType !== undefined) && if ((request.downsampType !== DownsampleStrategy.NONE && request.downsampType !== undefined) &&
request.requestSource == ImageKnifeRequestSource.SRC) { request.requestSource == ImageKnifeRequestSource.SRC) {
let reqSize = let reqSize =
new Downsampler().calculateScaling(typeValue, imageInfo.size.width, imageInfo.size.height, request.targetWidth, new Downsampler().calculateScaling(typeValue, size.width, size.height, request.targetWidth,
request.targetHeight, request.downsampType) request.targetHeight, request.downsampType)
opts = { opts = {
editable: true, editable: true,
@ -682,12 +682,12 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
type:typeValue type:typeValue
}; };
} }
let size = (await imageSource.getImageInfo()).size
let imageInfo = await imageSource.getImageInfo() // let imageInfo = await imageSource.getImageInfo()
if ((request.downsampType !== undefined && request.downsampType !== DownsampleStrategy.NONE) && if ((request.downsampType !== undefined && request.downsampType !== DownsampleStrategy.NONE) &&
request.requestSource == ImageKnifeRequestSource.SRC) { request.requestSource == ImageKnifeRequestSource.SRC) {
let reqSize = let reqSize =
new Downsampler().calculateScaling(typeValue, imageInfo.size.width, imageInfo.size.height, request.targetWidth, new Downsampler().calculateScaling(typeValue, size.width, size.height, request.targetWidth,
request.targetHeight, request.downsampType) request.targetHeight, request.downsampType)
decodingOptions = { decodingOptions = {
@ -698,7 +698,7 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
} }
} }
} }
let size = (await imageSource.getImageInfo()).size
await imageSource.createPixelMap(decodingOptions) await imageSource.createPixelMap(decodingOptions)
.then((pixelmap: PixelMap) => { .then((pixelmap: PixelMap) => {
resPixelmap = pixelmap resPixelmap = pixelmap

View File

@ -125,7 +125,7 @@ export class ImageKnifeOption {
onComplete?:(event:EventImage | undefined) => void onComplete?:(event:EventImage | undefined) => void
drawingColorFilter?: ColorFilter | drawing.ColorFilter drawingColorFilter?: ColorFilter | drawing.ColorFilter
// 下采样 // 下采样
downsampleOf?: DownsampleStrategy = DownsampleStrategy.NONE @Trace downsampleOf?: DownsampleStrategy = DownsampleStrategy.NONE
constructor(option?:ImageOption) { constructor(option?:ImageOption) {
this.loadSrc = option?.loadSrc == undefined ? "" : option?.loadSrc this.loadSrc = option?.loadSrc == undefined ? "" : option?.loadSrc

View File

@ -38,7 +38,7 @@ export struct ImageKnifeComponent {
@Param imageKnifeOption: ImageKnifeOption = new ImageKnifeOption(); @Param imageKnifeOption: ImageKnifeOption = new ImageKnifeOption();
@Monitor('imageKnifeOption', @Monitor('imageKnifeOption',
"imageKnifeOption.loadSrc","imageKnifeOption.signature","imageKnifeOption.transformation","imageKnifeOption.border","imageKnifeOption.objectFit") "imageKnifeOption.loadSrc","imageKnifeOption.signature","imageKnifeOption.transformation","imageKnifeOption.border","imageKnifeOption.objectFit",'imageKnifeOption.downsampleOf')
watchImageKnifeOption() { watchImageKnifeOption() {
this.clearLastRequest() this.clearLastRequest()
this.componentVersion++ this.componentVersion++

View File

@ -20,9 +20,9 @@ export class FitCenter implements BaseDownsampling {
return "FitCenter" return "FitCenter"
} }
getScaleFactor(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy getScaleFactor(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy |undefined
): number { ): number {
if (downsampType===DownsampleStrategy.FIT_CENTER_QUALITY) { if (downsampType===DownsampleStrategy.FIT_CENTER_MEMORY) {
const widthPercentage = requestedWidth / sourceWidth const widthPercentage = requestedWidth / sourceWidth
const heightPercentage = requestedHeight / sourceHeight const heightPercentage = requestedHeight / sourceHeight
return Math.min(widthPercentage, heightPercentage) return Math.min(widthPercentage, heightPercentage)
@ -34,7 +34,7 @@ export class FitCenter implements BaseDownsampling {
} }
//实现 getSampleSizeRounding 方法 //实现 getSampleSizeRounding 方法
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy|undefined
): number { ): number {
if (downsampType===DownsampleStrategy.FIT_CENTER_QUALITY) { if (downsampType===DownsampleStrategy.FIT_CENTER_QUALITY) {
return SampleSizeRounding.QUALITY; return SampleSizeRounding.QUALITY;
@ -82,7 +82,6 @@ export class CenterOutside implements BaseDownsampling {
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestedWidth: number, getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestedWidth: number,
requestedHeight: number): SampleSizeRounding { requestedHeight: number): SampleSizeRounding {
//根据 CenterOutside 的逻辑,总是返回 QUALITY
return SampleSizeRounding.QUALITY; return SampleSizeRounding.QUALITY;
} }
} }
@ -122,7 +121,7 @@ export class CenterInside implements BaseDownsampling {
return "CenterInside" return "CenterInside"
} }
getScaleFactor(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy getScaleFactor(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy|undefined
): number { ): number {
//获取 FIT_CENTER 的缩放因子 //获取 FIT_CENTER 的缩放因子
const fitCenterScaleFactor: ESObject = const fitCenterScaleFactor: ESObject =
@ -132,21 +131,20 @@ export class CenterInside implements BaseDownsampling {
} }
getScale(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy getScale(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy|undefined
): number { ): number {
if (downsampType===DownsampleStrategy.FIT_CENTER_QUALITY) { if (downsampType===DownsampleStrategy.FIT_CENTER_MEMORY) {
const widthPercentage = requestedWidth / sourceWidth const widthPercentage = requestedWidth / sourceWidth
const heightPercentage = requestedHeight / sourceHeight const heightPercentage = requestedHeight / sourceHeight
return Math.min(widthPercentage, heightPercentage) return Math.min(widthPercentage, heightPercentage)
} else { } else {
//类似 AT_LEAST,但只要求一个维度或另一个维度大于等于请求的尺寸
const maxIntegerFactor = Math.max(sourceHeight / requestedHeight, sourceWidth / requestedWidth); const maxIntegerFactor = Math.max(sourceHeight / requestedHeight, sourceWidth / requestedWidth);
return maxIntegerFactor === 0 ? 1 : 1 / highestOneBit(maxIntegerFactor); const a = maxIntegerFactor === 0 ? 1 : 1 / highestOneBit(maxIntegerFactor)
return a;
} }
} }
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy|undefined
): SampleSizeRounding { ): SampleSizeRounding {
//如果缩放因子为 1表示没有缩放优先选择质量 //如果缩放因子为 1表示没有缩放优先选择质量
if (this.getScaleFactor(sourceWidth, sourceHeight, requestedWidth, requestedHeight, downsampType) === 1) { if (this.getScaleFactor(sourceWidth, sourceHeight, requestedWidth, requestedHeight, downsampType) === 1) {
@ -156,12 +154,12 @@ export class CenterInside implements BaseDownsampling {
return this.getSampleSize(sourceWidth, sourceHeight, requestedWidth, requestedHeight,downsampType); return this.getSampleSize(sourceWidth, sourceHeight, requestedWidth, requestedHeight,downsampType);
} }
getSampleSize(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy getSampleSize(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,downsampType:DownsampleStrategy|undefined
): SampleSizeRounding { ): SampleSizeRounding {
if (downsampType===DownsampleStrategy.CENTER_INSIDE_QUALITY) { if (downsampType===DownsampleStrategy.CENTER_INSIDE_MEMORY) {
return SampleSizeRounding.QUALITY;
} else {
return SampleSizeRounding.MEMORY; return SampleSizeRounding.MEMORY;
} else {
return SampleSizeRounding.QUALITY;
} }
} }
} }

View File

@ -30,118 +30,72 @@ export interface calculateScaleType {
export class Downsampler { export class Downsampler {
calculateScaling( calculateScaling(
typeValue: string | null, typeValue: string | null,
sourceHeight: number, //原始宽高 // TODO 宽高调整
sourceWidth: number | undefined, //原始宽高 sourceWidth: number | undefined, //原始宽高
requestHeight: number, //请求宽高 sourceHeight: number, //原始宽高
requestWidth: number, //请求宽高 requestWidth: number, //请求宽高
requestHeight: number, //请求宽高
downsampType: DownsampleStrategy | undefined, downsampType: DownsampleStrategy | undefined,
): calculateScaleType { ): calculateScaleType {
let degreesToRotate: ESObject = 90;
const fileType = typeValue //获取图片类型 const fileType = typeValue //获取图片类型
let powerOfTwoWidth: number | null = null; // TODO 命名修改 powerOfTwoWidth改为targetWidth
let powerOfTwoHeight: number | null = null; let targetWidth: number | null = null;
let targetWidth: number = 0 let targetHeight: number | null = null;
let targetHeight: number = 0
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"); // TODO catch
} }
let orientedSourceWidth = sourceWidth; if(downsampType===undefined){
let orientedSourceHeight = sourceHeight; throw new Error("Cannot found downsampType");
if (this.isRotationRequired(degreesToRotate)) {
orientedSourceWidth = sourceHeight;
orientedSourceHeight = sourceWidth;
}
if (requestWidth && !requestHeight) {
targetWidth = this.round((requestHeight) * orientedSourceWidth / orientedSourceHeight)
} else if (requestHeight && !requestWidth) {
targetHeight = this.round((requestWidth) * orientedSourceHeight / orientedSourceWidth)
} else if (requestHeight && requestWidth) {
targetWidth =
requestHeight == sourceWidth ? (this.isRotationRequired(degreesToRotate) ? sourceHeight : sourceWidth) :
requestWidth;
targetHeight =
requestHeight == sourceHeight ? (this.isRotationRequired(degreesToRotate) ? sourceWidth : sourceHeight) :
requestWidth;
} else {
throw new Error("Cannot found width or height");
}
let exactScaleFactor: number | undefined
let rounding: SampleSizeRounding | undefined
switch (downsampType) {
case DownsampleStrategy.FIT_CENTER_MEMORY || DownsampleStrategy.FIT_CENTER_QUALITY:
exactScaleFactor = new FitCenter()
.getScaleFactor(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight,downsampType)
rounding = new FitCenter()
.getSampleSizeRounding(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight,downsampType)
break;
case DownsampleStrategy.NONE:
exactScaleFactor = new None()
.getScaleFactor(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
rounding = new None()
.getSampleSizeRounding(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
break
case DownsampleStrategy.AT_MOST:
exactScaleFactor = new AtMost()
.getScaleFactor(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
rounding = new AtMost()
.getSampleSizeRounding(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
break
case DownsampleStrategy.CENTER_INSIDE_MEMORY || DownsampleStrategy.CENTER_INSIDE_QUALITY:
exactScaleFactor = new CenterInside()
.getScaleFactor(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight,downsampType)
rounding = new CenterInside()
.getSampleSizeRounding(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight,downsampType)
break
case DownsampleStrategy.CENTER_OUTSIDE:
exactScaleFactor = new CenterOutside()
.getScaleFactor(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
rounding = new CenterOutside()
.getSampleSizeRounding(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
break
} }
let downsampler = this.getDownsampler(downsampType);
let exactScaleFactor : number = downsampler.getScaleFactor(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");
} }
if (rounding == undefined) { let outWidth: number = this.round(exactScaleFactor * sourceWidth);
throw new Error("Cannot round with null rounding"); let outHeight: number = this.round(exactScaleFactor * sourceHeight);
} let widthScaleFactor = sourceWidth / outWidth;
let outWidth: number = this.round(exactScaleFactor * orientedSourceWidth); let heightScaleFactor = sourceHeight / outHeight;
let outHeight: number = this.round(exactScaleFactor * orientedSourceHeight);
let widthScaleFactor = orientedSourceWidth / outWidth;
let heightScaleFactor = orientedSourceHeight / 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;
powerOfTwoSampleSize = Math.max(1, highestOneBit(scaleFactor)) powerOfTwoSampleSize = Math.max(1, highestOneBit(scaleFactor))
if (rounding == 1 && (powerOfTwoSampleSize < (1 / exactScaleFactor))) { if (rounding == 0 && (powerOfTwoSampleSize < (1 / exactScaleFactor))) {
powerOfTwoSampleSize = powerOfTwoSampleSize << 1; powerOfTwoSampleSize = powerOfTwoSampleSize << 1;
} }
//基于上一步得出的采样大小,根据不同的图片类型,计算采样后的图片尺寸 //基于上一步得出的采样大小,根据不同的图片类型,计算采样后的图片尺寸
if (fileType === "png") { if (fileType === "png") {
powerOfTwoWidth = Math.floor(orientedSourceWidth / powerOfTwoSampleSize); targetWidth = Math.floor(sourceWidth / powerOfTwoSampleSize);
powerOfTwoHeight = Math.floor(orientedSourceHeight / powerOfTwoSampleSize); targetHeight = Math.floor(sourceHeight / powerOfTwoSampleSize);
} else if (fileType === "webp") { } else if (fileType === "webp") {
powerOfTwoWidth = Math.round(orientedSourceWidth / powerOfTwoSampleSize); targetWidth = Math.round(sourceWidth / powerOfTwoSampleSize);
powerOfTwoHeight = Math.round(orientedSourceHeight / powerOfTwoSampleSize); targetHeight = Math.round(sourceHeight / powerOfTwoSampleSize);
} else { } else {
powerOfTwoWidth = orientedSourceWidth / powerOfTwoSampleSize; targetWidth = sourceWidth / powerOfTwoSampleSize;
powerOfTwoHeight = orientedSourceHeight / powerOfTwoSampleSize; targetHeight = sourceHeight / powerOfTwoSampleSize;
}
return { targetWidth, targetHeight }
}
getDownsampler(downsampType:DownsampleStrategy) {
switch (downsampType) {
case DownsampleStrategy.FIT_CENTER_MEMORY:
case DownsampleStrategy.FIT_CENTER_QUALITY:
return new FitCenter();
case DownsampleStrategy.NONE:
return new None();
case DownsampleStrategy.AT_MOST:
return new AtMost();
case DownsampleStrategy.CENTER_INSIDE_MEMORY:
case DownsampleStrategy.CENTER_INSIDE_QUALITY:
return new CenterInside();
case DownsampleStrategy.CENTER_OUTSIDE:
return new CenterOutside();
default:
throw new Error('Unsupported downsampling strategy');
} }
let a: calculateScaleType = {
"targetWidth": powerOfTwoWidth,
"targetHeight": powerOfTwoHeight
}
return a
} }
round(value: number): number { round(value: number): number {
return Math.floor(value + 0.5); return Math.floor(value + 0.5);
} }
isRotationRequired(degreesToRotate: number): boolean {
return degreesToRotate == 90 || degreesToRotate == 270;
}
} }