1.ArkTs整改12 整改imageknife->transform
Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
parent
3595190083
commit
ca0e3fe968
|
@ -14,5 +14,5 @@
|
|||
*/
|
||||
import { BusinessError } from '@ohos.base'
|
||||
export interface AsyncTransform<T> {
|
||||
asyncTransform:(err:BusinessError|string, data: T)=>void
|
||||
asyncTransform:(err:BusinessError|string, data: T | null)=>void
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@ import { TransformUtils } from "../transform/TransformUtils"
|
|||
import image from "@ohos.multimedia.image"
|
||||
import { fastBlur } from "../utils/FastBlur"
|
||||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
export class BlurTransformation implements BaseTransform<PixelMap> {
|
||||
private _mRadius: number;
|
||||
|
@ -38,23 +39,20 @@ export class BlurTransformation implements BaseTransform<PixelMap> {
|
|||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";BlurTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";BlurTransformation buf is empty", null);
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";BlurTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
TransformUtils.getPixelMapSize(imageSource, {asyncTransform:(error:BusinessError|string, size: Size|null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth = size.width;
|
||||
let pixelMapHeight = size.height;
|
||||
let targetWidth = request.size.width;
|
||||
let targetHeight = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -62,7 +60,7 @@ export class BlurTransformation implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
|
@ -77,10 +75,10 @@ export class BlurTransformation implements BaseTransform<PixelMap> {
|
|||
fastBlur.blur(data, this._mRadius, true, func);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
.catch((e:BusinessError) => {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
func(e, null);
|
||||
func?.asyncTransform(e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
}
|
|
@ -20,6 +20,8 @@ import { RequestOption } from "../../imageknife/RequestOption"
|
|||
import { LogUtil } from '../../imageknife/utils/LogUtil'
|
||||
import image from "@ohos.multimedia.image"
|
||||
import { GPUImageBrightnessFilter } from '@ohos/gpu_transform'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
/**
|
||||
* brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level
|
||||
|
@ -38,27 +40,27 @@ export class BrightnessFilterTransformation implements BaseTransform<PixelMap> {
|
|||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
|
||||
let imageInfo = await imageSource.getImageInfo();
|
||||
let size = {
|
||||
let imageInfo:image.ImageInfo = await imageSource.getImageInfo();
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
|
||||
if (!size) {
|
||||
func(new Error("GrayscaleTransformation The image size does not exist."), null)
|
||||
func?.asyncTransform("GrayscaleTransformation The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -66,7 +68,7 @@ export class BrightnessFilterTransformation implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
|
@ -85,12 +87,12 @@ export class BrightnessFilterTransformation implements BaseTransform<PixelMap> {
|
|||
let buf = await filter.getPixelMapBuf(0, 0, targetWidth, targetHeight);
|
||||
data.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", data);
|
||||
func?.asyncTransform("success", data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var dataArray = new Uint8Array(bufferData);
|
||||
let dataArray = new Uint8Array(bufferData);
|
||||
|
||||
for (let index = 0; index < dataArray.length; index += 4) {
|
||||
dataArray[index] = this.checkVisAble(dataArray[index] * this._mBrightness + dataArray[index]);
|
||||
|
@ -102,7 +104,7 @@ export class BrightnessFilterTransformation implements BaseTransform<PixelMap> {
|
|||
await data.writeBufferToPixels(bufferData);
|
||||
|
||||
if (func) {
|
||||
func("", data);
|
||||
func?.asyncTransform("", data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ import { RequestOption } from "../../imageknife/RequestOption"
|
|||
import { LogUtil } from '../../imageknife/utils/LogUtil'
|
||||
import image from "@ohos.multimedia.image"
|
||||
import { GPUImageContrastFilter } from '@ohos/gpu_transform'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
/**
|
||||
* 以24位色图像为例子,每种色彩都可以用0-255,
|
||||
|
@ -50,27 +52,27 @@ export class ContrastFilterTransformation implements BaseTransform<PixelMap> {
|
|||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";ContrastFilterTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";ContrastFilterTransformation buf is empty", null);
|
||||
if (func!=undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";ContrastFilterTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
|
||||
let imageInfo = await imageSource.getImageInfo();
|
||||
let size = {
|
||||
let imageInfo:image.ImageInfo = await imageSource.getImageInfo();
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
|
||||
if (!size) {
|
||||
func(new Error("ContrastFilterTransformation The image size does not exist."), null)
|
||||
func?.asyncTransform("ContrastFilterTransformation The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -78,7 +80,7 @@ export class ContrastFilterTransformation implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
|
@ -97,13 +99,13 @@ export class ContrastFilterTransformation implements BaseTransform<PixelMap> {
|
|||
filter.setContrast(this._mContrast)
|
||||
let buf = await filter.getPixelMapBuf(0, 0, targetWidth, targetHeight);
|
||||
data.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", data);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("success", data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var dataArray = new Uint8Array(bufferData);
|
||||
let dataArray = new Uint8Array(bufferData);
|
||||
|
||||
let brightness = 0; //亮度的偏移量,可以默认0
|
||||
for (let index = 0; index < dataArray.length; index += 4) {
|
||||
|
@ -114,8 +116,8 @@ export class ContrastFilterTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
|
||||
await data.writeBufferToPixels(bufferData);
|
||||
if (func) {
|
||||
func("", data);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("", data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ import { RequestOption } from "../../imageknife/RequestOption"
|
|||
import { TransformUtils } from "../transform/TransformUtils"
|
||||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||
import image from "@ohos.multimedia.image"
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
export class CropCircleTransformation implements BaseTransform<PixelMap> {
|
||||
private static TAG: string = "CropCircleTransformation";
|
||||
|
@ -36,37 +38,34 @@ export class CropCircleTransformation implements BaseTransform<PixelMap> {
|
|||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + CropCircleTransformation.TAG + " buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + CropCircleTransformation.TAG + " buf is empty", null);
|
||||
if (func!=undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + CropCircleTransformation.TAG + " buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
var that = this;
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
|
||||
TransformUtils.getPixelMapSize(imageSource, {asyncTransform:(error:BusinessError|string, size: Size | null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
if (pixelMapHeight < targetHeight) {
|
||||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
that.updatePixelMapSize(imageSource, targetWidth, targetHeight, func);
|
||||
})
|
||||
this.updatePixelMapSize(imageSource, targetWidth, targetHeight, func);
|
||||
}})
|
||||
}
|
||||
|
||||
private updatePixelMapSize(imageSource: any, outWith: number, outHeight: number, func?: AsyncTransform<PixelMap>) {
|
||||
var options = {
|
||||
private updatePixelMapSize(imageSource: image.ImageSource, outWith: number, outHeight: number, func?: AsyncTransform<PixelMap>) {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: outWith,
|
||||
|
@ -74,30 +73,30 @@ export class CropCircleTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
}
|
||||
imageSource.createPixelMap(options)
|
||||
.then(p => {
|
||||
.then((p:PixelMap) => {
|
||||
this.transformCircle(p, func);
|
||||
})
|
||||
.catch(e => {
|
||||
.catch((e:BusinessError) => {
|
||||
LogUtil.log(Constants.PROJECT_TAG + CropCircleTransformation.TAG + " transform e:" + e);
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + CropCircleTransformation.TAG + "e" + e, null);
|
||||
if (func!=undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + CropCircleTransformation.TAG + "e" + e, null);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private async transformCircle(data: any, func?: AsyncTransform<PixelMap>) {
|
||||
let imageInfo = await data.getImageInfo();
|
||||
let size = {
|
||||
private async transformCircle(data: PixelMap, func?: AsyncTransform<PixelMap>) {
|
||||
let imageInfo:image.ImageInfo = await data.getImageInfo();
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
|
||||
if (!size) {
|
||||
func(new Error("CropCircleTransformation The image size does not exist."), null)
|
||||
func?.asyncTransform("CropCircleTransformation The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
var height = size.height;
|
||||
var width = size.width;
|
||||
let height:number = size.height;
|
||||
let width:number = size.width;
|
||||
this.mRadius = 0;
|
||||
if (width > height) {
|
||||
this.mRadius = height / 2;
|
||||
|
@ -107,13 +106,13 @@ export class CropCircleTransformation implements BaseTransform<PixelMap> {
|
|||
this.mCenterX = width / 2;
|
||||
this.mCenterY = height / 2;
|
||||
|
||||
let bufferData = new ArrayBuffer(data.getPixelBytesNumber());
|
||||
let bufferData:ArrayBuffer = new ArrayBuffer(data.getPixelBytesNumber());
|
||||
await data.readPixelsToBuffer(bufferData);
|
||||
|
||||
var dataArray = new Uint8Array(bufferData);
|
||||
let dataArray = new Uint8Array(bufferData);
|
||||
|
||||
for (var h = 0;h <= height; h++) {
|
||||
for (var w = 0;w <= width; w++) {
|
||||
for (let h = 0;h <= height; h++) {
|
||||
for (let w = 0;w <= width; w++) {
|
||||
if (this.isContainsCircle(w, h)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -126,15 +125,15 @@ export class CropCircleTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
}
|
||||
await data.writeBufferToPixels(bufferData);
|
||||
if (func) {
|
||||
func("", data);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("", data);
|
||||
}
|
||||
}
|
||||
|
||||
isContainsCircle(x: number, y: number): boolean {
|
||||
var a = Math.pow((this.mCenterX - x), 2);
|
||||
var b = Math.pow((this.mCenterY - y), 2);
|
||||
var c = Math.sqrt((a + b));
|
||||
let a = Math.pow((this.mCenterX - x), 2);
|
||||
let b = Math.pow((this.mCenterY - y), 2);
|
||||
let c = Math.sqrt((a + b));
|
||||
return c <= this.mRadius;
|
||||
}
|
||||
}
|
|
@ -20,7 +20,13 @@ import { RequestOption } from "../../imageknife/RequestOption"
|
|||
import { TransformUtils } from "../transform/TransformUtils"
|
||||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||
import image from "@ohos.multimedia.image"
|
||||
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
export interface rgbColor{
|
||||
r_color: number,
|
||||
g_color: number,
|
||||
b_color: number,
|
||||
}
|
||||
export class CropCircleWithBorderTransformation implements BaseTransform<PixelMap> {
|
||||
private static TAG: string = "CropCircleTransformation";
|
||||
private mBorderSize: number = 5;
|
||||
|
@ -31,11 +37,7 @@ export class CropCircleWithBorderTransformation implements BaseTransform<PixelMa
|
|||
private mGColor: number = 0;
|
||||
private mBColor: number= 0;
|
||||
|
||||
constructor(border_size: number, value: {
|
||||
r_color?: number,
|
||||
g_color?: number,
|
||||
b_color?: number,
|
||||
}) {
|
||||
constructor(border_size: number, value: rgbColor) {
|
||||
this.mRColor = value.g_color;
|
||||
this.mGColor = value.g_color;
|
||||
this.mBColor = value.b_color;
|
||||
|
@ -55,37 +57,33 @@ export class CropCircleWithBorderTransformation implements BaseTransform<PixelMa
|
|||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
var that = this;
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
TransformUtils.getPixelMapSize(imageSource, {asyncTransform:(error:BusinessError|string, size:Size|null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth = size.width;
|
||||
let pixelMapHeight = size.height;
|
||||
let targetWidth = request.size.width;
|
||||
let targetHeight = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
if (pixelMapHeight < targetHeight) {
|
||||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
that.updatePixelMapSize(imageSource, targetWidth, targetHeight, func);
|
||||
})
|
||||
this.updatePixelMapSize(imageSource, targetWidth, targetHeight, func);
|
||||
}})
|
||||
}
|
||||
|
||||
private updatePixelMapSize(imageSource: any, outWith: number, outHeight: number, func?: AsyncTransform<PixelMap>) {
|
||||
var options = {
|
||||
private updatePixelMapSize(imageSource: image.ImageSource, outWith: number, outHeight: number, func?: AsyncTransform<PixelMap>) {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: outWith,
|
||||
|
@ -93,18 +91,18 @@ export class CropCircleWithBorderTransformation implements BaseTransform<PixelMa
|
|||
}
|
||||
}
|
||||
imageSource.createPixelMap(options)
|
||||
.then((pixelMap) => {
|
||||
.then((pixelMap:PixelMap) => {
|
||||
this.transformPixelMap(pixelMap, outWith, outHeight, func);
|
||||
})
|
||||
.catch(e => {
|
||||
.catch((e:BusinessError) => {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation e:" + e);
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation e:" + e, null);
|
||||
if (func!=undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation e:" + e, null);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private async transformPixelMap(pixelMap: any, width: number, height: number, func?: AsyncTransform<PixelMap>) {
|
||||
private async transformPixelMap(pixelMap: PixelMap, width: number, height: number, func?: AsyncTransform<PixelMap>) {
|
||||
this.mRadius = 0;
|
||||
if (width > height) {
|
||||
this.mRadius = height / 2;
|
||||
|
@ -118,7 +116,7 @@ export class CropCircleWithBorderTransformation implements BaseTransform<PixelMa
|
|||
let bufferData = new ArrayBuffer(pixelMap.getPixelBytesNumber());
|
||||
await pixelMap.readPixelsToBuffer(bufferData);
|
||||
|
||||
var dataArray = new Uint8Array(bufferData);
|
||||
let dataArray = new Uint8Array(bufferData);
|
||||
|
||||
for (let h = 0;h <= height; h++) {
|
||||
for (let w = 0;w <= width; w++) {
|
||||
|
@ -148,22 +146,22 @@ export class CropCircleWithBorderTransformation implements BaseTransform<PixelMa
|
|||
}
|
||||
|
||||
await pixelMap.writeBufferToPixels(bufferData);
|
||||
if (func) {
|
||||
func("", pixelMap);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("", pixelMap);
|
||||
}
|
||||
}
|
||||
|
||||
isContainsCircle(x: number, y: number): boolean {
|
||||
var a = Math.pow((this.mCenterX - x), 2);
|
||||
var b = Math.pow((this.mCenterY - y), 2);
|
||||
var c = Math.sqrt((a + b));
|
||||
let a:number = Math.pow((this.mCenterX - x), 2);
|
||||
let b:number = Math.pow((this.mCenterY - y), 2);
|
||||
let c:number = Math.sqrt((a + b));
|
||||
return c <= this.mRadius;
|
||||
}
|
||||
|
||||
isContainsSmallCircle(x: number, y: number): boolean {
|
||||
var a = Math.pow((this.mCenterX - x), 2);
|
||||
var b = Math.pow((this.mCenterY - y), 2);
|
||||
var c = Math.sqrt((a + b));
|
||||
let a:number = Math.pow((this.mCenterX - x), 2);
|
||||
let b:number = Math.pow((this.mCenterY - y), 2);
|
||||
let c:number = Math.sqrt((a + b));
|
||||
return c <= (this.mRadius - this.mBorderSize);
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@ import { AsyncTransform } from "../transform/AsyncTransform"
|
|||
import { Constants } from "../constants/Constants"
|
||||
import { RequestOption } from "../../imageknife/RequestOption"
|
||||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
import image from "@ohos.multimedia.image"
|
||||
|
||||
|
@ -31,8 +33,8 @@ export class CropSquareTransformation implements BaseTransform<PixelMap> {
|
|||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";CropSquareTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";CropSquareTransformation buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";CropSquareTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -40,21 +42,21 @@ export class CropSquareTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
|
||||
squareCrop(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
imageSource.getImageInfo()
|
||||
.then((p) => {
|
||||
var pw = p.size.width;
|
||||
var ph = p.size.height;
|
||||
var outWidth = request.size.width;
|
||||
var outHeight = request.size.height;
|
||||
.then((p:image.ImageInfo) => {
|
||||
let pw:number = p.size.width;
|
||||
let ph:number = p.size.height;
|
||||
let outWidth:number = request.size.width;
|
||||
let outHeight:number = request.size.height;
|
||||
if (pw < outWidth) {
|
||||
outWidth = pw;
|
||||
}
|
||||
if (ph < outHeight) {
|
||||
outHeight = ph;
|
||||
}
|
||||
var targetSize = outWidth > outHeight ? outHeight : outWidth;
|
||||
var options = {
|
||||
let targetSize:number = outWidth > outHeight ? outHeight : outWidth;
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
rotate: 0,
|
||||
desiredSize: {
|
||||
|
@ -68,19 +70,19 @@ export class CropSquareTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
imageSource.createPixelMap(options)
|
||||
.then(data => {
|
||||
if (func) {
|
||||
func("", data);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("", data);
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";CropSquareTransformation e:" + e, null);
|
||||
.catch((e:BusinessError) => {
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";CropSquareTransformation e:" + e, null);
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";CropSquareTransformation error:" + error, null);
|
||||
.catch((error:BusinessError) => {
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";CropSquareTransformation error:" + error, null);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -20,14 +20,16 @@ import { RequestOption } from "../../imageknife/RequestOption"
|
|||
import { TransformUtils } from "../transform/TransformUtils"
|
||||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||
import image from "@ohos.multimedia.image"
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
export class CropTransformation implements BaseTransform<PixelMap> {
|
||||
private static TAG: string = "CropCircleTransformation";
|
||||
private mWidth: number;
|
||||
private mHeight: number;
|
||||
private mWidth: number = 0;
|
||||
private mHeight: number = 0;
|
||||
private mCropType: CropType = CropType.CENTER;
|
||||
|
||||
constructor(width: number, height: number, cropType?: CropType) {
|
||||
constructor(width: number, height: number, cropType: CropType) {
|
||||
this.mWidth = width;
|
||||
this.mHeight = height;
|
||||
this.mCropType = cropType;
|
||||
|
@ -42,35 +44,32 @@ export class CropTransformation implements BaseTransform<PixelMap> {
|
|||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";CropTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";CropTransformation buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";CropTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
TransformUtils.getPixelMapSize(imageSource, {asyncTransform:(error:BusinessError|string, size: Size|null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
|
||||
this.mWidth = this.mWidth == 0 ? pixelMapWidth : this.mWidth;
|
||||
this.mHeight = this.mHeight == 0 ? pixelMapHeight : this.mHeight;
|
||||
|
||||
var scaleX = this.mWidth / pixelMapWidth;
|
||||
var scaleY = this.mHeight / pixelMapHeight;
|
||||
var scale = Math.max(scaleX, scaleY);
|
||||
let scaleX:number = this.mWidth / pixelMapWidth;
|
||||
let scaleY:number = this.mHeight / pixelMapHeight;
|
||||
let scale:number = Math.max(scaleX, scaleY);
|
||||
|
||||
var scaledWidth = scale * pixelMapWidth;
|
||||
var scaledHeight = scale * pixelMapHeight;
|
||||
var left = (this.mWidth - scaledWidth) / 2;
|
||||
var top = Math.abs(this.getTop(pixelMapHeight));
|
||||
var options = {
|
||||
let scaledWidth:number = scale * pixelMapWidth;
|
||||
let scaledHeight:number = scale * pixelMapHeight;
|
||||
let left:number = (this.mWidth - scaledWidth) / 2;
|
||||
let top:number = Math.abs(this.getTop(pixelMapHeight));
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredRegion: {
|
||||
size: {
|
||||
|
@ -82,23 +81,23 @@ export class CropTransformation implements BaseTransform<PixelMap> {
|
|||
},
|
||||
}
|
||||
imageSource.createPixelMap(options)
|
||||
.then((data) => {
|
||||
func("", data);
|
||||
.then((data:PixelMap) => {
|
||||
func?.asyncTransform("", data);
|
||||
})
|
||||
.catch((e) => {
|
||||
.catch((e:BusinessError) => {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
func(e, null);
|
||||
func?.asyncTransform(e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
|
||||
private getTop(scaledHeight: number): number{
|
||||
switch (this.mCropType.valueOf()) {
|
||||
case CropType.TOP.valueOf():
|
||||
switch (this.mCropType) {
|
||||
case CropType.TOP:
|
||||
return 0;
|
||||
case CropType.CENTER.valueOf():
|
||||
case CropType.CENTER:
|
||||
return (this.mHeight - scaledHeight) / 2;
|
||||
case CropType.BOTTOM.valueOf():
|
||||
case CropType.BOTTOM:
|
||||
return this.mHeight - scaledHeight;
|
||||
default:
|
||||
return 0;
|
||||
|
@ -107,7 +106,7 @@ export class CropTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
|
||||
export enum CropType {
|
||||
TOP,
|
||||
CENTER,
|
||||
BOTTOM
|
||||
TOP = 0,
|
||||
CENTER = 1,
|
||||
BOTTOM = 2
|
||||
}
|
|
@ -21,6 +21,8 @@ import { TransformUtils } from "../transform/TransformUtils"
|
|||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||
import image from "@ohos.multimedia.image"
|
||||
import { GPUImageGrayscaleFilter } from '@ohos/gpu_transform'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
export class GrayscaleTransformation implements BaseTransform<PixelMap> {
|
||||
getName() {
|
||||
|
@ -30,27 +32,27 @@ export class GrayscaleTransformation implements BaseTransform<PixelMap> {
|
|||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";GrayscaleTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
|
||||
let imageInfo = await imageSource.getImageInfo();
|
||||
let size = {
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
|
||||
if (!size) {
|
||||
func(new Error("GrayscaleTransformation The image size does not exist."), null)
|
||||
func?.asyncTransform("GrayscaleTransformation The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -58,14 +60,14 @@ export class GrayscaleTransformation implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
height: targetHeight
|
||||
}
|
||||
}
|
||||
let data = await imageSource.createPixelMap(options);
|
||||
let data:PixelMap= await imageSource.createPixelMap(options);
|
||||
|
||||
let bufferData = new ArrayBuffer(data.getPixelBytesNumber());
|
||||
let bufferNewData = new ArrayBuffer(data.getPixelBytesNumber());
|
||||
|
@ -76,15 +78,15 @@ export class GrayscaleTransformation implements BaseTransform<PixelMap> {
|
|||
filter.setImageData(bufferData, targetWidth, targetHeight);
|
||||
let buf = await filter.getPixelMapBuf(0, 0, targetWidth, targetHeight);
|
||||
data.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", data);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("success", data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var dataArray = new Uint8Array(bufferData);
|
||||
var dataNewArray = new Uint8Array(bufferNewData);
|
||||
let dataArray = new Uint8Array(bufferData);
|
||||
let dataNewArray = new Uint8Array(bufferNewData);
|
||||
|
||||
for (let index = 0; index < dataArray.length; index += 4) {
|
||||
const r = dataArray[index];
|
||||
|
@ -99,8 +101,8 @@ export class GrayscaleTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
|
||||
await data.writeBufferToPixels(bufferNewData);
|
||||
if (func) {
|
||||
func('', data);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform('', data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ import { RequestOption } from "../../imageknife/RequestOption"
|
|||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||
import image from "@ohos.multimedia.image"
|
||||
import { GPUImageColorInvertFilter } from '@ohos/gpu_transform'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
/**
|
||||
** Image inversion is particularly useful for enhancing white or gray detail in
|
||||
|
@ -37,28 +39,28 @@ export class InvertFilterTransformation implements BaseTransform<PixelMap> {
|
|||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";InvertFilterTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";InvertFilterTransformation buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";InvertFilterTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
|
||||
let imageInfo = await imageSource.getImageInfo();
|
||||
let size = {
|
||||
let imageInfo:image.ImageInfo = await imageSource.getImageInfo();
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
|
||||
if (!size) {
|
||||
func(new Error("InvertFilterTransformation The image size does not exist."), null)
|
||||
func?.asyncTransform("InvertFilterTransformation The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -66,7 +68,7 @@ export class InvertFilterTransformation implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
|
@ -74,7 +76,7 @@ export class InvertFilterTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
}
|
||||
|
||||
let data = await imageSource.createPixelMap(options);
|
||||
let data:PixelMap = await imageSource.createPixelMap(options);
|
||||
|
||||
let bufferData = new ArrayBuffer(data.getPixelBytesNumber());
|
||||
await data.readPixelsToBuffer(bufferData);
|
||||
|
@ -84,14 +86,14 @@ export class InvertFilterTransformation implements BaseTransform<PixelMap> {
|
|||
filter.setImageData(bufferData, targetWidth, targetHeight);
|
||||
let buf = await filter.getPixelMapBuf(0, 0, targetWidth, targetHeight);
|
||||
data.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", data);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("success", data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var dataArray = new Uint8Array(bufferData);
|
||||
let dataArray = new Uint8Array(bufferData);
|
||||
|
||||
for (let index = 0; index < dataArray.length; index += 4) {
|
||||
dataArray[index] = this.checkVisAble(255 - dataArray[index]);
|
||||
|
@ -99,8 +101,8 @@ export class InvertFilterTransformation implements BaseTransform<PixelMap> {
|
|||
dataArray[index+2] = this.checkVisAble(255 - dataArray[index+2]);
|
||||
}
|
||||
await data.writeBufferToPixels(bufferData);
|
||||
if (func) {
|
||||
func('', data);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform('', data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,10 +21,12 @@ import { TransformUtils } from "../transform/TransformUtils"
|
|||
import image from "@ohos.multimedia.image"
|
||||
import { LogUtil } from '../../imageknife/utils/LogUtil'
|
||||
import { GPUImageKuwaharaFilter } from '@ohos/gpu_transform'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
|
||||
export class KuwaharaFilterTransform implements BaseTransform<PixelMap> {
|
||||
private _mRadius: number;
|
||||
private _mRadius: number = 0;
|
||||
|
||||
constructor(radius: number) {
|
||||
this._mRadius = radius;
|
||||
|
@ -37,32 +39,29 @@ export class KuwaharaFilterTransform implements BaseTransform<PixelMap> {
|
|||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";KuwaharaFilterTransform buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";KuwaharaFilterTransform buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";KuwaharaFilterTransform buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!request.gpuEnabled) {
|
||||
LogUtil.error(Constants.PROJECT_TAG + ";the KuwaharaFilterTransform supported only in GPU mode");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";;the KuwaharaFilterTransform supported only in GPU mode", null);
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";;the KuwaharaFilterTransform supported only in GPU mode", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var that = this;
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
TransformUtils.getPixelMapSize(imageSource, {asyncTransform:(error:BusinessError|string, size: Size|null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -70,7 +69,7 @@ export class KuwaharaFilterTransform implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
|
@ -79,16 +78,16 @@ export class KuwaharaFilterTransform implements BaseTransform<PixelMap> {
|
|||
}
|
||||
imageSource.createPixelMap(options)
|
||||
.then((data) => {
|
||||
that.kuwahara(data, targetWidth, targetHeight, func);
|
||||
this.kuwahara(data, targetWidth, targetHeight, func);
|
||||
})
|
||||
.catch((e) => {
|
||||
.catch((e:BusinessError) => {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
func(e, null);
|
||||
func?.asyncTransform(e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
|
||||
private async kuwahara(bitmap: image.PixelMap, targetWidth: number, targetHeight: number, func: AsyncTransform<PixelMap>) {
|
||||
private async kuwahara(bitmap: image.PixelMap, targetWidth: number, targetHeight: number, func?: AsyncTransform<PixelMap>) {
|
||||
let bufferData = new ArrayBuffer(bitmap.getPixelBytesNumber());
|
||||
await bitmap.readPixelsToBuffer(bufferData);
|
||||
let filter = new GPUImageKuwaharaFilter();
|
||||
|
@ -96,8 +95,8 @@ export class KuwaharaFilterTransform implements BaseTransform<PixelMap> {
|
|||
filter.setRadius(this._mRadius);
|
||||
let buf = await filter.getPixelMapBuf(0, 0, targetWidth, targetHeight)
|
||||
bitmap.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", bitmap);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("success", bitmap);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,9 +23,11 @@ import image from "@ohos.multimedia.image"
|
|||
import resmgr from "@ohos.resourceManager"
|
||||
import { ImageKnifeGlobal } from '../ImageKnifeGlobal'
|
||||
import resourceManager from '@ohos.resourceManager'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
export class MaskTransformation implements BaseTransform<PixelMap> {
|
||||
private _mResourceData: Resource;
|
||||
private _mResourceData:Resource|undefined = undefined;
|
||||
|
||||
constructor(maskBitmap: Resource) {
|
||||
this._mResourceData = maskBitmap;
|
||||
|
@ -38,27 +40,27 @@ export class MaskTransformation implements BaseTransform<PixelMap> {
|
|||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";MaskTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";MaskTransformation buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";MaskTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
|
||||
let imageInfo = await imageSource.getImageInfo();
|
||||
let size = {
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
|
||||
if (!size) {
|
||||
func(new Error("MaskTransformation The image size does not exist."), null)
|
||||
func?.asyncTransform("MaskTransformation The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -66,7 +68,7 @@ export class MaskTransformation implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
|
@ -77,33 +79,40 @@ export class MaskTransformation implements BaseTransform<PixelMap> {
|
|||
.then(data => {
|
||||
this.openInternal(data, targetWidth, targetHeight, func)
|
||||
})
|
||||
.catch(e => {
|
||||
func(e, null);
|
||||
.catch((e:BusinessError )=> {
|
||||
func?.asyncTransform(e, null);
|
||||
})
|
||||
}
|
||||
|
||||
private openInternal(bitmap: any, width: number, height: number, func: AsyncTransform<PixelMap>) {
|
||||
private openInternal(bitmap: PixelMap, width: number, height: number, func?: AsyncTransform<PixelMap>) {
|
||||
if (!this._mResourceData) {
|
||||
throw new Error("MaskTransformation resource is empty");
|
||||
if(func != undefined){
|
||||
func.asyncTransform("MaskTransformation resource is empty", null)
|
||||
}
|
||||
}
|
||||
((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager).getMediaContent(this._mResourceData.id)
|
||||
.then(array => {
|
||||
let buffer = array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset);
|
||||
var imageSource = image.createImageSource(buffer as any);
|
||||
var options = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: width,
|
||||
height: height
|
||||
}
|
||||
let context = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>)
|
||||
if(context != undefined){
|
||||
let resourceManager = context.resourceManager as resourceManager.ResourceManager
|
||||
if(resourceManager != undefined && this._mResourceData != undefined)
|
||||
resourceManager.getMediaContent(this._mResourceData?.id)
|
||||
.then(array => {
|
||||
let buffer = array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset);
|
||||
let imageSource:image.ImageSource = image.createImageSource(buffer);
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: width,
|
||||
height: height
|
||||
}
|
||||
imageSource.createPixelMap(options)
|
||||
.then(maskBitmap => {
|
||||
MaskUtils.mask(bitmap, maskBitmap, func)
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
func("MaskTransformation openInternal error" + err, null);
|
||||
})
|
||||
}
|
||||
imageSource.createPixelMap(options)
|
||||
.then(maskBitmap => {
|
||||
MaskUtils.mask(bitmap, maskBitmap, func)
|
||||
})
|
||||
})
|
||||
.catch((err:BusinessError) => {
|
||||
func?.asyncTransform("MaskTransformation openInternal error" + err, null);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,6 +21,8 @@ import { TransformUtils } from "../transform/TransformUtils"
|
|||
import { LogUtil } from '../../imageknife/utils/LogUtil'
|
||||
import image from "@ohos.multimedia.image"
|
||||
import { pixelUtils } from "../utils/PixelUtils"
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
/**
|
||||
* Applies a Pixelation effect to the image.
|
||||
|
@ -42,24 +44,21 @@ export class PixelationFilterTransformation implements BaseTransform<PixelMap> {
|
|||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";PixelationFilterTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";PixelationFilterTransformation buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";PixelationFilterTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
TransformUtils.getPixelMapSize(imageSource, {asyncTransform:(error:BusinessError|string, size:Size|null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -67,7 +66,7 @@ export class PixelationFilterTransformation implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
|
@ -82,10 +81,10 @@ export class PixelationFilterTransformation implements BaseTransform<PixelMap> {
|
|||
pixelUtils.pixel(data, this._mPixel, func);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
.catch((e:BusinessError) => {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
func(e, null);
|
||||
func?.asyncTransform(e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
}
|
|
@ -18,11 +18,13 @@ import { Constants } from "../constants/Constants"
|
|||
import { RequestOption } from "../../imageknife/RequestOption"
|
||||
import { TransformUtils } from "../transform/TransformUtils"
|
||||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
import image from "@ohos.multimedia.image"
|
||||
|
||||
export class RotateImageTransformation implements BaseTransform<PixelMap> {
|
||||
private mDegreesToRotate: number;
|
||||
private mDegreesToRotate: number = 0;
|
||||
|
||||
constructor(degreesToRotate: number) {
|
||||
this.mDegreesToRotate = degreesToRotate;
|
||||
|
@ -35,24 +37,21 @@ export class RotateImageTransformation implements BaseTransform<PixelMap> {
|
|||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";RotateImageTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";RotateImageTransformation buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";RotateImageTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
TransformUtils.getPixelMapSize(imageSource, {asyncTransform:(error:BusinessError|string, size: Size|null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -60,7 +59,7 @@ export class RotateImageTransformation implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
rotate: this.mDegreesToRotate%360,
|
||||
desiredSize: {
|
||||
|
@ -70,12 +69,12 @@ export class RotateImageTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
imageSource.createPixelMap(options)
|
||||
.then((data) => {
|
||||
func("", data);
|
||||
func?.asyncTransform("", data);
|
||||
})
|
||||
.catch((e) => {
|
||||
.catch((e:BusinessError) => {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
func(e, null);
|
||||
func?.asyncTransform(e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
}
|
|
@ -19,23 +19,27 @@ import { Constants } from "../constants/Constants"
|
|||
import { RequestOption } from "../../imageknife/RequestOption"
|
||||
import { TransformUtils } from "../transform/TransformUtils"
|
||||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
import image from "@ohos.multimedia.image"
|
||||
|
||||
export interface RoundCorner{
|
||||
top_left: number,
|
||||
top_right: number,
|
||||
bottom_left: number,
|
||||
bottom_right: number
|
||||
}
|
||||
|
||||
export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
||||
private mTop_left: number = 0;
|
||||
private mTop_right: number = 0;
|
||||
private mBottom_left: number = 0;
|
||||
private mBottom_right: number = 0;
|
||||
private mTransform_pixelMap: any;
|
||||
private mPoint: ArcPoint[];
|
||||
private mTransform_pixelMap: PixelMap|undefined = undefined;
|
||||
private mPoint: ArcPoint[] = new Array();
|
||||
|
||||
constructor(value: {
|
||||
top_left?: number,
|
||||
top_right?: number,
|
||||
bottom_left?: number,
|
||||
bottom_right?: number
|
||||
}) {
|
||||
constructor(value:RoundCorner) {
|
||||
this.mTop_left = value.top_left;
|
||||
this.mTop_right = value.top_right;
|
||||
this.mBottom_left = value.bottom_left;
|
||||
|
@ -54,37 +58,33 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
+ 'buf is null ='+ (buf == null));
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";RoundedCornersTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";RoundedCornersTransformation buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";RoundedCornersTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
var that = this;
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
TransformUtils.getPixelMapSize(imageSource, {asyncTransform:(error:BusinessError|string, size: Size|null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
if (pixelMapHeight < targetHeight) {
|
||||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
that.transformPixelMap(imageSource, targetWidth, targetHeight, func);
|
||||
})
|
||||
this.transformPixelMap(imageSource, targetWidth, targetHeight, func);
|
||||
}})
|
||||
}
|
||||
|
||||
private transformPixelMap(imageSource: any, outWith: number, outHeight: number, func?: AsyncTransform<PixelMap>) {
|
||||
var options = {
|
||||
private transformPixelMap(imageSource: image.ImageSource, outWith: number, outHeight: number, func?: AsyncTransform<PixelMap>) {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: outWith,
|
||||
|
@ -96,8 +96,8 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
this.mTransform_pixelMap = pixelMap;
|
||||
this.mTransform_pixelMap.getImageInfo()
|
||||
.then((data) => {
|
||||
let width = data.size.width;
|
||||
let height = data.size.height;
|
||||
let width:number = data.size.width;
|
||||
let height:number = data.size.height;
|
||||
if (this.mTop_left > 0) {
|
||||
this.top_left_corners();
|
||||
}
|
||||
|
@ -110,18 +110,18 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
if (this.mBottom_right > 0) {
|
||||
this.bottom_right_corners(width, height);
|
||||
}
|
||||
if (func) {
|
||||
func("", this.mTransform_pixelMap);
|
||||
if (func != undefined && this.mTransform_pixelMap != undefined) {
|
||||
func?.asyncTransform("", this.mTransform_pixelMap);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch((error:BusinessError) => {
|
||||
LogUtil.log(Constants.PROJECT_TAG + "RoundedCornersTransformation error:" + error);
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
.catch((e:BusinessError) => {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
if (func) {
|
||||
func(e, null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(e, null);
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -129,10 +129,10 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
private top_left_corners() {
|
||||
this.mPoint = new Array<ArcPoint>();
|
||||
for (var time = 180; time < 270; time++) {
|
||||
var hudu = (2 * Math.PI / 360) * time;
|
||||
var x = this.mTop_left + Math.sin(hudu) * this.mTop_left;
|
||||
var y = this.mTop_left + Math.cos(hudu) * this.mTop_left;
|
||||
for (let time = 180; time < 270; time++) {
|
||||
let hudu:number = (2 * Math.PI / 360) * time;
|
||||
let x:number= this.mTop_left + Math.sin(hudu) * this.mTop_left;
|
||||
let y:number = this.mTop_left + Math.cos(hudu) * this.mTop_left;
|
||||
this.mPoint.push(new ArcPoint(x, y));
|
||||
}
|
||||
this.hand_pixel_point(this.mPoint);
|
||||
|
@ -140,10 +140,10 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
private top_right_corners(width: number) {
|
||||
this.mPoint = new Array<ArcPoint>();
|
||||
for (var time = 0; time < 90; time++) {
|
||||
var hudu = (2 * Math.PI / 360) * time;
|
||||
var x = (width - this.mTop_right) + Math.cos(hudu) * this.mTop_right;
|
||||
var y = this.mTop_right - Math.sin(hudu) * this.mTop_right;
|
||||
for (let time = 0; time < 90; time++) {
|
||||
let hudu:number = (2 * Math.PI / 360) * time;
|
||||
let x:number = (width - this.mTop_right) + Math.cos(hudu) * this.mTop_right;
|
||||
let y:number = this.mTop_right - Math.sin(hudu) * this.mTop_right;
|
||||
this.mPoint.push(new ArcPoint(x, y));
|
||||
}
|
||||
|
||||
|
@ -152,10 +152,10 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
private bottom_left_corners(width: number, height: number) {
|
||||
this.mPoint = new Array<ArcPoint>();
|
||||
for (var time = 90; time < 180; time++) {
|
||||
var hudu = (2 * Math.PI / 360) * time;
|
||||
var x = this.mBottom_left + Math.cos(hudu) * this.mBottom_left;
|
||||
var y = height - this.mBottom_left + Math.sin(hudu) * this.mBottom_left;
|
||||
for (let time = 90; time < 180; time++) {
|
||||
let hudu = (2 * Math.PI / 360) * time;
|
||||
let x = this.mBottom_left + Math.cos(hudu) * this.mBottom_left;
|
||||
let y = height - this.mBottom_left + Math.sin(hudu) * this.mBottom_left;
|
||||
this.mPoint.push(new ArcPoint(x, y));
|
||||
}
|
||||
this.hand_pixel_point(this.mPoint);
|
||||
|
@ -163,25 +163,25 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
private bottom_right_corners(width: number, height: number) {
|
||||
this.mPoint = new Array<ArcPoint>();
|
||||
for (var time = 0; time < 90; time++) {
|
||||
var hudu = (2 * Math.PI / 360) * time;
|
||||
var x = width - this.mBottom_right + Math.cos(hudu) * this.mBottom_right;
|
||||
var y = height - this.mBottom_right + Math.sin(hudu) * this.mBottom_right;
|
||||
for (let time = 0; time < 90; time++) {
|
||||
let hudu = (2 * Math.PI / 360) * time;
|
||||
let x = width - this.mBottom_right + Math.cos(hudu) * this.mBottom_right;
|
||||
let y = height - this.mBottom_right + Math.sin(hudu) * this.mBottom_right;
|
||||
this.mPoint.push(new ArcPoint(x, y));
|
||||
}
|
||||
this.hand_right_pixel_point(this.mPoint, width);
|
||||
}
|
||||
|
||||
private hand_pixel_point(points: ArcPoint[]) {
|
||||
for (var index = 0; index < points.length; index++) {
|
||||
for (let index = 0; index < points.length; index++) {
|
||||
const element = points[index];
|
||||
let x = element.getX();
|
||||
let y = element.getY();
|
||||
|
||||
for (var i = 0; i <= x; i++) {
|
||||
var buffer1 = new ArrayBuffer(5);
|
||||
var bytes1 = new Uint8Array(buffer1);
|
||||
var writePositionRen = {
|
||||
for (let i = 0; i <= x; i++) {
|
||||
let buffer1 = new ArrayBuffer(5);
|
||||
let bytes1 = new Uint8Array(buffer1);
|
||||
let writePositionRen:image.PositionArea = {
|
||||
pixels: buffer1,
|
||||
offset: 1,
|
||||
stride: 1024,
|
||||
|
@ -193,21 +193,23 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
for (let j = 0;j < 5; j++) {
|
||||
bytes1[j] = 0;
|
||||
}
|
||||
this.mTransform_pixelMap.writePixels(writePositionRen);
|
||||
if(this.mTransform_pixelMap != undefined) {
|
||||
this.mTransform_pixelMap.writePixels(writePositionRen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private hand_right_pixel_point(points: ArcPoint[], width: number) {
|
||||
for (var index = 0; index < points.length; index++) {
|
||||
for (let index = 0; index < points.length; index++) {
|
||||
const element = points[index];
|
||||
let x = element.getX();
|
||||
let y = element.getY();
|
||||
|
||||
for (var i = x; i <= width; i++) {
|
||||
var buffer1 = new ArrayBuffer(5);
|
||||
var bytes1 = new Uint8Array(buffer1);
|
||||
var writePositionRen = {
|
||||
for (let i = x; i <= width; i++) {
|
||||
let buffer1 = new ArrayBuffer(5);
|
||||
let bytes1 = new Uint8Array(buffer1);
|
||||
let writePositionRen:image.PositionArea = {
|
||||
pixels: buffer1,
|
||||
offset: 0,
|
||||
stride: 4,
|
||||
|
@ -219,7 +221,9 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
for (let j = 0;j < 5; j++) {
|
||||
bytes1[j] = 0;
|
||||
}
|
||||
this.mTransform_pixelMap.writePixels(writePositionRen);
|
||||
if(this.mTransform_pixelMap != undefined) {
|
||||
this.mTransform_pixelMap.writePixels(writePositionRen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ import { RequestOption } from "../../imageknife/RequestOption"
|
|||
import { LogUtil } from '../../imageknife/utils/LogUtil'
|
||||
import image from "@ohos.multimedia.image"
|
||||
import { GPUImageSepiaToneFilter } from '@ohos/gpu_transform'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
/**
|
||||
* Applies a simple sepia effect.
|
||||
|
@ -34,28 +36,28 @@ export class SepiaFilterTransformation implements BaseTransform<PixelMap> {
|
|||
async transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";SepiaFilterTransformation buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";SepiaFilterTransformation buf is empty", null);
|
||||
if (func!=undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";SepiaFilterTransformation buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
|
||||
let imageInfo = await imageSource.getImageInfo();
|
||||
let size = {
|
||||
let imageInfo:image.ImageInfo = await imageSource.getImageInfo();
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
|
||||
if (!size) {
|
||||
func(new Error("SepiaFilterTransformation The image size does not exist."), null)
|
||||
func?.asyncTransform("SepiaFilterTransformation The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -63,14 +65,14 @@ export class SepiaFilterTransformation implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
height: targetHeight
|
||||
}
|
||||
}
|
||||
let data = await imageSource.createPixelMap(options);
|
||||
let data:PixelMap = await imageSource.createPixelMap(options);
|
||||
|
||||
let bufferData = new ArrayBuffer(data.getPixelBytesNumber());
|
||||
await data.readPixelsToBuffer(bufferData);
|
||||
|
@ -80,21 +82,21 @@ export class SepiaFilterTransformation implements BaseTransform<PixelMap> {
|
|||
filter.setImageData(bufferData, targetWidth, targetHeight);
|
||||
let buf = await filter.getPixelMapBuf(0, 0, targetWidth, targetHeight);
|
||||
data.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", data);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("success", data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let bufferNewData = new ArrayBuffer(data.getPixelBytesNumber());
|
||||
var dataArray = new Uint8Array(bufferData);
|
||||
var dataNewArray = new Uint8Array(bufferNewData);
|
||||
let dataArray = new Uint8Array(bufferData);
|
||||
let dataNewArray = new Uint8Array(bufferNewData);
|
||||
|
||||
for (let index = 0; index < dataArray.length; index += 4) {
|
||||
const r = dataArray[index];
|
||||
const g = dataArray[index+1];
|
||||
const b = dataArray[index+2];
|
||||
const f = dataArray[index+3];
|
||||
const r:number = dataArray[index];
|
||||
const g:number = dataArray[index+1];
|
||||
const b:number = dataArray[index+2];
|
||||
const f:number = dataArray[index+3];
|
||||
|
||||
dataNewArray[index+2] = this.checkVisAble(this.colorBlend(this.noise()
|
||||
, (r * 0.272) + (g * 0.534) + (b * 0.131)
|
||||
|
@ -109,8 +111,8 @@ export class SepiaFilterTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
|
||||
await data.writeBufferToPixels(bufferNewData);
|
||||
if (func) {
|
||||
func("", data);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("", data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ import { RequestOption } from '../../imageknife/RequestOption'
|
|||
import { TransformUtils } from '../transform/TransformUtils'
|
||||
import image from '@ohos.multimedia.image'
|
||||
import { CalculatePixelUtils } from '../utils/CalculatePixelUtils'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
export class SketchFilterTransformation implements BaseTransform<PixelMap> {
|
||||
getName() {
|
||||
|
@ -28,25 +30,21 @@ export class SketchFilterTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
throw new Error(Constants.PROJECT_TAG + ';SketchFilterTransformation buf is empty');
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ';SketchFilterTransformation buf is empty', null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ';SketchFilterTransformation buf is empty', null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
TransformUtils.getPixelMapSize(imageSource, {asyncTransform:(error:BusinessError|string, size: Size|null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth: number = size.width;
|
||||
let pixelMapHeight: number = size.height;
|
||||
let targetWidth: number = request.size.width;
|
||||
let targetHeight: number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -54,7 +52,7 @@ export class SketchFilterTransformation implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options: image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
|
@ -69,9 +67,9 @@ export class SketchFilterTransformation implements BaseTransform<PixelMap> {
|
|||
CalculatePixelUtils.sketch(data, func);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
func(e, null);
|
||||
.catch((e:BusinessError) => {
|
||||
func?.asyncTransform(e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
}
|
|
@ -23,6 +23,8 @@ import { PixelEntry } from '../entry/PixelEntry'
|
|||
import { ColorUtils } from '../utils/ColorUtils'
|
||||
import { CalculatePixelUtils } from '../utils/CalculatePixelUtils'
|
||||
import { GPUImageSwirlFilter } from '@ohos/gpu_transform'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
export class SwirlFilterTransformation implements BaseTransform<PixelMap> {
|
||||
private radius: number = 0;
|
||||
|
@ -47,25 +49,21 @@ export class SwirlFilterTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
throw new Error(Constants.PROJECT_TAG + ';SwirlFilterTransformation buf is empty');
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ';SwirlFilterTransformation buf is empty', null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ';SwirlFilterTransformation buf is empty', null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
TransformUtils.getPixelMapSize(imageSource,{asyncTransform: (error:BusinessError|string, size:Size|null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -73,7 +71,7 @@ export class SwirlFilterTransformation implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
|
@ -84,23 +82,23 @@ export class SwirlFilterTransformation implements BaseTransform<PixelMap> {
|
|||
.then((data) => {
|
||||
this.swirl(data, this.radius, request, func);
|
||||
})
|
||||
.catch((e) => {
|
||||
func(e, null);
|
||||
.catch((e:BusinessError) => {
|
||||
func?.asyncTransform(e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
|
||||
private async swirl(bitmap: image.PixelMap, degree: number, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
let imageInfo = await bitmap.getImageInfo();
|
||||
let size = {
|
||||
let imageInfo:image.ImageInfo = await bitmap.getImageInfo();
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
if (!size) {
|
||||
return;
|
||||
}
|
||||
let width = size.width;
|
||||
let height = size.height;
|
||||
let width:number = size.width;
|
||||
let height:number = size.height;
|
||||
|
||||
|
||||
let bufferData = new ArrayBuffer(bitmap.getPixelBytesNumber());
|
||||
|
@ -113,8 +111,8 @@ export class SwirlFilterTransformation implements BaseTransform<PixelMap> {
|
|||
filter.setCenter(this._xCenter, this._yCenter)
|
||||
let buf = await filter.getPixelMapBuf(0, 0, width, height);
|
||||
bitmap.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", bitmap);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("success", bitmap);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -125,13 +123,13 @@ export class SwirlFilterTransformation implements BaseTransform<PixelMap> {
|
|||
|
||||
let dataArray = new Uint8Array(bufferData);
|
||||
|
||||
let ph = 0;
|
||||
let pw = 0;
|
||||
let ph:number = 0;
|
||||
let pw:number = 0;
|
||||
for (let index = 0; index < dataArray.length; index += 4) {
|
||||
const r = dataArray[index];
|
||||
const g = dataArray[index+1];
|
||||
const b = dataArray[index+2];
|
||||
const f = dataArray[index+3];
|
||||
const r:number = dataArray[index];
|
||||
const g:number = dataArray[index+1];
|
||||
const b:number = dataArray[index+2];
|
||||
const f:number = dataArray[index+3];
|
||||
|
||||
let entry = new PixelEntry();
|
||||
entry.a = 0;
|
||||
|
@ -201,8 +199,8 @@ export class SwirlFilterTransformation implements BaseTransform<PixelMap> {
|
|||
index++;
|
||||
}
|
||||
await bitmap.writeBufferToPixels(bufferNewData);
|
||||
if (func) {
|
||||
func("", bitmap);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("", bitmap);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,7 +21,8 @@ import { TransformUtils } from "../transform/TransformUtils"
|
|||
import image from "@ohos.multimedia.image"
|
||||
import { LogUtil } from '../../imageknife/utils/LogUtil'
|
||||
import { GPUImageToonFilter } from '@ohos/gpu_transform'
|
||||
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
export class ToonFilterTransform implements BaseTransform<PixelMap> {
|
||||
private threshold: number = 0.2;
|
||||
|
@ -43,32 +44,29 @@ export class ToonFilterTransform implements BaseTransform<PixelMap> {
|
|||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";ToonFilterTransform buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";ToonFilterTransform buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";ToonFilterTransform buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!request.gpuEnabled) {
|
||||
LogUtil.error(Constants.PROJECT_TAG + ";the ToonFilterTransform supported only in GPU mode");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";the ToonFilterTransform supported only in GPU mode", null);
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";the ToonFilterTransform supported only in GPU mode", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var that = this;
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
TransformUtils.getPixelMapSize(imageSource, {asyncTransform:(error:BusinessError|string, size: Size|null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -76,7 +74,7 @@ export class ToonFilterTransform implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
|
@ -85,16 +83,16 @@ export class ToonFilterTransform implements BaseTransform<PixelMap> {
|
|||
}
|
||||
imageSource.createPixelMap(options)
|
||||
.then((data) => {
|
||||
that.toon(data, targetWidth, targetHeight, func);
|
||||
this.toon(data, targetWidth, targetHeight, func);
|
||||
})
|
||||
.catch((e) => {
|
||||
.catch((e:BusinessError) => {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
func(e, null);
|
||||
func?.asyncTransform(e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
|
||||
private async toon(bitmap: image.PixelMap, targetWidth: number, targetHeight: number, func: AsyncTransform<PixelMap>) {
|
||||
private async toon(bitmap: image.PixelMap, targetWidth: number, targetHeight: number, func?: AsyncTransform<PixelMap>) {
|
||||
let bufferData = new ArrayBuffer(bitmap.getPixelBytesNumber());
|
||||
await bitmap.readPixelsToBuffer(bufferData);
|
||||
let filter = new GPUImageToonFilter();
|
||||
|
@ -103,8 +101,8 @@ export class ToonFilterTransform implements BaseTransform<PixelMap> {
|
|||
filter.setQuantizationLevels(this.quantizationLevels);
|
||||
let buf = await filter.getPixelMapBuf(0, 0, targetWidth, targetHeight)
|
||||
bitmap.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", bitmap);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("success", bitmap);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,18 +14,19 @@
|
|||
*/
|
||||
import {AsyncTransform} from '../transform/AsyncTransform'
|
||||
import image from '@ohos.multimedia.image'
|
||||
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
export class TransformUtils {
|
||||
static centerCrop(buf: ArrayBuffer, outWidth: number, outHeihgt: number,
|
||||
callback?: AsyncTransform<Promise<PixelMap>>) {
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
imageSource.getImageInfo()
|
||||
.then((p) => {
|
||||
var sw;
|
||||
var sh;
|
||||
var scale;
|
||||
var pw = p.size.width;
|
||||
var ph = p.size.height;
|
||||
let sw:number=0;
|
||||
let sh:number=0;
|
||||
let scale:number=1;
|
||||
let pw:number = p.size.width;
|
||||
let ph:number = p.size.height;
|
||||
if (pw == outWidth && ph == outHeihgt) {
|
||||
sw = outWidth;
|
||||
sh = outHeihgt;
|
||||
|
@ -38,7 +39,7 @@ export class TransformUtils {
|
|||
sw = pw * scale;
|
||||
sh = ph * scale;
|
||||
}
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
rotate: 0,
|
||||
desiredRegion: { size: { width: sw, height: sh },
|
||||
|
@ -47,18 +48,18 @@ export class TransformUtils {
|
|||
},
|
||||
}
|
||||
if (callback) {
|
||||
callback('', imageSource.createPixelMap(options));
|
||||
callback.asyncTransform('', imageSource.createPixelMap(options));
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
callback(error, null);
|
||||
.catch((error:BusinessError) => {
|
||||
callback?.asyncTransform(error, null);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
static rotateImage(buf: ArrayBuffer, degreesToRotate: number): Promise<PixelMap>{
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
var options = {
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
rotate: degreesToRotate
|
||||
}
|
||||
|
@ -67,36 +68,36 @@ export class TransformUtils {
|
|||
|
||||
static centerInside(buf: ArrayBuffer, outWidth: number, outHeihgt: number,
|
||||
callback?: AsyncTransform<Promise<PixelMap>>) {
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
imageSource.getImageInfo()
|
||||
.then((p) => {
|
||||
var pw = p.size.width;
|
||||
var ph = p.size.height;
|
||||
.then((p:image.ImageInfo) => {
|
||||
let pw = p.size.width;
|
||||
let ph = p.size.height;
|
||||
if (pw <= outWidth && ph <= outHeihgt) {
|
||||
callback('', imageSource.createPixelMap());
|
||||
callback?.asyncTransform('', imageSource.createPixelMap());
|
||||
} else {
|
||||
this.fitCenter(buf, outWidth, outHeihgt, callback);
|
||||
TransformUtils.fitCenter(buf, outWidth, outHeihgt, callback);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
callback(error, null);
|
||||
.catch((error:BusinessError) => {
|
||||
callback?.asyncTransform(error, null);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
static fitCenter(buf: ArrayBuffer, outWidth: number, outHeihgt: number
|
||||
, callback?: AsyncTransform<Promise<PixelMap>>) {
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
imageSource.getImageInfo()
|
||||
.then((p) => {
|
||||
var pw = p.size.width;
|
||||
var ph = p.size.height;
|
||||
var widthPercentage = outWidth / pw;
|
||||
var heightPercentage = outHeihgt / ph;
|
||||
var minPercentage = Math.min(widthPercentage, heightPercentage);
|
||||
.then((p:image.ImageInfo) => {
|
||||
let pw:number = p.size.width;
|
||||
let ph:number = p.size.height;
|
||||
let widthPercentage:number = outWidth / pw;
|
||||
let heightPercentage:number = outHeihgt / ph;
|
||||
let minPercentage:number = Math.min(widthPercentage, heightPercentage);
|
||||
|
||||
var targetWidth = Math.round(minPercentage * pw);
|
||||
var targetHeight = Math.round(minPercentage * ph);
|
||||
let targetWidth:number = Math.round(minPercentage * pw);
|
||||
let targetHeight:number = Math.round(minPercentage * ph);
|
||||
|
||||
if (pw == targetWidth && ph == targetHeight) {
|
||||
targetWidth = pw;
|
||||
|
@ -105,37 +106,34 @@ export class TransformUtils {
|
|||
targetWidth = minPercentage * pw;
|
||||
targetHeight = minPercentage * ph;
|
||||
}
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
rotate: 0,
|
||||
desiredSize: { width: targetWidth, height: targetHeight }
|
||||
}
|
||||
if (callback) {
|
||||
callback('', imageSource.createPixelMap(options));
|
||||
callback.asyncTransform('', imageSource.createPixelMap(options));
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
.catch((e:BusinessError) => {
|
||||
if (callback) {
|
||||
callback(e, null);
|
||||
callback.asyncTransform(e, null);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static getPixelMapSize(imageSource: any, func: AsyncTransform<{
|
||||
width: number,
|
||||
height: number
|
||||
}>) {
|
||||
static getPixelMapSize(imageSource: image.ImageSource, func: AsyncTransform<Size>) {
|
||||
if (!imageSource) {
|
||||
return;
|
||||
}
|
||||
imageSource.getImageInfo((err, value) => {
|
||||
imageSource.getImageInfo((err:BusinessError, value:image.ImageInfo) => {
|
||||
if (err) {
|
||||
func(err, null)
|
||||
func?.asyncTransform(err, null)
|
||||
return;
|
||||
}
|
||||
var pWidth = value.size.width;
|
||||
var pHeight = value.size.height;
|
||||
func('', { width: pWidth, height: pHeight });
|
||||
let pWidth:number = value.size.width;
|
||||
let pHeight:number = value.size.height;
|
||||
func?.asyncTransform('', { width: pWidth, height: pHeight });
|
||||
})
|
||||
}
|
||||
}
|
|
@ -21,6 +21,8 @@ import { TransformUtils } from "../transform/TransformUtils"
|
|||
import image from "@ohos.multimedia.image"
|
||||
import { LogUtil } from '../../imageknife/utils/LogUtil'
|
||||
import { GPUImageVignetterFilter } from '@ohos/gpu_transform'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
|
||||
|
||||
export class VignetteFilterTransform implements BaseTransform<PixelMap> {
|
||||
|
@ -47,32 +49,28 @@ export class VignetteFilterTransform implements BaseTransform<PixelMap> {
|
|||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";VignetteFilterTransform buf is empty");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";VignetteFilterTransform buf is empty", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";VignetteFilterTransform buf is empty", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!request.gpuEnabled) {
|
||||
LogUtil.error(Constants.PROJECT_TAG + ";the VignetteFilterTransform supported only in GPU mode");
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ";the VignetteFilterTransform supported only in GPU mode", null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ";the VignetteFilterTransform supported only in GPU mode", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var that = this;
|
||||
var imageSource = image.createImageSource(buf as any);
|
||||
TransformUtils.getPixelMapSize(imageSource, (error, size: {
|
||||
width: number,
|
||||
height: number
|
||||
}) => {
|
||||
let imageSource:image.ImageSource = image.createImageSource(buf);
|
||||
TransformUtils.getPixelMapSize(imageSource, {asyncTransform:(error:BusinessError|string, size: Size|null) => {
|
||||
if (!size) {
|
||||
func(error, null)
|
||||
func?.asyncTransform(error, null)
|
||||
return;
|
||||
}
|
||||
var pixelMapWidth = size.width;
|
||||
var pixelMapHeight = size.height;
|
||||
var targetWidth = request.size.width;
|
||||
var targetHeight = request.size.height;
|
||||
let pixelMapWidth:number = size.width;
|
||||
let pixelMapHeight:number = size.height;
|
||||
let targetWidth:number = request.size.width;
|
||||
let targetHeight:number = request.size.height;
|
||||
if (pixelMapWidth < targetWidth) {
|
||||
targetWidth = pixelMapWidth;
|
||||
}
|
||||
|
@ -80,7 +78,7 @@ export class VignetteFilterTransform implements BaseTransform<PixelMap> {
|
|||
targetHeight = pixelMapHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
let options:image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: targetWidth,
|
||||
|
@ -89,16 +87,16 @@ export class VignetteFilterTransform implements BaseTransform<PixelMap> {
|
|||
}
|
||||
imageSource.createPixelMap(options)
|
||||
.then((data) => {
|
||||
that.vignette(data, targetWidth, targetHeight, func);
|
||||
this.vignette(data, targetWidth, targetHeight, func);
|
||||
})
|
||||
.catch((e) => {
|
||||
.catch((e:BusinessError) => {
|
||||
LogUtil.log(Constants.PROJECT_TAG + ";error:" + e);
|
||||
func(e, null);
|
||||
func?.asyncTransform(e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
|
||||
private async vignette(bitmap: image.PixelMap, targetWidth: number, targetHeight: number, func: AsyncTransform<PixelMap>) {
|
||||
private async vignette(bitmap: image.PixelMap, targetWidth: number, targetHeight: number, func?: AsyncTransform<PixelMap>) {
|
||||
let bufferData = new ArrayBuffer(bitmap.getPixelBytesNumber());
|
||||
await bitmap.readPixelsToBuffer(bufferData);
|
||||
let filter = new GPUImageVignetterFilter();
|
||||
|
@ -109,8 +107,8 @@ export class VignetteFilterTransform implements BaseTransform<PixelMap> {
|
|||
filter.setVignetteEnd(this.vignetteSpace[1]);
|
||||
let buf = await filter.getPixelMapBuf(0, 0, targetWidth, targetHeight)
|
||||
bitmap.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", bitmap);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("success", bitmap);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ import {AsyncTransform} from '../AsyncTransform'
|
|||
import {Constants} from '../../constants/Constants'
|
||||
import {TransformUtils} from '../TransformUtils'
|
||||
import {RequestOption} from '../../../imageknife/RequestOption'
|
||||
|
||||
import { BusinessError } from '@ohos.base'
|
||||
export class CenterCrop implements BaseTransform<PixelMap> {
|
||||
getName() {
|
||||
return 'CenterCrop:' + this;
|
||||
|
@ -26,18 +26,17 @@ export class CenterCrop implements BaseTransform<PixelMap> {
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
throw new Error(Constants.PROJECT_TAG + ';CenterCrop buf is empty');
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ';CenterCrop buf is empty', null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ';CenterCrop buf is empty', null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
TransformUtils.centerCrop(buf, request.size.width, request.size.height, (error, data) => {
|
||||
data.then(p => {
|
||||
func('', p);
|
||||
}).catch(e => {
|
||||
func(Constants.PROJECT_TAG + ';CenterCrop error:' + e, null);
|
||||
TransformUtils.centerCrop(buf, request.size.width, request.size.height, {asyncTransform:(error:BusinessError|string, data:Promise<PixelMap>|null) => {
|
||||
data?.then(p => {
|
||||
func?.asyncTransform('', p);
|
||||
}).catch((e:BusinessError) => {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ';CenterCrop error:' + e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
}
|
|
@ -13,12 +13,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {BaseTransform} from '../BaseTransform'
|
||||
import {BaseTransform} from '../BaseTransform'
|
||||
import {AsyncTransform} from '../AsyncTransform'
|
||||
import {Constants} from '../../constants/Constants'
|
||||
import {TransformUtils} from '../TransformUtils'
|
||||
import {RequestOption} from '../../../imageknife/RequestOption'
|
||||
|
||||
import { BusinessError } from '@ohos.base'
|
||||
export class CenterInside implements BaseTransform<PixelMap> {
|
||||
getName() {
|
||||
return 'CenterInside:' + this;
|
||||
|
@ -26,18 +26,17 @@ export class CenterInside implements BaseTransform<PixelMap> {
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
throw new Error(Constants.PROJECT_TAG + ';CenterInside buf is empty');
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ';CenterInside buf is empty', null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ';CenterInside buf is empty', null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
TransformUtils.centerInside(buf, request.size.width, request.size.height, (error, data) => {
|
||||
data.then(p => {
|
||||
func('', p);
|
||||
}).catch(e => {
|
||||
func(Constants.PROJECT_TAG + ';CenterInside error:' + e, null);
|
||||
TransformUtils.centerInside(buf, request.size.width, request.size.height, {asyncTransform:(error:BusinessError|string, data:Promise<PixelMap>|null) => {
|
||||
data?.then(p => {
|
||||
func?.asyncTransform('', p);
|
||||
}).catch((e:BusinessError) => {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ';CenterInside error:' + e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ import {AsyncTransform} from '../AsyncTransform'
|
|||
import {Constants} from '../../constants/Constants'
|
||||
import {TransformUtils} from '../TransformUtils'
|
||||
import {RequestOption} from '../../../imageknife/RequestOption'
|
||||
|
||||
import { BusinessError } from '@ohos.base'
|
||||
export class FitCenter implements BaseTransform<PixelMap> {
|
||||
getName() {
|
||||
return 'FitCenter:' + this;
|
||||
|
@ -26,18 +26,17 @@ export class FitCenter implements BaseTransform<PixelMap> {
|
|||
|
||||
transform(buf: ArrayBuffer, request: RequestOption, func?: AsyncTransform<PixelMap>) {
|
||||
if (!buf || buf.byteLength <= 0) {
|
||||
throw new Error(Constants.PROJECT_TAG + ';FitCenter buf is empty');
|
||||
if (func) {
|
||||
func(Constants.PROJECT_TAG + ';FitCenter buf is empty', null);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ';FitCenter buf is empty', null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
TransformUtils.fitCenter(buf, request.size.width, request.size.height, (error, data) => {
|
||||
data.then(p => {
|
||||
func('', p);
|
||||
}).catch(e => {
|
||||
func(Constants.PROJECT_TAG + ';FitCenter error:' + e, null);
|
||||
TransformUtils.fitCenter(buf, request.size.width, request.size.height, {asyncTransform:(error:BusinessError|string, data:Promise<PixelMap>|null) => {
|
||||
data?.then(p => {
|
||||
func?.asyncTransform('', p);
|
||||
}).catch((e:BusinessError) => {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ';FitCenter error:' + e, null);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
}
|
|
@ -16,16 +16,17 @@ import { PixelEntry } from "../entry/PixelEntry"
|
|||
import { AsyncTransform } from "../transform/AsyncTransform"
|
||||
import { ColorUtils } from "./ColorUtils"
|
||||
import { GPUImageSketchFilter } from '@ohos/gpu_transform'
|
||||
import image from '@ohos.multimedia.image'
|
||||
|
||||
export namespace CalculatePixelUtils {
|
||||
export async function sketch(p: any, func: AsyncTransform<PixelMap>) {
|
||||
export async function sketch(p: PixelMap, func?: AsyncTransform<PixelMap>) {
|
||||
let imageInfo = await p.getImageInfo();
|
||||
let size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
if (!size) {
|
||||
func(new Error("sketch The image size does not exist."), null)
|
||||
func.asyncTransform("sketch The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -91,8 +92,8 @@ export namespace CalculatePixelUtils {
|
|||
}
|
||||
await p.writeBufferToPixels(bufferNewData);
|
||||
|
||||
if (func) {
|
||||
func("success", p);
|
||||
if (func != undefined) {
|
||||
func.asyncTransform("success", p);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,14 +299,14 @@ export namespace CalculatePixelUtils {
|
|||
return array;
|
||||
}
|
||||
|
||||
export async function sketchGpu(p: any, func: AsyncTransform<PixelMap>) {
|
||||
let imageInfo = await p.getImageInfo();
|
||||
export async function sketchGpu(p: PixelMap, func?: AsyncTransform<PixelMap>) {
|
||||
let imageInfo:image.ImageInfo = await p.getImageInfo();
|
||||
let size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
if (!size) {
|
||||
func(new Error("sketch The image size does not exist."), null)
|
||||
func?.asyncTransform("sketch The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -318,8 +319,8 @@ export namespace CalculatePixelUtils {
|
|||
filter.setImageData(bufferData, w, h);
|
||||
filter.getPixelMapBuf(0, 0, w, h).then((buf) => {
|
||||
p.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", p);
|
||||
if (func!=undefined) {
|
||||
func.asyncTransform("success", p);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@ import {PixelEntry} from "../entry/PixelEntry"
|
|||
import {AsyncTransform} from "../transform/AsyncTransform"
|
||||
import {ColorUtils} from "./ColorUtils"
|
||||
import { GPUImageBlurFilter } from '@ohos/gpu_transform'
|
||||
|
||||
import {Size} from '../../imageknife/RequestOption'
|
||||
import image from '@ohos.multimedia.image';
|
||||
export namespace fastBlur {
|
||||
|
||||
|
||||
export async function blur(bitmap: any, radius: number, canReuseInBitmap: boolean, func: AsyncTransform<PixelMap>) {
|
||||
export async function blur(bitmap: PixelMap, radius: number, canReuseInBitmap: boolean, func?: AsyncTransform<PixelMap>) {
|
||||
|
||||
|
||||
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
|
||||
|
@ -52,25 +53,25 @@ export namespace fastBlur {
|
|||
//
|
||||
|
||||
if (radius < 1) {
|
||||
func("error,radius must be greater than 1 ", null);
|
||||
func?.asyncTransform("error,radius must be greater than 1 ", null);
|
||||
return;
|
||||
}
|
||||
|
||||
let imageInfo = await bitmap.getImageInfo();
|
||||
let size = {
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
|
||||
if (!size) {
|
||||
func(new Error("fastBlur The image size does not exist."), null)
|
||||
func?.asyncTransform("fastBlur The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
|
||||
let w = size.width;
|
||||
let h = size.height;
|
||||
var pixEntry: Array<PixelEntry> = new Array()
|
||||
var pix: Array<number> = new Array()
|
||||
let pixEntry: Array<PixelEntry> = new Array()
|
||||
let pix: Array<number> = new Array()
|
||||
|
||||
|
||||
let bufferData = new ArrayBuffer(bitmap.getPixelBytesNumber());
|
||||
|
@ -103,7 +104,17 @@ export namespace fastBlur {
|
|||
let g = CalculatePixelUtils.createIntArray(wh);
|
||||
let b = CalculatePixelUtils.createIntArray(wh);
|
||||
|
||||
let rsum, gsum, bsum, x, y, i, p, yp, yi, yw: number;
|
||||
let rsum:number = 0;
|
||||
let gsum:number = 0;
|
||||
let bsum:number = 0;
|
||||
let x:number = 0;
|
||||
let y:number = 0;
|
||||
let i:number = 0;
|
||||
let p:number = 0;
|
||||
let yp:number = 0;
|
||||
let yi:number = 0;
|
||||
let yw: number = 0;
|
||||
|
||||
let vmin = CalculatePixelUtils.createIntArray(Math.max(w, h));
|
||||
|
||||
let divsum = (div + 1) >> 1;
|
||||
|
@ -115,7 +126,15 @@ export namespace fastBlur {
|
|||
|
||||
yw = yi = 0;
|
||||
let stack = CalculatePixelUtils.createInt2DArray(div, 3);
|
||||
let stackpointer, stackstart, rbs, routsum, goutsum, boutsum, rinsum, ginsum, binsum: number;
|
||||
let stackpointer:number=0;
|
||||
let stackstart:number=0;
|
||||
let rbs:number=0;
|
||||
let routsum:number=0;
|
||||
let goutsum:number=0;
|
||||
let boutsum:number=0;
|
||||
let rinsum:number=0;
|
||||
let ginsum:number=0;
|
||||
let binsum:number=0;
|
||||
let sir: Array<number>;
|
||||
let r1 = radius + 1;
|
||||
for (y = 0; y < h; y++) {
|
||||
|
@ -286,29 +305,29 @@ export namespace fastBlur {
|
|||
index++;
|
||||
}
|
||||
await bitmap.writeBufferToPixels(bufferNewData);
|
||||
if (func) {
|
||||
func("success", bitmap);
|
||||
if (func != undefined) {
|
||||
func?s.asyncTransform("success", bitmap);
|
||||
}
|
||||
}
|
||||
export async function blurGPU(bitmap: any, radius: number, canReuseInBitmap: boolean, func: AsyncTransform<PixelMap>) {
|
||||
export async function blurGPU(bitmap: PixelMap, radius: number, canReuseInBitmap: boolean, func?: AsyncTransform<PixelMap>) {
|
||||
if (radius < 1) {
|
||||
func("error,radius must be greater than 1 ", null);
|
||||
func?.asyncTransform("error,radius must be greater than 1 ", null);
|
||||
return;
|
||||
}
|
||||
|
||||
let imageInfo = await bitmap.getImageInfo();
|
||||
let size = {
|
||||
let imageInfo:image.ImageInfo = await bitmap.getImageInfo();
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
|
||||
if (!size) {
|
||||
func(new Error("fastBlur The image size does not exist."), null)
|
||||
func?.asyncTransform("fastBlur The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
|
||||
let w = size.width;
|
||||
let h = size.height;
|
||||
let w:number = size.width;
|
||||
let h:number = size.height;
|
||||
|
||||
let bufferData = new ArrayBuffer(bitmap.getPixelBytesNumber());
|
||||
await bitmap.readPixelsToBuffer(bufferData);
|
||||
|
@ -318,8 +337,8 @@ export namespace fastBlur {
|
|||
filter.setBlurOffset([1.0, 1.0])
|
||||
filter.getPixelMapBuf(0, 0, w, h).then((buf) => {
|
||||
bitmap.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", bitmap);
|
||||
if (func != undefined) {
|
||||
func?.asyncTransform("success", bitmap);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -17,23 +17,25 @@ import {CalculatePixelUtils} from "./CalculatePixelUtils"
|
|||
import {PixelEntry} from "../entry/PixelEntry"
|
||||
import {AsyncTransform} from "../transform/AsyncTransform"
|
||||
import {ColorUtils} from "./ColorUtils"
|
||||
import {Size} from "../../imageknife/RequestOption"
|
||||
import {GPUImagePixelationFilter} from '@ohos/gpu_transform'
|
||||
import image from '@ohos.multimedia.image';
|
||||
|
||||
export namespace pixelUtils {
|
||||
|
||||
export async function pixel(bitmap: any, pixel: number, func: AsyncTransform<PixelMap>) {
|
||||
export async function pixel(bitmap: PixelMap, pixel: number, func?: AsyncTransform<PixelMap>) {
|
||||
|
||||
let imageInfo = await bitmap.getImageInfo();
|
||||
let size = {
|
||||
let imageInfo:image.ImageInfo= await bitmap.getImageInfo();
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
if (!size) {
|
||||
func(new Error("GrayscaleTransformation The image size does not exist."), null)
|
||||
func.asyncTransform("GrayscaleTransformation The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
let targetWidth = size.width;
|
||||
let targetHeight = size.height;
|
||||
let targetWidth:number = size.width;
|
||||
let targetHeight:number = size.height;
|
||||
|
||||
var pixEntry: Array<PixelEntry> = new Array()
|
||||
let inPixels: Array<Array<number>> = CalculatePixelUtils.createInt2DArray(targetHeight, targetWidth);
|
||||
|
@ -42,8 +44,8 @@ export namespace pixelUtils {
|
|||
await bitmap.readPixelsToBuffer(bufferData);
|
||||
let dataArray = new Uint8Array(bufferData);
|
||||
|
||||
let ph = 0;
|
||||
let pw = 0;
|
||||
let ph:number = 0;
|
||||
let pw:number = 0;
|
||||
|
||||
|
||||
for (let index = 0; index < dataArray.length; index += 4) {
|
||||
|
@ -127,18 +129,18 @@ export namespace pixelUtils {
|
|||
}
|
||||
await bitmap.writeBufferToPixels(bufferNewData);
|
||||
if (func) {
|
||||
func("success", bitmap);
|
||||
func?.asyncTransform("success", bitmap);
|
||||
}
|
||||
}
|
||||
export async function pixelGPU(bitmap: any, pixel: number, func: AsyncTransform<PixelMap>) {
|
||||
export async function pixelGPU(bitmap: any, pixel: number, func?: AsyncTransform<PixelMap>) {
|
||||
|
||||
let imageInfo = await bitmap.getImageInfo();
|
||||
let size = {
|
||||
let size:Size = {
|
||||
width: imageInfo.size.width,
|
||||
height: imageInfo.size.height
|
||||
}
|
||||
if (!size) {
|
||||
func(new Error("GrayscaleTransformation The image size does not exist."), null)
|
||||
func?.asyncTransform("GrayscaleTransformation The image size does not exist.", null)
|
||||
return;
|
||||
}
|
||||
let w = size.width;
|
||||
|
@ -151,8 +153,8 @@ export namespace pixelUtils {
|
|||
filter.setPixel(pixel)
|
||||
filter.getPixelMapBuf(0, 0, w, h).then((buf) => {
|
||||
bitmap.writeBufferToPixels(buf);
|
||||
if (func) {
|
||||
func("success", bitmap);
|
||||
if (func!=undefined) {
|
||||
func?.asyncTransform("success", bitmap);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue