svn-gvsig-desktop / trunk / extensions / extRasterTools / src / org / gvsig / rasterTools / brightnessContrast / filter / ContrastImageFilter.java @ 5247
History | View | Annotate | Download (2.2 KB)
1 |
package org.gvsig.rasterTools.brightnessContrast.filter; |
---|---|
2 |
|
3 |
import java.awt.Image; |
4 |
import java.awt.image.BufferedImage; |
5 |
|
6 |
import org.cresques.io.raster.RasterBuf; |
7 |
|
8 |
/**
|
9 |
* Filtro de contraste para im?genes raster. Toma como entrada la imagen
|
10 |
* raster y el incremento de contraste introducido por el usuario y devuelve
|
11 |
* la imagen con el filtro aplicado.
|
12 |
* @author Miguel ?ngel Querol Carratal? <querol_mig@gva.es>
|
13 |
*
|
14 |
*/
|
15 |
public class ContrastImageFilter extends ContrastFilter { |
16 |
|
17 |
public ContrastImageFilter(){
|
18 |
super();
|
19 |
} |
20 |
|
21 |
public void pre(){ |
22 |
exec = true;
|
23 |
this.image = (Image) params.get("raster"); |
24 |
height = image.getHeight(null);
|
25 |
width = image.getWidth(null);
|
26 |
this.incrContraste = ((Integer)this.params.get("incrContraste")).intValue(); |
27 |
|
28 |
desplazamiento = incrContraste/2;
|
29 |
estiramiento = incrContraste/80;
|
30 |
|
31 |
if(estiramiento == 0) |
32 |
estiramiento += 1;
|
33 |
if(estiramiento < 0) |
34 |
estiramiento = -estiramiento; |
35 |
|
36 |
super.pre();
|
37 |
} |
38 |
|
39 |
public void process(int x, int y) { |
40 |
int px = ((BufferedImage) image).getRGB(x, y); |
41 |
int px3[] = {(px & 0xff000000) >> 24, |
42 |
(px & 0x00ff0000) >> 16, |
43 |
(px & 0x0000ff00) >> 8, |
44 |
(px & 0x000000ff)};
|
45 |
|
46 |
for (int i = 1 ; i < 4 ; i++){ |
47 |
/*if(incrContraste < 0)
|
48 |
result = (int)((px3[i] + desplazamiento) / estiramiento);
|
49 |
else
|
50 |
result = (int)((px3[i] - desplazamiento) * Math.pow(estiramiento, 2));
|
51 |
*/
|
52 |
desp = px3[i] - desplazamiento; |
53 |
if(desp <= 0) desp = 1; |
54 |
result = desp * (int)estiramiento;
|
55 |
|
56 |
if(result > 255) |
57 |
px3[i] = 255;
|
58 |
else if(result < 0) |
59 |
px3[i] = 0;
|
60 |
else
|
61 |
px3[i] = result; |
62 |
} |
63 |
|
64 |
((BufferedImage) this.image).setRGB(x, y, ((px3[0] << 24) & 0xff000000) | |
65 |
((px3[1] << 16) & 0x00ff0000) | |
66 |
((px3[2] << 8) & 0x0000ff00) | |
67 |
(px3[3] & 0x000000ff)); |
68 |
} |
69 |
|
70 |
public int getInRasterDataType() { |
71 |
return RasterBuf.TYPE_IMAGE;
|
72 |
} |
73 |
|
74 |
public int getOutRasterDataType() { |
75 |
return RasterBuf.TYPE_IMAGE;
|
76 |
} |
77 |
|
78 |
public Object getResult(String name) { |
79 |
if (name.equals("raster")) { |
80 |
return (Object) this.image; |
81 |
} else {
|
82 |
return null; |
83 |
} |
84 |
} |
85 |
|
86 |
public void processLine(int y) { |
87 |
// TODO Auto-generated method stub
|
88 |
|
89 |
} |
90 |
|
91 |
} |