Revision 11899 trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/ContrastByteFilter.java

View differences:

ContrastByteFilter.java
16 16
 * along with this program; if not, write to the Free Software
17 17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18 18
 */
19

  
20 19
package org.gvsig.raster.grid.filter.enhancement;
21 20

  
22 21
import org.gvsig.raster.buffer.RasterBuffer;
23

  
22
import org.gvsig.raster.dataset.IBuffer;
24 23
/**
25 24
 * Filtro de contraste para tipo de datos byte.
26
 *
27 25
 */
28 26
public class ContrastByteFilter extends ContrastFilter {
27
	protected IBuffer		rasterResult = null;
29 28

  
30 29
	/**
31 30
	 * Constructor. Llama al constructor de la clase
......
35 34
		super();
36 35
	}
37 36

  
38
	int diferencia = 0;
39

  
40 37
	/*
41 38
	 * (non-Javadoc)
42 39
	 * @see org.gvsig.raster.grid.filter.enhancement.ContrastFilter#pre()
......
45 42
		exec = true;
46 43
		this.raster = (RasterBuffer) params.get("raster");
47 44
		height = raster.getHeight();
48
        width = raster.getWidth();
45
		width = raster.getWidth();
49 46
		this.incrContraste = ((Integer) params.get("incrContraste")).intValue();
47

  
48
		rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
49

  
50 50
		super.pre();
51 51
	}
52 52
	
......
56 56
	 * @return valor de la banda con el algoritmo aplicado
57 57
	 */
58 58
	private int calcContrast(int px){	
59
		if(incrContraste >= 0){
60
			if (px < 127){
59
		int diferencia;
60
		int result = 0;
61
		if (incrContraste >= 0) {
62
			if (px < 127) {
61 63
				diferencia = 127 - px;
62
				result = px - (int)((diferencia * 5) * (incrContraste*0.1) / 25);
63
				if(result < 0)	result = 0;
64
				result = px - (int) ((diferencia * 5) * (incrContraste * 0.1) / 25);
65
				if (result < 0)
66
					result = 0;
64 67
			}
65
			if (px > 127){
68
			if (px > 127) {
66 69
				diferencia = px - 127;
67
				result = px + (int)((diferencia * 5) * (incrContraste * 0.1) / 25);
68
				if(result > 255)	result = 255;
70
				result = px + (int) ((diferencia * 5) * (incrContraste * 0.1) / 25);
71
				if (result > 255)
72
					result = 255;
69 73
			}
70
		}else{ //incrContraste < 0			
71
			if(px < 127){
74
		} else { // incrContraste < 0
75
			if (px < 127) {
72 76
				diferencia = 127 - px;
73
				result = px + ((int)diferencia * (int)(-incrContraste * 0.1) / 25);
74
				if(result > 127)	result = 127;
75
				if(px == 0 || px == 1)
76
					if(incrContraste > -255)
77
				result = px + ((int) diferencia * (int) (-incrContraste * 0.1) / 25);
78
				if (result > 127)
79
					result = 127;
80
				if (px == 0 || px == 1)
81
					if (incrContraste > -255)
77 82
						result = 0;
78 83
			}
79
			if(px > 127){
84
			if (px > 127) {
80 85
				diferencia = px - 127;
81
				result = px - ((int)diferencia * (int)(-incrContraste * 0.1) / 25);
82
				if (result < 127)	result = 127;
83
				if(px == 255 || px == 254)	
84
					if(incrContraste > -255)
86
				result = px - ((int) diferencia * (int) (-incrContraste * 0.1) / 25);
87
				if (result < 127)
88
					result = 127;
89
				if (px == 255 || px == 254)
90
					if (incrContraste > -255)
85 91
						result = 255;
86 92
			}
87 93
		}
88 94
		px = result;
89
		
95

  
90 96
		return px;
91 97
	}
92 98
	
99
	/*
100
	 * (non-Javadoc)
101
	 * @see org.gvsig.raster.grid.filter.enhancement.ContrastFilter#process(int, int)
102
	 */
93 103
	public void process(int col, int line) {
94
		for(int i = 0 ; i < raster.getBandCount() ; i++){
104
		for (int i = 0; i < raster.getBandCount(); i++) {
95 105
			int p = (raster.getElemByte(line, col, i) & 0x000000ff);
96 106
			p = calcContrast(p);
97
			raster.setElem(line, col, i, (byte)p);
107
			rasterResult.setElem(line, col, i, (byte) p);
98 108
		}
99 109
	}
100 110
		
111
	/*
112
	 * (non-Javadoc)
113
	 * @see org.gvsig.raster.grid.filter.enhancement.ContrastFilter#getInRasterDataType()
114
	 */
101 115
	public int getInRasterDataType() {
102 116
		return RasterBuffer.TYPE_BYTE;
103 117
	}
104 118

  
119
	/*
120
	 * (non-Javadoc)
121
	 * @see org.gvsig.raster.grid.filter.enhancement.ContrastFilter#getOutRasterDataType()
122
	 */
105 123
	public int getOutRasterDataType() {
106 124
		return RasterBuffer.TYPE_BYTE;
107 125
	}
108 126

  
127
	/*
128
	 * (non-Javadoc)
129
	 * @see org.gvsig.raster.grid.filter.enhancement.ContrastFilter#getResult(java.lang.String)
130
	 */
109 131
	public Object getResult(String name) {
110
		if (name.equals("raster")) {
111
            return (Object) this.raster;
112
        } else {
113
            return null;
114
        }
132
		if (name.equals("raster"))
133
			return (Object) this.rasterResult;
134
		return null;
115 135
	}
116
}
136
}

Also available in: Unified diff