1.transform code optimization 2
Signed-off-by: zhoulisheng <635547767@qq.com>
This commit is contained in:
parent
d60369beba
commit
e0bd0052e5
|
@ -18,7 +18,6 @@ import {AsyncTransform} from "../transform/AsyncTransform.ets"
|
||||||
import {Constants} from "../constants/Constants.ets"
|
import {Constants} from "../constants/Constants.ets"
|
||||||
import {RequestOption} from "../../glide/RequestOption.ets"
|
import {RequestOption} from "../../glide/RequestOption.ets"
|
||||||
import {TransformUtils} from "../transform/TransformUtils.ets"
|
import {TransformUtils} from "../transform/TransformUtils.ets"
|
||||||
|
|
||||||
import image from "@ohos.multimedia.image"
|
import image from "@ohos.multimedia.image"
|
||||||
|
|
||||||
export class CropTransformation implements BaseTransform<PixelMap> {
|
export class CropTransformation implements BaseTransform<PixelMap> {
|
||||||
|
@ -68,23 +67,27 @@ export class CropTransformation implements BaseTransform<PixelMap> {
|
||||||
|
|
||||||
var scaledWidth = scale * pixelMapWidth;
|
var scaledWidth = scale * pixelMapWidth;
|
||||||
var scaledHeight = scale * pixelMapHeight;
|
var scaledHeight = scale * pixelMapHeight;
|
||||||
var xx = (this.mWidth - scaledWidth) / 2;
|
var left = (this.mWidth - scaledWidth) / 2;
|
||||||
var yy = Math.abs(this.getTop(pixelMapHeight));
|
var top = Math.abs(this.getTop(pixelMapHeight));
|
||||||
var options = {
|
var options = {
|
||||||
editable: true,
|
editable: true,
|
||||||
desiredRegion: { size: { width: this.mWidth, height: this.mHeight },
|
desiredRegion: {
|
||||||
x: xx,
|
size: {
|
||||||
y: yy,
|
width: scaledWidth > pixelMapWidth ? pixelMapWidth : scaledWidth,
|
||||||
|
height: scaledHeight > pixelMapHeight ? pixelMapHeight : scaledHeight
|
||||||
|
},
|
||||||
|
x: left < 0 ? 0 : left,
|
||||||
|
y: top < 0 ? 0 : top,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
imageSource.createPixelMap(options)
|
imageSource.createPixelMap(options)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
func("", data);
|
func("", data);
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.log(Constants.PROJECT_TAG + ";error:" + e);
|
console.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||||
func(e, null);
|
func(e, null);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ export namespace CalculatePixelUtils {
|
||||||
await p.readPixelsToBuffer(bufferData);
|
await p.readPixelsToBuffer(bufferData);
|
||||||
let dataArray = new Uint8Array(bufferData);
|
let dataArray = new Uint8Array(bufferData);
|
||||||
|
|
||||||
for (let index = 0; index < dataArray.length; index++) {
|
for (let index = 0; index < dataArray.length; index += 4) {
|
||||||
const r = dataArray[index];
|
const r = dataArray[index];
|
||||||
const g = dataArray[index+1];
|
const g = dataArray[index+1];
|
||||||
const b = dataArray[index+2];
|
const b = dataArray[index+2];
|
||||||
|
|
|
@ -77,7 +77,7 @@ export namespace fastBlur {
|
||||||
await bitmap.readPixelsToBuffer(bufferData);
|
await bitmap.readPixelsToBuffer(bufferData);
|
||||||
let dataArray = new Uint8Array(bufferData);
|
let dataArray = new Uint8Array(bufferData);
|
||||||
|
|
||||||
for (let index = 0; index < dataArray.length; index++) {
|
for (let index = 0; index < dataArray.length; index+=4) {
|
||||||
const r = dataArray[index];
|
const r = dataArray[index];
|
||||||
const g = dataArray[index+1];
|
const g = dataArray[index+1];
|
||||||
const b = dataArray[index+2];
|
const b = dataArray[index+2];
|
||||||
|
|
|
@ -68,10 +68,10 @@ export class MaskUtils {
|
||||||
let pw_m = 0;
|
let pw_m = 0;
|
||||||
|
|
||||||
for (let index = 0; index < dataArray_m.length; index += 4) {
|
for (let index = 0; index < dataArray_m.length; index += 4) {
|
||||||
const r = bufferData_m[index];
|
const r = dataArray_m[index];
|
||||||
const g = bufferData_m[index+1];
|
const g = dataArray_m[index+1];
|
||||||
const b = bufferData_m[index+2];
|
const b = dataArray_m[index+2];
|
||||||
const f = bufferData_m[index+3];
|
const f = dataArray_m[index+3];
|
||||||
|
|
||||||
let entry = new PixelEntry();
|
let entry = new PixelEntry();
|
||||||
entry.a = 0;
|
entry.a = 0;
|
||||||
|
@ -81,7 +81,7 @@ export class MaskUtils {
|
||||||
entry.f = f;
|
entry.f = f;
|
||||||
entry.pixel = ColorUtils.rgb(entry.r, entry.g, entry.b);
|
entry.pixel = ColorUtils.rgb(entry.r, entry.g, entry.b);
|
||||||
pixEntry.push(entry);
|
pixEntry.push(entry);
|
||||||
if (entry.r == 0 && entry.g == 0 && entry.r == b) {
|
if (entry.r == 0 && entry.g == 0 && entry.b == 0) {
|
||||||
rgbDataMask[ph_m][pw_m] = rgbData[ph_m][pw_m];
|
rgbDataMask[ph_m][pw_m] = rgbData[ph_m][pw_m];
|
||||||
} else {
|
} else {
|
||||||
rgbDataMask[ph_m][pw_m] = ColorUtils.rgb(entry.r, entry.g, entry.b);
|
rgbDataMask[ph_m][pw_m] = ColorUtils.rgb(entry.r, entry.g, entry.b);
|
||||||
|
|
|
@ -45,7 +45,7 @@ export namespace pixelUtils {
|
||||||
let pw = 0;
|
let pw = 0;
|
||||||
|
|
||||||
|
|
||||||
for (let index = 0; index < dataArray.length; index++) {
|
for (let index = 0; index < dataArray.length; index += 4) {
|
||||||
const r = dataArray[index];
|
const r = dataArray[index];
|
||||||
const g = dataArray[index+1];
|
const g = dataArray[index+1];
|
||||||
const b = dataArray[index+2];
|
const b = dataArray[index+2];
|
||||||
|
|
Loading…
Reference in New Issue