gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / band / ColorBalanceRGBManager.java @ 2328
History | View | Annotate | Download (6.08 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 java.util.ArrayList; |
25 |
import java.util.List; |
26 |
|
27 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
28 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
29 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
30 |
import org.gvsig.fmap.dal.coverage.grid.AbstractRasterFilterManager; |
31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
32 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
33 |
import org.gvsig.fmap.dal.coverage.grid.filter.BaseRasterFilter; |
34 |
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl; |
35 |
import org.gvsig.raster.impl.store.ParamImpl; |
36 |
/**
|
37 |
* Gestor del filtro de balance de color RGB
|
38 |
*
|
39 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
40 |
*/
|
41 |
public class ColorBalanceRGBManager extends AbstractRasterFilterManager { |
42 |
private static String ID = "ColorBalanceRGB"; |
43 |
|
44 |
/**
|
45 |
* Default constructor. Sets the filter list.
|
46 |
* @param filterList
|
47 |
*/
|
48 |
public ColorBalanceRGBManager(RasterFilterList filterList) {
|
49 |
super(filterList);
|
50 |
} |
51 |
|
52 |
public String getManagerID() { |
53 |
return ID;
|
54 |
} |
55 |
|
56 |
public static void register() { |
57 |
AbstractRasterFilterManager.register(ID, ColorBalanceRGBManager.class); |
58 |
} |
59 |
|
60 |
public boolean isDataTypeSupported(int dataType) { |
61 |
if(dataType != Buffer.TYPE_BYTE) |
62 |
return false; |
63 |
return true; |
64 |
} |
65 |
|
66 |
public Class<?> getFilterClassByID(String id) { |
67 |
if( id.compareTo("colorbalancergb") == 0) |
68 |
return ColorTableFilter.class;
|
69 |
return null; |
70 |
} |
71 |
|
72 |
/**
|
73 |
* Constructor.
|
74 |
* Asigna la lista de filtros y el managener global.
|
75 |
*
|
76 |
* @param filterListManager
|
77 |
*/
|
78 |
public ColorBalanceRGBManager(RasterFilterListManagerImpl filterListManager) {
|
79 |
super(filterListManager.getFilterList());
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* A?ade un filtro de conversi?n de balance de color RGB.
|
84 |
* @throws FilterTypeException
|
85 |
*/
|
86 |
public void addColorBalanceFilter(int red, int green, int blue, boolean luminosity, int[] renderBands) throws FilterTypeException { |
87 |
BaseRasterFilter filter = new ColorBalanceRGBByteFilter();
|
88 |
|
89 |
//Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
90 |
|
91 |
if (filter != null) { |
92 |
filter.addParam("red", new Integer(red)); |
93 |
filter.addParam("green", new Integer(green)); |
94 |
filter.addParam("blue", new Integer(blue)); |
95 |
filter.addParam("luminosity", new Boolean(luminosity)); |
96 |
filter.addParam("renderBands", renderBands);
|
97 |
getFilterList().add(filter); |
98 |
} |
99 |
|
100 |
} |
101 |
|
102 |
public List<Class<?>> getRasterFilterList() { |
103 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
104 |
filters.add(ColorBalanceRGBFilter.class); |
105 |
return filters;
|
106 |
} |
107 |
|
108 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
109 |
if (ColorBalanceRGBFilter.class.isAssignableFrom(classFilter)) {
|
110 |
int red = 0, green = 0, blue = 0; |
111 |
boolean luminosity = false; |
112 |
int[] renderBands = { 0, 1, 2, 3 }; |
113 |
|
114 |
for (int i = 0; i < params.getNumParams(); i++) { |
115 |
if (((ParamImpl)params.getParam(i)).getId().equals("RenderBands") && |
116 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof String) { |
117 |
String[] bands = new String((String) ((ParamImpl)params.getParam(i)).getDefaultValue()).split(" "); |
118 |
renderBands[0] = new Integer(bands[0]).intValue(); |
119 |
renderBands[1] = new Integer(bands[1]).intValue(); |
120 |
renderBands[2] = new Integer(bands[2]).intValue(); |
121 |
continue;
|
122 |
} |
123 |
if (((ParamImpl)params.getParam(i)).getId().equals("alphaBand") && |
124 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer) { |
125 |
renderBands[3] = (Integer)((ParamImpl)params.getParam(i)).getDefaultValue(); |
126 |
continue;
|
127 |
} |
128 |
if (((ParamImpl)params.getParam(i)).getId().equals("red")) |
129 |
red = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
|
130 |
if (((ParamImpl)params.getParam(i)).getId().equals("green")) |
131 |
green = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
|
132 |
if (((ParamImpl)params.getParam(i)).getId().equals("blue")) |
133 |
blue = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
|
134 |
if (((ParamImpl)params.getParam(i)).getId().equals("luminosity")) |
135 |
luminosity = ((Boolean) ((ParamImpl)params.getParam(i)).getDefaultValue()).booleanValue();
|
136 |
} |
137 |
addColorBalanceFilter(red, green, blue, luminosity, renderBands); |
138 |
} |
139 |
} |
140 |
|
141 |
public RasterFilter createFilter(Params params) {
|
142 |
int[] renderBands = { 0, 1, 2 }; |
143 |
String b = ((String) params.getParamById("RenderBands").getDefaultValue()); |
144 |
String[] bands = b.split(" "); |
145 |
renderBands[0] = new Integer(bands[0]).intValue(); |
146 |
renderBands[1] = new Integer(bands[1]).intValue(); |
147 |
renderBands[2] = new Integer(bands[2]).intValue(); |
148 |
Double red = ((Double) params.getParamById("red").getDefaultValue()); |
149 |
Double green = ((Double) params.getParamById("green").getDefaultValue()); |
150 |
Double blue = ((Double) params.getParamById("blue").getDefaultValue()); |
151 |
Double lum = ((Double) params.getParamById("luminosity").getDefaultValue()); |
152 |
|
153 |
RasterFilter filter = new ColorBalanceRGBByteFilter();
|
154 |
filter.addParam("red", red);
|
155 |
filter.addParam("luminosity", lum);
|
156 |
filter.addParam("green", green);
|
157 |
filter.addParam("blue", blue);
|
158 |
filter.addParam("renderBands", renderBands);
|
159 |
return filter;
|
160 |
} |
161 |
|
162 |
public void addFilter(Params params) throws FilterTypeException { |
163 |
addFilter(ColorBalanceRGBFilter.class, params); |
164 |
} |
165 |
} |