root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / ContrastShortFilter.java @ 11067
History | View | Annotate | Download (2.41 KB)
1 |
package org.gvsig.raster.grid.filter.enhancement; |
---|---|
2 |
|
3 |
import org.gvsig.raster.dataaccess.buffer.RasterBuffer; |
4 |
|
5 |
/**
|
6 |
* Filtro de contraste para im?genes de 16 bits.
|
7 |
* @author Miguel ?ngel Querol Carratal? <querol_mig@gva.es>
|
8 |
*
|
9 |
*/
|
10 |
public class ContrastShortFilter extends ContrastFilter { |
11 |
private short[] px = new short[4]; |
12 |
/**
|
13 |
* Variable que contendra el incremento del contraste.
|
14 |
*/
|
15 |
private short incrContraste = 0; |
16 |
|
17 |
private short diferencia = 0; |
18 |
|
19 |
public ContrastShortFilter(){
|
20 |
super();
|
21 |
} |
22 |
|
23 |
public void pre(){ |
24 |
exec = true;
|
25 |
this.raster = (RasterBuffer) params.get("raster"); |
26 |
height = raster.getHeight(); |
27 |
width = raster.getWidth(); |
28 |
this.incrContraste = ((Integer)this.params.get("incrContraste")).shortValue(); |
29 |
|
30 |
super.pre();
|
31 |
} |
32 |
|
33 |
/**
|
34 |
* Algoritmo de contraste
|
35 |
* @param px3 valores ARGB
|
36 |
* @return valores ARGB con el algoritmo aplicado
|
37 |
*/
|
38 |
private short[] calcContrast(short[] px){ |
39 |
short result = 0; |
40 |
for (int i = 0 ; i < 3 ; i++){ |
41 |
if(incrContraste >= 0){ |
42 |
if (px[i] < 127){ |
43 |
diferencia = (short)(127 - px[i]); |
44 |
result = (short)(px[i] - (short)((diferencia * 5) * (incrContraste * 0.1) / 25)); |
45 |
if(result < 0) result = 0; |
46 |
|
47 |
} |
48 |
if (px[i] > 127){ |
49 |
diferencia = (short)(px[i] - 127); |
50 |
result = (short)(px[i] + (short)((diferencia * 5) * (incrContraste * 0.1) / 25)); |
51 |
if(result > 255) result = 255; |
52 |
} |
53 |
}else{ //incrContraste < 0 |
54 |
if(px[i] < 127){ |
55 |
diferencia = (short)(127 - px[i]); |
56 |
result = (short)(px[i] + (diferencia * (short)(-incrContraste * 0.1) / 25)); |
57 |
if(result > 127) result = 127; |
58 |
if(px[i] == 0 || px[i] == 0) |
59 |
if(incrContraste > -255) |
60 |
result = 0;
|
61 |
} |
62 |
if(px[i] > 127){ |
63 |
diferencia = (short)(px[i] - 127); |
64 |
result = (short)(px[i] - (diferencia * (short)(-incrContraste * 0.1) / 25)); |
65 |
if (result < 127) result = 127; |
66 |
if(px[i] == 255 || px[i] == 254) |
67 |
if(incrContraste > -255) |
68 |
result = 255;
|
69 |
} |
70 |
} |
71 |
px[i] = result; |
72 |
} |
73 |
return px;
|
74 |
} |
75 |
|
76 |
public void process(int col, int line) { |
77 |
raster.getElemShort(line, col, px); |
78 |
px = calcContrast(px); |
79 |
raster.setElemShort(line, col, px); |
80 |
} |
81 |
|
82 |
public int getInRasterDataType() { |
83 |
return RasterBuffer.TYPE_SHORT;
|
84 |
} |
85 |
|
86 |
public int getOutRasterDataType() { |
87 |
return RasterBuffer.TYPE_SHORT;
|
88 |
} |
89 |
|
90 |
public Object getResult(String name) { |
91 |
if (name.equals("raster")) |
92 |
return (Object) this.raster; |
93 |
else
|
94 |
return null; |
95 |
} |
96 |
|
97 |
} |