update library/src/main/ets/ImageKnifeLoader.ets.
Signed-off-by: 田双明 <tianshuangming@h-partners.com>
This commit is contained in:
parent
48c92b5fe7
commit
14be70d5e6
|
@ -39,6 +39,16 @@ class RequestData {
|
||||||
/**
|
/**
|
||||||
* ImageKnifeDispatcher 抽取出来的方法,因@Concurrent只能import方法,故抽取到另一个类
|
* ImageKnifeDispatcher 抽取出来的方法,因@Concurrent只能import方法,故抽取到另一个类
|
||||||
*/
|
*/
|
||||||
|
interface GeneratedObjectLiteralInterface_1 {
|
||||||
|
height: number;
|
||||||
|
width: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Generated {
|
||||||
|
editable: boolean;
|
||||||
|
desiredSize: Size;
|
||||||
|
}
|
||||||
|
|
||||||
export class ImageKnifeLoader {
|
export class ImageKnifeLoader {
|
||||||
static async parseImage(resBuf: ArrayBuffer, typeValue: string, fileKey: string,
|
static async parseImage(resBuf: ArrayBuffer, typeValue: string, fileKey: string,
|
||||||
request: RequestJobRequest): Promise<RequestJobResult> {
|
request: RequestJobRequest): Promise<RequestJobResult> {
|
||||||
|
@ -75,19 +85,15 @@ export class ImageKnifeLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
let size = (await imageSource.getImageInfo()).size
|
let size = (await imageSource.getImageInfo()).size
|
||||||
if ((request.downsampType !== undefined && request.downsampType !== DownsampleStrategy.NONE) &&
|
try{
|
||||||
request.requestSource == ImageKnifeRequestSource.SRC) {
|
if ((request.downsampType !== DownsampleStrategy.NONE) &&
|
||||||
let reqSize =
|
request.requestSource == ImageKnifeRequestSource.SRC ) {
|
||||||
new Downsampler().calculateScaling(typeValue, size.width, size.height, request.targetWidth,
|
decodingOptions =await ImageKnifeLoader.downsamplerReqSize(typeValue,request,size,ImageKnifeRequestSource.SRC)
|
||||||
request.targetHeight, request.downsampType)
|
|
||||||
decodingOptions = {
|
|
||||||
editable: request.requestSource === ImageKnifeRequestSource.SRC && request.transformation !== undefined ? true : false,
|
|
||||||
desiredSize: {
|
|
||||||
width: reqSize.targetWidth,
|
|
||||||
height: reqSize.targetHeight
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}catch(err){
|
||||||
|
return ImageKnifeLoader.makeEmptyResult("image.createImageSource failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
await imageSource.createPixelMap(decodingOptions)
|
await imageSource.createPixelMap(decodingOptions)
|
||||||
.then((pixelmap: PixelMap) => {
|
.then((pixelmap: PixelMap) => {
|
||||||
resPixelmap = pixelmap
|
resPixelmap = pixelmap
|
||||||
|
@ -125,18 +131,13 @@ export class ImageKnifeLoader {
|
||||||
editable: true,
|
editable: true,
|
||||||
desiredSize: defaultSize
|
desiredSize: defaultSize
|
||||||
};
|
};
|
||||||
if ((request.downsampType !== DownsampleStrategy.NONE && request.downsampType !== undefined) &&
|
try{
|
||||||
request.requestSource == ImageKnifeRequestSource.SRC) {
|
if ((request.downsampType !== DownsampleStrategy.NONE) &&
|
||||||
let reqSize =
|
request.requestSource == ImageKnifeRequestSource.SRC ) {
|
||||||
new Downsampler().calculateScaling(typeValue, size.width, size.height, request.targetWidth,
|
opts =await ImageKnifeLoader.downsamplerReqSize(typeValue,request,size)
|
||||||
request.targetHeight, request.downsampType)
|
|
||||||
opts = {
|
|
||||||
editable: true,
|
|
||||||
desiredSize: {
|
|
||||||
height: vp2px(reqSize.targetHeight),
|
|
||||||
width: vp2px(reqSize.targetWidth)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}catch(err){
|
||||||
|
return ImageKnifeLoader.makeEmptyResult("image.createImageSource failed")
|
||||||
}
|
}
|
||||||
await imageSource.createPixelMap(opts)
|
await imageSource.createPixelMap(opts)
|
||||||
.then((pixelmap: PixelMap) => {
|
.then((pixelmap: PixelMap) => {
|
||||||
|
@ -382,4 +383,25 @@ export class ImageKnifeLoader {
|
||||||
}
|
}
|
||||||
return resBuf
|
return resBuf
|
||||||
}
|
}
|
||||||
}
|
static async downsamplerReqSize(typeValue:string,request:RequestJobRequest ,size:Size,SRC?:ImageKnifeRequestSource): Promise<image.DecodingOptions>{
|
||||||
|
let reqSize = new Downsampler().calculateScaling(typeValue, size.width, size.height, request.targetWidth, request.targetHeight, request.downsampType)
|
||||||
|
if(typeValue=="svg") {
|
||||||
|
return ({
|
||||||
|
editable: true,
|
||||||
|
desiredSize: ({
|
||||||
|
height: vp2px(reqSize.targetHeight),
|
||||||
|
width: vp2px(reqSize.targetWidth)
|
||||||
|
} as Size)
|
||||||
|
} as image.DecodingOptions )
|
||||||
|
}else {
|
||||||
|
return( {
|
||||||
|
editable: request.requestSource ===SRC && request.transformation !== undefined ? true : false,
|
||||||
|
desiredSize: ({
|
||||||
|
width: reqSize.targetWidth,
|
||||||
|
height: reqSize.targetHeight
|
||||||
|
}as Size)
|
||||||
|
}as image.DecodingOptions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue