• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { BusinessError } from '@ohos.base';
17import image from '@ohos.multimedia.image';
18
19namespace effectKit {
20  loadLibrary('effectKit_ani')
21  /**
22   * The Filter of FilterChain.
23   * @typedef Filter
24   * @syscap SystemCapability.Multimedia.Image.Core
25   * @since 9
26   */
27  /**
28   * The Filter of FilterChain.
29   * @typedef Filter
30   * @syscap SystemCapability.Multimedia.Image.Core
31   * @form
32   * @atomicservice
33   * @since 12
34   */
35  export interface Filter {
36    /**
37    * A blur effect is added to the image.
38    * @param { number } radius - The degree of blur, the value is measured in pixels.
39    * @returns { Filter } Filters for the current effect have been added.
40    * @syscap SystemCapability.Multimedia.Image.Core
41    * @since 9
42    */
43    /**
44    * A blur effect is added to the image.
45    * @param { number } radius - The degree of blur, the value is measured in pixels.
46    * @returns { Filter } Filters for the current effect have been added.
47    * @syscap SystemCapability.Multimedia.Image.Core
48    * @form
49    * @atomicservice
50    * @since 12
51    */
52    blur(radius: number): Filter;
53
54    /**
55    * A Grayscale effect is added to the image.
56    * @returns { Filter } Filters for the current effect have been added.
57    * @syscap SystemCapability.Multimedia.Image.Core
58    * @since 9
59    */
60    /**
61    * A Grayscale effect is added to the image.
62    * @returns { Filter } Filters for the current effect have been added.
63    * @syscap SystemCapability.Multimedia.Image.Core
64    * @form
65    * @atomicservice
66    * @since 12
67    */
68    /**
69    * A Grayscale effect is added to the image.
70    * @returns { Filter } Filters for the current effect have been added.
71    * @syscap SystemCapability.Multimedia.Image.Core
72    * @form
73    * @atomicservice
74    * @since 14
75    */
76    grayscale(): Filter;
77
78    /**
79    * Gets the PixelMap where all filter effects have been added to the image.
80    * @returns { Promise<image.PixelMap> } - returns the PixelMap generated.
81    * @syscap SystemCapability.Multimedia.Image.Core
82    * @since 11
83    */
84    /**
85    * Gets the PixelMap where all filter effects have been added to the image.
86    * @returns { Promise<image.PixelMap> } - returns the PixelMap generated.
87    * @syscap SystemCapability.Multimedia.Image.Core
88    * @form
89    * @atomicservice
90    * @since 12
91    */
92    getEffectPixelMap(): Promise<image.PixelMap>;
93  }
94
95  export class FilterInternal implements Filter {
96    private nativeObj: long = 0;
97
98    constructor(context: long) {
99      if (this.nativeObj == 0) {
100        this.nativeObj = context;
101      }
102    }
103
104    public native blurNative(radius: double): Filter;
105
106    public native grayscaleNative(): Filter;
107
108    public native getEffectPixelMapNative(): image.PixelMap;
109
110    public blur(radius: number): Filter {
111      return this.blurNative(radius);
112    }
113
114    public grayscale(): Filter {
115      return this.grayscaleNative();
116    }
117
118    public getEffectPixelMap(): Promise<image.PixelMap> {
119      return new Promise<image.PixelMap>((resolve: (value: image.PixelMap) => void,
120        reject: (error: BusinessError) => void) => {
121        taskpool.execute((): image.PixelMap => {
122          let pixelMap = this.getEffectPixelMapNative();
123          return pixelMap;
124        }).then((ret: NullishType) => {
125          resolve(ret as image.PixelMap);
126        }).catch((err: NullishType) => {
127          reject(err as BusinessError);
128        });
129      });
130    }
131  }
132
133  export native function createEffect(source: image.PixelMap): Filter;
134}
135
136export default effectKit;