Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/unix/classes/sun/java2d/xr/XRUtils.java
41159 views
1
/*
2
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.java2d.xr;
27
28
import java.awt.*;
29
import java.awt.geom.Point2D;
30
import java.awt.MultipleGradientPaint.*;
31
import java.awt.geom.AffineTransform;
32
import java.awt.image.*;
33
import sun.java2d.loops.*;
34
import static java.awt.AlphaComposite.*;
35
36
/**
37
* XRender constants and utility methods.
38
*
39
* @author Clemens Eisserer
40
*/
41
42
public class XRUtils {
43
public static final int None = 0;
44
45
/* Composition Operators */
46
public static final byte PictOpClear = 0;
47
public static final byte PictOpSrc = 1;
48
public static final byte PictOpDst = 2;
49
public static final byte PictOpOver = 3;
50
public static final byte PictOpOverReverse = 4;
51
public static final byte PictOpIn = 5;
52
public static final byte PictOpInReverse = 6;
53
public static final byte PictOpOut = 7;
54
public static final byte PictOpOutReverse = 8;
55
public static final byte PictOpAtop = 9;
56
public static final byte PictOpAtopReverse = 10;
57
public static final byte PictOpXor = 11;
58
public static final byte PictOpAdd = 12;
59
public static final byte PictOpSaturate = 13;
60
61
/* Repeats */
62
public static final int RepeatNone = 0;
63
public static final int RepeatNormal = 1;
64
public static final int RepeatPad = 2;
65
public static final int RepeatReflect = 3;
66
67
/* Interpolation qualities */
68
public static final int FAST = 0;
69
public static final int GOOD = 1;
70
public static final int BEST = 2;
71
public static final byte[] FAST_NAME = "fast".getBytes();
72
public static final byte[] GOOD_NAME = "good".getBytes();
73
public static final byte[] BEST_NAME = "best".getBytes();
74
75
/* PictFormats */
76
public static final int PictStandardARGB32 = 0;
77
public static final int PictStandardRGB24 = 1;
78
public static final int PictStandardA8 = 2;
79
public static final int PictStandardA4 = 3;
80
public static final int PictStandardA1 = 4;
81
82
/**
83
* Maps the specified affineTransformOp to the corresponding XRender image
84
* filter.
85
*/
86
public static int ATransOpToXRQuality(int affineTranformOp) {
87
88
switch (affineTranformOp) {
89
case AffineTransformOp.TYPE_NEAREST_NEIGHBOR:
90
return FAST;
91
92
case AffineTransformOp.TYPE_BILINEAR:
93
return GOOD;
94
95
case AffineTransformOp.TYPE_BICUBIC:
96
return BEST;
97
}
98
99
return -1;
100
}
101
102
/**
103
* Maps the specified affineTransformOp to the corresponding XRender image
104
* filter.
105
*/
106
public static byte[] ATransOpToXRQualityName(int affineTranformOp) {
107
108
switch (affineTranformOp) {
109
case AffineTransformOp.TYPE_NEAREST_NEIGHBOR:
110
return FAST_NAME;
111
112
case AffineTransformOp.TYPE_BILINEAR:
113
return GOOD_NAME;
114
115
case AffineTransformOp.TYPE_BICUBIC:
116
return BEST_NAME;
117
}
118
119
return null;
120
}
121
122
123
public static byte[] getFilterName(int filterType) {
124
switch (filterType) {
125
case FAST:
126
return FAST_NAME;
127
case GOOD:
128
return GOOD_NAME;
129
case BEST:
130
return BEST_NAME;
131
}
132
133
return null;
134
}
135
136
137
/**
138
* Returns the XRender picture Format which is required to fullfill the
139
* Java2D transparency requirement.
140
*/
141
public static int getPictureFormatForTransparency(int transparency) {
142
switch (transparency) {
143
case Transparency.OPAQUE:
144
return PictStandardRGB24;
145
146
case Transparency.BITMASK:
147
case Transparency.TRANSLUCENT:
148
return PictStandardARGB32;
149
}
150
151
return -1;
152
}
153
154
155
public static SurfaceType getXRSurfaceTypeForTransparency(int transparency) {
156
if (transparency == Transparency.OPAQUE) {
157
return SurfaceType.IntRgb;
158
}else {
159
return SurfaceType.IntArgbPre;
160
}
161
}
162
163
/**
164
* Maps Java2D CycleMethod to XRender's Repeat property.
165
*/
166
public static int getRepeatForCycleMethod(CycleMethod cycleMethod) {
167
if (cycleMethod.equals(CycleMethod.NO_CYCLE)) {
168
return RepeatPad;
169
} else if (cycleMethod.equals(CycleMethod.REFLECT)) {
170
return RepeatReflect;
171
} else if (cycleMethod.equals(CycleMethod.REPEAT)) {
172
return RepeatNormal;
173
}
174
175
return RepeatNone;
176
}
177
178
/**
179
* Converts a double into an XFixed.
180
*/
181
public static int XDoubleToFixed(double dbl) {
182
return (int) (dbl * 65536);
183
}
184
185
public static double XFixedToDouble(int fixed) {
186
return ((double) fixed) / 65536;
187
}
188
189
public static int[] convertFloatsToFixed(float[] values) {
190
int[] fixed = new int[values.length];
191
192
for (int i = 0; i < values.length; i++) {
193
fixed[i] = XDoubleToFixed(values[i]);
194
}
195
196
return fixed;
197
}
198
199
public static long intToULong(int signed) {
200
if (signed < 0) {
201
return ((long) signed) + (((long) Integer.MAX_VALUE) -
202
((long) Integer.MIN_VALUE) + 1);
203
}
204
205
return signed;
206
}
207
208
/**
209
* Maps the specified Java2D composition rule, to the corresponding XRender
210
* composition rule.
211
*/
212
public static byte j2dAlphaCompToXR(int j2dRule) {
213
switch (j2dRule) {
214
case CLEAR:
215
return PictOpClear;
216
217
case SRC:
218
return PictOpSrc;
219
220
case DST:
221
return PictOpDst;
222
223
case SRC_OVER:
224
return PictOpOver;
225
226
case DST_OVER:
227
return PictOpOverReverse;
228
229
case SRC_IN:
230
return PictOpIn;
231
232
case DST_IN:
233
return PictOpInReverse;
234
235
case SRC_OUT:
236
return PictOpOut;
237
238
case DST_OUT:
239
return PictOpOutReverse;
240
241
case SRC_ATOP:
242
return PictOpAtop;
243
244
case DST_ATOP:
245
return PictOpAtopReverse;
246
247
case XOR:
248
return PictOpXor;
249
}
250
251
throw new InternalError("No XRender equivalent available for requested java2d composition rule: "+j2dRule);
252
}
253
254
public static short clampToShort(int x) {
255
return (short) (x > Short.MAX_VALUE
256
? Short.MAX_VALUE
257
: (x < Short.MIN_VALUE ? Short.MIN_VALUE : x));
258
}
259
260
public static int clampToUShort(int x) {
261
return (x > 65535 ? 65535 : (x < 0) ? 0 : x);
262
}
263
264
public static boolean isDoubleInShortRange(double dbl) {
265
return dbl <= Short.MAX_VALUE && dbl >= Short.MIN_VALUE;
266
}
267
268
public static boolean isPointCoordInShortRange(Point2D p) {
269
return isDoubleInShortRange(p.getX()) && isDoubleInShortRange(p.getY());
270
}
271
272
273
public static boolean isTransformQuadrantRotated(AffineTransform tr) {
274
return ((tr.getType() & (AffineTransform.TYPE_GENERAL_ROTATION |
275
AffineTransform.TYPE_GENERAL_TRANSFORM)) == 0);
276
}
277
278
public static boolean isMaskEvaluated(byte xrCompRule) {
279
switch (xrCompRule) {
280
case PictOpOver:
281
case PictOpOverReverse:
282
case PictOpAtop:
283
case PictOpXor:
284
return true;
285
}
286
287
return false;
288
}
289
}
290
291