forked from floraachy/ImageKnife
文件缓存初始化增加默认值、预加载接口新增返回加载错误信息、加载队列从队列从Queue改为Stack以及fileType新增heic格式
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
This commit is contained in:
parent
52e5d1f5bf
commit
945e842e69
|
@ -1,5 +1,9 @@
|
||||||
## 3.0.0-rc.6
|
## 3.0.0-rc.6
|
||||||
- 支持多种组合变换
|
- 支持多种组合变换
|
||||||
|
- 文件缓存初始化增加默认值
|
||||||
|
- 预加载接口新增返回加载错误信息
|
||||||
|
- 加载队列改为使用堆Stack
|
||||||
|
- fileType图片格式新增heic格式
|
||||||
|
|
||||||
## 3.0.0-rc.5
|
## 3.0.0-rc.5
|
||||||
- 图片加载事件增加请求开始的回调,以及修复有缓存时,没有回调的bug
|
- 图片加载事件增加请求开始的回调,以及修复有缓存时,没有回调的bug
|
||||||
|
|
|
@ -55,12 +55,12 @@ export default function DefaultJobQueueTest() {
|
||||||
|
|
||||||
expect(job.getQueueLength()).assertEqual(7)
|
expect(job.getQueueLength()).assertEqual(7)
|
||||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("high1")
|
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("high1")
|
||||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium1")
|
|
||||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium2")
|
|
||||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium3")
|
|
||||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium4")
|
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium4")
|
||||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("low1")
|
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium3")
|
||||||
|
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium2")
|
||||||
|
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium1")
|
||||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("low2")
|
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("low2")
|
||||||
|
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("low1")
|
||||||
expect(job.pop()).assertEqual(undefined)
|
expect(job.pop()).assertEqual(undefined)
|
||||||
expect(job.getQueueLength()).assertEqual(0)
|
expect(job.getQueueLength()).assertEqual(0)
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ export class ImageKnife {
|
||||||
* @param size 缓存数量
|
* @param size 缓存数量
|
||||||
* @param memory 内存大小
|
* @param memory 内存大小
|
||||||
*/
|
*/
|
||||||
async initFileCache(context: Context, size: number, memory: number) {
|
async initFileCache(context: Context, size: number = 256, memory: number = 256 * 1024 * 1024) {
|
||||||
this.fileCache = new FileCache(context, size, memory)
|
this.fileCache = new FileCache(context, size, memory)
|
||||||
await this.fileCache.initFileCache()
|
await this.fileCache.initFileCache()
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,14 @@ export class ImageKnife {
|
||||||
let fileKey = this.getEngineKeyImpl().generateFileKey(imageKnifeOption.loadSrc, imageKnifeOption.signature)
|
let fileKey = this.getEngineKeyImpl().generateFileKey(imageKnifeOption.loadSrc, imageKnifeOption.signature)
|
||||||
let cachePath = ImageKnife.getInstance().getFileCache().getFileToPath(fileKey)
|
let cachePath = ImageKnife.getInstance().getFileCache().getFileToPath(fileKey)
|
||||||
if (cachePath == null || cachePath == "" || cachePath == undefined) {
|
if (cachePath == null || cachePath == "" || cachePath == undefined) {
|
||||||
|
imageKnifeOption.onLoadListener = {
|
||||||
|
onLoadSuccess(){
|
||||||
|
resolve(ImageKnife.getInstance().getFileCache().getFileToPath(fileKey))
|
||||||
|
},
|
||||||
|
onLoadFailed(err) {
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
let request = new ImageKnifeRequest(
|
let request = new ImageKnifeRequest(
|
||||||
imageKnifeOption,
|
imageKnifeOption,
|
||||||
imageKnifeOption.context !== undefined ? imageKnifeOption.context : getContext(this) as common.UIAbilityContext,
|
imageKnifeOption.context !== undefined ? imageKnifeOption.context : getContext(this) as common.UIAbilityContext,
|
||||||
|
@ -171,7 +179,6 @@ export class ImageKnife {
|
||||||
0,
|
0,
|
||||||
{
|
{
|
||||||
showPixelMap(version: number, pixelMap: PixelMap | string) {
|
showPixelMap(version: number, pixelMap: PixelMap | string) {
|
||||||
resolve(ImageKnife.getInstance().getFileCache().getFileToPath(fileKey))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
import { ImageKnifeRequest } from '../ImageKnifeRequest';
|
import { ImageKnifeRequest } from '../ImageKnifeRequest';
|
||||||
import { IJobQueue } from './IJobQueue'
|
import { IJobQueue } from './IJobQueue'
|
||||||
import Queue from '@ohos.util.Queue';
|
import Queue from '@ohos.util.Queue';
|
||||||
import { taskpool } from '@kit.ArkTS';
|
import { taskpool,Stack } from '@kit.ArkTS';
|
||||||
|
|
||||||
export class DefaultJobQueue implements IJobQueue {
|
export class DefaultJobQueue implements IJobQueue {
|
||||||
highQueue: Queue<ImageKnifeRequest> = new Queue();
|
highQueue: Stack<ImageKnifeRequest> = new Stack();
|
||||||
normalQueue: Queue<ImageKnifeRequest> = new Queue();
|
normalQueue: Stack<ImageKnifeRequest> = new Stack();
|
||||||
lowQueue: Queue<ImageKnifeRequest> = new Queue();
|
lowQueue: Stack<ImageKnifeRequest> = new Stack();
|
||||||
|
|
||||||
getQueueLength(): number {
|
getQueueLength(): number {
|
||||||
return this.highQueue.length + this.normalQueue.length + this.lowQueue.length
|
return this.highQueue.length + this.normalQueue.length + this.lowQueue.length
|
||||||
|
@ -28,11 +28,11 @@ export class DefaultJobQueue implements IJobQueue {
|
||||||
|
|
||||||
add(request: ImageKnifeRequest): void {
|
add(request: ImageKnifeRequest): void {
|
||||||
if (request.imageKnifeOption.priority === undefined || request.imageKnifeOption.priority === taskpool.Priority.MEDIUM) {
|
if (request.imageKnifeOption.priority === undefined || request.imageKnifeOption.priority === taskpool.Priority.MEDIUM) {
|
||||||
this.normalQueue.add(request)
|
this.normalQueue.push(request)
|
||||||
} else if (request.imageKnifeOption.priority === taskpool.Priority.HIGH) {
|
} else if (request.imageKnifeOption.priority === taskpool.Priority.HIGH) {
|
||||||
this.highQueue.add(request)
|
this.highQueue.push(request)
|
||||||
} else {
|
} else {
|
||||||
this.lowQueue.add(request)
|
this.lowQueue.push(request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ export class FileTypeUtil {
|
||||||
'webp': [new Uint8Array([0x52, 0x49, 0x46, 0x46])],
|
'webp': [new Uint8Array([0x52, 0x49, 0x46, 0x46])],
|
||||||
'tiff': [new Uint8Array([0x49, 0x20, 0x49]), new Uint8Array([0x49, 0x49, 0x2A, 0x00]), new Uint8Array([0x4D, 0x4D, 0x00, 0x2A]), new Uint8Array([0x4D, 0x4D, 0x00, 0x2B])],
|
'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])],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +41,8 @@ export class FileTypeUtil {
|
||||||
value == SupportFormat.webp ||
|
value == SupportFormat.webp ||
|
||||||
value == SupportFormat.bmp ||
|
value == SupportFormat.bmp ||
|
||||||
value == SupportFormat.gif ||
|
value == SupportFormat.gif ||
|
||||||
value == SupportFormat.svg
|
value == SupportFormat.svg ||
|
||||||
|
value == SupportFormat.heic
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -105,5 +107,6 @@ export enum SupportFormat {
|
||||||
bmp = 'bmp',
|
bmp = 'bmp',
|
||||||
gif = 'gif',
|
gif = 'gif',
|
||||||
svg = 'svg',
|
svg = 'svg',
|
||||||
tiff = 'tiff'
|
tiff = 'tiff',
|
||||||
|
heic = 'heic'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue