From 22dfe82aa903145b5b0002a587eb205c568c72df Mon Sep 17 00:00:00 2001 From: zgf Date: Tue, 24 Dec 2024 15:52:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=9B=BE=E7=89=87=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E4=B8=8D=E9=87=8D=E5=A4=8D=E5=88=9B=E5=BB=BA=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E4=BC=98=E5=8C=96heif=E5=9B=BE=E7=89=87=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=96=87=E4=BB=B6=E9=AD=94=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- CHANGELOG.md | 2 + .../ets/components/ImageKnifeComponent.ets | 70 ++++++++++--------- library/src/main/ets/utils/FileTypeUtil.ets | 2 +- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fec8946..1cc4c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 +- Default image request does not require duplicate creation ## 3.2.0-rc.6 - Support LogUtil to turn off log diff --git a/library/src/main/ets/components/ImageKnifeComponent.ets b/library/src/main/ets/components/ImageKnifeComponent.ets index 2cad1ea..fe45efb 100644 --- a/library/src/main/ets/components/ImageKnifeComponent.ets +++ b/library/src/main/ets/components/ImageKnifeComponent.ets @@ -140,40 +140,46 @@ export struct ImageKnifeComponent { } getRequest(width: number, height: number,componentId: number): ImageKnifeRequest { - this.request = new ImageKnifeRequest( - this.imageKnifeOption, - this.imageKnifeOption.context !== undefined ? this.imageKnifeOption.context : this.getCurrentContext(), - width, - height, - this.componentVersion, - { - showPixelMap: (version: number, pixelMap: PixelMap | string,size:Size, requestSource: ImageKnifeRequestSource) => { - if (version !== this.componentVersion) { - return //针对reuse场景,不显示历史图片 - } - this.pixelMap = pixelMap - LogUtil.info('image load showPixelMap:' + this.request?.componentId + ',srcType:' + requestSource + - ',version:' + this.request?.componentVersion + - ',size:' + JSON.stringify(size)) - if (this.imageKnifeOption.objectFit === ImageFit.Auto && this.isImageFitAutoResize == false && requestSource == ImageKnifeRequestSource.SRC) { - this.adaptiveHeight = undefined - this.isImageFitAutoResize = true - } + if (this.imageKnifeOption.downsampleOf !== undefined) { + this.request = undefined + } + + if (this.request == undefined) { + this.request = new ImageKnifeRequest( + this.imageKnifeOption, + this.imageKnifeOption.context !== undefined ? this.imageKnifeOption.context : this.getCurrentContext(), + width, + height, + this.componentVersion, + { + showPixelMap: (version: number, pixelMap: PixelMap | string,size:Size, requestSource: ImageKnifeRequestSource) => { + if (version !== this.componentVersion) { + return //针对reuse场景,不显示历史图片 + } + this.pixelMap = pixelMap + LogUtil.info('image load showPixelMap:' + this.request?.componentId + ',srcType:' + requestSource + + ',version:' + this.request?.componentVersion + + ',size:' + JSON.stringify(size)) + if (this.imageKnifeOption.objectFit === ImageFit.Auto && this.isImageFitAutoResize == false && requestSource == ImageKnifeRequestSource.SRC) { + this.adaptiveHeight = undefined + this.isImageFitAutoResize = true + } - if (requestSource == ImageKnifeRequestSource.SRC) { - this.objectFit = - this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit - } else if (requestSource == ImageKnifeRequestSource.PLACE_HOLDER) { - this.objectFit = - this.imageKnifeOption.placeholderObjectFit === undefined ? (this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit) : this.imageKnifeOption.placeholderObjectFit - } else { - this.objectFit = - this.imageKnifeOption.errorholderObjectFit === undefined ? (this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit) : this.imageKnifeOption.errorholderObjectFit + if (requestSource == ImageKnifeRequestSource.SRC) { + this.objectFit = + this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit + } else if (requestSource == ImageKnifeRequestSource.PLACE_HOLDER) { + this.objectFit = + this.imageKnifeOption.placeholderObjectFit === undefined ? (this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit) : this.imageKnifeOption.placeholderObjectFit + } else { + this.objectFit = + this.imageKnifeOption.errorholderObjectFit === undefined ? (this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit) : this.imageKnifeOption.errorholderObjectFit + } } - } - }, - componentId - ) + }, + componentId + ) + } return this.request } } diff --git a/library/src/main/ets/utils/FileTypeUtil.ets b/library/src/main/ets/utils/FileTypeUtil.ets index 4c20316..7f070df 100644 --- a/library/src/main/ets/utils/FileTypeUtil.ets +++ b/library/src/main/ets/utils/FileTypeUtil.ets @@ -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])], };