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