1.ArkTs整改4 更改ImageKnife->compress文件夹
Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
parent
803f4934ae
commit
e7d70fea9d
|
@ -25,13 +25,19 @@ import { ImageKnife } from '../ImageKnife'
|
||||||
import { ImageKnifeGlobal } from '../ImageKnifeGlobal';
|
import { ImageKnifeGlobal } from '../ImageKnifeGlobal';
|
||||||
|
|
||||||
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;
|
private _mRenameListener: OnRenameListener = {reName:()=>{return ''}};
|
||||||
private _mCompressListener: OnCompressListener;
|
private _mCompressListener: OnCompressListener={
|
||||||
private _mCompressionPredicate: CompressionPredicate
|
start:()=> {},
|
||||||
private _mStreamProviders: Array<CompressAdapter>;
|
onScuccess:(p: PixelMap|null|undefined, path: string)=> {},
|
||||||
private _mFocusAlpha: boolean;
|
onError:(s: string)=> {}
|
||||||
|
};
|
||||||
|
private _mCompressionPredicate: CompressionPredicate ={
|
||||||
|
apply:(path: string)=> { return false }
|
||||||
|
}
|
||||||
|
private _mStreamProviders: Array<CompressAdapter> = new Array<CompressAdapter>();
|
||||||
|
private _mFocusAlpha: boolean = false;
|
||||||
private _outFilePath: string;
|
private _outFilePath: string;
|
||||||
constructor() {
|
constructor() {
|
||||||
this._mStreamProviders = new Array();
|
this._mStreamProviders = new Array();
|
||||||
|
@ -109,7 +115,7 @@ export class CompressBuilder {
|
||||||
if (!this._mTargetDir) {
|
if (!this._mTargetDir) {
|
||||||
let context:Record<string,Object> = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>);
|
let context:Record<string,Object> = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>);
|
||||||
let path = context.filesDir;
|
let path = context.filesDir;
|
||||||
var timestamp = (new Date()).valueOf();
|
let timestamp = (new Date()).valueOf();
|
||||||
this._outFilePath = path + "/compress/" + timestamp + (Math.random() * 100).toFixed(0) + ".jpg";
|
this._outFilePath = path + "/compress/" + timestamp + (Math.random() * 100).toFixed(0) + ".jpg";
|
||||||
let result = await this.startAsyncCompress();
|
let result = await this.startAsyncCompress();
|
||||||
return result;
|
return result;
|
||||||
|
@ -120,15 +126,15 @@ export class CompressBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async startAsyncCompress():Promise<string> {
|
private async startAsyncCompress():Promise<string> {
|
||||||
let compressPromise = new Promise((resolve, reject) => {
|
let compressPromise:Promise<string> = new Promise((resolve, reject) => {
|
||||||
|
|
||||||
let compressListener: OnCompressListener = {
|
let compressListener: OnCompressListener = {
|
||||||
start() {
|
start:()=>{
|
||||||
},
|
},
|
||||||
onScuccess(p: PixelMap, path: string) {
|
onScuccess:(p: PixelMap|undefined|null, path: string)=> {
|
||||||
resolve(path);
|
resolve(path);
|
||||||
},
|
},
|
||||||
onError(s: string) {
|
onError:(s: string)=> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +145,7 @@ export class CompressBuilder {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < this._mStreamProviders.length; i++) {
|
for (let i = 0; i < this._mStreamProviders.length; i++) {
|
||||||
let element = this._mStreamProviders[i];
|
let element = this._mStreamProviders[i];
|
||||||
let isOpenfilter = false;
|
let isOpenfilter = false;
|
||||||
if (this._mCompressionPredicate) {
|
if (this._mCompressionPredicate) {
|
||||||
|
@ -172,11 +178,11 @@ export class CompressBuilder {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this._mRenameListener) {
|
if (this._mRenameListener) {
|
||||||
var name = this._mRenameListener.reName();
|
let name = this._mRenameListener.reName();
|
||||||
if (this._outFilePath && name) {
|
if (this._outFilePath && name) {
|
||||||
var start = this._outFilePath.lastIndexOf("/") + 1
|
let start = this._outFilePath.lastIndexOf("/") + 1
|
||||||
var end = this._outFilePath.length;
|
let end = this._outFilePath.length;
|
||||||
var replaceStr = this._outFilePath.substring(start, end);
|
let replaceStr = this._outFilePath.substring(start, end);
|
||||||
this._outFilePath = this._outFilePath.replace(replaceStr, name);
|
this._outFilePath = this._outFilePath.replace(replaceStr, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,7 +190,7 @@ export class CompressBuilder {
|
||||||
this._mCompressListener.start();
|
this._mCompressListener.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < this._mStreamProviders.length; i++) {
|
for (let i = 0; i < this._mStreamProviders.length; i++) {
|
||||||
let element = this._mStreamProviders[i];
|
let element = this._mStreamProviders[i];
|
||||||
let isOpenfilter = false;
|
let isOpenfilter = false;
|
||||||
if (this._mCompressionPredicate) {
|
if (this._mCompressionPredicate) {
|
||||||
|
@ -203,7 +209,7 @@ export class CompressBuilder {
|
||||||
|
|
||||||
private getImageCacheFile() {
|
private getImageCacheFile() {
|
||||||
let context:Record<string,Object> = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>)
|
let context:Record<string,Object> = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>)
|
||||||
var timestamp = (new Date()).valueOf();
|
let timestamp = (new Date()).valueOf();
|
||||||
this._outFilePath = context.filesDir + "/compress/" + timestamp + (Math.random() * 100).toFixed(0) + ".jpg";
|
this._outFilePath = context.filesDir + "/compress/" + timestamp + (Math.random() * 100).toFixed(0) + ".jpg";
|
||||||
this.startCompress();
|
this.startCompress();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ import {DataStringPathProvider} from '../compress/provider/DataStringPathProvide
|
||||||
import { RecourseProvider } from '../compress/provider/RecourseProvider'
|
import { RecourseProvider } from '../compress/provider/RecourseProvider'
|
||||||
import { FileUtils } from '../../cache/FileUtils'
|
import { FileUtils } from '../../cache/FileUtils'
|
||||||
import image from "@ohos.multimedia.image"
|
import image from "@ohos.multimedia.image"
|
||||||
import fileio from '@ohos.fileio';
|
import fs from '@ohos.file.fs';
|
||||||
|
import { BusinessError } from '@ohos.base'
|
||||||
|
|
||||||
export class Engine {
|
export class Engine {
|
||||||
private mFocusAlpha: boolean;
|
private mFocusAlpha: boolean;
|
||||||
|
@ -48,10 +49,10 @@ export class Engine {
|
||||||
srcWidth = srcWidth % 2 == 1 ? srcWidth + 1 : srcWidth;
|
srcWidth = srcWidth % 2 == 1 ? srcWidth + 1 : srcWidth;
|
||||||
srcHeight = srcHeight % 2 == 1 ? srcHeight + 1 : srcHeight;
|
srcHeight = srcHeight % 2 == 1 ? srcHeight + 1 : srcHeight;
|
||||||
|
|
||||||
var longSide = Math.max(srcWidth, srcHeight);
|
let longSide = Math.max(srcWidth, srcHeight);
|
||||||
var shortSide = Math.min(srcWidth, srcHeight);
|
let shortSide = Math.min(srcWidth, srcHeight);
|
||||||
|
|
||||||
var scale = shortSide / longSide;
|
let scale = shortSide / longSide;
|
||||||
if (scale <= 1 && scale > 0.5625) {
|
if (scale <= 1 && scale > 0.5625) {
|
||||||
if (longSide < 1664) {
|
if (longSide < 1664) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -72,7 +73,7 @@ export class Engine {
|
||||||
compress() {
|
compress() {
|
||||||
if (this.mCompressAdapter instanceof DataStringPathProvider) {
|
if (this.mCompressAdapter instanceof DataStringPathProvider) {
|
||||||
// file
|
// file
|
||||||
this.mCompressAdapter.openInternal((buffer) => {
|
this.mCompressAdapter.openInternal({ compressDataListener: (buffer: ArrayBuffer) => {
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
if (this.mCompressListener) {
|
if (this.mCompressListener) {
|
||||||
this.mCompressListener.onError("file read fail,and date is empty")
|
this.mCompressListener.onError("file read fail,and date is empty")
|
||||||
|
@ -83,14 +84,14 @@ export class Engine {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var imageResource = image.createImageSource(buffer as any);
|
let imageResource: image.ImageSource = image.createImageSource(buffer as any);
|
||||||
imageResource.getImageInfo()
|
imageResource.getImageInfo()
|
||||||
.then(info => {
|
.then(info => {
|
||||||
var height = info.size.height;
|
let height = info.size.height;
|
||||||
var width = info.size.width;
|
let width = info.size.width;
|
||||||
var computeSize = this.computeSize(width, height);
|
let computeSize = this.computeSize(width, height);
|
||||||
console.info("Engine compress computeSize:" + computeSize);
|
console.info("Engine compress computeSize:" + computeSize);
|
||||||
let options = {
|
let options: image.DecodingOptions = {
|
||||||
editable: true,
|
editable: true,
|
||||||
sampleSize: computeSize,
|
sampleSize: computeSize,
|
||||||
desiredPixelFormat: image.PixelMapFormat.RGB_565,
|
desiredPixelFormat: image.PixelMapFormat.RGB_565,
|
||||||
|
@ -99,20 +100,20 @@ export class Engine {
|
||||||
.then(bitmap => {
|
.then(bitmap => {
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error: BusinessError) => {
|
||||||
this.mCompressListener.onError("ptah createPixelMap fail,because error:" + JSON.stringify(error))
|
this.mCompressListener.onError("ptah createPixelMap fail,because error:" + JSON.stringify(error as BusinessError))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error: BusinessError) => {
|
||||||
this.mCompressListener.onError("ptah getImageInfo fail,because error:" + JSON.stringify(error))
|
this.mCompressListener.onError("ptah getImageInfo fail,because error:" + JSON.stringify(error as BusinessError))
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
} })
|
||||||
} else if (this.mCompressAdapter instanceof RecourseProvider) {
|
} else if (this.mCompressAdapter instanceof RecourseProvider) {
|
||||||
// resource
|
// resource
|
||||||
this.mCompressAdapter.openInternal((buffer) => {
|
this.mCompressAdapter.openInternal({ compressDataListener: (buffer: ArrayBuffer) => {
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
if (this.mCompressListener) {
|
if (this.mCompressListener) {
|
||||||
this.mCompressListener.onError("resource read fail,and date is empty")
|
this.mCompressListener.onError("resource read fail,and date is empty")
|
||||||
|
@ -122,18 +123,18 @@ export class Engine {
|
||||||
if (!this.checkNeedCompress(buffer)) {
|
if (!this.checkNeedCompress(buffer)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var imageResource = image.createImageSource(buffer as any);
|
let imageResource: image.ImageSource = image.createImageSource(buffer);
|
||||||
imageResource.getImageInfo()
|
imageResource.getImageInfo()
|
||||||
.then(info => {
|
.then(info => {
|
||||||
var height = info.size.height;
|
let height = info.size.height;
|
||||||
var width = info.size.width;
|
let width = info.size.width;
|
||||||
var computeSize = this.computeSize(width, height);
|
let computeSize = this.computeSize(width, height);
|
||||||
let packer = {
|
let packer: image.PackingOption = {
|
||||||
format: ["image/jpeg"],
|
format: "image/jpeg",
|
||||||
quality: computeSize,
|
quality: computeSize,
|
||||||
}
|
}
|
||||||
var imagePacker = image.createImagePacker();
|
let imagePacker: image.ImagePacker = image.createImagePacker();
|
||||||
imagePacker.packing(imageResource, packer as any, (err,compressBuffer)=>{
|
imagePacker.packing(imageResource, packer, (err, compressBuffer) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.mCompressListener.onError("resource packing fail,because error:" + err);
|
this.mCompressListener.onError("resource packing fail,because error:" + err);
|
||||||
}
|
}
|
||||||
|
@ -141,12 +142,12 @@ export class Engine {
|
||||||
console.log("compressBuffer is null =" + (compressBuffer == null));
|
console.log("compressBuffer is null =" + (compressBuffer == null));
|
||||||
console.log("compressBuffer is undefined =" + (compressBuffer == undefined));
|
console.log("compressBuffer is undefined =" + (compressBuffer == undefined));
|
||||||
let dirPath = this.mPath.substring(0, this.mPath.lastIndexOf("/") + 1);
|
let dirPath = this.mPath.substring(0, this.mPath.lastIndexOf("/") + 1);
|
||||||
var isDirectory = this.checkDirExist(dirPath);
|
let isDirectory = this.checkDirExist(dirPath);
|
||||||
if (isDirectory) {
|
if (isDirectory) {
|
||||||
this.saveFile(this.mPath, compressBuffer);
|
this.saveFile(this.mPath, compressBuffer);
|
||||||
this.handResult(compressBuffer, this.mPath);
|
this.handResult(compressBuffer, this.mPath);
|
||||||
} else {
|
} else {
|
||||||
fileio.mkdir(dirPath)
|
fs.mkdir(dirPath)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.saveFile(this.mPath, compressBuffer);
|
this.saveFile(this.mPath, compressBuffer);
|
||||||
this.handResult(compressBuffer, this.mPath);
|
this.handResult(compressBuffer, this.mPath);
|
||||||
|
@ -156,16 +157,15 @@ export class Engine {
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
} })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private handResult(buffer: ArrayBuffer, path: string) {
|
private handResult(buffer: ArrayBuffer, path: string) {
|
||||||
var imageRes = image.createImageSource(buffer as any);
|
let imageRes:image.ImageSource = image.createImageSource(buffer);
|
||||||
let a={
|
let a:image.DecodingOptions = {
|
||||||
editable: true,
|
editable: true,
|
||||||
}
|
}
|
||||||
imageRes.createPixelMap(a)
|
imageRes.createPixelMap(a)
|
||||||
|
@ -174,9 +174,9 @@ export class Engine {
|
||||||
this.mCompressListener.onScuccess(bitmap, path);
|
this.mCompressListener.onScuccess(bitmap, path);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error:BusinessError) => {
|
||||||
if (this.mCompressListener) {
|
if (this.mCompressListener) {
|
||||||
this.mCompressListener.onError("buffer generated pixelMap fail,because error:" + JSON.stringify(error))
|
this.mCompressListener.onError("buffer generated pixelMap fail,because error:" + JSON.stringify(error as BusinessError))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ export class Engine {
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var length = buf.byteLength / 1024;
|
let length = buf.byteLength / 1024;
|
||||||
return length > this._mLeastCompressSize;
|
return length > this._mLeastCompressSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,14 +194,7 @@ export class Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkDirExist(dirPath: string): boolean {
|
private checkDirExist(dirPath: string): boolean {
|
||||||
var isExist;
|
let isExist:boolean = fs.accessSync(dirPath);
|
||||||
try {
|
|
||||||
fileio.accessSync(dirPath, 0)
|
|
||||||
isExist = true;
|
|
||||||
} catch (e) {
|
|
||||||
//不符合条件则进入
|
|
||||||
isExist = false;
|
|
||||||
}
|
|
||||||
return isExist;
|
return isExist;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,5 +14,5 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export interface CompressDataListener<T> {
|
export interface CompressDataListener<T> {
|
||||||
(t: T);
|
compressDataListener:(t: T)=>void;
|
||||||
}
|
}
|
|
@ -17,5 +17,5 @@
|
||||||
* filter out unsupported
|
* filter out unsupported
|
||||||
*/
|
*/
|
||||||
export interface CompressionPredicate {
|
export interface CompressionPredicate {
|
||||||
apply(path: string): boolean;
|
apply:(path: string)=>boolean;
|
||||||
}
|
}
|
|
@ -19,13 +19,13 @@ export interface OnCompressListener {
|
||||||
/**
|
/**
|
||||||
* compress start
|
* compress start
|
||||||
*/
|
*/
|
||||||
start();
|
start:()=>void;
|
||||||
/**
|
/**
|
||||||
* compress success
|
* compress success
|
||||||
*/
|
*/
|
||||||
onScuccess(p: PixelMap, path: string);
|
onScuccess:(p: PixelMap|undefined|null, path: string)=>void;
|
||||||
/**
|
/**
|
||||||
* compress fail
|
* compress fail
|
||||||
*/
|
*/
|
||||||
onError(s: string);
|
onError:(s: string)=>void;
|
||||||
}
|
}
|
|
@ -17,5 +17,5 @@
|
||||||
* rename listener
|
* rename listener
|
||||||
*/
|
*/
|
||||||
export interface OnRenameListener {
|
export interface OnRenameListener {
|
||||||
reName():string;
|
reName:()=>string;
|
||||||
}
|
}
|
|
@ -35,7 +35,7 @@ export abstract class CompressAdapter implements CompressProvider {
|
||||||
|
|
||||||
abstract getRecoursePath(): string;
|
abstract getRecoursePath(): string;
|
||||||
|
|
||||||
abstract getPixelMapFormat(): PixelMapFormat;
|
abstract getPixelMapFormat(): PixelMapFormat | undefined;
|
||||||
|
|
||||||
getFormat(s: string): PixelMapFormat | undefined{
|
getFormat(s: string): PixelMapFormat | undefined{
|
||||||
if (!s) {
|
if (!s) {
|
||||||
|
|
|
@ -31,14 +31,14 @@ export class DataStringPathProvider extends CompressAdapter {
|
||||||
if (!this.mPath) {
|
if (!this.mPath) {
|
||||||
throw new Error('DataStringPathProvider error path is empty');
|
throw new Error('DataStringPathProvider error path is empty');
|
||||||
}
|
}
|
||||||
var buffer = FileUtils.getInstance().readFilePic(this.mPath);
|
let buffer = FileUtils.getInstance().readFilePic(this.mPath);
|
||||||
this.mData = buffer;
|
this.mData = buffer;
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(buffer);
|
callback.compressDataListener(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getPixelMapFormat(): PixelMapFormat{
|
getPixelMapFormat(): PixelMapFormat|undefined{
|
||||||
if (!this.mPath) {
|
if (!this.mPath) {
|
||||||
return PixelMapFormat.NONE;
|
return PixelMapFormat.NONE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,19 +18,20 @@ import {CompressDataListener} from "../listener/CompressDataListener"
|
||||||
import { FileTypeUtil } from '../../../imageknife/utils/FileTypeUtil'
|
import { FileTypeUtil } from '../../../imageknife/utils/FileTypeUtil'
|
||||||
import { ImageKnifeGlobal } from '../../ImageKnifeGlobal';
|
import { ImageKnifeGlobal } from '../../ImageKnifeGlobal';
|
||||||
import resourceManager from '@ohos.resourceManager';
|
import resourceManager from '@ohos.resourceManager';
|
||||||
|
import { BusinessError } from '@ohos.base'
|
||||||
|
|
||||||
export class RecourseProvider extends CompressAdapter {
|
export class RecourseProvider extends CompressAdapter {
|
||||||
private static CHARS: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
private static CHARS: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||||
private static DEFAULT_RESOURCE_PATH: string = "Resource"
|
private static DEFAULT_RESOURCE_PATH: string = "Resource"
|
||||||
private _mLookup: Uint8Array = new Uint8Array(256);
|
private _mLookup: Uint8Array = new Uint8Array(256);
|
||||||
private _mResourceData: Resource;
|
private _mResourceData?: Resource = undefined;
|
||||||
private _mPixelMapHeader: string;
|
private _mPixelMapHeader: string = '';
|
||||||
|
|
||||||
constructor(s: Resource) {
|
constructor(s: Resource) {
|
||||||
super()
|
super()
|
||||||
this._mResourceData = s;
|
this._mResourceData = s;
|
||||||
this.mPath = RecourseProvider.DEFAULT_RESOURCE_PATH;
|
this.mPath = RecourseProvider.DEFAULT_RESOURCE_PATH;
|
||||||
for (var index = 0; index < RecourseProvider.CHARS.length; index++) {
|
for (let index = 0; index < RecourseProvider.CHARS.length; index++) {
|
||||||
this._mLookup[RecourseProvider.CHARS.charCodeAt(index)] = index;
|
this._mLookup[RecourseProvider.CHARS.charCodeAt(index)] = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,21 +45,22 @@ export class RecourseProvider extends CompressAdapter {
|
||||||
if (!this._mResourceData) {
|
if (!this._mResourceData) {
|
||||||
throw Error("compress resource is empty");
|
throw Error("compress resource is empty");
|
||||||
}
|
}
|
||||||
((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
|
((ImageKnifeGlobal.getInstance()
|
||||||
|
.getHapContext() as Record<string, Object>).resourceManager as resourceManager.ResourceManager)
|
||||||
.getMediaContent(this._mResourceData.id)
|
.getMediaContent(this._mResourceData.id)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
let buffer = this.uint8ArrayToBuffer(data);
|
let buffer = this.uint8ArrayToBuffer(data);
|
||||||
let fileTypeUtil = new FileTypeUtil()
|
let fileTypeUtil = new FileTypeUtil()
|
||||||
this._mPixelMapHeader = fileTypeUtil.getFileType(buffer);
|
this._mPixelMapHeader = fileTypeUtil.getFileType(buffer);
|
||||||
callback(buffer);
|
callback.compressDataListener(buffer);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err: BusinessError) => {
|
||||||
console.log("RecourseProvider openInternal err" + JSON.stringify(err));
|
console.log("RecourseProvider openInternal err" + JSON.stringify(err as BusinessError));
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getPixelMapFormat(): PixelMapFormat{
|
getPixelMapFormat(): PixelMapFormat|undefined{
|
||||||
if (!this._mPixelMapHeader) {
|
if (!this._mPixelMapHeader) {
|
||||||
return PixelMapFormat.NONE;
|
return PixelMapFormat.NONE;
|
||||||
}
|
}
|
||||||
|
@ -68,14 +70,14 @@ export class RecourseProvider extends CompressAdapter {
|
||||||
* data decode
|
* data decode
|
||||||
*/
|
*/
|
||||||
decode(base64: string, callback: CompressDataListener<ArrayBuffer>) {
|
decode(base64: string, callback: CompressDataListener<ArrayBuffer>) {
|
||||||
let bufferLength = base64.length,
|
let bufferLength: number = base64.length;
|
||||||
len = base64.length,
|
let len: number = base64.length;
|
||||||
i,
|
let i: number = 0;
|
||||||
p = 0,
|
let p: number = 0;
|
||||||
encoded1,
|
let encoded1: number = 0;
|
||||||
encoded2,
|
let encoded2: number = 0;
|
||||||
encoded3,
|
let encoded3: number = 0;
|
||||||
encoded4;
|
let encoded4: number = 0;
|
||||||
|
|
||||||
if (base64[base64.length - 1] === '=') {
|
if (base64[base64.length - 1] === '=') {
|
||||||
bufferLength--;
|
bufferLength--;
|
||||||
|
@ -100,7 +102,7 @@ export class RecourseProvider extends CompressAdapter {
|
||||||
}
|
}
|
||||||
this.mData = arraybuffer;
|
this.mData = arraybuffer;
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(arraybuffer);
|
callback.compressDataListener(arraybuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue