开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (2)
main
gh-pages
main
分支 (2)
main
gh-pages
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (2)
main
gh-pages
Java-Notes
/
JavaSourceLearn
/
src
/
java
/
awt
/
RadialGradientPaintContext.java
Java-Notes
/
JavaSourceLearn
/
src
/
java
/
awt
/
RadialGradientPaintContext.java
RadialGradientPaintContext.java 16.59 KB
一键复制 编辑 原始数据 按行查看 历史
cxylk 提交于 2021年01月21日 16:33 +08:00 . :rainbow: idea构建jdk源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package java.awt;
import java.awt.MultipleGradientPaint.CycleMethod;
import java.awt.MultipleGradientPaint.ColorSpaceType;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;
/**
* Provides the actual implementation for the RadialGradientPaint.
* This is where the pixel processing is done. A RadialGradienPaint
* only supports circular gradients, but it should be possible to scale
* the circle to look approximately elliptical, by means of a
* gradient transform passed into the RadialGradientPaint constructor.
*
* @author Nicholas Talian, Vincent Hardy, Jim Graham, Jerry Evans
*/
final class RadialGradientPaintContext extends MultipleGradientPaintContext {
/** True when (focus == center). */
private boolean isSimpleFocus = false;
/** True when (cycleMethod == NO_CYCLE). */
private boolean isNonCyclic = false;
/** Radius of the outermost circle defining the 100% gradient stop. */
private float radius;
/** Variables representing center and focus points. */
private float centerX, centerY, focusX, focusY;
/** Radius of the gradient circle squared. */
private float radiusSq;
/** Constant part of X, Y user space coordinates. */
private float constA, constB;
/** Constant second order delta for simple loop. */
private float gDeltaDelta;
/**
* This value represents the solution when focusX == X. It is called
* trivial because it is easier to calculate than the general case.
*/
private float trivial;
/** Amount for offset when clamping focus. */
private static final float SCALEBACK = .99f;
/**
* Constructor for RadialGradientPaintContext.
*
* @param paint the {@code RadialGradientPaint} from which this context
* is created
* @param cm the {@code ColorModel} that receives
* the {@code Paint} data (this is used only as a hint)
* @param deviceBounds the device space bounding box of the
* graphics primitive being rendered
* @param userBounds the user space bounding box of the
* graphics primitive being rendered
* @param t the {@code AffineTransform} from user
* space into device space (gradientTransform should be
* concatenated with this)
* @param hints the hints that the context object uses to choose
* between rendering alternatives
* @param cx the center X coordinate in user space of the circle defining
* the gradient. The last color of the gradient is mapped to
* the perimeter of this circle.
* @param cy the center Y coordinate in user space of the circle defining
* the gradient. The last color of the gradient is mapped to
* the perimeter of this circle.
* @param r the radius of the circle defining the extents of the
* color gradient
* @param fx the X coordinate in user space to which the first color
* is mapped
* @param fy the Y coordinate in user space to which the first color
* is mapped
* @param fractions the fractions specifying the gradient distribution
* @param colors the gradient colors
* @param cycleMethod either NO_CYCLE, REFLECT, or REPEAT
* @param colorSpace which colorspace to use for interpolation,
* either SRGB or LINEAR_RGB
*/
RadialGradientPaintContext(RadialGradientPaint paint,
ColorModel cm,
Rectangle deviceBounds,
Rectangle2D userBounds,
AffineTransform t,
RenderingHints hints,
float cx, float cy,
float r,
float fx, float fy,
float[] fractions,
Color[] colors,
CycleMethod cycleMethod,
ColorSpaceType colorSpace)
{
super(paint, cm, deviceBounds, userBounds, t, hints,
fractions, colors, cycleMethod, colorSpace);
// copy some parameters
centerX = cx;
centerY = cy;
focusX = fx;
focusY = fy;
radius = r;
this.isSimpleFocus = (focusX == centerX) && (focusY == centerY);
this.isNonCyclic = (cycleMethod == CycleMethod.NO_CYCLE);
// for use in the quadractic equation
radiusSq = radius * radius;
float dX = focusX - centerX;
float dY = focusY - centerY;
double distSq = (dX * dX) + (dY * dY);
// test if distance from focus to center is greater than the radius
if (distSq > radiusSq * SCALEBACK) {
// clamp focus to radius
float scalefactor = (float)Math.sqrt(radiusSq * SCALEBACK / distSq);
dX = dX * scalefactor;
dY = dY * scalefactor;
focusX = centerX + dX;
focusY = centerY + dY;
}
// calculate the solution to be used in the case where X == focusX
// in cyclicCircularGradientFillRaster()
trivial = (float)Math.sqrt(radiusSq - (dX * dX));
// constant parts of X, Y user space coordinates
constA = a02 - centerX;
constB = a12 - centerY;
// constant second order delta for simple loop
gDeltaDelta = 2 * ( a00 * a00 + a10 * a10) / radiusSq;
}
/**
* Return a Raster containing the colors generated for the graphics
* operation.
*
* @param x,y,w,h the area in device space for which colors are
* generated.
*/
protected void fillRaster(int pixels[], int off, int adjust,
int x, int y, int w, int h)
{
if (isSimpleFocus && isNonCyclic && isSimpleLookup) {
simpleNonCyclicFillRaster(pixels, off, adjust, x, y, w, h);
} else {
cyclicCircularGradientFillRaster(pixels, off, adjust, x, y, w, h);
}
}
/**
* This code works in the simplest of cases, where the focus == center
* point, the gradient is noncyclic, and the gradient lookup method is
* fast (single array index, no conversion necessary).
*/
private void simpleNonCyclicFillRaster(int pixels[], int off, int adjust,
int x, int y, int w, int h)
{
/* We calculate sqrt(X^2 + Y^2) relative to the radius
* size to get the fraction for the color to use.
*
* Each step along the scanline adds (a00, a10) to (X, Y).
* If we precalculate:
* gRel = X^2+Y^2
* for the start of the row, then for each step we need to
* calculate:
* gRel' = (X+a00)^2 + (Y+a10)^2
* = X^2 + 2*X*a00 + a00^2 + Y^2 + 2*Y*a10 + a10^2
* = (X^2+Y^2) + 2*(X*a00+Y*a10) + (a00^2+a10^2)
* = gRel + 2*(X*a00+Y*a10) + (a00^2+a10^2)
* = gRel + 2*DP + SD
* (where DP = dot product between X,Y and a00,a10
* and SD = dot product square of the delta vector)
* For the step after that we get:
* gRel'' = (X+2*a00)^2 + (Y+2*a10)^2
* = X^2 + 4*X*a00 + 4*a00^2 + Y^2 + 4*Y*a10 + 4*a10^2
* = (X^2+Y^2) + 4*(X*a00+Y*a10) + 4*(a00^2+a10^2)
* = gRel + 4*DP + 4*SD
* = gRel' + 2*DP + 3*SD
* The increment changed by:
* (gRel'' - gRel') - (gRel' - gRel)
* = (2*DP + 3*SD) - (2*DP + SD)
* = 2*SD
* Note that this value depends only on the (inverse of the)
* transformation matrix and so is a constant for the loop.
* To make this all relative to the unit circle, we need to
* divide all values as follows:
* [XY] /= radius
* gRel /= radiusSq
* DP /= radiusSq
* SD /= radiusSq
*/
// coordinates of UL corner in "user space" relative to center
float rowX = (a00*x) + (a01*y) + constA;
float rowY = (a10*x) + (a11*y) + constB;
// second order delta calculated in constructor
float gDeltaDelta = this.gDeltaDelta;
// adjust is (scan-w) of pixels array, we need (scan)
adjust += w;
// rgb of the 1.0 color used when the distance exceeds gradient radius
int rgbclip = gradient[fastGradientArraySize];
for (int j = 0; j < h; j++) {
// these values depend on the coordinates of the start of the row
float gRel = (rowX * rowX + rowY * rowY) / radiusSq;
float gDelta = (2 * ( a00 * rowX + a10 * rowY) / radiusSq +
gDeltaDelta/2);
/* Use optimized loops for any cases where gRel >= 1.
* We do not need to calculate sqrt(gRel) for these
* values since sqrt(N>=1) == (M>=1).
* Note that gRel follows a parabola which can only be < 1
* for a small region around the center on each scanline. In
* particular:
* gDeltaDelta is always positive
* gDelta is <0 until it crosses the midpoint, then >0
* To the left and right of that region, it will always be
* >=1 out to infinity, so we can process the line in 3
* regions:
* out to the left - quick fill until gRel < 1, updating gRel
* in the heart - slow fraction=sqrt fill while gRel < 1
* out to the right - quick fill rest of scanline, ignore gRel
*/
int i = 0;
// Quick fill for "out to the left"
while (i < w && gRel >= 1.0f) {
pixels[off + i] = rgbclip;
gRel += gDelta;
gDelta += gDeltaDelta;
i++;
}
// Slow fill for "in the heart"
while (i < w && gRel < 1.0f) {
int gIndex;
if (gRel <= 0) {
gIndex = 0;
} else {
float fIndex = gRel * SQRT_LUT_SIZE;
int iIndex = (int) (fIndex);
float s0 = sqrtLut[iIndex];
float s1 = sqrtLut[iIndex+1] - s0;
fIndex = s0 + (fIndex - iIndex) * s1;
gIndex = (int) (fIndex * fastGradientArraySize);
}
// store the color at this point
pixels[off + i] = gradient[gIndex];
// incremental calculation
gRel += gDelta;
gDelta += gDeltaDelta;
i++;
}
// Quick fill to end of line for "out to the right"
while (i < w) {
pixels[off + i] = rgbclip;
i++;
}
off += adjust;
rowX += a01;
rowY += a11;
}
}
// SQRT_LUT_SIZE must be a power of 2 for the test above to work.
private static final int SQRT_LUT_SIZE = (1 << 11);
private static float sqrtLut[] = new float[SQRT_LUT_SIZE+1];
static {
for (int i = 0; i < sqrtLut.length; i++) {
sqrtLut[i] = (float) Math.sqrt(i / ((float) SQRT_LUT_SIZE));
}
}
/**
* Fill the raster, cycling the gradient colors when a point falls outside
* of the perimeter of the 100% stop circle.
*
* This calculation first computes the intersection point of the line
* from the focus through the current point in the raster, and the
* perimeter of the gradient circle.
*
* Then it determines the percentage distance of the current point along
* that line (focus is 0%, perimeter is 100%).
*
* Equation of a circle centered at (a,b) with radius r:
* (x-a)^2 + (y-b)^2 = r^2
* Equation of a line with slope m and y-intercept b:
* y = mx + b
* Replacing y in the circle equation and solving using the quadratic
* formula produces the following set of equations. Constant factors have
* been extracted out of the inner loop.
*/
private void cyclicCircularGradientFillRaster(int pixels[], int off,
int adjust,
int x, int y,
int w, int h)
{
// constant part of the C factor of the quadratic equation
final double constC =
-radiusSq + (centerX * centerX) + (centerY * centerY);
// coefficients of the quadratic equation (Ax^2 + Bx + C = 0)
double A, B, C;
// slope and y-intercept of the focus-perimeter line
double slope, yintcpt;
// intersection with circle X,Y coordinate
double solutionX, solutionY;
// constant parts of X, Y coordinates
final float constX = (a00*x) + (a01*y) + a02;
final float constY = (a10*x) + (a11*y) + a12;
// constants in inner loop quadratic formula
final float precalc2 = 2 * centerY;
final float precalc3 = -2 * centerX;
// value between 0 and 1 specifying position in the gradient
float g;
// determinant of quadratic formula (should always be > 0)
float det;
// sq distance from the current point to focus
float currentToFocusSq;
// sq distance from the intersect point to focus
float intersectToFocusSq;
// temp variables for change in X,Y squared
float deltaXSq, deltaYSq;
// used to index pixels array
int indexer = off;
// incremental index change for pixels array
int pixInc = w+adjust;
// for every row
for (int j = 0; j < h; j++) {
// user space point; these are constant from column to column
float X = (a01*j) + constX;
float Y = (a11*j) + constY;
// for every column (inner loop begins here)
for (int i = 0; i < w; i++) {
if (X == focusX) {
// special case to avoid divide by zero
solutionX = focusX;
solutionY = centerY;
solutionY += (Y > focusY) ? trivial : -trivial;
} else {
// slope and y-intercept of the focus-perimeter line
slope = (Y - focusY) / (X - focusX);
yintcpt = Y - (slope * X);
// use the quadratic formula to calculate the
// intersection point
A = (slope * slope) + 1;
B = precalc3 + (-2 * slope * (centerY - yintcpt));
C = constC + (yintcpt* (yintcpt - precalc2));
det = (float)Math.sqrt((B * B) - (4 * A * C));
solutionX = -B;
// choose the positive or negative root depending
// on where the X coord lies with respect to the focus
solutionX += (X < focusX)? -det : det;
solutionX = solutionX / (2 * A); // divisor
solutionY = (slope * solutionX) + yintcpt;
}
// Calculate the square of the distance from the current point
// to the focus and the square of the distance from the
// intersection point to the focus. Want the squares so we can
// do 1 square root after division instead of 2 before.
deltaXSq = X - focusX;
deltaXSq = deltaXSq * deltaXSq;
deltaYSq = Y - focusY;
deltaYSq = deltaYSq * deltaYSq;
currentToFocusSq = deltaXSq + deltaYSq;
deltaXSq = (float)solutionX - focusX;
deltaXSq = deltaXSq * deltaXSq;
deltaYSq = (float)solutionY - focusY;
deltaYSq = deltaYSq * deltaYSq;
intersectToFocusSq = deltaXSq + deltaYSq;
// get the percentage (0-1) of the current point along the
// focus-circumference line
g = (float)Math.sqrt(currentToFocusSq / intersectToFocusSq);
// store the color at this point
pixels[indexer + i] = indexIntoGradientsArrays(g);
// incremental change in X, Y
X += a00;
Y += a10;
} //end inner loop
indexer += pixInc;
} //end outer loop
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

Java学习过程中遇到的知识点总结,复习笔记
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cxylk/Java-Notes.git
git@gitee.com:cxylk/Java-Notes.git
cxylk
Java-Notes
Java-Notes
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /