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 / enhancement / BrightnessContrastListManager.java @ 1426
History | View | Annotate | Download (8.2 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.enhancement; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
import java.util.List; |
26 |
|
27 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
28 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
29 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
30 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
32 |
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl; |
33 |
import org.gvsig.raster.impl.store.ParamImpl; |
34 |
import org.gvsig.tools.ToolsLocator; |
35 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
36 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
37 |
/**
|
38 |
* Gestor de los filtros de brillo y contraste. Contiene m?todos para a?adir
|
39 |
* ambos tipos de filtro en la pila.
|
40 |
*
|
41 |
* @author Miguel ?ngel Querol Carratal? (miguelangel.querol@iver.es)
|
42 |
*/
|
43 |
public class BrightnessContrastListManager implements RasterFilterListManager { |
44 |
protected RasterFilterList filterList = null; |
45 |
|
46 |
/**
|
47 |
* Default constructor. Sets the filter list.
|
48 |
* @param filterList
|
49 |
*/
|
50 |
public BrightnessContrastListManager(RasterFilterList filterList) {
|
51 |
this.filterList = filterList;
|
52 |
} |
53 |
|
54 |
/**
|
55 |
* Constructor. Asigna la lista de filtros y el manager.
|
56 |
* @param filterListManager
|
57 |
*/
|
58 |
public BrightnessContrastListManager(RasterFilterListManagerImpl filterListManager) {
|
59 |
this.filterList = filterListManager.getFilterList();
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* Registra BrightnessContrastListManager en los puntos de extension de RasterFilter
|
64 |
*/
|
65 |
public static void register() { |
66 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
67 |
ExtensionPoint point = extensionPoints.get("RasterFilter");
|
68 |
point.append("BrightnessContrast", "", BrightnessContrastListManager.class); |
69 |
} |
70 |
|
71 |
/**
|
72 |
* A?ade un filtro de brillo a la pila de filtros.
|
73 |
* @param incrBrillo valor de brillo a aplicar
|
74 |
* @param removeAll true si se desea eliminar cualquier filtro de brillo que
|
75 |
* hubiera en la pila antes y false si se acumula sobre lo que haya
|
76 |
* @throws FilterTypeException
|
77 |
*/
|
78 |
public void addBrightnessFilter(int incrBrillo) throws FilterTypeException { |
79 |
RasterFilter filter = createBrightnessFilter(incrBrillo); |
80 |
|
81 |
if (filter != null) |
82 |
filterList.add(filter); |
83 |
} |
84 |
|
85 |
public Class<?> getFilterClassByID(String id) { |
86 |
if(id.compareTo("brightness") == 0) |
87 |
return BrightnessFilter.class;
|
88 |
if(id.compareTo("contrast") == 0) |
89 |
return ContrastFilter.class;
|
90 |
return null; |
91 |
} |
92 |
|
93 |
public static RasterFilter createBrightnessFilter(int incrBrillo) { |
94 |
RasterFilter filter = new BrightnessByteFilter();
|
95 |
|
96 |
// Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
97 |
if (filter != null) { |
98 |
filter.addParam("incrBrillo", new Integer(incrBrillo)); |
99 |
} |
100 |
return filter;
|
101 |
} |
102 |
|
103 |
/**
|
104 |
* A?ade un filtro de contraste a la pila de filtros.
|
105 |
* @param incrBrillo
|
106 |
* @throws FilterTypeException
|
107 |
*/
|
108 |
public void addContrastFilter(int incrContraste) throws FilterTypeException { |
109 |
RasterFilter filter = createContrastFilter(incrContraste); |
110 |
|
111 |
// Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
112 |
if (filter != null) |
113 |
filterList.add(filter); |
114 |
} |
115 |
|
116 |
public static RasterFilter createContrastFilter(int incrContraste) { |
117 |
RasterFilter filter = new ContrastByteFilter();
|
118 |
|
119 |
// Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
120 |
if (filter != null) |
121 |
filter.addParam("incrContraste", new Integer(incrContraste)); |
122 |
|
123 |
return filter;
|
124 |
} |
125 |
|
126 |
public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) { |
127 |
|
128 |
if ((rf instanceof BrightnessFilter) || (rf instanceof ContrastFilter)) { |
129 |
filterList.add("filter.brightCont.active=true");
|
130 |
} |
131 |
|
132 |
if (rf instanceof BrightnessFilter) { |
133 |
BrightnessFilter bright = (BrightnessFilter) rf; |
134 |
filterList.add("filter.brightness.incrBrillo=" + bright.incrBrillo);
|
135 |
} else if (rf instanceof ContrastFilter) { |
136 |
ContrastFilter contrast = (ContrastFilter) rf; |
137 |
filterList.add("filter.contrast.incrContraste=" + contrast.incrContraste);
|
138 |
} |
139 |
|
140 |
return filterList;
|
141 |
} |
142 |
|
143 |
public int createFilterListFromStrings(List<String> filters, String fil, int filteri) throws FilterTypeException { |
144 |
if ((fil.startsWith("filter.brightCont.active")) && (RasterFilterListManagerImpl.getValue(fil).equals("true"))) { |
145 |
|
146 |
int incrBrillo = 0; |
147 |
int incrContraste = 0; |
148 |
filters.remove(0);
|
149 |
|
150 |
for (int prop = 0; prop < filters.size(); prop++) { |
151 |
String elem = (String) filters.get(prop); |
152 |
if (elem.startsWith("filter.brightness.incrBrillo")) { |
153 |
incrBrillo = Integer.parseInt(RasterFilterListManagerImpl.getValue(elem));
|
154 |
addBrightnessFilter(incrBrillo); |
155 |
filters.remove(prop); |
156 |
prop--; |
157 |
} |
158 |
|
159 |
if (elem.startsWith("filter.contrast.incrContraste")) { |
160 |
incrContraste = Integer.parseInt(RasterFilterListManagerImpl.getValue(elem));
|
161 |
addContrastFilter(incrContraste); |
162 |
filters.remove(prop); |
163 |
prop--; |
164 |
} |
165 |
} |
166 |
filteri = -1;
|
167 |
} |
168 |
return filteri;
|
169 |
} |
170 |
|
171 |
public List<Class<?>> getRasterFilterList() { |
172 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
173 |
filters.add(BrightnessFilter.class); |
174 |
filters.add(ContrastFilter.class); |
175 |
return filters;
|
176 |
} |
177 |
|
178 |
/*
|
179 |
* (non-Javadoc)
|
180 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#addFilter(java.lang.Class, org.gvsig.raster.dataset.Params)
|
181 |
*/
|
182 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
183 |
if (ContrastFilter.class.isAssignableFrom(classFilter)) {
|
184 |
int contrast = 0; |
185 |
for (int i = 0; i < params.getNumParams(); i++) { |
186 |
if (((ParamImpl)params.getParam(i)).getId().equals("Contrast")) |
187 |
contrast = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
|
188 |
} |
189 |
addContrastFilter(contrast); |
190 |
} |
191 |
if (BrightnessFilter.class.isAssignableFrom(classFilter)) {
|
192 |
int brightness = 0; |
193 |
for (int i = 0; i < params.getNumParams(); i++) { |
194 |
if (((ParamImpl)params.getParam(i)).getId().equals("Brightness") && ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer) |
195 |
brightness = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
|
196 |
} |
197 |
addBrightnessFilter(brightness); |
198 |
} |
199 |
} |
200 |
|
201 |
/*
|
202 |
* (non-Javadoc)
|
203 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#addFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
204 |
*/
|
205 |
public void addFilter(Params params) throws FilterTypeException { |
206 |
addFilter(ContrastFilter.class, params); |
207 |
} |
208 |
|
209 |
/*
|
210 |
* (non-Javadoc)
|
211 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#createFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
212 |
*/
|
213 |
public RasterFilter createFilter(Params params) {
|
214 |
if( params.getParamById("Brightness") != null) { |
215 |
int brightness = ((Integer) params.getParamById("Brightness").getDefaultValue()).intValue(); |
216 |
return createBrightnessFilter(brightness);
|
217 |
} |
218 |
if( params.getParamById("Contrast") != null) { |
219 |
int contrast = ((Integer) params.getParamById("Contrast").getDefaultValue()).intValue(); |
220 |
return createContrastFilter(contrast);
|
221 |
} |
222 |
return null; |
223 |
} |
224 |
|
225 |
/*
|
226 |
* (non-Javadoc)
|
227 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#getFilterList()
|
228 |
*/
|
229 |
public RasterFilterList getFilterList() {
|
230 |
return filterList;
|
231 |
} |
232 |
|
233 |
/*
|
234 |
* (non-Javadoc)
|
235 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#setFilterList(org.gvsig.fmap.dal.coverage.grid.RasterFilterList)
|
236 |
*/
|
237 |
public void setFilterList(RasterFilterList filterList) { |
238 |
this.filterList = filterList;
|
239 |
} |
240 |
} |