ARGB.java
net.minecraft.util.ARGB
信息
- 全限定名:net.minecraft.util.ARGB
- 类型:public class
- 包:net.minecraft.util
- 源码路径:src/main/java/net/minecraft/util/ARGB.java
- 起始行号:L7
- 职责:
TODO
字段/常量
-
LINEAR_CHANNEL_DEPTH- 类型:
int - 修饰符:
private static final - 源码定位:
L8 - 说明:
TODO
- 类型:
-
SRGB_TO_LINEAR- 类型:
short[] - 修饰符:
private static final - 源码定位:
L9 - 说明:
TODO
- 类型:
-
LINEAR_TO_SRGB- 类型:
byte[] - 修饰符:
private static final - 源码定位:
L15 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
private static float computeSrgbToLinear(float x) @ L22
- 方法名:computeSrgbToLinear
- 源码定位:L22
- 返回类型:float
- 修饰符:private static
参数:
- x: float
说明:
TODO
private static float computeLinearToSrgb(float x) @ L26
- 方法名:computeLinearToSrgb
- 源码定位:L26
- 返回类型:float
- 修饰符:private static
参数:
- x: float
说明:
TODO
public static float srgbToLinearChannel(int srgb) @ L30
- 方法名:srgbToLinearChannel
- 源码定位:L30
- 返回类型:float
- 修饰符:public static
参数:
- srgb: int
说明:
TODO
public static int linearToSrgbChannel(float linear) @ L34
- 方法名:linearToSrgbChannel
- 源码定位:L34
- 返回类型:int
- 修饰符:public static
参数:
- linear: float
说明:
TODO
public static int meanLinear(int srgb1, int srgb2, int srgb3, int srgb4) @ L38
- 方法名:meanLinear
- 源码定位:L38
- 返回类型:int
- 修饰符:public static
参数:
- srgb1: int
- srgb2: int
- srgb3: int
- srgb4: int
说明:
TODO
private static int linearChannelMean(int c1, int c2, int c3, int c4) @ L47
- 方法名:linearChannelMean
- 源码定位:L47
- 返回类型:int
- 修饰符:private static
参数:
- c1: int
- c2: int
- c3: int
- c4: int
说明:
TODO
public static int alpha(int color) @ L52
- 方法名:alpha
- 源码定位:L52
- 返回类型:int
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static int red(int color) @ L56
- 方法名:red
- 源码定位:L56
- 返回类型:int
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static int green(int color) @ L60
- 方法名:green
- 源码定位:L60
- 返回类型:int
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static int blue(int color) @ L64
- 方法名:blue
- 源码定位:L64
- 返回类型:int
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static int color(int alpha, int red, int green, int blue) @ L68
- 方法名:color
- 源码定位:L68
- 返回类型:int
- 修饰符:public static
参数:
- alpha: int
- red: int
- green: int
- blue: int
说明:
TODO
public static int color(int red, int green, int blue) @ L72
- 方法名:color
- 源码定位:L72
- 返回类型:int
- 修饰符:public static
参数:
- red: int
- green: int
- blue: int
说明:
TODO
public static int color(Vec3 vec) @ L76
- 方法名:color
- 源码定位:L76
- 返回类型:int
- 修饰符:public static
参数:
- vec: Vec3
说明:
TODO
public static int multiply(int lhs, int rhs) @ L80
- 方法名:multiply
- 源码定位:L80
- 返回类型:int
- 修饰符:public static
参数:
- lhs: int
- rhs: int
说明:
TODO
public static int addRgb(int lhs, int rhs) @ L90
- 方法名:addRgb
- 源码定位:L90
- 返回类型:int
- 修饰符:public static
参数:
- lhs: int
- rhs: int
说明:
TODO
public static int subtractRgb(int lhs, int rhs) @ L94
- 方法名:subtractRgb
- 源码定位:L94
- 返回类型:int
- 修饰符:public static
参数:
- lhs: int
- rhs: int
说明:
TODO
public static int multiplyAlpha(int color, float alphaMultiplier) @ L98
- 方法名:multiplyAlpha
- 源码定位:L98
- 返回类型:int
- 修饰符:public static
参数:
- color: int
- alphaMultiplier: float
说明:
TODO
public static int scaleRGB(int color, float scale) @ L106
- 方法名:scaleRGB
- 源码定位:L106
- 返回类型:int
- 修饰符:public static
参数:
- color: int
- scale: float
说明:
TODO
public static int scaleRGB(int color, float scaleR, float scaleG, float scaleB) @ L110
- 方法名:scaleRGB
- 源码定位:L110
- 返回类型:int
- 修饰符:public static
参数:
- color: int
- scaleR: float
- scaleG: float
- scaleB: float
说明:
TODO
public static int scaleRGB(int color, int scale) @ L119
- 方法名:scaleRGB
- 源码定位:L119
- 返回类型:int
- 修饰符:public static
参数:
- color: int
- scale: int
说明:
TODO
public static int greyscale(int color) @ L128
- 方法名:greyscale
- 源码定位:L128
- 返回类型:int
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static int alphaBlend(int destination, int source) @ L133
- 方法名:alphaBlend
- 源码定位:L133
- 返回类型:int
- 修饰符:public static
参数:
- destination: int
- source: int
说明:
TODO
private static int alphaBlendChannel(int resultAlpha, int sourceAlpha, int destination, int source) @ L151
- 方法名:alphaBlendChannel
- 源码定位:L151
- 返回类型:int
- 修饰符:private static
参数:
- resultAlpha: int
- sourceAlpha: int
- destination: int
- source: int
说明:
TODO
public static int srgbLerp(float alpha, int p0, int p1) @ L155
- 方法名:srgbLerp
- 源码定位:L155
- 返回类型:int
- 修饰符:public static
参数:
- alpha: float
- p0: int
- p1: int
说明:
TODO
public static int linearLerp(float alpha, int p0, int p1) @ L163
- 方法名:linearLerp
- 源码定位:L163
- 返回类型:int
- 修饰符:public static
参数:
- alpha: float
- p0: int
- p1: int
说明:
TODO
public static int opaque(int color) @ L172
- 方法名:opaque
- 源码定位:L172
- 返回类型:int
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static int transparent(int color) @ L176
- 方法名:transparent
- 源码定位:L176
- 返回类型:int
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static int color(int alpha, int rgb) @ L180
- 方法名:color
- 源码定位:L180
- 返回类型:int
- 修饰符:public static
参数:
- alpha: int
- rgb: int
说明:
TODO
public static int color(float alpha, int rgb) @ L184
- 方法名:color
- 源码定位:L184
- 返回类型:int
- 修饰符:public static
参数:
- alpha: float
- rgb: int
说明:
TODO
public static int white(float alpha) @ L188
- 方法名:white
- 源码定位:L188
- 返回类型:int
- 修饰符:public static
参数:
- alpha: float
说明:
TODO
public static int white(int alpha) @ L192
- 方法名:white
- 源码定位:L192
- 返回类型:int
- 修饰符:public static
参数:
- alpha: int
说明:
TODO
public static int black(float alpha) @ L196
- 方法名:black
- 源码定位:L196
- 返回类型:int
- 修饰符:public static
参数:
- alpha: float
说明:
TODO
public static int black(int alpha) @ L200
- 方法名:black
- 源码定位:L200
- 返回类型:int
- 修饰符:public static
参数:
- alpha: int
说明:
TODO
public static int gray(float brightness) @ L204
- 方法名:gray
- 源码定位:L204
- 返回类型:int
- 修饰符:public static
参数:
- brightness: float
说明:
TODO
public static int colorFromFloat(float alpha, float red, float green, float blue) @ L209
- 方法名:colorFromFloat
- 源码定位:L209
- 返回类型:int
- 修饰符:public static
参数:
- alpha: float
- red: float
- green: float
- blue: float
说明:
TODO
public static Vector3f vector3fFromRGB24(int color) @ L213
- 方法名:vector3fFromRGB24
- 源码定位:L213
- 返回类型:Vector3f
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static Vector4f vector4fFromARGB32(int color) @ L217
- 方法名:vector4fFromARGB32
- 源码定位:L217
- 返回类型:Vector4f
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static int average(int lhs, int rhs) @ L221
- 方法名:average
- 源码定位:L221
- 返回类型:int
- 修饰符:public static
参数:
- lhs: int
- rhs: int
说明:
TODO
public static int as8BitChannel(float value) @ L225
- 方法名:as8BitChannel
- 源码定位:L225
- 返回类型:int
- 修饰符:public static
参数:
- value: float
说明:
TODO
public static float alphaFloat(int color) @ L229
- 方法名:alphaFloat
- 源码定位:L229
- 返回类型:float
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static float redFloat(int color) @ L233
- 方法名:redFloat
- 源码定位:L233
- 返回类型:float
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static float greenFloat(int color) @ L237
- 方法名:greenFloat
- 源码定位:L237
- 返回类型:float
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static float blueFloat(int color) @ L241
- 方法名:blueFloat
- 源码定位:L241
- 返回类型:float
- 修饰符:public static
参数:
- color: int
说明:
TODO
private static float from8BitChannel(int value) @ L245
- 方法名:from8BitChannel
- 源码定位:L245
- 返回类型:float
- 修饰符:private static
参数:
- value: int
说明:
TODO
public static int toABGR(int color) @ L249
- 方法名:toABGR
- 源码定位:L249
- 返回类型:int
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static int fromABGR(int color) @ L253
- 方法名:fromABGR
- 源码定位:L253
- 返回类型:int
- 修饰符:public static
参数:
- color: int
说明:
TODO
public static int setBrightness(int color, float brightness) @ L257
- 方法名:setBrightness
- 源码定位:L257
- 返回类型:int
- 修饰符:public static
参数:
- color: int
- brightness: float
说明:
TODO
代码
public class ARGB {
private static final int LINEAR_CHANNEL_DEPTH = 1024;
private static final short[] SRGB_TO_LINEAR = Util.make(new short[256], lookup -> {
for (int i = 0; i < lookup.length; i++) {
float channel = i / 255.0F;
lookup[i] = (short)Math.round(computeSrgbToLinear(channel) * 1023.0F);
}
});
private static final byte[] LINEAR_TO_SRGB = Util.make(new byte[1024], lookup -> {
for (int i = 0; i < lookup.length; i++) {
float channel = i / 1023.0F;
lookup[i] = (byte)Math.round(computeLinearToSrgb(channel) * 255.0F);
}
});
private static float computeSrgbToLinear(float x) {
return x >= 0.04045F ? (float)Math.pow((x + 0.055) / 1.055, 2.4) : x / 12.92F;
}
private static float computeLinearToSrgb(float x) {
return x >= 0.0031308F ? (float)(1.055 * Math.pow(x, 0.4166666666666667) - 0.055) : 12.92F * x;
}
public static float srgbToLinearChannel(int srgb) {
return SRGB_TO_LINEAR[srgb] / 1023.0F;
}
public static int linearToSrgbChannel(float linear) {
return LINEAR_TO_SRGB[Mth.floor(linear * 1023.0F)] & 0xFF;
}
public static int meanLinear(int srgb1, int srgb2, int srgb3, int srgb4) {
return color(
(alpha(srgb1) + alpha(srgb2) + alpha(srgb3) + alpha(srgb4)) / 4,
linearChannelMean(red(srgb1), red(srgb2), red(srgb3), red(srgb4)),
linearChannelMean(green(srgb1), green(srgb2), green(srgb3), green(srgb4)),
linearChannelMean(blue(srgb1), blue(srgb2), blue(srgb3), blue(srgb4))
);
}
private static int linearChannelMean(int c1, int c2, int c3, int c4) {
int linear = (SRGB_TO_LINEAR[c1] + SRGB_TO_LINEAR[c2] + SRGB_TO_LINEAR[c3] + SRGB_TO_LINEAR[c4]) / 4;
return LINEAR_TO_SRGB[linear] & 0xFF;
}
public static int alpha(int color) {
return color >>> 24;
}
public static int red(int color) {
return color >> 16 & 0xFF;
}
public static int green(int color) {
return color >> 8 & 0xFF;
}
public static int blue(int color) {
return color & 0xFF;
}
public static int color(int alpha, int red, int green, int blue) {
return (alpha & 0xFF) << 24 | (red & 0xFF) << 16 | (green & 0xFF) << 8 | blue & 0xFF;
}
public static int color(int red, int green, int blue) {
return color(255, red, green, blue);
}
public static int color(Vec3 vec) {
return color(as8BitChannel((float)vec.x()), as8BitChannel((float)vec.y()), as8BitChannel((float)vec.z()));
}
public static int multiply(int lhs, int rhs) {
if (lhs == -1) {
return rhs;
} else {
return rhs == -1
? lhs
: color(alpha(lhs) * alpha(rhs) / 255, red(lhs) * red(rhs) / 255, green(lhs) * green(rhs) / 255, blue(lhs) * blue(rhs) / 255);
}
}
public static int addRgb(int lhs, int rhs) {
return color(alpha(lhs), Math.min(red(lhs) + red(rhs), 255), Math.min(green(lhs) + green(rhs), 255), Math.min(blue(lhs) + blue(rhs), 255));
}
public static int subtractRgb(int lhs, int rhs) {
return color(alpha(lhs), Math.max(red(lhs) - red(rhs), 0), Math.max(green(lhs) - green(rhs), 0), Math.max(blue(lhs) - blue(rhs), 0));
}
public static int multiplyAlpha(int color, float alphaMultiplier) {
if (color == 0 || alphaMultiplier <= 0.0F) {
return 0;
} else {
return alphaMultiplier >= 1.0F ? color : color(alphaFloat(color) * alphaMultiplier, color);
}
}
public static int scaleRGB(int color, float scale) {
return scaleRGB(color, scale, scale, scale);
}
public static int scaleRGB(int color, float scaleR, float scaleG, float scaleB) {
return color(
alpha(color),
Math.clamp((long)((int)(red(color) * scaleR)), 0, 255),
Math.clamp((long)((int)(green(color) * scaleG)), 0, 255),
Math.clamp((long)((int)(blue(color) * scaleB)), 0, 255)
);
}
public static int scaleRGB(int color, int scale) {
return color(
alpha(color),
Math.clamp((long)red(color) * scale / 255L, 0, 255),
Math.clamp((long)green(color) * scale / 255L, 0, 255),
Math.clamp((long)blue(color) * scale / 255L, 0, 255)
);
}
public static int greyscale(int color) {
int greyscale = (int)(red(color) * 0.3F + green(color) * 0.59F + blue(color) * 0.11F);
return color(alpha(color), greyscale, greyscale, greyscale);
}
public static int alphaBlend(int destination, int source) {
int destinationAlpha = alpha(destination);
int sourceAlpha = alpha(source);
if (sourceAlpha == 255) {
return source;
} else if (sourceAlpha == 0) {
return destination;
} else {
int alpha = sourceAlpha + destinationAlpha * (255 - sourceAlpha) / 255;
return color(
alpha,
alphaBlendChannel(alpha, sourceAlpha, red(destination), red(source)),
alphaBlendChannel(alpha, sourceAlpha, green(destination), green(source)),
alphaBlendChannel(alpha, sourceAlpha, blue(destination), blue(source))
);
}
}
private static int alphaBlendChannel(int resultAlpha, int sourceAlpha, int destination, int source) {
return (source * sourceAlpha + destination * (resultAlpha - sourceAlpha)) / resultAlpha;
}
public static int srgbLerp(float alpha, int p0, int p1) {
int a = Mth.lerpInt(alpha, alpha(p0), alpha(p1));
int red = Mth.lerpInt(alpha, red(p0), red(p1));
int green = Mth.lerpInt(alpha, green(p0), green(p1));
int blue = Mth.lerpInt(alpha, blue(p0), blue(p1));
return color(a, red, green, blue);
}
public static int linearLerp(float alpha, int p0, int p1) {
return color(
Mth.lerpInt(alpha, alpha(p0), alpha(p1)),
LINEAR_TO_SRGB[Mth.lerpInt(alpha, SRGB_TO_LINEAR[red(p0)], SRGB_TO_LINEAR[red(p1)])] & 0xFF,
LINEAR_TO_SRGB[Mth.lerpInt(alpha, SRGB_TO_LINEAR[green(p0)], SRGB_TO_LINEAR[green(p1)])] & 0xFF,
LINEAR_TO_SRGB[Mth.lerpInt(alpha, SRGB_TO_LINEAR[blue(p0)], SRGB_TO_LINEAR[blue(p1)])] & 0xFF
);
}
public static int opaque(int color) {
return color | 0xFF000000;
}
public static int transparent(int color) {
return color & 16777215;
}
public static int color(int alpha, int rgb) {
return alpha << 24 | rgb & 16777215;
}
public static int color(float alpha, int rgb) {
return as8BitChannel(alpha) << 24 | rgb & 16777215;
}
public static int white(float alpha) {
return as8BitChannel(alpha) << 24 | 16777215;
}
public static int white(int alpha) {
return alpha << 24 | 16777215;
}
public static int black(float alpha) {
return as8BitChannel(alpha) << 24;
}
public static int black(int alpha) {
return alpha << 24;
}
public static int gray(float brightness) {
int channel = as8BitChannel(brightness);
return color(channel, channel, channel);
}
public static int colorFromFloat(float alpha, float red, float green, float blue) {
return color(as8BitChannel(alpha), as8BitChannel(red), as8BitChannel(green), as8BitChannel(blue));
}
public static Vector3f vector3fFromRGB24(int color) {
return new Vector3f(redFloat(color), greenFloat(color), blueFloat(color));
}
public static Vector4f vector4fFromARGB32(int color) {
return new Vector4f(redFloat(color), greenFloat(color), blueFloat(color), alphaFloat(color));
}
public static int average(int lhs, int rhs) {
return color((alpha(lhs) + alpha(rhs)) / 2, (red(lhs) + red(rhs)) / 2, (green(lhs) + green(rhs)) / 2, (blue(lhs) + blue(rhs)) / 2);
}
public static int as8BitChannel(float value) {
return Mth.floor(value * 255.0F);
}
public static float alphaFloat(int color) {
return from8BitChannel(alpha(color));
}
public static float redFloat(int color) {
return from8BitChannel(red(color));
}
public static float greenFloat(int color) {
return from8BitChannel(green(color));
}
public static float blueFloat(int color) {
return from8BitChannel(blue(color));
}
private static float from8BitChannel(int value) {
return value / 255.0F;
}
public static int toABGR(int color) {
return color & -16711936 | (color & 0xFF0000) >> 16 | (color & 0xFF) << 16;
}
public static int fromABGR(int color) {
return toABGR(color);
}
public static int setBrightness(int color, float brightness) {
int red = red(color);
int green = green(color);
int blue = blue(color);
int alpha = alpha(color);
int rgbMax = Math.max(Math.max(red, green), blue);
int rgbMin = Math.min(Math.min(red, green), blue);
float rgbConstantRange = rgbMax - rgbMin;
float saturation;
if (rgbMax != 0) {
saturation = rgbConstantRange / rgbMax;
} else {
saturation = 0.0F;
}
float hue;
if (saturation == 0.0F) {
hue = 0.0F;
} else {
float constantRed = (rgbMax - red) / rgbConstantRange;
float constantGreen = (rgbMax - green) / rgbConstantRange;
float constantBlue = (rgbMax - blue) / rgbConstantRange;
if (red == rgbMax) {
hue = constantBlue - constantGreen;
} else if (green == rgbMax) {
hue = 2.0F + constantRed - constantBlue;
} else {
hue = 4.0F + constantGreen - constantRed;
}
hue /= 6.0F;
if (hue < 0.0F) {
hue++;
}
}
if (saturation == 0.0F) {
red = green = blue = Math.round(brightness * 255.0F);
return color(alpha, red, green, blue);
} else {
float colorWheelSegment = (hue - (float)Math.floor(hue)) * 6.0F;
float colorWheelOffset = colorWheelSegment - (float)Math.floor(colorWheelSegment);
float primaryColor = brightness * (1.0F - saturation);
float secondaryColor = brightness * (1.0F - saturation * colorWheelOffset);
float tertiaryColor = brightness * (1.0F - saturation * (1.0F - colorWheelOffset));
switch ((int)colorWheelSegment) {
case 0:
red = Math.round(brightness * 255.0F);
green = Math.round(tertiaryColor * 255.0F);
blue = Math.round(primaryColor * 255.0F);
break;
case 1:
red = Math.round(secondaryColor * 255.0F);
green = Math.round(brightness * 255.0F);
blue = Math.round(primaryColor * 255.0F);
break;
case 2:
red = Math.round(primaryColor * 255.0F);
green = Math.round(brightness * 255.0F);
blue = Math.round(tertiaryColor * 255.0F);
break;
case 3:
red = Math.round(primaryColor * 255.0F);
green = Math.round(secondaryColor * 255.0F);
blue = Math.round(brightness * 255.0F);
break;
case 4:
red = Math.round(tertiaryColor * 255.0F);
green = Math.round(primaryColor * 255.0F);
blue = Math.round(brightness * 255.0F);
break;
case 5:
red = Math.round(brightness * 255.0F);
green = Math.round(primaryColor * 255.0F);
blue = Math.round(secondaryColor * 255.0F);
}
return color(alpha, red, green, blue);
}
}
}