gpt4 book ai didi

java - 仅更改一个值 HSL

转载 作者:行者123 更新时间:2023-12-01 13:42:59 27 4
gpt4 key购买 nike

这是我当前用来更改图像的色相、饱和度和亮度的代码。我如何只改变饱和度或亮度而不添加色调?或者如何找到像素的当前色调值以便我可以使用它?

    public static final int MAX_COLOR = 256;

private final float LUMINANCE_RED = 0.2126f;
private final float LUMINANCE_GREEN = 0.7152f;
private final float LUMINANCE_BLUE = 0.0722f;

private double hue = 180;
private double saturation = 50;
private double lightness = 0;

private int[] lum_red_lookup;
private int[] lum_green_lookup;
private int[] lum_blue_lookup;

private int[] final_red_lookup;
private int[] final_green_lookup;
private int[] final_blue_lookup;

public void doHSB(double t_hue, double t_sat, double t_bri, BufferedImage image)
{
hue = t_hue;
saturation = t_sat;
lightness = t_bri;
doInit();
doColorize(image);
}
private void doInit()
{
lum_red_lookup = new int[MAX_COLOR];
lum_green_lookup = new int[MAX_COLOR];
lum_blue_lookup = new int[MAX_COLOR];

double temp_hue = hue / 360f;
double temp_sat = saturation / 100f;

final_red_lookup = new int[MAX_COLOR];
final_green_lookup = new int[MAX_COLOR];
final_blue_lookup = new int[MAX_COLOR];

for (int i = 0; i < MAX_COLOR; ++i)
{
lum_red_lookup[i] = (int) (i * LUMINANCE_RED);
lum_green_lookup[i] = (int) (i * LUMINANCE_GREEN);
lum_blue_lookup[i] = (int) (i * LUMINANCE_BLUE);

double temp_light = (double) i / 255f;

Color color = new Color(Color.HSBtoRGB((float) temp_hue, (float) temp_sat, (float) temp_light));

final_red_lookup[i] = (int) (color.getRed());
final_green_lookup[i] = (int) (color.getGreen());
final_blue_lookup[i] = (int) (color.getBlue());
}
}

private void doColorize(BufferedImage image)
{
int height = image.getHeight();
int width;

while (height-- != 0)
{
width = image.getWidth();

while (width-- != 0)
{
Color color = new Color(image.getRGB(width, height), true);

int lum = lum_red_lookup[color.getRed()] + lum_green_lookup[color.getGreen()] + lum_blue_lookup[color.getBlue()];

if (lightness > 0)
{
lum = (int) ((double) lum * (100f - lightness) / 100f);
lum += 255f - (100f - lightness) * 255f / 100f;
}
else if (lightness < 0)
{
lum = (int) (((double) lum * (lightness + 100f)) / 100f);
}
Color final_color = new Color(final_red_lookup[lum], final_green_lookup[lum], final_blue_lookup[lum], color.getAlpha());
image.setRGB(width, height, final_color.getRGB());
}
}
}

最佳答案

HSL Color类允许您单独调整每个属性。

关于java - 仅更改一个值 HSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20553656/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com