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 / HSLToRGBManager.java @ 2328
History | View | Annotate | Download (4.64 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 conversi?n de HSL a RGB.
|
38 |
*
|
39 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
40 |
*
|
41 |
*/
|
42 |
public class HSLToRGBManager extends AbstractRasterFilterManager { |
43 |
private static String ID = "HSLToRGB"; |
44 |
|
45 |
/**
|
46 |
* Default constructor. Sets the filter list.
|
47 |
* @param filterList
|
48 |
*/
|
49 |
public HSLToRGBManager(RasterFilterList filterList) {
|
50 |
super(filterList);
|
51 |
} |
52 |
|
53 |
public String getManagerID() { |
54 |
return ID;
|
55 |
} |
56 |
|
57 |
public static void register() { |
58 |
AbstractRasterFilterManager.register(ID, HSLToRGBManager.class); |
59 |
} |
60 |
|
61 |
public boolean isDataTypeSupported(int dataType) { |
62 |
if(dataType != Buffer.TYPE_BYTE) |
63 |
return false; |
64 |
return true; |
65 |
} |
66 |
|
67 |
public Class<?> getFilterClassByID(String id) { |
68 |
if( id.compareTo("hsltorgb") == 0) |
69 |
return HSLToRGBFilter.class;
|
70 |
return null; |
71 |
} |
72 |
|
73 |
/**
|
74 |
* Constructor.
|
75 |
* Asigna la lista de filtros y el managener global.
|
76 |
*
|
77 |
* @param filterListManager
|
78 |
*/
|
79 |
public HSLToRGBManager(RasterFilterListManagerImpl filterListManager) {
|
80 |
super(filterListManager.getFilterList());
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* A?ade un filtro de conversi?n de RGB a HSL a la pila de filtros.
|
85 |
* @throws FilterTypeException
|
86 |
*/
|
87 |
public void addHSLToRGBFilter(int[] renderBands) throws FilterTypeException { |
88 |
BaseRasterFilter filter = new HSLToRGBByteFilter();
|
89 |
|
90 |
//Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
91 |
|
92 |
if (filter != null) { |
93 |
getFilterList().add(filter); |
94 |
filter.addParam("renderBands", renderBands);
|
95 |
} |
96 |
} |
97 |
|
98 |
public List<Class<?>> getRasterFilterList() { |
99 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
100 |
filters.add(HSLToRGBFilter.class); |
101 |
return filters;
|
102 |
} |
103 |
|
104 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
105 |
if (HSLToRGBFilter.class.isAssignableFrom(classFilter)) {
|
106 |
int[] renderBands = { 0, 1, 2, 3 }; |
107 |
for (int i = 0; i < params.getNumParams(); i++) { |
108 |
if (((ParamImpl)params.getParam(i)).getId().equals("RenderBands") && |
109 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof String) { |
110 |
String[] bands = new String((String) ((ParamImpl)params.getParam(i)).getDefaultValue()).split(" "); |
111 |
renderBands[0] = new Integer(bands[0]).intValue(); |
112 |
renderBands[1] = new Integer(bands[1]).intValue(); |
113 |
renderBands[2] = new Integer(bands[2]).intValue(); |
114 |
continue;
|
115 |
} |
116 |
if (((ParamImpl)params.getParam(i)).getId().equals("alphaBand") && |
117 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer) { |
118 |
renderBands[3] = (Integer)((ParamImpl)params.getParam(i)).getDefaultValue(); |
119 |
continue;
|
120 |
} |
121 |
} |
122 |
addHSLToRGBFilter(renderBands); |
123 |
} |
124 |
} |
125 |
|
126 |
public void addFilter(Params params) throws FilterTypeException { |
127 |
addFilter(HSLToRGBFilter.class, params); |
128 |
} |
129 |
|
130 |
public RasterFilter createFilter(Params params) {
|
131 |
int[] renderBands = { 0, 1, 2 }; |
132 |
String b = ((String) params.getParamById("RenderBands").getDefaultValue()); |
133 |
String[] bands = b.split(" "); |
134 |
renderBands[0] = new Integer(bands[0]).intValue(); |
135 |
renderBands[1] = new Integer(bands[1]).intValue(); |
136 |
renderBands[2] = new Integer(bands[2]).intValue(); |
137 |
|
138 |
RasterFilter filter = new HSLToRGBByteFilter();
|
139 |
filter.addParam("renderBands", renderBands);
|
140 |
return filter;
|
141 |
} |
142 |
} |