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