|
|
|
@ -13,28 +13,26 @@
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { RequestOption } from '../../imageknife/RequestOption'
|
|
|
|
|
import { RequestOption,Size } from '../../imageknife/RequestOption'
|
|
|
|
|
import { DiskLruCache } from '@ohos/disklrucache'
|
|
|
|
|
import { LruCache } from '../../cache/LruCache'
|
|
|
|
|
import { SparkMD5 } from '../../3rd_party/sparkmd5/spark-md5'
|
|
|
|
|
import { MemoryCacheProxy } from '../requestmanage/MemoryCacheProxy'
|
|
|
|
|
import { DiskCacheProxy } from '../requestmanage/DiskCacheProxy'
|
|
|
|
|
import { FileTypeUtil } from '../utils/FileTypeUtil'
|
|
|
|
|
import type { IDataFetch } from '../../imageknife/networkmanage/IDataFetch'
|
|
|
|
|
import type { IResourceFetch } from '../../imageknife/resourcemanage/IResourceFetch'
|
|
|
|
|
import { IDataFetch } from '../../imageknife/networkmanage/IDataFetch'
|
|
|
|
|
import { IResourceFetch } from '../../imageknife/resourcemanage/IResourceFetch'
|
|
|
|
|
import { ImageKnifeData, ImageKnifeType } from '../ImageKnifeData'
|
|
|
|
|
import { AllCacheInfo } from '../../imageknife/interface/IAllCacheInfoCallback'
|
|
|
|
|
import { ParseImageUtil } from '../utils/ParseImageUtil'
|
|
|
|
|
import type { IParseImage } from '../interface/IParseImage'
|
|
|
|
|
import { IParseImage } from '../interface/IParseImage'
|
|
|
|
|
import image from '@ohos.multimedia.image'
|
|
|
|
|
import { SVGParseImpl } from '../utils/svg/SVGParseImpl'
|
|
|
|
|
import { GIFParseImpl } from '../utils/gif/GIFParseImpl'
|
|
|
|
|
import { GIFFrame } from '../utils/gif/GIFFrame'
|
|
|
|
|
import { LogUtil } from '../../imageknife/utils/LogUtil'
|
|
|
|
|
import { BusinessError } from '@ohos.base'
|
|
|
|
|
|
|
|
|
|
export interface AsyncString {
|
|
|
|
|
(data: string): void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum Stage {
|
|
|
|
|
|
|
|
|
@ -64,13 +62,13 @@ export enum RunReason {
|
|
|
|
|
export class RequestManager {
|
|
|
|
|
private TAG: string = "RequestManager";
|
|
|
|
|
private options: RequestOption;
|
|
|
|
|
private mMemoryCacheProxy: MemoryCacheProxy<string, any>;
|
|
|
|
|
private mMemoryCacheProxy: MemoryCacheProxy<string, ImageKnifeData>;
|
|
|
|
|
private mDiskCacheProxy: DiskCacheProxy;
|
|
|
|
|
private mIDataFetch: IDataFetch;
|
|
|
|
|
private mIResourceFetch: IResourceFetch;
|
|
|
|
|
private mParseImageUtil: IParseImage;
|
|
|
|
|
private mParseImageUtil: IParseImage<PixelMap>;
|
|
|
|
|
|
|
|
|
|
constructor(option: RequestOption, memoryCache1: LruCache<string, any>, diskMemoryCache1: DiskLruCache, dataFetch: IDataFetch, resourceFetch: IResourceFetch) {
|
|
|
|
|
constructor(option: RequestOption, memoryCache1: LruCache<string, ImageKnifeData>, diskMemoryCache1: DiskLruCache, dataFetch: IDataFetch, resourceFetch: IResourceFetch) {
|
|
|
|
|
this.options = option;
|
|
|
|
|
|
|
|
|
|
// 缓存部分
|
|
|
|
@ -87,23 +85,27 @@ export class RequestManager {
|
|
|
|
|
this.mParseImageUtil = new ParseImageUtil();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static execute(option: RequestOption, memoryCache1: LruCache<string, any>, diskMemoryCache1: DiskLruCache, dataFetch: IDataFetch, resourceFetch: IResourceFetch) {
|
|
|
|
|
static execute(option: RequestOption, memoryCache1: LruCache<string, ImageKnifeData>, diskMemoryCache1: DiskLruCache, dataFetch: IDataFetch, resourceFetch: IResourceFetch) {
|
|
|
|
|
LogUtil.log("RequestManager execute")
|
|
|
|
|
let manager = new RequestManager(option, memoryCache1, diskMemoryCache1, dataFetch, resourceFetch);
|
|
|
|
|
return new Promise<PixelMap>(manager.process.bind(manager))
|
|
|
|
|
.then(option.loadComplete.bind(option))
|
|
|
|
|
.then(manager.loadCompleteAfter.bind(manager))
|
|
|
|
|
.catch(option.loadError.bind(option));
|
|
|
|
|
return new Promise<ImageKnifeData>(manager.process)
|
|
|
|
|
.then(option.loadComplete)
|
|
|
|
|
.then(manager.loadCompleteAfter)
|
|
|
|
|
.catch(option.loadError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadCompleteAfter() {
|
|
|
|
|
loadCompleteAfter =()=>{
|
|
|
|
|
try { // 内部消化问题
|
|
|
|
|
LogUtil.log("loadCompleteAfter!")
|
|
|
|
|
if (this.options.allCacheInfoCallback) {
|
|
|
|
|
LogUtil.log("RequestOption =" + JSON.stringify(this.options));
|
|
|
|
|
|
|
|
|
|
// 内存缓存
|
|
|
|
|
let allCacheInfo = new AllCacheInfo();
|
|
|
|
|
let allCacheInfo:AllCacheInfo = {
|
|
|
|
|
memoryCacheInfo:{key:'', data:new ImageKnifeData()},
|
|
|
|
|
resourceCacheInfo:{key:'', path:''},
|
|
|
|
|
dataCacheInfo:{key:'',path:''}
|
|
|
|
|
};
|
|
|
|
|
let memoryCache = this.mMemoryCacheProxy.getValue(this.options.generateCacheKey);
|
|
|
|
|
allCacheInfo.memoryCacheInfo = {
|
|
|
|
|
key: this.options.generateCacheKey,
|
|
|
|
@ -133,12 +135,12 @@ export class RequestManager {
|
|
|
|
|
private mStage: Stage = Stage.INITIALIZE;
|
|
|
|
|
private mRunReason: RunReason = RunReason.INITIALIZE;
|
|
|
|
|
|
|
|
|
|
process(onComplete, onError) {
|
|
|
|
|
process = (onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void)=>{
|
|
|
|
|
LogUtil.log("RequestManager process !");
|
|
|
|
|
this.loadLeve1MemoryCache(onComplete, onError)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private runWrapped(request: RequestOption, runReason: RunReason, onComplete, onError) {
|
|
|
|
|
private runWrapped(request: RequestOption, runReason: RunReason, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
|
|
|
|
LogUtil.log("RequestManager runWrapped")
|
|
|
|
|
if (runReason == RunReason.INITIALIZE) {
|
|
|
|
|
this.mStage = this.getNextStage(request, this.mStage);
|
|
|
|
@ -169,7 +171,7 @@ export class RequestManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//究竟从哪里加载数据
|
|
|
|
|
private searchLoadFrom(request: RequestOption, current: Stage, onComplete, onError) {
|
|
|
|
|
private searchLoadFrom(request: RequestOption, current: Stage, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
|
|
|
|
LogUtil.log("RequestManager searchLoadFrom")
|
|
|
|
|
if (current == Stage.RESOURCE_CACHE) {
|
|
|
|
|
this.loadDiskFromTransform(request, onComplete, onError);
|
|
|
|
@ -185,8 +187,8 @@ export class RequestManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载网络资源
|
|
|
|
|
private loadSourceFromNetwork(request: RequestOption, onComplete, onError) {
|
|
|
|
|
let success = (arraybuffer) => {
|
|
|
|
|
private loadSourceFromNetwork(request: RequestOption, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
|
|
|
|
let success = (arraybuffer:ArrayBuffer) => {
|
|
|
|
|
this.downloadSuccess(arraybuffer, onComplete, onError)
|
|
|
|
|
}
|
|
|
|
|
let error = (errorMsg:string) =>{
|
|
|
|
@ -196,10 +198,10 @@ export class RequestManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载本地资源
|
|
|
|
|
private loadSourceFormNative(request: RequestOption, onComplete, onError) {
|
|
|
|
|
private loadSourceFormNative(request: RequestOption, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
|
|
|
|
LogUtil.log("RequestManager loadSourceFormNative")
|
|
|
|
|
// 本地解析后进行一级缓存
|
|
|
|
|
let success = (arrayBuffer) => {
|
|
|
|
|
let success = (arrayBuffer:ArrayBuffer) => {
|
|
|
|
|
// 使用媒体子系统 ImageSource解析文件 获取PixelMap
|
|
|
|
|
let fileTypeUtil = new FileTypeUtil();
|
|
|
|
|
let typeValue = fileTypeUtil.getFileType(arrayBuffer)
|
|
|
|
@ -217,7 +219,7 @@ export class RequestManager {
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
if (request.transformations[0]) {
|
|
|
|
|
request.transformations[0].transform(arrayBuffer, request, (error, pixelMap: PixelMap) => {
|
|
|
|
|
request.transformations[0].transform(arrayBuffer, request, {asyncTransform:(error:BusinessError|string, pixelMap: PixelMap) => {
|
|
|
|
|
// 输出给Image
|
|
|
|
|
if (pixelMap) {
|
|
|
|
|
|
|
|
|
@ -227,7 +229,7 @@ export class RequestManager {
|
|
|
|
|
} else {
|
|
|
|
|
onError(error);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}})
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let success = (value: PixelMap) => {
|
|
|
|
@ -242,7 +244,7 @@ export class RequestManager {
|
|
|
|
|
this.mIResourceFetch.loadResource(request.loadSrc as Resource, success, onError);
|
|
|
|
|
}
|
|
|
|
|
// 加载磁盘缓存 原图
|
|
|
|
|
private loadDiskFromSource(request: RequestOption, onComplete, onError) {
|
|
|
|
|
private loadDiskFromSource(request: RequestOption, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
|
|
|
|
LogUtil.log("RequestManager loadDiskFromSource")
|
|
|
|
|
let cached = this.mDiskCacheProxy.getValue(request.generateDataKey)
|
|
|
|
|
if (cached != null && cached.byteLength > 0) {
|
|
|
|
@ -254,7 +256,7 @@ export class RequestManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载磁盘缓存 变换后图片
|
|
|
|
|
private loadDiskFromTransform(request: RequestOption, onComplete, onError) {
|
|
|
|
|
private loadDiskFromTransform(request: RequestOption, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
|
|
|
|
LogUtil.log("RequestManager loadDiskFromTransform")
|
|
|
|
|
let cached = this.mDiskCacheProxy.getValue(request.generateResourceKey)
|
|
|
|
|
if (cached != null) {
|
|
|
|
@ -265,7 +267,7 @@ export class RequestManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parseSource(request: RequestOption, onComplete, onError) {
|
|
|
|
|
parseSource(request: RequestOption, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
|
|
|
|
LogUtil.log("RequestManager parseSource")
|
|
|
|
|
if ((typeof (request.loadSrc as image.PixelMap).isEditable) == 'boolean') {
|
|
|
|
|
// PixelMap 外层捕获效率更高,不会进入这里
|
|
|
|
@ -282,7 +284,7 @@ export class RequestManager {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private loadLeve1MemoryCache(onComplete, onError) {
|
|
|
|
|
private loadLeve1MemoryCache(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
|
|
|
|
LogUtil.log("RequestManager loadLeve1MemoryCache")
|
|
|
|
|
// 一级缓存 内存获取
|
|
|
|
|
let cache = this.mMemoryCacheProxy.loadMemoryCache(this.options.generateCacheKey, this.options.isCacheable);
|
|
|
|
@ -297,7 +299,7 @@ export class RequestManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析磁盘文件变成PixeMap
|
|
|
|
|
private parseDiskFile2PixelMap(request: RequestOption, source: ArrayBuffer, onComplete, onError) {
|
|
|
|
|
private parseDiskFile2PixelMap(request: RequestOption, source: ArrayBuffer, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
|
|
|
|
// 步骤一:文件转为pixelMap 然后变换 给Image组件
|
|
|
|
|
let fileTypeUtil = new FileTypeUtil();
|
|
|
|
|
let typeValue = fileTypeUtil.getFileType(source);
|
|
|
|
@ -314,23 +316,23 @@ export class RequestManager {
|
|
|
|
|
} else {
|
|
|
|
|
if (this.options.transformations[0]) {
|
|
|
|
|
if (this.options.thumbSizeMultiplier) {
|
|
|
|
|
let thumbOption = new RequestOption();
|
|
|
|
|
let thumbOption:RequestOption = new RequestOption();
|
|
|
|
|
thumbOption.setImageViewSize({
|
|
|
|
|
width: Math.round(this.options.thumbSizeMultiplier * this.options.size.width),
|
|
|
|
|
height: Math.round(this.options.thumbSizeMultiplier * this.options.size.height)
|
|
|
|
|
})
|
|
|
|
|
let thumbCallback = this.options.thumbholderOnComplete.bind(this.options);
|
|
|
|
|
let thumbError = this.options.thumbholderOnError.bind(this.options);
|
|
|
|
|
this.options.transformations[0].transform(source, thumbOption, (error, pixelMap: PixelMap) => {
|
|
|
|
|
let thumbCallback = this.options.thumbholderOnComplete;
|
|
|
|
|
let thumbError = this.options.thumbholderOnError;
|
|
|
|
|
this.options.transformations[0].transform(source, thumbOption,{asyncTransform: (error:BusinessError|string, pixelMap: PixelMap) => {
|
|
|
|
|
if (pixelMap) {
|
|
|
|
|
let imageKnifeData = this.createImagePixelMap(ImageKnifeType.PIXELMAP, pixelMap);
|
|
|
|
|
thumbCallback(imageKnifeData);
|
|
|
|
|
} else {
|
|
|
|
|
thumbError(error);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}})
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
this.options.transformations[0].transform(source, request, (error, pixelMap: PixelMap) => {
|
|
|
|
|
this.options.transformations[0].transform(source, request, {asyncTransform: (error:BusinessError|string, pixelMap: PixelMap) => {
|
|
|
|
|
if (pixelMap) {
|
|
|
|
|
// 保存一份变换后的图片PixelMap到MemoryCache
|
|
|
|
|
let imageKnifeData = this.createImagePixelMap(ImageKnifeType.PIXELMAP, pixelMap);
|
|
|
|
@ -339,11 +341,11 @@ export class RequestManager {
|
|
|
|
|
} else {
|
|
|
|
|
onError(error);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}})
|
|
|
|
|
},this.options.thumbDelayTime);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.options.transformations[0].transform(source, request, (error, pixelMap: PixelMap) => {
|
|
|
|
|
this.options.transformations[0].transform(source, request, {asyncTransform: (error:BusinessError|string, pixelMap: PixelMap) => {
|
|
|
|
|
if (pixelMap) {
|
|
|
|
|
// 保存一份变换后的图片PixelMap到MemoryCache
|
|
|
|
|
let imageKnifeData = this.createImagePixelMap(ImageKnifeType.PIXELMAP, pixelMap);
|
|
|
|
@ -352,13 +354,13 @@ export class RequestManager {
|
|
|
|
|
} else {
|
|
|
|
|
onError(error);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}})
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// thumbnail 缩略图部分
|
|
|
|
|
if (request.thumbSizeMultiplier) {
|
|
|
|
|
let thumbCallback = this.options.thumbholderOnComplete.bind(this.options);
|
|
|
|
|
let thumbError = this.options.thumbholderOnError.bind(this.options);
|
|
|
|
|
let thumbCallback = this.options.thumbholderOnComplete
|
|
|
|
|
let thumbError = this.options.thumbholderOnError
|
|
|
|
|
let thumbSuccess = (value: PixelMap) => {
|
|
|
|
|
let imageKnifeData = this.createImagePixelMap(ImageKnifeType.PIXELMAP, value);
|
|
|
|
|
thumbCallback(imageKnifeData);
|
|
|
|
@ -386,13 +388,13 @@ export class RequestManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析磁盘变换后文件变成PixeMap
|
|
|
|
|
private parseDiskTransformFile2PixelMap(request: RequestOption, source: ArrayBuffer, onComplete, onError) {
|
|
|
|
|
private parseDiskTransformFile2PixelMap(request: RequestOption, source: ArrayBuffer, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
|
|
|
|
let fileTypeUtil = new FileTypeUtil();
|
|
|
|
|
let typeValue = fileTypeUtil.getFileType(source);
|
|
|
|
|
// thumbnail 缩略图部分
|
|
|
|
|
if (request.thumbSizeMultiplier) {
|
|
|
|
|
let thumbCallback = this.options.thumbholderOnComplete.bind(this.options);
|
|
|
|
|
let thumbError = this.options.thumbholderOnError.bind(this.options);
|
|
|
|
|
let thumbCallback = this.options.thumbholderOnComplete
|
|
|
|
|
let thumbError = this.options.thumbholderOnError
|
|
|
|
|
let thumbSuccess = (value: PixelMap) => {
|
|
|
|
|
let imageKnifeData = this.createImagePixelMap(ImageKnifeType.PIXELMAP, value);
|
|
|
|
|
thumbCallback(imageKnifeData);
|
|
|
|
@ -416,7 +418,7 @@ export class RequestManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private downloadSuccess(source: ArrayBuffer, onComplete, onError) {
|
|
|
|
|
private downloadSuccess(source: ArrayBuffer, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
|
|
|
|
LogUtil.log('Download task completed.');
|
|
|
|
|
|
|
|
|
|
if(source == null || source == undefined || source.byteLength <= 0){
|
|
|
|
@ -447,8 +449,8 @@ export class RequestManager {
|
|
|
|
|
.then(async (arraybuffer: ArrayBuffer)=>{
|
|
|
|
|
await this.mDiskCacheProxy.putValue(this.options.generateDataKey, arraybuffer)
|
|
|
|
|
})
|
|
|
|
|
.catch(err=>{
|
|
|
|
|
LogUtil.log('download file is ='+ImageKnifeData.GIF+'and save diskLruCache error ='+ err)
|
|
|
|
|
.catch( (err:BusinessError)=>{
|
|
|
|
|
LogUtil.log('download file is ='+ImageKnifeData.GIF+'and save diskLruCache error ='+ (err as BusinessError))
|
|
|
|
|
})
|
|
|
|
|
}else if(ImageKnifeData.SVG == filetype){
|
|
|
|
|
// 处理svg
|
|
|
|
@ -461,8 +463,8 @@ export class RequestManager {
|
|
|
|
|
.then(async (arraybuffer: ArrayBuffer)=>{
|
|
|
|
|
await this.mDiskCacheProxy.putValue(this.options.generateDataKey, arraybuffer)
|
|
|
|
|
})
|
|
|
|
|
.catch(err=>{
|
|
|
|
|
LogUtil.log('download file is ='+ImageKnifeData.SVG+'and save diskLruCache error ='+ err)
|
|
|
|
|
.catch((err:BusinessError)=>{
|
|
|
|
|
LogUtil.log('download file is ='+ImageKnifeData.SVG+'and save diskLruCache error ='+ (err as BusinessError))
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
// 进行变换
|
|
|
|
@ -471,19 +473,19 @@ export class RequestManager {
|
|
|
|
|
if (this.options.thumbSizeMultiplier) {
|
|
|
|
|
this.thumbnailProcess(source, filetype, onComplete, onError);
|
|
|
|
|
} else {
|
|
|
|
|
this.options.transformations[0].transform(source, this.options, (error, pixelMap: PixelMap) => {
|
|
|
|
|
this.options.transformations[0].transform(source, this.options, {asyncTransform: (error:BusinessError|string, pixelMap: PixelMap) => {
|
|
|
|
|
if (pixelMap) {
|
|
|
|
|
this.saveCacheAndDisk(pixelMap, filetype, onComplete, source);
|
|
|
|
|
} else {
|
|
|
|
|
onError(error);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}})
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// thumbnail 缩略图部分
|
|
|
|
|
if (this.options.thumbSizeMultiplier) {
|
|
|
|
|
let thumbCallback = this.options.thumbholderOnComplete.bind(this.options);
|
|
|
|
|
let thumbError = this.options.thumbholderOnError.bind(this.options);
|
|
|
|
|
let thumbCallback = this.options.thumbholderOnComplete
|
|
|
|
|
let thumbError = this.options.thumbholderOnError
|
|
|
|
|
let thumbSuccess = (value: PixelMap) => {
|
|
|
|
|
let imageKnifeData = this.createImagePixelMap(ImageKnifeType.PIXELMAP, value);
|
|
|
|
|
thumbCallback(imageKnifeData);
|
|
|
|
@ -515,16 +517,16 @@ export class RequestManager {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private saveCacheAndDisk(value: PixelMap, filetype:string, onComplete, source:ArrayBuffer) {
|
|
|
|
|
private saveCacheAndDisk(value: PixelMap, filetype:string, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, source:ArrayBuffer) {
|
|
|
|
|
let imageKnifeData = this.createImagePixelMap(ImageKnifeType.PIXELMAP, value);
|
|
|
|
|
this.mMemoryCacheProxy.putValue(this.options.generateCacheKey, imageKnifeData);
|
|
|
|
|
let save2DiskCache = async (arraybuffer) => {
|
|
|
|
|
let save2DiskCache = async (arraybuffer:ArrayBuffer) => {
|
|
|
|
|
await this.mDiskCacheProxy.putValue(this.options.generateDataKey, arraybuffer)
|
|
|
|
|
// 落盘之后需要主动移除当前request并且调用下一个加载
|
|
|
|
|
let removeCurrentAndSearchNextRun = this.options.removeCurrentAndSearchNext.bind(this.options)
|
|
|
|
|
let removeCurrentAndSearchNextRun = this.options.removeCurrentAndSearchNext
|
|
|
|
|
removeCurrentAndSearchNextRun();
|
|
|
|
|
}
|
|
|
|
|
let runSave2Disk = (resolve, reject) => {
|
|
|
|
|
let runSave2Disk = (resolve:(value:ArrayBuffer)=>void|PromiseLike<ArrayBuffer>, reject:(reason?:BusinessError|string)=>void) => {
|
|
|
|
|
resolve(source);
|
|
|
|
|
}
|
|
|
|
|
let promise = new Promise(runSave2Disk);
|
|
|
|
@ -533,49 +535,49 @@ export class RequestManager {
|
|
|
|
|
onComplete(imageKnifeData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
thumbnailProcess(source:ArrayBuffer, filetype:string, onComplete, onError){
|
|
|
|
|
thumbnailProcess(source:ArrayBuffer, filetype:string, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void){
|
|
|
|
|
let thumbOption = new RequestOption();
|
|
|
|
|
thumbOption.setImageViewSize({
|
|
|
|
|
width: Math.round(this.options.thumbSizeMultiplier * this.options.size.width),
|
|
|
|
|
height: Math.round(this.options.thumbSizeMultiplier * this.options.size.height)
|
|
|
|
|
})
|
|
|
|
|
let thumbCallback = this.options.thumbholderOnComplete.bind(this.options);
|
|
|
|
|
let thumbError = this.options.thumbholderOnError.bind(this.options);
|
|
|
|
|
this.options.transformations[0].transform(source, thumbOption, (error, pixelMap: PixelMap) => {
|
|
|
|
|
let thumbCallback = this.options.thumbholderOnComplete
|
|
|
|
|
let thumbError = this.options.thumbholderOnError
|
|
|
|
|
this.options.transformations[0].transform(source, thumbOption, {asyncTransform: (error:BusinessError|string, pixelMap: PixelMap) => {
|
|
|
|
|
if (pixelMap) {
|
|
|
|
|
let imageKnifeData = this.createImagePixelMap(ImageKnifeType.PIXELMAP, pixelMap);
|
|
|
|
|
thumbCallback(imageKnifeData);
|
|
|
|
|
} else {
|
|
|
|
|
thumbError(error);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}})
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.options.transformations[0].transform(source, this.options, (error, pixelMap: PixelMap) => {
|
|
|
|
|
this.options.transformations[0].transform(source, this.options,{asyncTransform: (error:BusinessError|string, pixelMap: PixelMap) => {
|
|
|
|
|
if (pixelMap) {
|
|
|
|
|
this.saveCacheAndDisk(pixelMap, filetype, onComplete, source);
|
|
|
|
|
} else {
|
|
|
|
|
onError(error);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}})
|
|
|
|
|
}, this.options.thumbDelayTime)
|
|
|
|
|
}
|
|
|
|
|
private svgProcess(onComplete, onError, arraybuffer, typeValue, cacheStrategy?: (cacheData: ImageKnifeData) => void) {
|
|
|
|
|
private svgProcess(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void, arraybuffer:ArrayBuffer, typeValue:string, cacheStrategy?: (cacheData: ImageKnifeData) => void) {
|
|
|
|
|
let svgParseImpl = new SVGParseImpl()
|
|
|
|
|
let size = { width: this.options.size.width, height: this.options.size.height }
|
|
|
|
|
let size:Size = { width: this.options.size.width, height: this.options.size.height }
|
|
|
|
|
svgParseImpl.parseSvg(arraybuffer, size).then((value: PixelMap) => {
|
|
|
|
|
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
|
|
|
|
if(cacheStrategy){
|
|
|
|
|
cacheStrategy(imageKnifeData)
|
|
|
|
|
}
|
|
|
|
|
onComplete(imageKnifeData)
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
}).catch((err:BusinessError) => {
|
|
|
|
|
onError(err)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private gifProcess(onComplete, onError, arraybuffer, typeValue, cacheStrategy?: (cacheData: ImageKnifeData) => void) {
|
|
|
|
|
private gifProcess(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void, arraybuffer:ArrayBuffer, typeValue:string, cacheStrategy?: (cacheData: ImageKnifeData) => void) {
|
|
|
|
|
let gifParseImpl = new GIFParseImpl()
|
|
|
|
|
gifParseImpl.parseGifs(arraybuffer, (data?,err?)=>{
|
|
|
|
|
gifParseImpl.parseGifs(arraybuffer, (data?:GIFFrame[],err?:BusinessError|string)=>{
|
|
|
|
|
if(err){
|
|
|
|
|
onError(err)
|
|
|
|
|
}
|
|
|
|
|