Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / platform_tools / android / apps / AndroidKit / src / main / java / org / skia / androidkit / ImageFilter.java
1 /*
2  * Copyright 2021 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 package org.skia.androidkit;
9
10 import android.support.annotation.NonNull;
11 import android.support.annotation.Nullable;
12
13 public class ImageFilter {
14     private long mNativeInstance;
15
16     private ImageFilter(long native_instance) {
17         mNativeInstance = native_instance;
18     }
19
20     /**
21      *  Create a filter that calculates the diffuse illumination from a distant light source,
22      *  interpreting the alpha channel of the input as the height profile of the surface (to
23      *  approximate normal vectors).
24      *  @param x, y, z      The direction to the distance light.
25      *  @param c            The color of the diffuse light source.
26      *  @param surfaceScale Scale factor to transform from alpha values to physical height.
27      *  @param kd           Diffuse reflectance coefficient.
28      *  @param input        The input filter that defines surface normals (as alpha), or uses the
29      *                      source bitmap when null.
30      */
31     public static ImageFilter distantLitDiffuse(float x, float y, float z, Color c,
32                                                 float surfaceScale, float kd, @Nullable ImageFilter input) {
33         long nativeInput = 0;
34         if (input != null) {
35             nativeInput = input.getNativeInstance();
36         }
37         return new ImageFilter(nDistantLitDiffuse(x, y, z, c.r(), c.g(), c.b(),
38                                                   surfaceScale, kd, nativeInput));
39     }
40
41     /**
42      *  Create a filter that calculates the diffuse illumination from a distant light source,
43      *  interpreting the alpha channel of the input as the height profile of the surface (to
44      *  approximate normal vectors).
45      *  @param sigmaX   The Gaussian sigma value for blurring along the X axis.
46      *  @param sigmaY   The Gaussian sigma value for blurring along the Y axis.
47      *  @param tileMode The tile mode applied at edges
48      *  @param input    The input filter that is blurred, uses source bitmap if this is null.
49      */
50     public static ImageFilter blur(float sigmaX, float sigmaY, TileMode tileMode, @Nullable ImageFilter input) {
51         long nativeInput = 0;
52         if (input != null) {
53             nativeInput = input.getNativeInstance();
54         }
55         return new ImageFilter(nBlur(sigmaX, sigmaY, tileMode.nativeInt, nativeInput));
56     }
57
58     /**
59      *  Create a filter that draws a drop shadow under the input content. This filter produces an
60      *  image that includes the inputs' content.
61      *  @param dx       The X offset of the shadow.
62      *  @param dy       The Y offset of the shadow.
63      *  @param sigmaX   The blur radius for the shadow, along the X axis.
64      *  @param sigmaY   The blur radius for the shadow, along the Y axis.
65      *  @param c    The color of the drop shadow.
66      *  @param input    The input filter, or will use the source bitmap if this is null.
67      */
68     public static ImageFilter dropShadow(float dx, float dy,
69                                          float sigmaX, float sigmaY,
70                                          Color c, @Nullable ImageFilter input) {
71         long nativeInput = 0;
72         if (input != null) {
73             nativeInput = input.getNativeInstance();
74         }
75         return new ImageFilter(nDropShadow(dx, dy, sigmaX, sigmaY, c.r(), c.g(), c.b(), nativeInput));
76     }
77
78     public static ImageFilter blend(BlendMode blendMode, @Nullable ImageFilter background,
79                                                          @Nullable ImageFilter foreground) {
80         long nativeBackground = 0;
81         long nativeForeground = 0;
82         if (background != null) {
83             nativeBackground = background.getNativeInstance();
84         }
85         if (foreground != null) {
86             nativeForeground = foreground.getNativeInstance();
87         }
88         return new ImageFilter(nBlend(blendMode.nativeInt, nativeBackground, nativeForeground));
89     }
90
91     public static ImageFilter image(@NonNull Image image) {
92         return new ImageFilter(nImage(image.getNativeInstance()));
93     }
94
95     /**
96      * Releases any resources associated with this Shader.
97      */
98     public void release() {
99         nRelease(mNativeInstance);
100         mNativeInstance = 0;
101     }
102
103     @Override
104     protected void finalize() throws Throwable {
105         release();
106     }
107
108     // package private
109     long getNativeInstance() { return mNativeInstance; }
110     private static native void nRelease(long nativeInstance);
111     private static native long nDistantLitDiffuse(float x, float y, float z,
112                                                   float r, float g, float b,
113                                                   float surfaceScale, float kd,
114                                                   long native_input);
115     private static native long nBlur(float sigmaX, float sigmaY, int tileMode, long native_input);
116     private static native long nDropShadow(float dx, float dy, float sigmaX, float sigmaY,
117                                            float r, float g, float b, long native_input);
118     private static native long nBlend(int blendMode, long native_background, long native_foreground);
119     private static native long nImage(long native_image);
120 }