forked from floraachy/ImageKnife
1.将console.log封装至ImageKnife.log,由开关控制日志输出
Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
parent
01eea2d9c2
commit
42d2713acb
|
@ -59,6 +59,8 @@ export class ImageKnife {
|
|||
|
||||
private defaultLifeCycle: IDrawLifeCycle;
|
||||
|
||||
private debugLog: boolean = false;
|
||||
|
||||
private constructor(imgCtx) {
|
||||
this.imageKnifeContext = imgCtx;
|
||||
|
||||
|
@ -175,6 +177,20 @@ export class ImageKnife {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否开启日志打印 true开启 false关闭 默认不开启
|
||||
* @param openLog
|
||||
*/
|
||||
public setDebugLog(openLog:boolean){
|
||||
this.debugLog = openLog
|
||||
}
|
||||
|
||||
public log(info:string){
|
||||
if(this.debugLog){
|
||||
globalThis.ImageKnife.log(info)
|
||||
}
|
||||
}
|
||||
|
||||
// 预加载 resource资源一级缓存,string资源实现二级缓存
|
||||
preload(request: RequestOption) {
|
||||
// 每个request 公共信息补充
|
||||
|
@ -326,7 +342,7 @@ export class ImageKnife {
|
|||
}
|
||||
}
|
||||
else {
|
||||
console.log("key没有生成无法进入存取!")
|
||||
globalThis.ImageKnife.log("key没有生成无法进入存取!")
|
||||
}
|
||||
|
||||
|
||||
|
@ -370,7 +386,7 @@ export class ImageKnife {
|
|||
request.diskCacheStrategy(none);
|
||||
this.loadResources(request);
|
||||
} else {
|
||||
console.error("输入参数有问题!")
|
||||
globalThis.ImageKnife.error("输入参数有问题!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ export struct ImageKnifeComponent {
|
|||
// 前提:宽高值均有效,值>0. 条件1:当前宽高与上一次宽高不同 条件2:当前是第一次绘制
|
||||
if( (this.currentHeight != this.lastHeight || this.currentWidth != this.lastWidth) || this.firstDrawFlag){
|
||||
this.firstDrawFlag = false;
|
||||
console.log('ImageKnifeComponent onAreaChange isValid Canvas currentWidth =' + this.currentWidth + ' currentHeight=' + this.currentHeight)
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent onAreaChange isValid Canvas currentWidth =' + this.currentWidth + ' currentHeight=' + this.currentHeight)
|
||||
this.lastWidth = this.currentWidth
|
||||
this.lastHeight = this.currentHeight
|
||||
this.imageKnifeExecute()
|
||||
|
@ -107,7 +107,7 @@ export struct ImageKnifeComponent {
|
|||
.onReady(() => {
|
||||
this.canvasHasReady = true;
|
||||
if(this.onReadyNext){
|
||||
console.log('ImageKnifeComponent onReadyNext is running!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent onReadyNext is running!')
|
||||
this.onReadyNext()
|
||||
this.onReadyNext = undefined;
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ export struct ImageKnifeComponent {
|
|||
}
|
||||
|
||||
watchImageKnifeOption() {
|
||||
console.log('ImageKnifeComponent watchImageKnifeOption is happened!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent watchImageKnifeOption is happened!')
|
||||
this.whetherWaitSize();
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ export struct ImageKnifeComponent {
|
|||
this.firstDrawFlag = true;
|
||||
}
|
||||
}else{
|
||||
console.log('ImageKnifeComponent whetherWaitSize 宽高有效 直接发送请求')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent whetherWaitSize 宽高有效 直接发送请求')
|
||||
this.imageKnifeExecute()
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ export struct ImageKnifeComponent {
|
|||
configNecessary(request: RequestOption) {
|
||||
request.load(this.imageKnifeOption.loadSrc)
|
||||
.addListener((err, data) => {
|
||||
console.log('ImageKnifeComponent request.load callback')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent request.load callback')
|
||||
this.runNextFunction(this.displayMainSource.bind(this,data));
|
||||
return false;
|
||||
})
|
||||
|
@ -200,20 +200,20 @@ export struct ImageKnifeComponent {
|
|||
configDisplay(request: RequestOption) {
|
||||
if (this.imageKnifeOption.placeholderSrc) {
|
||||
request.placeholder(this.imageKnifeOption.placeholderSrc, (data) => {
|
||||
console.log('ImageKnifeComponent request.placeholder callback')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent request.placeholder callback')
|
||||
this.runNextFunction(this.displayPlaceholder.bind(this,data))
|
||||
|
||||
})
|
||||
}
|
||||
if (this.imageKnifeOption.thumbSizeMultiplier) {
|
||||
request.thumbnail(this.imageKnifeOption.thumbSizeMultiplier, (data) => {
|
||||
console.log('ImageKnifeComponent request.thumbnail callback')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent request.thumbnail callback')
|
||||
this.runNextFunction(this.displayThumbSizeMultiplier.bind(this,data))
|
||||
}, this.imageKnifeOption.thumbSizeDelay)
|
||||
}
|
||||
if (this.imageKnifeOption.errorholderSrc) {
|
||||
request.errorholder(this.imageKnifeOption.errorholderSrc, (data) => {
|
||||
console.log('ImageKnifeComponent request.errorholder callback')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent request.errorholder callback')
|
||||
this.runNextFunction(this.displayErrorholder.bind(this, data))
|
||||
})
|
||||
}
|
||||
|
@ -235,14 +235,14 @@ export struct ImageKnifeComponent {
|
|||
if (this.imageKnifeOption.displayProgress) {
|
||||
request.addProgressListener((percentValue: number) => {
|
||||
// 如果进度条百分比 未展示大小,展示其动画
|
||||
console.log('ImageKnifeComponent request.addProgressListener callback')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent request.addProgressListener callback')
|
||||
this.runNextFunction(this.displayProgress.bind(this,percentValue))
|
||||
})
|
||||
}
|
||||
|
||||
if (this.imageKnifeOption.retryholderSrc) {
|
||||
request.retryholder(this.imageKnifeOption.retryholderSrc, (data) => {
|
||||
console.log('ImageKnifeComponent request.retryholder callback')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent request.retryholder callback')
|
||||
this.hasDisplayRetryholder = true
|
||||
this.runNextFunction(this.displayRetryholder.bind(this,data))
|
||||
})
|
||||
|
@ -366,16 +366,16 @@ export struct ImageKnifeComponent {
|
|||
}
|
||||
|
||||
drawPlaceholder(context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) {
|
||||
console.log('ImageKnifeComponent default drawPlaceholder start!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent default drawPlaceholder start!')
|
||||
// @ts-ignore
|
||||
data.drawPixelMap.imagePixelMap.getImageInfo().then((imageInfo) => {
|
||||
console.log('ImageKnifeComponent imageinfo widht =' + imageInfo.size.width + ' height=' + imageInfo.size.height)
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent imageinfo widht =' + imageInfo.size.width + ' height=' + imageInfo.size.height)
|
||||
let scaleType = (typeof imageKnifeOption.placeholderScaleType == 'number') ? imageKnifeOption.placeholderScaleType : ScaleType.FIT_CENTER
|
||||
context.save();
|
||||
context.clearRect(0, 0, compWidth, compHeight)
|
||||
ScaleTypeHelper.drawImageWithScaleType(context, scaleType, data.drawPixelMap.imagePixelMap, px2vp(imageInfo.size.width), px2vp(imageInfo.size.height), compWidth, compHeight, 0, 0)
|
||||
context.restore();
|
||||
console.log('ImageKnifeComponent default drawPlaceholder end!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent default drawPlaceholder end!')
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -421,31 +421,31 @@ export struct ImageKnifeComponent {
|
|||
}
|
||||
|
||||
drawThumbSizeMultiplier(context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) {
|
||||
console.log('ImageKnifeComponent default drawThumbSizeMultiplier start!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent default drawThumbSizeMultiplier start!')
|
||||
// @ts-ignore
|
||||
data.drawPixelMap.imagePixelMap.getImageInfo().then((imageInfo) => {
|
||||
console.log('ImageKnifeComponent imageinfo widht =' + imageInfo.size.width + ' height=' + imageInfo.size.height)
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent imageinfo widht =' + imageInfo.size.width + ' height=' + imageInfo.size.height)
|
||||
let scaleType = (typeof imageKnifeOption.thumbSizeMultiplierScaleType == 'number') ? imageKnifeOption.thumbSizeMultiplierScaleType : ScaleType.FIT_CENTER
|
||||
context.save();
|
||||
context.clearRect(0, 0, compWidth, compHeight)
|
||||
ScaleTypeHelper.drawImageWithScaleType(context, scaleType, data.drawPixelMap.imagePixelMap, px2vp(imageInfo.size.width), px2vp(imageInfo.size.height), compWidth, compHeight, 0, 0)
|
||||
context.restore();
|
||||
console.log('ImageKnifeComponent default drawThumbSizeMultiplier end!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent default drawThumbSizeMultiplier end!')
|
||||
})
|
||||
}
|
||||
|
||||
drawMainSource(context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) {
|
||||
console.log('ImageKnifeComponent default drawMainSource start!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent default drawMainSource start!')
|
||||
if (data.isPixelMap()) {
|
||||
// @ts-ignore
|
||||
data.drawPixelMap.imagePixelMap.getImageInfo().then((imageInfo) => {
|
||||
let scaleType = (typeof imageKnifeOption.mainScaleType == 'number') ? imageKnifeOption.mainScaleType : ScaleType.FIT_CENTER
|
||||
console.log('ImageKnifeComponent imageinfo width =' + imageInfo.size.width + ' height=' + imageInfo.size.height + 'scaleType=' + scaleType)
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent imageinfo width =' + imageInfo.size.width + ' height=' + imageInfo.size.height + 'scaleType=' + scaleType)
|
||||
context.save();
|
||||
context.clearRect(0, 0, compWidth, compHeight)
|
||||
ScaleTypeHelper.drawImageWithScaleType(context, scaleType, data.drawPixelMap.imagePixelMap, px2vp(imageInfo.size.width), px2vp(imageInfo.size.height), compWidth, compHeight, 0, 0)
|
||||
context.restore();
|
||||
console.log('ImageKnifeComponent default drawMainSource end!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent default drawMainSource end!')
|
||||
})
|
||||
} else if (data.isGIFFrame()) {
|
||||
this.drawGIFFrame(context, data, imageKnifeOption, compWidth, compHeight, setGifTimeId)
|
||||
|
@ -453,30 +453,30 @@ export struct ImageKnifeComponent {
|
|||
}
|
||||
|
||||
drawRetryholder(context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) {
|
||||
console.log('ImageKnifeComponent default drawRetryholder start!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent default drawRetryholder start!')
|
||||
// @ts-ignore
|
||||
data.drawPixelMap.imagePixelMap.getImageInfo().then((imageInfo) => {
|
||||
console.log('ImageKnifeComponent imageinfo width =' + imageInfo.size.width + ' height=' + imageInfo.size.height)
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent imageinfo width =' + imageInfo.size.width + ' height=' + imageInfo.size.height)
|
||||
let scaleType = (typeof imageKnifeOption.retryholderScaleType == 'number') ? imageKnifeOption.retryholderScaleType : ScaleType.FIT_CENTER
|
||||
context.save();
|
||||
context.clearRect(0, 0, compWidth, compHeight)
|
||||
ScaleTypeHelper.drawImageWithScaleType(context, scaleType, data.drawPixelMap.imagePixelMap, px2vp(imageInfo.size.width), px2vp(imageInfo.size.height), compWidth, compHeight, 0, 0)
|
||||
context.restore();
|
||||
console.log('ImageKnifeComponent default drawRetryholder end!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent default drawRetryholder end!')
|
||||
})
|
||||
}
|
||||
|
||||
drawErrorholder(context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) {
|
||||
console.log('ImageKnifeComponent default drawErrorholder start!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent default drawErrorholder start!')
|
||||
// @ts-ignore
|
||||
data.drawPixelMap.imagePixelMap.getImageInfo().then((imageInfo) => {
|
||||
console.log('ImageKnifeComponent imageinfo widht =' + imageInfo.size.width + ' height=' + imageInfo.size.height)
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent imageinfo widht =' + imageInfo.size.width + ' height=' + imageInfo.size.height)
|
||||
let scaleType = (typeof imageKnifeOption.errorholderSrcScaleType == 'number') ? imageKnifeOption.errorholderSrcScaleType : ScaleType.FIT_CENTER
|
||||
context.save();
|
||||
context.clearRect(0, 0, compWidth, compHeight)
|
||||
ScaleTypeHelper.drawImageWithScaleType(context, scaleType, data.drawPixelMap.imagePixelMap, px2vp(imageInfo.size.width), px2vp(imageInfo.size.height), compWidth, compHeight, 0, 0)
|
||||
context.restore();
|
||||
console.log('ImageKnifeComponent default drawErrorholder end!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent default drawErrorholder end!')
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -523,13 +523,13 @@ export struct ImageKnifeComponent {
|
|||
}
|
||||
|
||||
aboutToAppear() {
|
||||
console.log('ImageKnifeComponent aboutToAppear happened!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent aboutToAppear happened!')
|
||||
this.canvasHasReady = false;
|
||||
this.whetherWaitSize(true);
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
console.log('ImageKnifeComponent aboutToDisappear happened!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent aboutToDisappear happened!')
|
||||
this.resetGifData();
|
||||
}
|
||||
|
||||
|
@ -557,7 +557,7 @@ export struct ImageKnifeComponent {
|
|||
|
||||
private drawGIFFrame(context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) {
|
||||
let frames = data.drawGIFFrame.imageGIFFrames as GIFFrame[]
|
||||
console.log('ImageKnifeComponent gifFrameLength =' + frames.length);
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent gifFrameLength =' + frames.length);
|
||||
if (imageKnifeOption.gif && (typeof (imageKnifeOption.gif.seekTo) == 'number') && imageKnifeOption.gif.seekTo >= 0) {
|
||||
this.autoPlay = false;
|
||||
context.clearRect(0, 0, compWidth, compHeight)
|
||||
|
@ -586,7 +586,7 @@ export struct ImageKnifeComponent {
|
|||
}
|
||||
|
||||
private renderFrames(frames: GIFFrame[], index: number, context: CanvasRenderingContext2D, compWidth: number, compHeight: number) {
|
||||
console.log('ImageKnifeComponent renderFrames frames length =' + frames.length)
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent renderFrames frames length =' + frames.length)
|
||||
let start = new Date().getTime();
|
||||
if (index === 0) {
|
||||
// 如果是第一帧,我们只从开始渲染前记录时间
|
||||
|
@ -647,7 +647,7 @@ export struct ImageKnifeComponent {
|
|||
|
||||
// 具体绘制过程
|
||||
private canvasDrawPixelMap(frames: GIFFrame[], index: number, context: CanvasRenderingContext2D, compWidth: number, compHeight: number) {
|
||||
console.log('ImageKnifeComponent canvasDrawPixelMap index=' + index)
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent canvasDrawPixelMap index=' + index)
|
||||
let frame = frames[index];
|
||||
let pixelmap = frame['drawPixelMap']
|
||||
let disposal = 0
|
||||
|
@ -666,7 +666,7 @@ export struct ImageKnifeComponent {
|
|||
ScaleTypeHelper.drawImageWithScaleType(context, scaleType, pixelmap, px2vp(frameW), px2vp(frameH), compWidth, compHeight, px2vp(frame.dims.left), px2vp(frame.dims.top))
|
||||
// tips:worker如果不是在展示页面中创建,使用子线程回来的数据创建的图片,会导致canvas绘制不出来
|
||||
context.restore();
|
||||
console.log('ImageKnifeComponent default drawMainSource end!')
|
||||
globalThis.ImageKnife.log('ImageKnifeComponent default drawMainSource end!')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -237,7 +237,6 @@ export class ImageKnifeDrawFactory{
|
|||
context.restore();
|
||||
}
|
||||
context.restore();
|
||||
console.log('TestImageKnifeOptionChangedPage4 drawMainSource end!')
|
||||
})
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -327,8 +327,8 @@ export class RequestOption {
|
|||
|
||||
// 占位图解析成功
|
||||
placeholderOnComplete(imageKnifeData: ImageKnifeData) {
|
||||
console.log("placeholderOnComplete has called!");
|
||||
console.log("Main Image is Ready:" + this.loadMainReady);
|
||||
globalThis.ImageKnife.log("placeholderOnComplete has called!");
|
||||
globalThis.ImageKnife.log("Main Image is Ready:" + this.loadMainReady);
|
||||
if (!this.loadMainReady && !(this.loadErrorReady || this.loadRetryReady) && !this.loadThumbnailReady) {
|
||||
// 主图未加载成功,并且未加载失败 显示占位图 主图加载成功或者加载失败后=>不展示占位图
|
||||
this.placeholderFunc(imageKnifeData)
|
||||
|
@ -337,7 +337,7 @@ export class RequestOption {
|
|||
|
||||
// 占位图解析失败
|
||||
placeholderOnError(error) {
|
||||
console.log("占位图解析失败 error =" + error)
|
||||
globalThis.ImageKnife.log("占位图解析失败 error =" + error)
|
||||
}
|
||||
|
||||
|
||||
|
@ -353,7 +353,7 @@ export class RequestOption {
|
|||
|
||||
// 缩略图解析失败
|
||||
thumbholderOnError(error) {
|
||||
console.log("缩略图解析失败 error =" + error)
|
||||
globalThis.ImageKnife.log("缩略图解析失败 error =" + error)
|
||||
}
|
||||
|
||||
// 加载失败 占位图解析成功
|
||||
|
@ -367,7 +367,7 @@ export class RequestOption {
|
|||
|
||||
//加载失败 占位图解析失败
|
||||
errorholderOnError(error) {
|
||||
console.log("失败占位图解析失败 error =" + error)
|
||||
globalThis.ImageKnife.log("失败占位图解析失败 error =" + error)
|
||||
}
|
||||
|
||||
retryholderOnComplete(imageKnifeData: ImageKnifeData){
|
||||
|
@ -378,7 +378,7 @@ export class RequestOption {
|
|||
}
|
||||
|
||||
retryholderOnError(error){
|
||||
console.log("重试占位图解析失败 error ="+ error)
|
||||
globalThis.ImageKnife.log("重试占位图解析失败 error ="+ error)
|
||||
}
|
||||
|
||||
loadComplete(imageKnifeData: ImageKnifeData) {
|
||||
|
@ -395,8 +395,8 @@ export class RequestOption {
|
|||
}
|
||||
|
||||
loadError(err) {
|
||||
console.log("loadError:"+err);
|
||||
console.log("loadError stack=:"+JSON.stringify(err.stack));
|
||||
globalThis.ImageKnife.log("loadError:"+err);
|
||||
globalThis.ImageKnife.log("loadError stack=:"+JSON.stringify(err.stack));
|
||||
//失败占位图展示规则
|
||||
if (this.retryholderFunc) {
|
||||
// 重试图层优先于加载失败展示
|
||||
|
|
|
@ -40,7 +40,7 @@ export class ErrorHolderManager {
|
|||
}
|
||||
|
||||
private displayErrorholder(onComplete, onError) {
|
||||
console.log("displayErrorholder")
|
||||
globalThis.ImageKnife.log("displayErrorholder")
|
||||
if ((typeof (this.options.errorholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.errorholderSrc as PixelMap)
|
||||
onComplete(imageKnifeData);
|
||||
|
|
|
@ -42,7 +42,7 @@ export class PlaceHolderManager {
|
|||
}
|
||||
|
||||
private displayPlaceholder(onComplete, onError) {
|
||||
console.log("displayPlaceholder")
|
||||
globalThis.ImageKnife.log("displayPlaceholder")
|
||||
if ((typeof (this.options.placeholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.placeholderSrc as PixelMap)
|
||||
onComplete(imageKnifeData);
|
||||
|
|
|
@ -42,7 +42,7 @@ export class RetryHolderManager {
|
|||
}
|
||||
|
||||
private displayRetryholder(onComplete, onError) {
|
||||
console.log("displayRetryholder")
|
||||
globalThis.ImageKnife.log("displayRetryholder")
|
||||
if ((typeof (this.options.retryholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.placeholderSrc as PixelMap)
|
||||
onComplete(imageKnifeData);
|
||||
|
|
|
@ -88,7 +88,7 @@ export class RequestManager {
|
|||
}
|
||||
|
||||
static execute(option: RequestOption, memoryCache1: LruCache<string, any>, diskMemoryCache1: DiskLruCache, dataFetch: IDataFetch, resourceFetch: IResourceFetch) {
|
||||
console.log("RequestManager execute")
|
||||
globalThis.ImageKnife.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))
|
||||
|
@ -98,9 +98,9 @@ export class RequestManager {
|
|||
|
||||
loadCompleteAfter() {
|
||||
try { // 内部消化问题
|
||||
console.log("loadCompleteAfter!")
|
||||
globalThis.ImageKnife.log("loadCompleteAfter!")
|
||||
if (this.options.allCacheInfoCallback) {
|
||||
console.log("RequestOption =" + JSON.stringify(this.options));
|
||||
globalThis.ImageKnife.log("RequestOption =" + JSON.stringify(this.options));
|
||||
|
||||
// 内存缓存
|
||||
let allCacheInfo = new AllCacheInfo();
|
||||
|
@ -124,7 +124,7 @@ export class RequestManager {
|
|||
this.options.allCacheInfoCallback(allCacheInfo)
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("after err =" + err)
|
||||
globalThis.ImageKnife.log("after err =" + err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,12 +134,12 @@ export class RequestManager {
|
|||
private mRunReason: RunReason = RunReason.INITIALIZE;
|
||||
|
||||
process(onComplete, onError) {
|
||||
console.log("RequestManager process !");
|
||||
globalThis.ImageKnife.log("RequestManager process !");
|
||||
this.loadLeve1MemoryCache(onComplete, onError)
|
||||
}
|
||||
|
||||
private runWrapped(request: RequestOption, runReason: RunReason, onComplete, onError) {
|
||||
console.log("RequestManager runWrapped")
|
||||
globalThis.ImageKnife.log("RequestManager runWrapped")
|
||||
if (runReason == RunReason.INITIALIZE) {
|
||||
this.mStage = this.getNextStage(request, this.mStage);
|
||||
this.searchLoadFrom(this.options, this.mStage, onComplete, onError);
|
||||
|
@ -170,7 +170,7 @@ export class RequestManager {
|
|||
|
||||
//究竟从哪里加载数据
|
||||
private searchLoadFrom(request: RequestOption, current: Stage, onComplete, onError) {
|
||||
console.log("RequestManager searchLoadFrom")
|
||||
globalThis.ImageKnife.log("RequestManager searchLoadFrom")
|
||||
if (current == Stage.RESOURCE_CACHE) {
|
||||
this.loadDiskFromTransform(request, onComplete, onError);
|
||||
} else if (current == Stage.DATA_CACHE) {
|
||||
|
@ -194,13 +194,13 @@ export class RequestManager {
|
|||
|
||||
// 加载本地资源
|
||||
private loadSourceFormNative(request: RequestOption, onComplete, onError) {
|
||||
console.log("RequestManager loadSourceFormNative")
|
||||
globalThis.ImageKnife.log("RequestManager loadSourceFormNative")
|
||||
// 本地解析后进行一级缓存
|
||||
let success = (arrayBuffer) => {
|
||||
// 使用媒体子系统 ImageSource解析文件 获取PixelMap
|
||||
let fileTypeUtil = new FileTypeUtil();
|
||||
let typeValue = fileTypeUtil.getFileType(arrayBuffer)
|
||||
console.log("RequestManager - 文件类型为= " + typeValue)
|
||||
globalThis.ImageKnife.log("RequestManager - 文件类型为= " + typeValue)
|
||||
// gif处理
|
||||
if(ImageKnifeData.GIF == typeValue && !request.dontAnimateFlag){
|
||||
// 处理gif
|
||||
|
@ -240,7 +240,7 @@ export class RequestManager {
|
|||
}
|
||||
// 加载磁盘缓存 原图
|
||||
private loadDiskFromSource(request: RequestOption, onComplete, onError) {
|
||||
console.log("RequestManager loadDiskFromSource")
|
||||
globalThis.ImageKnife.log("RequestManager loadDiskFromSource")
|
||||
let cached = this.mDiskCacheProxy.getValue(request.generateDataKey)
|
||||
if (cached != null) {
|
||||
this.parseDiskFile2PixelMap(request, cached, onComplete, onError)
|
||||
|
@ -252,7 +252,7 @@ export class RequestManager {
|
|||
|
||||
// 加载磁盘缓存 变换后图片
|
||||
private loadDiskFromTransform(request: RequestOption, onComplete, onError) {
|
||||
console.log("RequestManager loadDiskFromTransform")
|
||||
globalThis.ImageKnife.log("RequestManager loadDiskFromTransform")
|
||||
let cached = this.mDiskCacheProxy.getValue(request.generateResourceKey)
|
||||
if (cached != null) {
|
||||
this.parseDiskTransformFile2PixelMap(request, cached, onComplete, onError)
|
||||
|
@ -263,7 +263,7 @@ export class RequestManager {
|
|||
}
|
||||
|
||||
parseSource(request: RequestOption, onComplete, onError) {
|
||||
console.log("RequestManager parseSource")
|
||||
globalThis.ImageKnife.log("RequestManager parseSource")
|
||||
if ((typeof (request.loadSrc as image.PixelMap).isEditable) == 'boolean') {
|
||||
// PixelMap 外层捕获效率更高,不会进入这里
|
||||
} else if (typeof request.loadSrc == 'string') {
|
||||
|
@ -273,14 +273,14 @@ export class RequestManager {
|
|||
if (typeof res.id != 'undefined' && typeof res.id != 'undefined') {
|
||||
this.loadSourceFormNative(request, onComplete, onError)
|
||||
} else {
|
||||
console.log("输入参数有问题!")
|
||||
globalThis.ImageKnife.log("输入参数有问题!")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private loadLeve1MemoryCache(onComplete, onError) {
|
||||
console.log("RequestManager loadLeve1MemoryCache")
|
||||
globalThis.ImageKnife.log("RequestManager loadLeve1MemoryCache")
|
||||
// 一级缓存 内存获取
|
||||
let cache = this.mMemoryCacheProxy.loadMemoryCache(this.options.generateCacheKey, this.options.isCacheable);
|
||||
if (cache == null || typeof cache == 'undefined') {
|
||||
|
@ -414,7 +414,7 @@ export class RequestManager {
|
|||
}
|
||||
|
||||
private downloadSuccess(source: ArrayBuffer, onComplete, onError) {
|
||||
console.info('Download task completed.');
|
||||
globalThis.ImageKnife.info('Download task completed.');
|
||||
|
||||
if(source == null || source == undefined || source.byteLength <= 0){
|
||||
onError('Download task completed. but download file is empty!')
|
||||
|
@ -445,7 +445,7 @@ export class RequestManager {
|
|||
await this.mDiskCacheProxy.putValue(this.options.generateDataKey, arraybuffer)
|
||||
})
|
||||
.catch(err=>{
|
||||
console.log('download file is ='+ImageKnifeData.GIF+'and save diskLruCache error ='+ err)
|
||||
globalThis.ImageKnife.log('download file is ='+ImageKnifeData.GIF+'and save diskLruCache error ='+ err)
|
||||
})
|
||||
}else if(ImageKnifeData.SVG == filetype){
|
||||
// 处理svg
|
||||
|
@ -459,7 +459,7 @@ export class RequestManager {
|
|||
await this.mDiskCacheProxy.putValue(this.options.generateDataKey, arraybuffer)
|
||||
})
|
||||
.catch(err=>{
|
||||
console.log('download file is ='+ImageKnifeData.SVG+'and save diskLruCache error ='+ err)
|
||||
globalThis.ImageKnife.log('download file is ='+ImageKnifeData.SVG+'and save diskLruCache error ='+ err)
|
||||
})
|
||||
} else {
|
||||
// 进行变换
|
||||
|
@ -572,12 +572,12 @@ export class RequestManager {
|
|||
if(err){
|
||||
onError(err)
|
||||
}
|
||||
console.log("gifProcess data is null:"+(data == null));
|
||||
globalThis.ImageKnife.log("gifProcess data is null:"+(data == null));
|
||||
if(!!data){
|
||||
let imageKnifeData = this.createImageGIFFrame(ImageKnifeType.GIFFRAME,data)
|
||||
console.log('gifProcess 生成gif 返回数据类型')
|
||||
globalThis.ImageKnife.log('gifProcess 生成gif 返回数据类型')
|
||||
if(cacheStrategy){
|
||||
console.log('gifProcess 生成gif并且存入了缓存策略')
|
||||
globalThis.ImageKnife.log('gifProcess 生成gif并且存入了缓存策略')
|
||||
cacheStrategy(imageKnifeData)
|
||||
}
|
||||
onComplete(imageKnifeData)
|
||||
|
|
|
@ -35,7 +35,7 @@ export class BlurTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";BlurTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";BlurTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";BlurTransformation buf is empty", null);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ export class BlurTransformation implements BaseTransform<PixelMap> {
|
|||
fastBlur.blur(data, this._mRadius, true, func);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
func(e, null);
|
||||
})
|
||||
})
|
||||
|
|
|
@ -36,7 +36,7 @@ export class BrightnessFilterTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty", null);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export class ContrastFilterTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";ContrastFilterTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";ContrastFilterTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";ContrastFilterTransformation buf is empty", null);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ export class CropCircleTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.error(Constants.PROJECT_TAG + CropCircleTransformation.TAG + " buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + CropCircleTransformation.TAG + " buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + CropCircleTransformation.TAG + " buf is empty", null);
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ export class CropCircleTransformation implements BaseTransform<PixelMap> {
|
|||
this.transformCircle(p, func);
|
||||
})
|
||||
.catch(e => {
|
||||
console.error(Constants.PROJECT_TAG + CropCircleTransformation.TAG + " transform e:" + e);
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + CropCircleTransformation.TAG + " transform e:" + e);
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + CropCircleTransformation.TAG + "e" + e, null);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ export class CropCircleWithBorderTransformation implements BaseTransform<PixelMa
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation buf is empty", null);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ export class CropCircleWithBorderTransformation implements BaseTransform<PixelMa
|
|||
this.transformPixelMap(pixelMap, outWith, outHeight, func);
|
||||
})
|
||||
.catch(e => {
|
||||
console.log(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation e:" + e);
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation e:" + e);
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation e:" + e, null);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ export class CropSquareTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";CropSquareTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";CropSquareTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";CropSquareTransformation buf is empty", null);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ export class CropTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";CropTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";CropTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";CropTransformation buf is empty", null);
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ export class CropTransformation implements BaseTransform<PixelMap> {
|
|||
func("", data);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
func(e, null);
|
||||
})
|
||||
})
|
||||
|
|
|
@ -27,7 +27,7 @@ export class GrayscaleTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty", null);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ export class InvertFilterTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";InvertFilterTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";InvertFilterTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";InvertFilterTransformation buf is empty", null);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ export class MaskTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";MaskTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";MaskTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";MaskTransformation buf is empty", null);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ export class PixelationFilterTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";PixelationFilterTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";PixelationFilterTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";PixelationFilterTransformation buf is empty", null);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ export class PixelationFilterTransformation implements BaseTransform<PixelMap> {
|
|||
pixelUtils.pixel(data, this._mPixel, func);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
func(e, null);
|
||||
})
|
||||
})
|
||||
|
|
|
@ -33,7 +33,7 @@ export class RotateImageTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";RotateImageTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";RotateImageTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";RotateImageTransformation buf is empty", null);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ export class RotateImageTransformation implements BaseTransform<PixelMap> {
|
|||
func("", data);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
func(e, null);
|
||||
})
|
||||
})
|
||||
|
|
|
@ -49,10 +49,10 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
console.log('RoundedCornersTransformation = '+ this.getName()
|
||||
globalThis.ImageKnife.log('RoundedCornersTransformation = '+ this.getName()
|
||||
+ 'buf is null ='+ (buf == null));
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";RoundedCornersTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";RoundedCornersTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";RoundedCornersTransformation buf is empty", null);
|
||||
}
|
||||
|
@ -114,11 +114,11 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(Constants.PROJECT_TAG + "RoundedCornersTransformation error:" + error);
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + "RoundedCornersTransformation error:" + error);
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
if (func) {
|
||||
func(e, null);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ export class SepiaFilterTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
console.log(Constants.PROJECT_TAG + ";SepiaFilterTransformation buf is empty");
|
||||
globalThis.ImageKnife.log(Constants.PROJECT_TAG + ";SepiaFilterTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";SepiaFilterTransformation buf is empty", null);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ export class FileTypeUtil {
|
|||
}
|
||||
|
||||
let dataView = new DataView(arraybuffer);
|
||||
console.log('dataView +'+this.getDataViewAt(dataView,0)+this.getDataViewAt(dataView,1))
|
||||
globalThis.ImageKnife.log('dataView +'+this.getDataViewAt(dataView,0)+this.getDataViewAt(dataView,1))
|
||||
|
||||
for(var [key,value] of this.map){
|
||||
let keySplit = key.split(',')
|
||||
|
@ -58,10 +58,10 @@ export class FileTypeUtil {
|
|||
fileMagic+=this.getDataViewAt(dataView,offset+start)
|
||||
start++;
|
||||
}
|
||||
// console.log('magic='+fileMagic+' keySplit[1]='+keySplit[1]+' fileMagic == keySplit[1] ='+(fileMagic == keySplit[1])+
|
||||
// globalThis.ImageKnife.log('magic='+fileMagic+' keySplit[1]='+keySplit[1]+' fileMagic == keySplit[1] ='+(fileMagic == keySplit[1])+
|
||||
// ' fileMagic type ='+typeof(fileMagic) + ' keySplit[1]='+typeof(keySplit[1]))
|
||||
if(fileMagic == keySplit[1]){
|
||||
console.log('匹配到了 fileType='+value)
|
||||
globalThis.ImageKnife.log('匹配到了 fileType='+value)
|
||||
fileType = value
|
||||
break;
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ export class FileTypeUtil {
|
|||
|
||||
private printMapContent(){
|
||||
for(var [key,value] of this.map){
|
||||
console.log('key='+key+'---value='+value)
|
||||
globalThis.ImageKnife.log('key='+key+'---value='+value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,14 +21,14 @@ import image from '@ohos.multimedia.image'
|
|||
export class GIFParseImpl implements IParseGif {
|
||||
parseGifs(imageinfo: ArrayBuffer, callback: (data?, err?) => void, worker?,runMainThread?:boolean) {
|
||||
let resolveWorker = worker;
|
||||
console.log('parseGifs resolveWorker1 is null =' + (resolveWorker == null))
|
||||
globalThis.ImageKnife.log('parseGifs resolveWorker1 is null =' + (resolveWorker == null))
|
||||
if (!resolveWorker) {
|
||||
resolveWorker = globalThis.ImageKnife.getGifWorker();
|
||||
}
|
||||
console.log('parseGifs resolveWorker2 is null =' + (resolveWorker == null))
|
||||
globalThis.ImageKnife.log('parseGifs resolveWorker2 is null =' + (resolveWorker == null))
|
||||
|
||||
if (!!resolveWorker && !runMainThread) {
|
||||
console.log('parseGifs in worker thread!')
|
||||
globalThis.ImageKnife.log('parseGifs in worker thread!')
|
||||
this.useWorkerParse(resolveWorker, imageinfo, (data, err) => {
|
||||
if (err) {
|
||||
callback(undefined, err)
|
||||
|
@ -48,9 +48,9 @@ export class GIFParseImpl implements IParseGif {
|
|||
}
|
||||
})
|
||||
} else {
|
||||
console.log('parseGifs in main thread!')
|
||||
globalThis.ImageKnife.log('parseGifs in main thread!')
|
||||
let frames = parseBufferToFrame(imageinfo)
|
||||
console.log('frames length =' + frames.length)
|
||||
globalThis.ImageKnife.log('frames length =' + frames.length)
|
||||
this.createPixelMapAll(frames).then((pixelmaps) => {
|
||||
if (pixelmaps.length == frames.length) {
|
||||
for (let i = 0;i < frames.length; i++) {
|
||||
|
@ -58,11 +58,11 @@ export class GIFParseImpl implements IParseGif {
|
|||
frame['drawPixelMap'] = pixelmaps[i];
|
||||
frame['patch'] = null;
|
||||
}
|
||||
console.log('parseGifs in main thread! callback is done!')
|
||||
globalThis.ImageKnife.log('parseGifs in main thread! callback is done!')
|
||||
callback(frames, undefined)
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log('parseGifs in main thread! err =' + err)
|
||||
globalThis.ImageKnife.log('parseGifs in main thread! err =' + err)
|
||||
callback(undefined, err)
|
||||
})
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ export class GIFParseImpl implements IParseGif {
|
|||
}
|
||||
|
||||
worker.onexit = function () {
|
||||
console.log('gifWork worker.onexit!')
|
||||
globalThis.ImageKnife.log('gifWork worker.onexit!')
|
||||
}
|
||||
|
||||
worker.onmessage = (e) => {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue