forked from floraachy/ImageKnife
1.codecheck整改
Signed-off-by: zhoulisheng <635547767@qq.com>
This commit is contained in:
parent
70a1c0911e
commit
d87cda1d15
|
@ -28,10 +28,10 @@ export default class EntryAbility extends UIAbility {
|
||||||
let atManager = abilityAccessCtrl.createAtManager();
|
let atManager = abilityAccessCtrl.createAtManager();
|
||||||
atManager.requestPermissionsFromUser(this.context, list, (err: BusinessError, result: Object) => {
|
atManager.requestPermissionsFromUser(this.context, list, (err: BusinessError, result: Object) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("dodo requestPermissionsFromUserError:" + JSON.stringify(err));
|
|
||||||
} else {
|
} else {
|
||||||
permissionRequestResult = result;
|
permissionRequestResult = result;
|
||||||
console.log("dodo permissionRequestResult:" + JSON.stringify(permissionRequestResult))
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -47,10 +47,10 @@ export default class EntryAbility extends UIAbility {
|
||||||
.setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5))
|
.setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5))
|
||||||
// 全局配置缓存key
|
// 全局配置缓存key
|
||||||
imageKnife.setEngineKeyImpl(new CustomEngineKeyImpl())
|
imageKnife.setEngineKeyImpl(new CustomEngineKeyImpl())
|
||||||
//设置全局内存缓存大小张数
|
// 设置全局内存缓存大小张数
|
||||||
imageKnife.setLruCacheSize(100, 100 * 1204 * 1024)
|
imageKnife.setLruCacheSize(100, 100 * 1204 * 1024)
|
||||||
}
|
}
|
||||||
//开启ImageKnife所有级别日志开关
|
// 开启ImageKnife所有级别日志开关
|
||||||
LogUtil.mLogLevel = LogUtil.ALL
|
LogUtil.mLogLevel = LogUtil.ALL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ export default function LogUtilTest() {
|
||||||
})
|
})
|
||||||
it('TestLogUtilLevel',0, ()=> {
|
it('TestLogUtilLevel',0, ()=> {
|
||||||
|
|
||||||
console.log("tag:LogUtil LogUtil.mLogLevel="+LogUtil.mLogLevel);
|
|
||||||
LogUtil.mLogLevel = LogUtil.OFF;
|
LogUtil.mLogLevel = LogUtil.OFF;
|
||||||
expect(LogUtil.mLogLevel).assertEqual(LogUtil.OFF);
|
expect(LogUtil.mLogLevel).assertEqual(LogUtil.OFF);
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ export default function lruCacheTest() {
|
||||||
expect(key).assertEqual("2")
|
expect(key).assertEqual("2")
|
||||||
expect(value).assertEqual("2")
|
expect(value).assertEqual("2")
|
||||||
}
|
}
|
||||||
console.log('dodo count='+count+' key='+key+' value='+value)
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
memoryCache.foreachLruCache( (value:string, key:string, map:Map<string,string>)=> {
|
memoryCache.foreachLruCache( (value:string, key:string, map:Map<string,string>)=> {
|
||||||
|
@ -117,7 +117,7 @@ export default function lruCacheTest() {
|
||||||
expect(key).assertEqual("1")
|
expect(key).assertEqual("1")
|
||||||
expect(value).assertEqual("1")
|
expect(value).assertEqual("1")
|
||||||
}
|
}
|
||||||
console.log('dodo count='+count+' key='+key+' value='+value)
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
memoryCache.foreachLruCache( (value:string, key:string, map:Map<string,string>)=> {
|
memoryCache.foreachLruCache( (value:string, key:string, map:Map<string,string>)=> {
|
||||||
|
|
|
@ -270,7 +270,7 @@ export class FileUtils {
|
||||||
* @param 文件夹绝对路径
|
* @param 文件夹绝对路径
|
||||||
*/
|
*/
|
||||||
createFolder(path: string) {
|
createFolder(path: string) {
|
||||||
//创建文件夹
|
// 创建文件夹
|
||||||
if (!this.existFolder(path)) {
|
if (!this.existFolder(path)) {
|
||||||
fs.mkdirSync(path)
|
fs.mkdirSync(path)
|
||||||
}
|
}
|
||||||
|
@ -297,11 +297,11 @@ export class FileUtils {
|
||||||
* @param content 文件内容数据
|
* @param content 文件内容数据
|
||||||
*/
|
*/
|
||||||
createFileProcess(folder: string, file: string, content: ArrayBuffer | string) {
|
createFileProcess(folder: string, file: string, content: ArrayBuffer | string) {
|
||||||
//创建文件夹
|
// 创建文件夹
|
||||||
this.createFolder(folder);
|
this.createFolder(folder);
|
||||||
//创建文件
|
// 创建文件
|
||||||
this.createFile(file);
|
this.createFile(file);
|
||||||
//写入数据
|
// 写入数据
|
||||||
this.writeFile(file, content)
|
this.writeFile(file, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -360,9 +360,9 @@ export class ImageKnife {
|
||||||
|
|
||||||
// 执行相同key的pending队列请求
|
// 执行相同key的pending队列请求
|
||||||
private keyEqualPendingToRun(nextPending: RequestOption) {
|
private keyEqualPendingToRun(nextPending: RequestOption) {
|
||||||
// let nextPending = this.pendingRequest.splice(index, 1)[0];
|
|
||||||
// this.runningRequest.push(nextPending)
|
|
||||||
// RequestManager.execute((nextPending as RequestOption), this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch)
|
|
||||||
|
|
||||||
this.pendingMaps.remove(nextPending.uuid)
|
this.pendingMaps.remove(nextPending.uuid)
|
||||||
this.runningMaps.put(nextPending.uuid, nextPending);
|
this.runningMaps.put(nextPending.uuid, nextPending);
|
||||||
|
@ -445,11 +445,11 @@ export class ImageKnife {
|
||||||
if (hasRunningRequest) {
|
if (hasRunningRequest) {
|
||||||
this.pendingMaps.put(request.uuid, request);
|
this.pendingMaps.put(request.uuid, request);
|
||||||
|
|
||||||
// this.pendingRequest.push(request);
|
|
||||||
} else {
|
} else {
|
||||||
this.runningMaps.put(request.uuid, request)
|
this.runningMaps.put(request.uuid, request)
|
||||||
|
|
||||||
// this.runningRequest.push(request);
|
|
||||||
// 不存在相同key的 任务可以并行
|
// 不存在相同key的 任务可以并行
|
||||||
RequestManager.execute(request, this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch)
|
RequestManager.execute(request, this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch)
|
||||||
}
|
}
|
||||||
|
@ -516,7 +516,7 @@ export class ImageKnife {
|
||||||
} else {
|
} else {
|
||||||
let res = request.loadSrc as Resource;
|
let res = request.loadSrc as Resource;
|
||||||
if (typeof res.id != 'undefined' && typeof res.type != 'undefined') {
|
if (typeof res.id != 'undefined' && typeof res.type != 'undefined') {
|
||||||
//进入三级缓存模型 本地资源不参与磁盘缓存
|
// 进入三级缓存模型 本地资源不参与磁盘缓存
|
||||||
let none = new NONE();
|
let none = new NONE();
|
||||||
request.diskCacheStrategy(none);
|
request.diskCacheStrategy(none);
|
||||||
this.loadResources(request);
|
this.loadResources(request);
|
||||||
|
|
|
@ -26,8 +26,8 @@ export enum ImageKnifeType {
|
||||||
|
|
||||||
export class DrawPixelMap {
|
export class DrawPixelMap {
|
||||||
imagePixelMap: PixelMap | undefined = undefined
|
imagePixelMap: PixelMap | undefined = undefined
|
||||||
isShowOnComponent: boolean = false; //gif是否显示在组件上 true:显示在组件上 false:不显示在组件上
|
isShowOnComponent: boolean = false; // gif是否显示在组件上 true:显示在组件上 false:不显示在组件上
|
||||||
isLruCacheRelease: boolean = false; //当前lru是否释放gif资源,true的就释放了gif资源 false就是没有释放
|
isLruCacheRelease: boolean = false; // 当前lru是否释放gif资源,true的就释放了gif资源 false就是没有释放
|
||||||
|
|
||||||
detachFromLayoutPixelMap: DetachFromLayout = {
|
detachFromLayoutPixelMap: DetachFromLayout = {
|
||||||
detach: () => {
|
detach: () => {
|
||||||
|
|
|
@ -439,12 +439,12 @@ export class ImageKnifeDrawFactory{
|
||||||
private static drawDefaultProgress(context: CanvasRenderingContext2D, progress: number, imageKnifeOption: ImageKnifeOption,
|
private static drawDefaultProgress(context: CanvasRenderingContext2D, progress: number, imageKnifeOption: ImageKnifeOption,
|
||||||
compWidth: number, compHeight: number,
|
compWidth: number, compHeight: number,
|
||||||
fontColor:string, fontSizeRate:number,setGifTimeId?: (timeId: number) => void,){
|
fontColor:string, fontSizeRate:number,setGifTimeId?: (timeId: number) => void,){
|
||||||
let pi = Math.PI * 2 / 100; //pi 讲圆的周长划分为100份
|
let pi = Math.PI * 2 / 100; // pi 讲圆的周长划分为100份
|
||||||
let rate = progress - 25;
|
let rate = progress - 25;
|
||||||
let diameter = compWidth > compHeight ? compHeight : compWidth
|
let diameter = compWidth > compHeight ? compHeight : compWidth
|
||||||
context.lineWidth = Math.floor(diameter * 0.03)
|
context.lineWidth = Math.floor(diameter * 0.03)
|
||||||
context.lineCap = "round"
|
context.lineCap = "round"
|
||||||
context.fillStyle = fontColor//"#10a5ff"
|
context.fillStyle = fontColor// "#10a5ff"
|
||||||
context.font = Math.floor(diameter * fontSizeRate *px2vp(1))+'px'
|
context.font = Math.floor(diameter * fontSizeRate *px2vp(1))+'px'
|
||||||
let x0 = (compWidth - diameter) / 2.0 + Math.floor(diameter * 0.5)
|
let x0 = (compWidth - diameter) / 2.0 + Math.floor(diameter * 0.5)
|
||||||
let y0 = (compHeight - diameter) / 2.0 + Math.floor(diameter * 0.1)
|
let y0 = (compHeight - diameter) / 2.0 + Math.floor(diameter * 0.1)
|
||||||
|
|
|
@ -95,7 +95,7 @@ export class ImageKnifeOption {
|
||||||
displayProgress?: boolean;
|
displayProgress?: boolean;
|
||||||
|
|
||||||
|
|
||||||
//自定义缓存关键字
|
// 自定义缓存关键字
|
||||||
signature?: ObjectKey;
|
signature?: ObjectKey;
|
||||||
|
|
||||||
// 重试图层 可点击
|
// 重试图层 可点击
|
||||||
|
|
|
@ -90,7 +90,7 @@ export class RequestOption {
|
||||||
onlyRetrieveFromCache: boolean = false;
|
onlyRetrieveFromCache: boolean = false;
|
||||||
isCacheable: boolean = true;
|
isCacheable: boolean = true;
|
||||||
|
|
||||||
//开启GPU变换绘制
|
// 开启GPU变换绘制
|
||||||
gpuEnabled: boolean = false;
|
gpuEnabled: boolean = false;
|
||||||
// 变换相关
|
// 变换相关
|
||||||
transformations: Array<BaseTransform<PixelMap>> = new Array();
|
transformations: Array<BaseTransform<PixelMap>> = new Array();
|
||||||
|
@ -100,7 +100,7 @@ export class RequestOption {
|
||||||
filesPath: string = ""; // data/data/包名/files目录
|
filesPath: string = ""; // data/data/包名/files目录
|
||||||
cachesPath: string = ""; // 网络下载默认存储在data/data/包名/cache/ImageKnifeNetworkFolder/目标md5.img下面
|
cachesPath: string = ""; // 网络下载默认存储在data/data/包名/cache/ImageKnifeNetworkFolder/目标md5.img下面
|
||||||
|
|
||||||
//自定义缓存关键字
|
// 自定义缓存关键字
|
||||||
signature?: ObjectKey;
|
signature?: ObjectKey;
|
||||||
|
|
||||||
// 下载原始文件地址
|
// 下载原始文件地址
|
||||||
|
@ -438,7 +438,7 @@ export class RequestOption {
|
||||||
this.transformations = inputs;
|
this.transformations = inputs;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
//开启GPU变换绘制
|
// 开启GPU变换绘制
|
||||||
enableGPU() {
|
enableGPU() {
|
||||||
this.gpuEnabled = true;
|
this.gpuEnabled = true;
|
||||||
return this;
|
return this;
|
||||||
|
@ -465,7 +465,7 @@ export class RequestOption {
|
||||||
// 缩略图解析成功
|
// 缩略图解析成功
|
||||||
thumbholderOnComplete = (imageKnifeData: ImageKnifeData)=> {
|
thumbholderOnComplete = (imageKnifeData: ImageKnifeData)=> {
|
||||||
if (!this.loadMainReady && !(this.loadErrorReady || this.loadRetryReady)) {
|
if (!this.loadMainReady && !(this.loadErrorReady || this.loadRetryReady)) {
|
||||||
//主图未加载成功,并且未加载失败 显示占位图 主图加载成功或者加载失败后=>不展示占位图
|
// 主图未加载成功,并且未加载失败 显示占位图 主图加载成功或者加载失败后=>不展示占位图
|
||||||
if(this.thumbHolderFunc != undefined) {
|
if(this.thumbHolderFunc != undefined) {
|
||||||
this.thumbHolderFunc?.asyncSuccess(imageKnifeData)
|
this.thumbHolderFunc?.asyncSuccess(imageKnifeData)
|
||||||
}
|
}
|
||||||
|
@ -488,7 +488,7 @@ export class RequestOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//加载失败 占位图解析失败
|
// 加载失败 占位图解析失败
|
||||||
errorholderOnError = (error:BusinessError|string)=> {
|
errorholderOnError = (error:BusinessError|string)=> {
|
||||||
LogUtil.log("失败占位图解析失败 error =" + error)
|
LogUtil.log("失败占位图解析失败 error =" + error)
|
||||||
}
|
}
|
||||||
|
@ -529,11 +529,11 @@ export class RequestOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 加载成功之后
|
|
||||||
// let imageKnife:ImageKnife | undefined = ImageKnifeGlobal.getInstance().getImageKnife();
|
|
||||||
// if(imageKnife != undefined) {
|
|
||||||
// imageKnife.removeRunning(this);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 图片文件落盘之后会自动去寻找下一个数据加载
|
// 图片文件落盘之后会自动去寻找下一个数据加载
|
||||||
|
@ -545,7 +545,7 @@ export class RequestOption {
|
||||||
|
|
||||||
loadError = (err:BusinessError|string)=>{
|
loadError = (err:BusinessError|string)=>{
|
||||||
LogUtil.log("loadError:" + err);
|
LogUtil.log("loadError:" + err);
|
||||||
//失败占位图展示规则
|
// 失败占位图展示规则
|
||||||
if (this.retryholderFunc) {
|
if (this.retryholderFunc) {
|
||||||
// 重试图层优先于加载失败展示
|
// 重试图层优先于加载失败展示
|
||||||
this.loadRetryReady = true;
|
this.loadRetryReady = true;
|
||||||
|
|
|
@ -27,7 +27,7 @@ import common from '@ohos.app.ability.common';
|
||||||
|
|
||||||
export class CompressBuilder {
|
export class CompressBuilder {
|
||||||
private _mTargetDir: string = '';
|
private _mTargetDir: string = '';
|
||||||
private _mLeastCompressSize: number= 100; //KB
|
private _mLeastCompressSize: number= 100; // KB
|
||||||
private _mRenameListener: OnRenameListener = {reName:()=>{return ''}};
|
private _mRenameListener: OnRenameListener = {reName:()=>{return ''}};
|
||||||
private _mCompressListener: OnCompressListener={
|
private _mCompressListener: OnCompressListener={
|
||||||
start:()=> {},
|
start:()=> {},
|
||||||
|
|
|
@ -29,7 +29,7 @@ export class Engine {
|
||||||
private mPredicate: CompressionPredicate
|
private mPredicate: CompressionPredicate
|
||||||
private mCompressAdapter: CompressAdapter
|
private mCompressAdapter: CompressAdapter
|
||||||
private mPath: string
|
private mPath: string
|
||||||
private _mLeastCompressSize: number; //KB
|
private _mLeastCompressSize: number; // KB
|
||||||
|
|
||||||
constructor(compressAdapter: CompressAdapter,
|
constructor(compressAdapter: CompressAdapter,
|
||||||
outPath: string,
|
outPath: string,
|
||||||
|
|
|
@ -15,5 +15,6 @@
|
||||||
import { BusinessError } from '@ohos.base'
|
import { BusinessError } from '@ohos.base'
|
||||||
export interface IParseImage<T> {
|
export interface IParseImage<T> {
|
||||||
parseImage:(imageinfo:ArrayBuffer, onCompleteFunction:(value:T)=>void | PromiseLike<T>, onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
|
parseImage:(imageinfo:ArrayBuffer, onCompleteFunction:(value:T)=>void | PromiseLike<T>, onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
|
||||||
parseImageThumbnail:(scale:number, imageinfo:ArrayBuffer, onCompleteFunction:(value:T)=>void | PromiseLike<T>, onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
|
parseImageThumbnail:(scale:number, imageinfo:ArrayBuffer, onCompleteFunction:(value:T)=>void | PromiseLike<T>,
|
||||||
|
onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
|
||||||
}
|
}
|
|
@ -44,7 +44,6 @@ export class DownloadClient implements IDataFetch {
|
||||||
this.dataShareFileClient.loadData(request, onCompleteFunction, onErrorFunction)
|
this.dataShareFileClient.loadData(request, onCompleteFunction, onErrorFunction)
|
||||||
} else {
|
} else {
|
||||||
// 网络下载
|
// 网络下载
|
||||||
// this.networkDownloadClient.loadData(request, onCompleteFunction, onErrorFunction)
|
|
||||||
this.httpDownloadClient.loadData(request, onCompleteFunction, onErrorFunction)
|
this.httpDownloadClient.loadData(request, onCompleteFunction, onErrorFunction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ export class HttpDownloadClient implements IDataFetch {
|
||||||
method: http.RequestMethod.GET,
|
method: http.RequestMethod.GET,
|
||||||
expectDataType: http.HttpDataType.ARRAY_BUFFER,
|
expectDataType: http.HttpDataType.ARRAY_BUFFER,
|
||||||
connectTimeout: 60000, // 可选 默认60000ms
|
connectTimeout: 60000, // 可选 默认60000ms
|
||||||
readTimeout: 0, //可选, 默认为60000ms
|
readTimeout: 0, // 可选, 默认为60000ms
|
||||||
usingProtocol: http.HttpProtocol.HTTP1_1, // 可选,协议类型默认值由系统自动指定
|
usingProtocol: http.HttpProtocol.HTTP1_1, // 可选,协议类型默认值由系统自动指定
|
||||||
},
|
},
|
||||||
(err: BusinessError, data: number) => {
|
(err: BusinessError, data: number) => {
|
||||||
|
|
|
@ -170,7 +170,7 @@ export class RequestManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//究竟从哪里加载数据
|
// 究竟从哪里加载数据
|
||||||
private searchLoadFrom(request: RequestOption, current: Stage, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
private searchLoadFrom(request: RequestOption, current: Stage, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
||||||
LogUtil.log("RequestManager searchLoadFrom")
|
LogUtil.log("RequestManager searchLoadFrom")
|
||||||
if (current == Stage.RESOURCE_CACHE) {
|
if (current == Stage.RESOURCE_CACHE) {
|
||||||
|
|
|
@ -18,5 +18,6 @@ import common from '@ohos.app.ability.common';
|
||||||
|
|
||||||
// 本地资源解析抽象接口
|
// 本地资源解析抽象接口
|
||||||
export interface IResourceFetch<T> {
|
export interface IResourceFetch<T> {
|
||||||
loadResource:(context:common.UIAbilityContext ,res: Resource, onCompleteFunction:(value:T)=>void | PromiseLike<T>, onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
|
loadResource:(context:common.UIAbilityContext ,res: Resource, onCompleteFunction:(value:T)=>void | PromiseLike<T>,
|
||||||
|
onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@ import {AsyncTransform} from "../transform/AsyncTransform"
|
||||||
import {RequestOption} from "../../imageknife/RequestOption"
|
import {RequestOption} from "../../imageknife/RequestOption"
|
||||||
|
|
||||||
export interface BaseTransform<T> {
|
export interface BaseTransform<T> {
|
||||||
//实现类 返回作为key生成的一部分
|
// 实现类 返回作为key生成的一部分
|
||||||
getName(): string;
|
getName(): string;
|
||||||
|
|
||||||
transform(value: ArrayBuffer, request: RequestOption, func: AsyncTransform<T>);
|
transform(value: ArrayBuffer, request: RequestOption, func: AsyncTransform<T>);
|
||||||
|
|
|
@ -107,7 +107,7 @@ export class ContrastFilterTransformation implements BaseTransform<PixelMap> {
|
||||||
|
|
||||||
let dataArray = new Uint8Array(bufferData);
|
let dataArray = new Uint8Array(bufferData);
|
||||||
|
|
||||||
let brightness = 0; //亮度的偏移量,可以默认0
|
let brightness = 0; // 亮度的偏移量,可以默认0
|
||||||
for (let index = 0; index < dataArray.length; index += 4) {
|
for (let index = 0; index < dataArray.length; index += 4) {
|
||||||
dataArray[index] = this.checkVisAble((dataArray[index] - 127) * this._mContrast + brightness + 127);
|
dataArray[index] = this.checkVisAble((dataArray[index] - 127) * this._mContrast + brightness + 127);
|
||||||
dataArray[index+1] = this.checkVisAble((dataArray[index+1] - 127) * this._mContrast + brightness + 127);
|
dataArray[index+1] = this.checkVisAble((dataArray[index+1] - 127) * this._mContrast + brightness + 127);
|
||||||
|
|
|
@ -118,7 +118,7 @@ export class CropCircleTransformation implements BaseTransform<PixelMap> {
|
||||||
if (this.isContainsCircle(w, h)) {
|
if (this.isContainsCircle(w, h)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//针对的点
|
// 针对的点
|
||||||
let index = (h * width + w) * 4;
|
let index = (h * width + w) * 4;
|
||||||
dataArray[index] = 0;
|
dataArray[index] = 0;
|
||||||
dataArray[index+1] = 0;
|
dataArray[index+1] = 0;
|
||||||
|
|
|
@ -122,9 +122,9 @@ export class CropCircleWithBorderTransformation implements BaseTransform<PixelMa
|
||||||
|
|
||||||
for (let h = 0;h <= height; h++) {
|
for (let h = 0;h <= height; h++) {
|
||||||
for (let w = 0;w <= width; w++) {
|
for (let w = 0;w <= width; w++) {
|
||||||
//不在大圆之内的设置透明
|
// 不在大圆之内的设置透明
|
||||||
//在大圆与小圆之间的 设置rgb值
|
// 在大圆与小圆之间的 设置rgb值
|
||||||
//小圆之内的不变
|
// 小圆之内的不变
|
||||||
let isSmallCircle: boolean = this.isContainsSmallCircle(w, h);
|
let isSmallCircle: boolean = this.isContainsSmallCircle(w, h);
|
||||||
let isBigCircle: boolean = this.isContainsCircle(w, h);
|
let isBigCircle: boolean = this.isContainsCircle(w, h);
|
||||||
if (isSmallCircle) {
|
if (isSmallCircle) {
|
||||||
|
@ -133,13 +133,13 @@ export class CropCircleWithBorderTransformation implements BaseTransform<PixelMa
|
||||||
|
|
||||||
let index = (h * width + w) * 4;
|
let index = (h * width + w) * 4;
|
||||||
if (!isBigCircle) {
|
if (!isBigCircle) {
|
||||||
//设置透明
|
// 设置透明
|
||||||
dataArray[index] = 0;
|
dataArray[index] = 0;
|
||||||
dataArray[index+1] = 0;
|
dataArray[index+1] = 0;
|
||||||
dataArray[index+2] = 0;
|
dataArray[index+2] = 0;
|
||||||
dataArray[index+3] = 0;
|
dataArray[index+3] = 0;
|
||||||
} else {
|
} else {
|
||||||
//设置broke
|
// 设置broke
|
||||||
dataArray[index] = this.mRColor;
|
dataArray[index] = this.mRColor;
|
||||||
dataArray[index+1] = this.mGColor;
|
dataArray[index+1] = this.mGColor;
|
||||||
dataArray[index+2] = this.mBColor;
|
dataArray[index+2] = this.mBColor;
|
||||||
|
|
|
@ -93,7 +93,7 @@ export class GrayscaleTransformation implements BaseTransform<PixelMap> {
|
||||||
const g = dataArray[index+1];
|
const g = dataArray[index+1];
|
||||||
const b = dataArray[index+2];
|
const b = dataArray[index+2];
|
||||||
const f = dataArray[index+3];
|
const f = dataArray[index+3];
|
||||||
//b g r
|
// b g r
|
||||||
dataNewArray[index] = this.grayscale(r, g, b);
|
dataNewArray[index] = this.grayscale(r, g, b);
|
||||||
dataNewArray[index+1] = this.grayscale(r, g, b);
|
dataNewArray[index+1] = this.grayscale(r, g, b);
|
||||||
dataNewArray[index+2] = this.grayscale(r, g, b);
|
dataNewArray[index+2] = this.grayscale(r, g, b);
|
||||||
|
|
|
@ -14,13 +14,6 @@
|
||||||
*/
|
*/
|
||||||
import { LogUtil } from '../../imageknife/utils/LogUtil'
|
import { LogUtil } from '../../imageknife/utils/LogUtil'
|
||||||
|
|
||||||
// jpg = 'jpg,0,FFD8',
|
|
||||||
// png = 'png,0,89504E470D0A1A0A',
|
|
||||||
// bmp = 'bmp,0,424D',
|
|
||||||
// gif = 'gif,0,474946383961',
|
|
||||||
// svg = 'svg,0,3C3F786D6C',
|
|
||||||
// webp = 'webp,0,52494646',
|
|
||||||
// tiff = 'tiff,0,492049|49492A00|4D4D002A|4D4D002B'
|
|
||||||
|
|
||||||
export class FileTypeUtil {
|
export class FileTypeUtil {
|
||||||
private fileSignatureMap: Record<string, Array<Uint8Array>> = {
|
private fileSignatureMap: Record<string, Array<Uint8Array>> = {
|
||||||
|
|
|
@ -25,7 +25,8 @@ export class ParseImageUtil implements IParseImage<PixelMap> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// scale(0,1)
|
// scale(0,1)
|
||||||
parseImageThumbnail(scale: number, imageinfo: ArrayBuffer, onCompleteFunction: (value: PixelMap) => void | PromiseLike<PixelMap>, onErrorFunction: (reason?: BusinessError | string) => void) {
|
parseImageThumbnail(scale: number, imageinfo: ArrayBuffer, onCompleteFunction: (value: PixelMap) => void | PromiseLike<PixelMap>,
|
||||||
|
onErrorFunction: (reason?: BusinessError | string) => void) {
|
||||||
// taskPoolExecutePixelMap(imageinfo,scale,onCompleteFunction,onErrorFunction);
|
// taskPoolExecutePixelMap(imageinfo,scale,onCompleteFunction,onErrorFunction);
|
||||||
|
|
||||||
let imageSource:image.ImageSource = image.createImageSource(imageinfo); // 步骤一:文件转为pixelMap 然后变换 给Image组件
|
let imageSource:image.ImageSource = image.createImageSource(imageinfo); // 步骤一:文件转为pixelMap 然后变换 给Image组件
|
||||||
|
|
|
@ -74,9 +74,9 @@ export namespace pixelUtils {
|
||||||
let realPixel_W = pixel > targetWidth ? targetWidth : pixel;
|
let realPixel_W = pixel > targetWidth ? targetWidth : pixel;
|
||||||
let realPixel_H = pixel > targetHeight ? targetHeight : pixel;
|
let realPixel_H = pixel > targetHeight ? targetHeight : pixel;
|
||||||
|
|
||||||
//横排的正方形个数
|
// 横排的正方形个数
|
||||||
let x_index = Math.floor(targetWidth / realPixel_W);
|
let x_index = Math.floor(targetWidth / realPixel_W);
|
||||||
//纵排的正方形个数
|
// 纵排的正方形个数
|
||||||
let y_index = Math.floor(targetHeight / realPixel_H);
|
let y_index = Math.floor(targetHeight / realPixel_H);
|
||||||
|
|
||||||
for (let ch = 0; ch < y_index; ch++) {
|
for (let ch = 0; ch < y_index; ch++) {
|
||||||
|
@ -89,9 +89,9 @@ export namespace pixelUtils {
|
||||||
let min_x = cw * realPixel_W;
|
let min_x = cw * realPixel_W;
|
||||||
let min_y = ch * realPixel_H;
|
let min_y = ch * realPixel_H;
|
||||||
|
|
||||||
//取左上角的像素值
|
// 取左上角的像素值
|
||||||
let center_p = inPixels[min_y+1][min_x+1];
|
let center_p = inPixels[min_y+1][min_x+1];
|
||||||
//设置该正方形里的像素统一
|
// 设置该正方形里的像素统一
|
||||||
for (let zh = min_y; zh < max_y; zh++) {
|
for (let zh = min_y; zh < max_y; zh++) {
|
||||||
for (let zw = min_x; zw < max_x; zw++) {
|
for (let zw = min_x; zw < max_x; zw++) {
|
||||||
inPixels[zh][zw] = center_p;
|
inPixels[zh][zw] = center_p;
|
||||||
|
|
|
@ -45,7 +45,7 @@ export class GIFParseImpl implements IParseGif {
|
||||||
}
|
}
|
||||||
let data:GIFFrame[] = [];
|
let data:GIFFrame[] = [];
|
||||||
imageSource.createPixelMapList(decodeOpts).then((pixelList: Array<PixelMap>) => {
|
imageSource.createPixelMapList(decodeOpts).then((pixelList: Array<PixelMap>) => {
|
||||||
//sdk的api接口发生变更:从.getDelayTime() 变为.getDelayTimeList()
|
// sdk的api接口发生变更:从.getDelayTime() 变为.getDelayTimeList()
|
||||||
imageSource.getDelayTimeList().then(delayTimes => {
|
imageSource.getDelayTimeList().then(delayTimes => {
|
||||||
if (pixelList.length > 0) {
|
if (pixelList.length > 0) {
|
||||||
let pixelmap = pixelList[0];
|
let pixelmap = pixelList[0];
|
||||||
|
@ -112,7 +112,7 @@ function taskPoolExecutePixelMapList(arrayBuffer: ArrayBuffer, callback: (data?:
|
||||||
LogUtil.log("ceshi321 : arrayBuffer长度" + arrayBuffer.byteLength)
|
LogUtil.log("ceshi321 : arrayBuffer长度" + arrayBuffer.byteLength)
|
||||||
let task = new taskpool.Task(taskParseGif, arrayBuffer)
|
let task = new taskpool.Task(taskParseGif, arrayBuffer)
|
||||||
taskpool.execute(task).then((imageFrames: GIFFrame[]) => {
|
taskpool.execute(task).then((imageFrames: GIFFrame[]) => {
|
||||||
// LogUtil.log('ceshi321 : Succeeded in creating pixelmap Ui .' + imageFrames.getPixelBytesNumber())
|
|
||||||
callback(imageFrames,undefined)
|
callback(imageFrames,undefined)
|
||||||
}).catch((err: string) => {
|
}).catch((err: string) => {
|
||||||
LogUtil.log("ceshi321 : test occur error: " + err)
|
LogUtil.log("ceshi321 : test occur error: " + err)
|
||||||
|
|
Loading…
Reference in New Issue