Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ImageFilter.java
Go to the documentation of this file.
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
8package org.skia.jetski;
9
10import androidx.annotation.NonNull;
11import androidx.annotation.Nullable;
12
13public 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 left Left, top, right, bottom are used to make the crop rect
49 * @param input The input filter that is blurred, uses source bitmap if this is null.
50 */
51 public static ImageFilter blur(float sigmaX, float sigmaY, TileMode tileMode,
52 float left, float top, float right, float bottom,
53 @Nullable ImageFilter input) {
54 long nativeInput = 0;
55 if (input != null) {
56 nativeInput = input.getNativeInstance();
57 }
58 return new ImageFilter(nBlur(sigmaX, sigmaY, tileMode.nativeInt,
59 left, top, right, bottom, nativeInput));
60 }
61
62 /**
63 * Create a filter that draws a drop shadow under the input content. This filter produces an
64 * image that includes the inputs' content.
65 * @param dx The X offset of the shadow.
66 * @param dy The Y offset of the shadow.
67 * @param sigmaX The blur radius for the shadow, along the X axis.
68 * @param sigmaY The blur radius for the shadow, along the Y axis.
69 * @param c The color of the drop shadow.
70 * @param input The input filter, or will use the source bitmap if this is null.
71 */
72 public static ImageFilter dropShadow(float dx, float dy,
73 float sigmaX, float sigmaY,
74 Color c, @Nullable ImageFilter input) {
75 long nativeInput = 0;
76 if (input != null) {
77 nativeInput = input.getNativeInstance();
78 }
79 return new ImageFilter(nDropShadow(dx, dy, sigmaX, sigmaY, c.r(), c.g(), c.b(), nativeInput));
80 }
81
82 public static ImageFilter blend(BlendMode blendMode, @Nullable ImageFilter background,
83 @Nullable ImageFilter foreground) {
84 long nativeBackground = 0;
85 long nativeForeground = 0;
86 if (background != null) {
87 nativeBackground = background.getNativeInstance();
88 }
89 if (foreground != null) {
90 nativeForeground = foreground.getNativeInstance();
91 }
92 return new ImageFilter(nBlend(blendMode.nativeInt, nativeBackground, nativeForeground));
93 }
94
95 public static ImageFilter image(@NonNull Image image) {
96 return new ImageFilter(nImage(image.getNativeInstance()));
97 }
98
99 /**
100 * Releases any resources associated with this Shader.
101 */
102 public void release() {
103 nRelease(mNativeInstance);
104 mNativeInstance = 0;
105 }
106
107 @Override
108 protected void finalize() throws Throwable {
109 release();
110 }
111
112 // package private
113 long getNativeInstance() { return mNativeInstance; }
114 private static native void nRelease(long nativeInstance);
115 private static native long nDistantLitDiffuse(float x, float y, float z,
116 float r, float g, float b,
117 float surfaceScale, float kd,
118 long native_input);
119 private static native long nBlur(float sigmaX, float sigmaY, int tileMode,
120 float l, float t, float r, float b, long native_input);
121 private static native long nDropShadow(float dx, float dy, float sigmaX, float sigmaY,
122 float r, float g, float b, long native_input);
123 private static native long nBlend(int blendMode, long native_background, long native_foreground);
124 private static native long nImage(long native_image);
125}
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
static ImageFilter distantLitDiffuse(float x, float y, float z, Color c, float surfaceScale, float kd, @Nullable ImageFilter input)
static ImageFilter dropShadow(float dx, float dy, float sigmaX, float sigmaY, Color c, @Nullable ImageFilter input)
static ImageFilter image(@NonNull Image image)
static ImageFilter blur(float sigmaX, float sigmaY, TileMode tileMode, float left, float top, float right, float bottom, @Nullable ImageFilter input)
static ImageFilter blend(BlendMode blendMode, @Nullable ImageFilter background, @Nullable ImageFilter foreground)
sk_sp< SkImage > image
Definition examples.cpp:29
static bool b
double y
double x