gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / band / RGBToHSLFilter.java @ 2443
History | View | Annotate | Download (3.98 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.impl.grid.filter.band; |
23 |
|
24 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
25 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
26 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
27 |
import org.gvsig.fmap.dal.coverage.exception.FilterAddException; |
28 |
import org.gvsig.fmap.dal.coverage.grid.filter.BaseRasterFilter; |
29 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
30 |
import org.gvsig.raster.impl.store.ParamsImpl; |
31 |
import org.gvsig.raster.util.DefaultColorConversion; |
32 |
/**
|
33 |
* <P>
|
34 |
* Clase base para los filtros de conversi?n de RGB a HSL. La entrada ser?
|
35 |
* siempre un raster de 3 bandas que ser?n tomadas como RGB.
|
36 |
* </P>
|
37 |
*
|
38 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
39 |
*/
|
40 |
public class RGBToHSLFilter extends BaseRasterFilter { |
41 |
public static String[] names = new String[] { "rgbtohsl" }; |
42 |
protected DefaultColorConversion colorConversion = null; |
43 |
protected int out = Buffer.TYPE_BYTE; |
44 |
protected int redBandNumber = -1; |
45 |
protected int greenBandNumber = -1; |
46 |
protected int blueBandNumber = -1; |
47 |
|
48 |
/**
|
49 |
* Constructor
|
50 |
*/
|
51 |
public RGBToHSLFilter() {
|
52 |
super();
|
53 |
setName(names[0]);
|
54 |
} |
55 |
|
56 |
public void pre() throws FilterAddException { |
57 |
super.pre();
|
58 |
out = ((Integer) params.get("outputType")).intValue(); |
59 |
|
60 |
//A este filtro ya llega una imagen RGB con el orden de las bandas correcto
|
61 |
//ColorInterpretation colorInterpretation = getColorInterpretation();
|
62 |
redBandNumber = 0;//colorInterpretation.getBand(ColorInterpretation.RED_BAND); |
63 |
greenBandNumber = 1;//colorInterpretation.getBand(ColorInterpretation.GREEN_BAND); |
64 |
blueBandNumber = 2;//colorInterpretation.getBand(ColorInterpretation.BLUE_BAND); |
65 |
|
66 |
if(out == Buffer.TYPE_BYTE) |
67 |
createARGBBufferResult(); |
68 |
else {
|
69 |
createBufferResult(out, 3);
|
70 |
} |
71 |
|
72 |
if(colorConversion == null) |
73 |
colorConversion = new DefaultColorConversion();
|
74 |
} |
75 |
|
76 |
/**
|
77 |
* Gets the result of this filter
|
78 |
*/
|
79 |
public Object getResult(String name) { |
80 |
if (name.equals(RESULT_TRANSPARENCY)) {
|
81 |
if(super.getResult(RESULT_TRANSPARENCY) == null) { |
82 |
String[] values = new String[rasterResult.getBandCount()]; |
83 |
for (int i = 0; i < values.length; i++) { |
84 |
values[i] = ColorInterpretation.UNDEF_BAND; |
85 |
} |
86 |
ColorInterpretation ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation(values); |
87 |
transparency.setColorInterpretation(ci); |
88 |
transparency.activeTransparency(); |
89 |
return transparency;
|
90 |
} |
91 |
} |
92 |
return super.getResult(name); |
93 |
} |
94 |
|
95 |
public String getGroup() { |
96 |
return "colores"; |
97 |
} |
98 |
|
99 |
public String[] getNames() { |
100 |
return names;
|
101 |
} |
102 |
|
103 |
public Params getUIParams(String nameFilter) { |
104 |
Params params = new ParamsImpl();
|
105 |
params.setParam("outputType",
|
106 |
new Integer(0), |
107 |
Params.CHOICE, |
108 |
new String[]{ "Byte", "Double"}); |
109 |
return params;
|
110 |
} |
111 |
|
112 |
public void post() { |
113 |
|
114 |
} |
115 |
|
116 |
public void process(int x, int y) { |
117 |
} |
118 |
|
119 |
public int getOutRasterDataType() { |
120 |
return Buffer.TYPE_BYTE; |
121 |
} |
122 |
|
123 |
public boolean isVisible() { |
124 |
return true; |
125 |
} |
126 |
|
127 |
public int getInRasterDataType() { |
128 |
return Buffer.TYPE_BYTE; |
129 |
} |
130 |
} |