svn-gvsig-desktop / trunk / extensions / extRasterTools / src / org / gvsig / rasterTools / brightnessContrast / filter / ContrastImageFilter.java @ 5497
History | View | Annotate | Download (3.54 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
|
20 |
package org.gvsig.rasterTools.brightnessContrast.filter; |
21 |
|
22 |
import java.awt.Image; |
23 |
import java.awt.image.BufferedImage; |
24 |
|
25 |
import org.cresques.io.raster.RasterBuf; |
26 |
import org.cresques.io.raster.RasterFilter; |
27 |
import org.cresques.io.raster.RasterFilterStack; |
28 |
|
29 |
/**
|
30 |
* Filtro de contraste para im?genes raster. Toma como entrada la imagen
|
31 |
* raster y el incremento de contraste introducido por el usuario y devuelve
|
32 |
* la imagen con el filtro aplicado.
|
33 |
* @author Miguel ?ngel Querol Carratal? <querol_mig@gva.es>
|
34 |
*
|
35 |
*/
|
36 |
public class ContrastImageFilter extends ContrastFilter { |
37 |
|
38 |
public ContrastImageFilter(){
|
39 |
super();
|
40 |
} |
41 |
|
42 |
int diferencia = 0; |
43 |
double dif = 0; |
44 |
double incr = 0; |
45 |
double mov = 0; |
46 |
|
47 |
|
48 |
public void pre(){ |
49 |
exec = true;
|
50 |
this.image = (Image) params.get("raster"); |
51 |
height = image.getHeight(null);
|
52 |
width = image.getWidth(null);
|
53 |
this.incrContraste = ((Integer)this.params.get("incrContraste")).intValue(); |
54 |
|
55 |
|
56 |
super.pre();
|
57 |
} |
58 |
|
59 |
public void process(int x, int y) { |
60 |
int px = ((BufferedImage) image).getRGB(x, y); |
61 |
int px3[] = {(px & 0xff000000) >> 24, |
62 |
(px & 0x00ff0000) >> 16, |
63 |
(px & 0x0000ff00) >> 8, |
64 |
(px & 0x000000ff)};
|
65 |
|
66 |
for (int i = 1 ; i < 4 ; i++){ |
67 |
//************ALGORITMO DE CONTRASTE*************
|
68 |
if(incrContraste >= 0){ |
69 |
if (px3[i] < 127){ |
70 |
diferencia = 127 - px3[i];
|
71 |
result = px3[i] - (diferencia / 10) * (incrContraste/4); |
72 |
if(result < 0) result = 0; |
73 |
|
74 |
} |
75 |
if (px3[i] > 127){ |
76 |
diferencia = px3[i] - 127;
|
77 |
result = px3[i] + (diferencia / 10) * (incrContraste/4); |
78 |
if(result > 255) result = 255; |
79 |
} |
80 |
} |
81 |
if(incrContraste < 0){ |
82 |
if(px3[i] < 127){ |
83 |
diferencia = 127 - px3[i];
|
84 |
result = px3[i] + (diferencia / 10) * (-incrContraste/20); |
85 |
if(result > 127) result = 127; |
86 |
if(px3[i] == 0 || px3[i] == 0) |
87 |
if(incrContraste > -255) |
88 |
result = 0;
|
89 |
} |
90 |
if(px3[i] > 127){ |
91 |
diferencia = px3[i] - 127;
|
92 |
result = px3[i] - (diferencia / 10) * (-incrContraste/20); |
93 |
if (result < 127) result = 127; |
94 |
if(px3[i] == 255 || px3[i] == 254) |
95 |
if(incrContraste > -255) |
96 |
result = 255;
|
97 |
} |
98 |
} |
99 |
px3[i] = result; |
100 |
} |
101 |
|
102 |
((BufferedImage) this.image).setRGB(x, y, ((px3[0] << 24) & 0xff000000) | |
103 |
((px3[1] << 16) & 0x00ff0000) | |
104 |
((px3[2] << 8) & 0x0000ff00) | |
105 |
(px3[3] & 0x000000ff)); |
106 |
} |
107 |
|
108 |
public int getInRasterDataType() { |
109 |
return RasterBuf.TYPE_IMAGE;
|
110 |
} |
111 |
|
112 |
public int getOutRasterDataType() { |
113 |
return RasterBuf.TYPE_IMAGE;
|
114 |
} |
115 |
|
116 |
public Object getResult(String name) { |
117 |
if (name.equals("raster")) { |
118 |
return (Object) this.image; |
119 |
} else {
|
120 |
return null; |
121 |
} |
122 |
} |
123 |
|
124 |
public void processLine(int y) { |
125 |
// TODO Auto-generated method stub
|
126 |
|
127 |
} |
128 |
|
129 |
} |