1 /*
2 * Copyright (c) 2002, 2003, 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
121 h *= 60.0f;
122 if (h < 0) {
123 h += 360.0f;
124 }
125 }
126 if (hls == null) {
127 hls = new float[3];
128 }
129 hls[0] = h;
130 hls[1] = l;
131 hls[2] = s;
132 return hls;
133 }
134
135 /**
136 * Creates and returns a new color derived from the passed in color.
137 * The transformation is done in the HLS color space using the specified
138 * arguments to scale.
139 *
140 * @param color Color to alter
141 * @param hFactory Amount to scale the hue
142 * @param lFactor Amount to scale the lightness
143 * @param sFactory Amount to sacle saturation
144 * @return newly created color
145 */
146 static Color adjustColor(Color color, float hFactor, float lFactor,
147 float sFactor) {
148 float h;
149 float l;
150 float s;
151
152 synchronized(HLS_COLOR_LOCK) {
153 float[] hls = rgbToHLS(color.getRGB(), HLS_COLORS);
154 h = hls[0];
155 l = hls[1];
156 s = hls[2];
157 }
158 h = Math.min(360, hFactor * h);
159 l = Math.min(1, lFactor * l);
160 s = Math.min(1, sFactor * s);
161 return new ColorUIResource(hlsToRGB(h, l, s));
162 }
163
|
1 /*
2 * Copyright (c) 2002, 2017, 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
121 h *= 60.0f;
122 if (h < 0) {
123 h += 360.0f;
124 }
125 }
126 if (hls == null) {
127 hls = new float[3];
128 }
129 hls[0] = h;
130 hls[1] = l;
131 hls[2] = s;
132 return hls;
133 }
134
135 /**
136 * Creates and returns a new color derived from the passed in color.
137 * The transformation is done in the HLS color space using the specified
138 * arguments to scale.
139 *
140 * @param color Color to alter
141 * @param hFactor Amount to scale the hue
142 * @param lFactor Amount to scale the lightness
143 * @param sFactor Amount to sacle saturation
144 * @return newly created color
145 */
146 static Color adjustColor(Color color, float hFactor, float lFactor,
147 float sFactor) {
148 float h;
149 float l;
150 float s;
151
152 synchronized(HLS_COLOR_LOCK) {
153 float[] hls = rgbToHLS(color.getRGB(), HLS_COLORS);
154 h = hls[0];
155 l = hls[1];
156 s = hls[2];
157 }
158 h = Math.min(360, hFactor * h);
159 l = Math.min(1, lFactor * l);
160 s = Math.min(1, sFactor * s);
161 return new ColorUIResource(hlsToRGB(h, l, s));
162 }
163
|