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

📄 brightnessretriever.java

📁 java编写的程序
💻 JAVA
字号:

import java.awt.image.*;

public class BrightnessRetriever extends PointProcessor
{
	float scale = 1.0f;
	int lower_valve = 0;
	int upper_valve = 255;
	public BrightnessRetriever(float scale)
	{
		this.type = this.PIXEL_BRIGHTNESS_SCALE;
		this.scale = scale;
			
	}
	
	public BrightnessRetriever(float scale,int lower,int upper)
	{
		this.type = this.PIXEL_BRIGHTNESS_SCALE;
		this.scale = scale;
		if(lower > upper)
		{
			this.lower_valve = upper;
			this.upper_valve = lower;
		}
		else
		{
			this.lower_valve = lower;
			this.upper_valve = upper;
		}
		
	}
	
	public void setRetrieverType(int type)
	{
		switch(type)
		{
			case 0:		this.type = this.PIXEL_BRIGHTNESS_SCALE;break;
			case 1:		this.type = this.PIXEL_BRIGHTNESS_REVERSE;break;
			default:	this.type = this.PIXEL_BRIGHTNESS_SCALE;break;
		}
	
	}
	
	public boolean retrieveRGB(int[] src,int scansize,int[] dst)
	{
		if(scansize == 0)return false;
		int height = src.length / scansize;
		return (this.retrieveRGB(src,0,0,scansize,height,scansize,dst));
	}
	
	public boolean retrieveRGB(int[] src,int x,int y,int w,int h,int scansize,int[] dst)
	{
		if(scansize <= 0) return false;
		
		int nTotal = src.length;
		
		
		//原图像的宽度
		int srcWidth = scansize;
		
		//原图像可以扫描的总行数:即原图像的高度
		int srcHeight =  nTotal / scansize;
		
		//作一些合法性准备:越界则不进行任何处理
		if((x > (scansize - 1)) || (y > (srcHeight - 1)))return false;

		int width = w;
		int height = h;

		if((x + w) > scansize)  width = scansize  - x;
		if((y + h) > srcHeight)  height = srcHeight  - y;
 		System.arraycopy(src,0,dst,0, nTotal);

		ColorModel colorModel = ColorModel.getRGBdefault();
		
		int i = 0;int j = 0;
		
		for(i = 0; i < height;i++)
		{
			int indexBase = (y + i) * scansize;
 			for(j = 0;j < width;j++)
			{
				int index = indexBase + x + j;
				
				int r,g,b;
				r = colorModel.getRed(src[index]);
				g = colorModel.getGreen(src[index]);
				b = colorModel.getBlue(src[index]);
				
				dst[index] = retrieve(r,g,b);
			}
		}
		
		return true;
	}

	
	public int retrieve(int r,int g,int b)
	{
		switch(this.type)
			{
				//亮度比例化
				case this.PIXEL_BRIGHTNESS_SCALE :
					r = (int)(r * scale);
					g = (int)(g * scale);
					b = (int)(b * scale);
			
					r = (r < lower_valve) ? lower_valve : ((r > upper_valve) ? upper_valve : r);
					g = (g < lower_valve) ? lower_valve : ((g > upper_valve) ? upper_valve : g);
					b = (b < lower_valve) ? lower_valve : ((b > upper_valve) ? upper_valve : b);
					
					break;
				
				//亮度反置
				case this.PIXEL_BRIGHTNESS_REVERSE :
					
					r = (255 - r);
					g = (255 - g);
					b = (255 - b);
					
					break;
			default:break;
			}
			return (0xFF000000 | (( r << 16 ) | ( g << 8 ) | b ));
	}
}

⌨️ 快捷键说明

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