1.transform code optimization 2

Signed-off-by: zhoulisheng <635547767@qq.com>
This commit is contained in:
zhoulisheng 2022-04-07 15:33:55 +08:00
parent d60369beba
commit e0bd0052e5
5 changed files with 22 additions and 19 deletions

View File

@ -18,7 +18,6 @@ import {AsyncTransform} from "../transform/AsyncTransform.ets"
import {Constants} from "../constants/Constants.ets"
import {RequestOption} from "../../glide/RequestOption.ets"
import {TransformUtils} from "../transform/TransformUtils.ets"
import image from "@ohos.multimedia.image"
export class CropTransformation implements BaseTransform<PixelMap> {
@ -68,13 +67,17 @@ export class CropTransformation implements BaseTransform<PixelMap> {
var scaledWidth = scale * pixelMapWidth;
var scaledHeight = scale * pixelMapHeight;
var xx = (this.mWidth - scaledWidth) / 2;
var yy = Math.abs(this.getTop(pixelMapHeight));
var left = (this.mWidth - scaledWidth) / 2;
var top = Math.abs(this.getTop(pixelMapHeight));
var options = {
editable: true,
desiredRegion: { size: { width: this.mWidth, height: this.mHeight },
x: xx,
y: yy,
desiredRegion: {
size: {
width: scaledWidth > pixelMapWidth ? pixelMapWidth : scaledWidth,
height: scaledHeight > pixelMapHeight ? pixelMapHeight : scaledHeight
},
x: left < 0 ? 0 : left,
y: top < 0 ? 0 : top,
},
}
imageSource.createPixelMap(options)

View File

@ -25,7 +25,7 @@ export namespace CalculatePixelUtils {
await p.readPixelsToBuffer(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 g = dataArray[index+1];
const b = dataArray[index+2];

View File

@ -77,7 +77,7 @@ export namespace fastBlur {
await bitmap.readPixelsToBuffer(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 g = dataArray[index+1];
const b = dataArray[index+2];

View File

@ -68,10 +68,10 @@ export class MaskUtils {
let pw_m = 0;
for (let index = 0; index < dataArray_m.length; index += 4) {
const r = bufferData_m[index];
const g = bufferData_m[index+1];
const b = bufferData_m[index+2];
const f = bufferData_m[index+3];
const r = dataArray_m[index];
const g = dataArray_m[index+1];
const b = dataArray_m[index+2];
const f = dataArray_m[index+3];
let entry = new PixelEntry();
entry.a = 0;
@ -81,7 +81,7 @@ export class MaskUtils {
entry.f = f;
entry.pixel = ColorUtils.rgb(entry.r, entry.g, entry.b);
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];
} else {
rgbDataMask[ph_m][pw_m] = ColorUtils.rgb(entry.r, entry.g, entry.b);

View File

@ -45,7 +45,7 @@ export namespace pixelUtils {
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 g = dataArray[index+1];
const b = dataArray[index+2];