svn-gvsig-desktop / tags / v1_1_Build_1010 / libraries / libCq CMS for java.old / src / org / cresques / filter / enhancement / LinearEnhancementImageFilter.java @ 12804
History | View | Annotate | Download (3.84 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.filter.enhancement; |
25 |
|
26 |
import java.awt.Image; |
27 |
import java.awt.image.BufferedImage; |
28 |
|
29 |
import org.cresques.io.data.RasterBuf; |
30 |
import org.cresques.io.datastruct.Statistic; |
31 |
|
32 |
|
33 |
/**
|
34 |
* Realzado Lineal (Amplitude Rescaling) para objetos Image.
|
35 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
36 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
37 |
*/
|
38 |
public class LinearEnhancementImageFilter extends LinearEnhancementFilter { |
39 |
/**
|
40 |
* Constructor
|
41 |
*/
|
42 |
public LinearEnhancementImageFilter() {
|
43 |
super();
|
44 |
} |
45 |
|
46 |
/* (non-Javadoc)
|
47 |
* @see org.cresques.io.raster.IRasterFilter#pre()
|
48 |
*/
|
49 |
public void pre() { |
50 |
//Obtenci?n de par?metros
|
51 |
this.image = (Image) params.get("raster"); |
52 |
this.stats = (Statistic) params.get("stats"); |
53 |
this.removeExtrema = ((Boolean) params.get("remove")).booleanValue(); |
54 |
this.filename = (String) params.get("filename"); |
55 |
height = image.getHeight(null);
|
56 |
width = image.getWidth(null);
|
57 |
super.pre();
|
58 |
} |
59 |
|
60 |
/* (non-Javadoc)
|
61 |
* @see org.cresques.io.raster.IRasterFilter#process(int, int)
|
62 |
*/
|
63 |
public void process(int x, int y) { |
64 |
int pt = ((BufferedImage) image).getRGB(x, y); |
65 |
int[] px4 = { |
66 |
((pt & 0xff000000) >> 24) & 0xff, |
67 |
((pt & 0xff0000) >> 16) & 0xff, |
68 |
((pt & 0xff00) >> 8) & 0xff, pt & 0xff |
69 |
}; |
70 |
|
71 |
for (int i = 0; i < 3; i++) { |
72 |
if (px4[i + 1] > maxBandValue[i]) { |
73 |
px4[i + 1] = maxBandValue[i];
|
74 |
} else if (px4[i + 1] < minBandValue[i]) { |
75 |
px4[i + 1] = minBandValue[i];
|
76 |
} |
77 |
|
78 |
px4[i + 1] = (((int) ((((double) px4[i + 1]) * scale[i]) + |
79 |
offset[i])) & 0xff);
|
80 |
} |
81 |
|
82 |
((BufferedImage) image).setRGB(x, y,
|
83 |
(((px4[0] << 24) & 0xff000000) | |
84 |
((px4[1] << 16) & 0xff0000) | |
85 |
((px4[2] << 8) & 0xff00) | |
86 |
(px4[3] & 0xff))); |
87 |
} |
88 |
|
89 |
/* (non-Javadoc)
|
90 |
* @see org.cresques.io.raster.IRasterFilter#getResult(java.lang.String)
|
91 |
*/
|
92 |
public Object getResult(String name) { |
93 |
if (name.equals("raster")) { |
94 |
return (Object) this.image; |
95 |
} else {
|
96 |
return null; |
97 |
} |
98 |
} |
99 |
|
100 |
/* (non-Javadoc)
|
101 |
* @see org.cresques.io.raster.IRasterFilter#getInRasterDataType()
|
102 |
*/
|
103 |
public int getInRasterDataType() { |
104 |
return RasterBuf.TYPE_IMAGE;
|
105 |
} |
106 |
|
107 |
/* (non-Javadoc)
|
108 |
* @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType()
|
109 |
*/
|
110 |
public int getOutRasterDataType() { |
111 |
return RasterBuf.TYPE_IMAGE;
|
112 |
} |
113 |
|
114 |
/* (non-Javadoc)
|
115 |
* @see org.cresques.io.raster.IRasterFilter#post()
|
116 |
*/
|
117 |
public void post() { |
118 |
} |
119 |
|
120 |
/* (non-Javadoc)
|
121 |
* @see org.cresques.io.raster.RasterFilter#processLine(int)
|
122 |
*/
|
123 |
public void processLine(int y) { |
124 |
} |
125 |
} |