gvsig-raster / org.gvsig.raster.tools / branches / org.gvsig.raster.tools_dataaccess_refactoring / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / filter / grayscale / GrayScaleManager.java @ 2328
History | View | Annotate | Download (3.58 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.tools.app.basic.tool.filter.grayscale; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
|
26 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
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.AbstractRasterFilterManager; |
30 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
32 |
/**
|
33 |
* Gestor del filtro de conversi?n a escala de grises
|
34 |
*
|
35 |
* @author Nacho Brodin nachobrodin@gmail.com
|
36 |
*/
|
37 |
public class GrayScaleManager extends AbstractRasterFilterManager { |
38 |
private static String ID = "GrayScale"; |
39 |
|
40 |
public String getManagerID() { |
41 |
return ID;
|
42 |
} |
43 |
|
44 |
public static void register() { |
45 |
AbstractRasterFilterManager.register(ID, GrayScaleManager.class); |
46 |
} |
47 |
|
48 |
public boolean isDataTypeSupported(int dataType) { |
49 |
if(dataType != Buffer.TYPE_BYTE) |
50 |
return false; |
51 |
return true; |
52 |
} |
53 |
|
54 |
public Class<?> getFilterClassByID(String id) { |
55 |
if( id.compareTo("grayscale") == 0) |
56 |
return GrayScaleFilter.class;
|
57 |
return null; |
58 |
} |
59 |
|
60 |
/**
|
61 |
* Constructor.
|
62 |
* Asigna la lista de filtros y el managener global.
|
63 |
*
|
64 |
* @param filterListManager
|
65 |
*/
|
66 |
public GrayScaleManager(RasterFilterList filterList) {
|
67 |
super(filterList);
|
68 |
} |
69 |
|
70 |
/**
|
71 |
* A?ade un filtro de conversi?n de balance de color RGB.
|
72 |
* @param type. par?metro para el filtro que indica que banda o combinaci?n de
|
73 |
* estas es usada para la conversi?n a escala de gris. El valor de este par?mtro
|
74 |
* est? definido en las constantes de la clase GrayScaleFilter
|
75 |
* @throws FilterTypeException
|
76 |
*/
|
77 |
public void addGrayScaleFilter(int type) throws FilterTypeException { |
78 |
RasterFilter filter = new GrayScaleByteFilter();
|
79 |
|
80 |
if (filter != null) { |
81 |
filter.addParam("typeBand", new Integer(type)); |
82 |
getFilterList().add(filter); |
83 |
} |
84 |
} |
85 |
|
86 |
@SuppressWarnings("unchecked") |
87 |
public ArrayList getRasterFilterList() { |
88 |
ArrayList filters = new ArrayList(); |
89 |
filters.add(GrayScaleFilter.class); |
90 |
return filters;
|
91 |
} |
92 |
|
93 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
94 |
if (classFilter.equals(GrayScaleFilter.class)) {
|
95 |
int type = 0; |
96 |
|
97 |
for (int i = 0; i < params.getNumParams(); i++) { |
98 |
if (params.getParam(i).getId().equals("typeBand")) |
99 |
type = ((Integer) params.getParam(i).getDefaultValue()).intValue();
|
100 |
} |
101 |
addGrayScaleFilter(type); |
102 |
} |
103 |
} |
104 |
|
105 |
public RasterFilter createFilter(Params params) {
|
106 |
Integer type = ((Integer) params.getParamById("typeBand").getDefaultValue()); |
107 |
|
108 |
RasterFilter filter = new GrayScaleByteFilter();
|
109 |
filter.addParam("typeBand", type);
|
110 |
return filter;
|
111 |
} |
112 |
|
113 |
public void addFilter(Params params) throws FilterTypeException { |
114 |
addFilter(GrayScaleFilter.class, params); |
115 |
} |
116 |
} |