⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hslcolor.java

📁 java 文件下载器。可自定义
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   HSLColor.java

package org.gudy.azureus2.ui.swt.mainwindow;


public class HSLColor
{

	private static final int HSLMAX = 255;
	private static final int RGBMAX = 255;
	private static final int UNDEFINED = 170;
	private int pHue;
	private int pSat;
	private int pLum;
	private int pRed;
	private int pGreen;
	private int pBlue;

	public HSLColor()
	{
	}

	public void initHSLbyRGB(int R, int G, int B)
	{
		pRed = R;
		pGreen = G;
		pBlue = B;
		int cMax = iMax(iMax(R, G), B);
		int cMin = iMin(iMin(R, G), B);
		int cMinus = cMax - cMin;
		int cPlus = cMax + cMin;
		pLum = (cPlus * 255 + 255) / 510;
		if (cMax == cMin)
		{
			pSat = 0;
			pHue = 170;
		} else
		{
			if (pLum <= 127)
				pSat = (int)(((double)(cMinus * 255) + 0.5D) / (double)cPlus);
			else
				pSat = (int)(((double)(cMinus * 255) + 0.5D) / (double)(510 - cPlus));
			int RDelta = (int)(((double)((cMax - R) * 42) + 0.5D) / (double)cMinus);
			int GDelta = (int)(((double)((cMax - G) * 42) + 0.5D) / (double)cMinus);
			int BDelta = (int)(((double)((cMax - B) * 42) + 0.5D) / (double)cMinus);
			if (cMax == R)
				pHue = BDelta - GDelta;
			else
			if (cMax == G)
				pHue = (85 + RDelta) - BDelta;
			else
			if (cMax == B)
				pHue = (170 + GDelta) - RDelta;
			if (pHue < 0)
				pHue = pHue + 255;
		}
	}

	public void initRGBbyHSL(int H, int S, int L)
	{
		pHue = H;
		pLum = L;
		pSat = S;
		if (S == 0)
		{
			pRed = (L * 255) / 255;
			pGreen = pRed;
			pBlue = pRed;
		} else
		{
			int Magic2;
			if (L <= 127)
				Magic2 = (L * (255 + S) + 127) / 255;
			else
				Magic2 = (L + S) - (L * S + 127) / 255;
			int Magic1 = 2 * L - Magic2;
			pRed = (hueToRGB(Magic1, Magic2, H + 85) * 255 + 127) / 255;
			if (pRed > 255)
				pRed = 255;
			pGreen = (hueToRGB(Magic1, Magic2, H) * 255 + 127) / 255;
			if (pGreen > 255)
				pGreen = 255;
			pBlue = (hueToRGB(Magic1, Magic2, H - 85) * 255 + 127) / 255;
			if (pBlue > 255)
				pBlue = 255;
		}
	}

	private int hueToRGB(int mag1, int mag2, int Hue)
	{
		if (Hue < 0)
			Hue += 255;
		else
		if (Hue > 255)
			Hue -= 255;
		if (Hue < 42)
			return mag1 + ((mag2 - mag1) * Hue + 21) / 42;
		if (Hue < 127)
			return mag2;
		if (Hue < 170)
			return mag1 + ((mag2 - mag1) * (170 - Hue) + 21) / 42;
		else
			return mag1;
	}

	private int iMax(int a, int b)
	{
		if (a > b)
			return a;
		else
			return b;
	}

	private int iMin(int a, int b)
	{
		if (a < b)
			return a;
		else
			return b;
	}

	private void greyscale()
	{
		initRGBbyHSL(170, 0, pLum);
	}

	public int getHue()
	{
		return pHue;
	}

	public void setHue(int iToValue)
	{
		for (; iToValue < 0; iToValue = 255 + iToValue);
		for (; iToValue > 255; iToValue -= 255);
		initRGBbyHSL(iToValue, pSat, pLum);
	}

	public int getSaturation()
	{
		return pSat;
	}

	public void setSaturation(int iToValue)
	{
		if (iToValue < 0)
			iToValue = 0;
		else
		if (iToValue > 255)
			iToValue = 255;
		initRGBbyHSL(pHue, iToValue, pLum);
	}

	public int getLuminence()
	{
		return pLum;
	}

	public void setLuminence(int iToValue)
	{
		if (iToValue < 0)
			iToValue = 0;
		else
		if (iToValue > 255)
			iToValue = 255;
		initRGBbyHSL(pHue, pSat, iToValue);
	}

	public int getRed()
	{
		return pRed;
	}

	private void setRed(int iNewValue)
	{
		initHSLbyRGB(iNewValue, pGreen, pBlue);
	}

	public int getGreen()
	{
		return pGreen;
	}

	private void setGreen(int iNewValue)
	{
		initHSLbyRGB(pRed, iNewValue, pBlue);
	}

	public int getBlue()
	{
		return pBlue;
	}

	private void setBlue(int iNewValue)
	{
		initHSLbyRGB(pRed, pGreen, iNewValue);
	}

	public void reverseColor()
	{
		setHue(pHue + 127);
	}

	private void reverseLight()
	{
		setLuminence(255 - pLum);
	}

	public void brighten(float fPercent)
	{
		if (fPercent == 0.0F)
			return;
		int L = (int)((float)pLum * fPercent);
		if (L < 0)
			L = 0;
		if (L > 255)
			L = 255;
		setLuminence(L);
	}

	public void blend(int R, int G, int B, float fPercent)
	{
		if (fPercent >= 1.0F)
		{
			initHSLbyRGB(R, G, B);
			return;
		}
		if (fPercent <= 0.0F)
		{
			return;
		} else
		{
			int newR = (int)((double)((float)R * fPercent) + (double)pRed * (1.0D - (double)fPercent));
			int newG = (int)((double)((float)G * fPercent) + (double)pGreen * (1.0D - (double)fPercent));
			int newB = (int)((double)((float)B * fPercent) + (double)pBlue * (1.0D - (double)fPercent));
			initHSLbyRGB(newR, newG, newB);
			return;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -