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 / RGBToCMYKManager.java @ 1426
History | View | Annotate | Download (6.4 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.RasterFilter; |
31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
32 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
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 |
import org.gvsig.tools.ToolsLocator; |
37 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
38 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
39 |
/**
|
40 |
* Gestor del filtro de conversi?n de RGB a CMYK.
|
41 |
*
|
42 |
* @version 30/11/2007
|
43 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
44 |
*/
|
45 |
public class RGBToCMYKManager implements RasterFilterListManager { |
46 |
|
47 |
protected RasterFilterList filterList = null; |
48 |
|
49 |
/**
|
50 |
* Registra RGBToCMYKManager en los puntos de extension de RasterFilter
|
51 |
*/
|
52 |
public static void register() { |
53 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
54 |
ExtensionPoint point = extensionPoints.get("RasterFilter");
|
55 |
point.append("RGBToCMYK", "", RGBToCMYKManager.class); |
56 |
} |
57 |
|
58 |
public Class<?> getFilterClassByID(String id) { |
59 |
if( id.compareTo("rgbtocmyk") == 0) |
60 |
return RGBToCMYKFilter.class;
|
61 |
return null; |
62 |
} |
63 |
|
64 |
/**
|
65 |
* Default constructor. Sets the filter list.
|
66 |
* @param filterList
|
67 |
*/
|
68 |
public RGBToCMYKManager(RasterFilterList filterList) {
|
69 |
this.filterList = filterList;
|
70 |
} |
71 |
|
72 |
/**
|
73 |
* Constructor.
|
74 |
* Asigna la lista de filtros y el managener global.
|
75 |
*
|
76 |
* @param filterListManager
|
77 |
*/
|
78 |
public RGBToCMYKManager(RasterFilterListManagerImpl filterListManager) {
|
79 |
this.filterList = filterListManager.getFilterList();
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* A?ade un filtro de conversi?n de RGB a CMYK a la pila de filtros.
|
84 |
* @throws FilterTypeException
|
85 |
*/
|
86 |
public void addRGBToCMYKFilter(int outputType, int[] renderBands) throws FilterTypeException { |
87 |
BaseRasterFilter filter = new RGBToCMYKByteFilter();
|
88 |
|
89 |
// Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
90 |
if (filter != null) { |
91 |
filter.addParam("outputType", new Integer(outputType)); |
92 |
filter.addParam("renderBands", renderBands);
|
93 |
filterList.add(filter); |
94 |
} |
95 |
} |
96 |
|
97 |
public List<Class<?>> getRasterFilterList() { |
98 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
99 |
filters.add(RGBToCMYKFilter.class); |
100 |
return filters;
|
101 |
} |
102 |
|
103 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
104 |
int[] renderBands = { 0, 1, 2 }; |
105 |
if (RGBToCMYKFilter.class.isAssignableFrom(classFilter)) {
|
106 |
int out = Buffer.TYPE_BYTE; |
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("outputType")) { |
117 |
int value = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue(); |
118 |
if(value == 0) |
119 |
out = Buffer.TYPE_BYTE;
|
120 |
if(value == 1) |
121 |
out = Buffer.TYPE_DOUBLE;
|
122 |
} |
123 |
} |
124 |
addRGBToCMYKFilter(out, renderBands); |
125 |
} |
126 |
} |
127 |
|
128 |
/*
|
129 |
* (non-Javadoc)
|
130 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#createFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
131 |
*/
|
132 |
public RasterFilter createFilter(Params params) {
|
133 |
int[] renderBands = { 0, 1, 2 }; |
134 |
String b = ((String) params.getParamById("RenderBands").getDefaultValue()); |
135 |
String[] bands = b.split(" "); |
136 |
renderBands[0] = new Integer(bands[0]).intValue(); |
137 |
renderBands[1] = new Integer(bands[1]).intValue(); |
138 |
renderBands[2] = new Integer(bands[2]).intValue(); |
139 |
Integer outputType = ((Integer) params.getParamById("outputType").getDefaultValue()); |
140 |
|
141 |
RasterFilter filter = new RGBToCMYKByteFilter();
|
142 |
filter.addParam("outputType", outputType);
|
143 |
filter.addParam("renderBands", renderBands);
|
144 |
return filter;
|
145 |
} |
146 |
|
147 |
/*
|
148 |
* (non-Javadoc)
|
149 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#addFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
150 |
*/
|
151 |
public void addFilter(Params params) throws FilterTypeException { |
152 |
addFilter(RGBToCMYKFilter.class, params); |
153 |
} |
154 |
|
155 |
/*
|
156 |
* (non-Javadoc)
|
157 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#createFilterListFromStrings(java.util.ArrayList, java.lang.String, int)
|
158 |
*/
|
159 |
public int createFilterListFromStrings(List<String> filters, String fil, int filteri) { |
160 |
return filteri;
|
161 |
} |
162 |
|
163 |
/*
|
164 |
* (non-Javadoc)
|
165 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getStringsFromFilterList(java.util.ArrayList, org.gvsig.raster.grid.filter.RasterFilter)
|
166 |
*/
|
167 |
public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) { |
168 |
return filterList;
|
169 |
} |
170 |
|
171 |
/*
|
172 |
* (non-Javadoc)
|
173 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#getFilterList()
|
174 |
*/
|
175 |
public RasterFilterList getFilterList() {
|
176 |
return filterList;
|
177 |
} |
178 |
|
179 |
/*
|
180 |
* (non-Javadoc)
|
181 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#setFilterList(org.gvsig.fmap.dal.coverage.grid.RasterFilterList)
|
182 |
*/
|
183 |
public void setFilterList(RasterFilterList filterList) { |
184 |
this.filterList = filterList;
|
185 |
} |
186 |
} |