修改样例resource泄露、heic格式补充、降采样优化、增加解码和文件读取debug日志
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
This commit is contained in:
parent
990a9a363f
commit
1efe55db1e
|
@ -5,6 +5,8 @@
|
|||
- Modify memory cache limit and file cache limit
|
||||
- Fix record decodeEndTime in imageKinfaData
|
||||
- Add image buffersize in memory cache
|
||||
- Optimize the magic number of heif format image files
|
||||
- Fix bug: The width and height of the downsampling component are inconsistent with the image resolution unit
|
||||
|
||||
## 3.2.0-rc.6
|
||||
- Support LogUtil to turn off log
|
||||
|
|
|
@ -145,8 +145,11 @@ struct DownSamplePage {
|
|||
|
||||
// 创建pixelMap
|
||||
imageSource.createPixelMap(decodingOptions).then((pixelMap: image.PixelMap) => {
|
||||
imageSource.release()
|
||||
this.afterSampling = pixelMap.getPixelBytesNumber()
|
||||
pixelMap.release()
|
||||
}).catch((err: BusinessError) => {
|
||||
imageSource.release()
|
||||
console.error('Failed to create PixelMap')
|
||||
});
|
||||
}
|
||||
|
@ -160,8 +163,11 @@ struct DownSamplePage {
|
|||
}
|
||||
// 创建pixelMap
|
||||
imageSource.createPixelMap(decodingOptions).then((pixelMap: image.PixelMap) => {
|
||||
imageSource.release()
|
||||
this.beforeSampling = pixelMap.getPixelBytesNumber()
|
||||
pixelMap.release()
|
||||
}).catch((err: BusinessError) => {
|
||||
imageSource.release()
|
||||
console.error('Failed to create PixelMap')
|
||||
});
|
||||
}
|
||||
|
@ -191,8 +197,8 @@ struct DownSamplePage {
|
|||
ImageKnifeComponent({
|
||||
imageKnifeOption: this.imageKnifeOption
|
||||
})
|
||||
.height(300)
|
||||
.width(300)
|
||||
.height(px2vp(300))
|
||||
.width(px2vp(300))
|
||||
.borderWidth(1)
|
||||
.borderColor(Color.Pink)
|
||||
}
|
||||
|
|
|
@ -130,6 +130,7 @@ struct SingleImage {
|
|||
editable: true,
|
||||
}
|
||||
imageSource.createPixelMap(decodingOptions,(err,pixelMap)=>{
|
||||
imageSource.release()
|
||||
this.pixelMap = pixelMap;
|
||||
})
|
||||
}
|
||||
|
|
|
@ -81,7 +81,6 @@ export class ImageKnifeDispatcher {
|
|||
// 回调请求开始
|
||||
if (requestSource === ImageKnifeRequestSource.SRC && request.imageKnifeOption.onLoadListener?.onLoadStart !== undefined) {
|
||||
request.imageKnifeOption.onLoadListener.onLoadStart(request)
|
||||
LogUtil.log('MemoryCache_onLoadStart:' + request.componentId + ',srcType:' + requestSource + ',version:' + request.componentVersion)
|
||||
}
|
||||
LogUtil.log('MemoryCache_showPixelMap.start:' + request.componentId + ',srcType:' + requestSource + ',version:' + request.componentVersion)
|
||||
request.ImageKnifeRequestCallback?.showPixelMap(request.componentVersion, memoryCache.source,
|
||||
|
@ -94,7 +93,6 @@ export class ImageKnifeDispatcher {
|
|||
if (request.imageKnifeOption.onLoadListener?.onLoadSuccess !== undefined) {
|
||||
this.copyMemoryCacheInfo(memoryCache, request.imageKnifeData);
|
||||
request.imageKnifeOption.onLoadListener.onLoadSuccess(memoryCache.source, memoryCache, request)
|
||||
LogUtil.log('MemoryCache_onLoadSuccess:' + request.componentId + ',srcType:' + requestSource + ',version:' + request.componentVersion)
|
||||
}
|
||||
} else if (requestSource == ImageKnifeRequestSource.ERROR_HOLDER) {
|
||||
request.requestState = ImageKnifeRequestState.ERROR
|
||||
|
@ -194,7 +192,6 @@ export class ImageKnifeDispatcher {
|
|||
LogUtil.log('getAndShowImage.start:' + currentRequest.componentId + ',srcType:' + requestSource + ',version:' + currentRequest.componentVersion)
|
||||
if (requestSource === ImageKnifeRequestSource.SRC && currentRequest.imageKnifeOption.onLoadListener?.onLoadStart !== undefined) {
|
||||
currentRequest.imageKnifeOption.onLoadListener?.onLoadStart(currentRequest)
|
||||
LogUtil.log('getAndShowImage_onLoadStart:' + currentRequest.componentId + ',srcType:' + requestSource + ',version:' + currentRequest.componentVersion)
|
||||
}
|
||||
|
||||
let memoryKey: string = this.engineKey.generateMemoryKey(imageSrc, requestSource, currentRequest.imageKnifeOption,isAnimator, currentRequest.componentWidth, currentRequest.componentHeight)
|
||||
|
@ -267,7 +264,6 @@ export class ImageKnifeDispatcher {
|
|||
if (isWatchProgress){
|
||||
emitter.off(Constants.PROGRESS_EMITTER + memoryKey)
|
||||
}
|
||||
LogUtil.log('getAndShowImage_execute.end:'+ currentRequest.componentId + ',srcType:' + requestSource + ',version:' + currentRequest.componentVersion)
|
||||
LogUtil.log('getAndShowImage.end:'+ currentRequest.componentId + ',srcType:' + requestSource + ',version:' + currentRequest.componentVersion)
|
||||
})
|
||||
if (ImageKnife.getInstance().isRequestInSubThread){
|
||||
|
@ -286,7 +282,6 @@ export class ImageKnifeDispatcher {
|
|||
}).catch((err: BusinessError) => {
|
||||
emitter.off(Constants.CALLBACK_EMITTER + memoryKey)
|
||||
LogUtil.error('Fail to requestJob in sub thread src=' + imageSrc + ' err=' + err)
|
||||
LogUtil.log('getAndShowImage.end:' + currentRequest.componentId + ',srcType:' + requestSource + ',version:' + currentRequest.componentVersion)
|
||||
if (isWatchProgress){
|
||||
emitter.off(Constants.PROGRESS_EMITTER + memoryKey)
|
||||
}
|
||||
|
@ -314,7 +309,6 @@ export class ImageKnifeDispatcher {
|
|||
}).catch((err: BusinessError) => {
|
||||
emitter.off(Constants.CALLBACK_EMITTER + memoryKey)
|
||||
LogUtil.error('Fail to requestJob in main thread src=' + imageSrc + ' err=' + err)
|
||||
LogUtil.log('getAndShowImage.end:' + currentRequest.componentId + ',srcType:' + requestSource + ',version:' + currentRequest.componentVersion)
|
||||
|
||||
this.doTaskCallback({
|
||||
pixelMap: undefined,
|
||||
|
@ -374,7 +368,6 @@ export class ImageKnifeDispatcher {
|
|||
requestJobResult.loadFail) {
|
||||
this.assembleImageKnifeData(requestWithSource.request.imageKnifeData, requestJobResult.imageKnifeData, requestWithSource.request)
|
||||
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadFailed(requestJobResult.loadFail,requestWithSource.request);
|
||||
LogUtil.log('getAndShowImage_onLoadFailed:' + currentRequest.componentId + ',srcType:' + requestSource + ',version:' + currentRequest.componentVersion)
|
||||
}
|
||||
if (requestWithSource.source === ImageKnifeRequestSource.SRC &&
|
||||
requestWithSource.request.imageKnifeOption.errorholderSrc !== undefined) {
|
||||
|
@ -462,7 +455,6 @@ export class ImageKnifeDispatcher {
|
|||
this.assembleImageKnifeData(requestWithSource.request.imageKnifeData, imageKnifeData,requestWithSource.request);
|
||||
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess(imageKnifeData.source,
|
||||
saveCacheImageData, requestWithSource.request);
|
||||
LogUtil.log('getAndShowImage_onLoadSuccess:' + currentRequest.componentId + ',srcType:' + requestSource + ',version:' + currentRequest.componentVersion)
|
||||
}
|
||||
} else if (requestWithSource.source == ImageKnifeRequestSource.ERROR_HOLDER) {
|
||||
requestWithSource.request.requestState = ImageKnifeRequestState.ERROR;
|
||||
|
@ -483,7 +475,7 @@ export class ImageKnifeDispatcher {
|
|||
}
|
||||
this.assembleImageKnifeData(callBackData,requestJobResult.imageKnifeData,requestWithSource.request)
|
||||
LogUtil.log('getAndShowImage cancel:' + requestWithSource.request.componentId + ',srcType:' + requestSource + ',version:' + requestWithSource.request.componentVersion)
|
||||
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadCancel('component has destroyed', requestWithSource.request)
|
||||
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadCancel('component has destroyed from load', requestWithSource.request)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -530,7 +522,7 @@ export class ImageKnifeDispatcher {
|
|||
callBackData.errorInfo = errorInfo;
|
||||
}
|
||||
LogUtil.log('dispatchNextJob cancel:' + request.componentId + ',version:' + request.componentVersion)
|
||||
request.imageKnifeOption.onLoadListener.onLoadCancel('component has destroyed', request)
|
||||
request.imageKnifeOption.onLoadListener.onLoadCancel('component has destroyed from queue', request)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,7 @@ export class ImageKnifeLoader {
|
|||
}
|
||||
|
||||
static async parseNormalImage(resBuf: ArrayBuffer, typeValue: string, fileKey: string, request: RequestJobRequest, callBackData: ImageKnifeData) {
|
||||
LogUtil.log('image parse pixelmap start:' + request.componentId + ',srcType:' + request.requestSource + ',' + request.componentVersion)
|
||||
let resPixelmap: PixelMap | undefined = undefined
|
||||
let timeInfo: TimeInfo = ImageKnifeLoader.getTimeInfo(callBackData);
|
||||
|
||||
|
@ -206,6 +207,7 @@ export class ImageKnifeLoader {
|
|||
type:typeValue,
|
||||
imageKnifeData:callBackData
|
||||
}
|
||||
LogUtil.log('image parse pixelmap end:' + request.componentId + ',srcType:' + request.requestSource + ',' + request.componentVersion)
|
||||
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { 'value': res } })
|
||||
}
|
||||
static async parseSvgImage(resBuf: ArrayBuffer, typeValue: string, fileKey: string,
|
||||
|
@ -478,9 +480,11 @@ export class ImageKnifeLoader {
|
|||
if (request.src.indexOf('http://') == 0 || request.src.indexOf('https://') == 0) { //从网络下载
|
||||
// 先从文件缓存获取
|
||||
ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_NET)
|
||||
LogUtil.log('get fileCache buffer start:' + request.componentId + ',srcType:' + request.requestSource + ',' + request.componentVersion)
|
||||
callBackTimeInfo.diskCheckStartTime = Date.now()
|
||||
resBuf = FileCache.getFileCacheByFile(request.context, fileKey , request.fileCacheFolder)
|
||||
callBackTimeInfo.diskCheckEndTime = Date.now()
|
||||
LogUtil.log('get fileCache buffer end:' + request.componentId + ',srcType:' + request.requestSource + ',' + request.componentVersion)
|
||||
if (resBuf !== undefined){
|
||||
LogUtil.log('success get image from filecache for key = ' + fileKey + ' src = ' + request.componentId + ',srcType:' + request.requestSource + ',' + request.componentVersion)
|
||||
}
|
||||
|
@ -523,8 +527,6 @@ export class ImageKnifeLoader {
|
|||
expectDataType: http.HttpDataType.ARRAY_BUFFER,
|
||||
connectTimeout: request.connectTimeout == undefined ? 60000 : request.connectTimeout,
|
||||
readTimeout: request.readTimeout == undefined ? 30000 : request.readTimeout,
|
||||
// usingProtocol:http.HttpProtocol.HTTP1_1
|
||||
// header: new Header('application/json')
|
||||
caPath: request.caPath === undefined ? undefined : request.caPath,
|
||||
});
|
||||
|
||||
|
@ -629,8 +631,8 @@ export class ImageKnifeLoader {
|
|||
static getDownsamplerDecodingOptions(typeValue: string, request: RequestJobRequest, size: Size,
|
||||
SRC?: ImageKnifeRequestSource):image.DecodingOptions {
|
||||
let reqSize =
|
||||
new Downsampler().calculateScaling(typeValue, size.width, size.height, request.targetWidth, request.targetHeight,
|
||||
request.downsampType)
|
||||
new Downsampler().calculateScaling(typeValue, size.width, size.height,
|
||||
vp2px(request.targetWidth), vp2px(request.targetHeight), request.downsampType)
|
||||
if (typeValue == 'svg') {
|
||||
return {
|
||||
editable: true,
|
||||
|
|
|
@ -86,6 +86,7 @@ export class MaskTransformation extends PixelMapTransformation {
|
|||
}
|
||||
};
|
||||
let maskBitmap: PixelMap = await imageSource.createPixelMap(options);
|
||||
imageSource.release()
|
||||
return await this.mask(bitmap, maskBitmap);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ export class FileTypeUtil {
|
|||
'ico': [new Uint8Array([0x00,0x00,0x01,0x00])],
|
||||
'tiff': [new Uint8Array([0x49, 0x20, 0x49]), new Uint8Array([0x49, 0x49, 0x2A, 0x00]), new Uint8Array([0x4D, 0x4D, 0x00, 0x2A]), new Uint8Array([0x4D, 0x4D, 0x00, 0x2B])],
|
||||
// 添加更多的文件类型和特征
|
||||
'heic': [new Uint8Array([0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70, 0x68, 0x65, 0x69, 0x63, 0x00, 0x00, 0x00, 0x00]),new Uint8Array([0x00, 0x00, 0x00, 0x1C, 0x66, 0x74, 0x79, 0x70, 0x68, 0x65, 0x69, 0x63, 0x00, 0x00, 0x00, 0x00])],
|
||||
'heic': [new Uint8Array([0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70, 0x68, 0x65, 0x69, 0x63]),new Uint8Array([0x00, 0x00, 0x00, 0x1C, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x69, 0x66, 0x31])],
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue