Statistics
| Revision:

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 / ColorBalanceRGBManager.java @ 2328

History | View | Annotate | Download (6.08 KB)

1 21 nbrodin
/* 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 1426 nbrodin
import java.util.List;
26 21 nbrodin
27 1427 nbrodin
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
28 21 nbrodin
import org.gvsig.fmap.dal.coverage.datastruct.Params;
29
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException;
30 2328 nbrodin
import org.gvsig.fmap.dal.coverage.grid.AbstractRasterFilterManager;
31 21 nbrodin
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
32
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList;
33 151 nbrodin
import org.gvsig.fmap.dal.coverage.grid.filter.BaseRasterFilter;
34 137 nbrodin
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl;
35 761 nbrodin
import org.gvsig.raster.impl.store.ParamImpl;
36 21 nbrodin
/**
37
 * Gestor del filtro de balance de color RGB
38
 *
39
 * @author Nacho Brodin (nachobrodin@gmail.com)
40
 */
41 2328 nbrodin
public class ColorBalanceRGBManager  extends AbstractRasterFilterManager {
42
        private static String   ID = "ColorBalanceRGB";
43
44 21 nbrodin
        /**
45 2328 nbrodin
         * Default constructor. Sets the filter list.
46
         * @param filterList
47 21 nbrodin
         */
48 2328 nbrodin
        public ColorBalanceRGBManager(RasterFilterList filterList) {
49
                super(filterList);
50
        }
51
52
        public String getManagerID() {
53
                return ID;
54
        }
55
56 21 nbrodin
        public static void register() {
57 2328 nbrodin
                AbstractRasterFilterManager.register(ID, ColorBalanceRGBManager.class);
58 21 nbrodin
        }
59 164 nbrodin
60 1427 nbrodin
        public boolean isDataTypeSupported(int dataType) {
61
                if(dataType != Buffer.TYPE_BYTE)
62
                        return false;
63
                return true;
64
        }
65
66 1426 nbrodin
        public Class<?> getFilterClassByID(String id) {
67 164 nbrodin
                if( id.compareTo("colorbalancergb") == 0)
68
                        return ColorTableFilter.class;
69
                return null;
70
        }
71 21 nbrodin
72
        /**
73
         * Constructor.
74
         * Asigna la lista de filtros y el managener global.
75
         *
76
         * @param filterListManager
77
         */
78 137 nbrodin
        public ColorBalanceRGBManager(RasterFilterListManagerImpl filterListManager) {
79 2328 nbrodin
                super(filterListManager.getFilterList());
80 21 nbrodin
        }
81
82
        /**
83
         * A?ade un filtro de conversi?n de balance de color RGB.
84
 * @throws FilterTypeException
85
         */
86
        public void addColorBalanceFilter(int red, int green, int blue, boolean luminosity, int[] renderBands) throws FilterTypeException {
87 151 nbrodin
                BaseRasterFilter filter = new ColorBalanceRGBByteFilter();
88 21 nbrodin
89
                //Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
90
91
                if (filter != null) {
92
                        filter.addParam("red", new Integer(red));
93
                        filter.addParam("green", new Integer(green));
94
                        filter.addParam("blue", new Integer(blue));
95
                        filter.addParam("luminosity", new Boolean(luminosity));
96
                        filter.addParam("renderBands", renderBands);
97 2328 nbrodin
                        getFilterList().add(filter);
98 21 nbrodin
                }
99
100
        }
101
102 1426 nbrodin
        public List<Class<?>> getRasterFilterList() {
103
                List<Class<?>> filters = new ArrayList<Class<?>>();
104 21 nbrodin
                filters.add(ColorBalanceRGBFilter.class);
105
                return filters;
106
        }
107 2308 nbrodin
108 1426 nbrodin
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
109 761 nbrodin
                if (ColorBalanceRGBFilter.class.isAssignableFrom(classFilter)) {
110 21 nbrodin
                        int red = 0, green = 0, blue = 0;
111
                        boolean luminosity = false;
112 2308 nbrodin
                        int[] renderBands = { 0, 1, 2, 3 };
113 21 nbrodin
114
                        for (int i = 0; i < params.getNumParams(); i++) {
115 107 nbrodin
                                if (((ParamImpl)params.getParam(i)).getId().equals("RenderBands") &&
116
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof String) {
117
                                        String[] bands = new String((String) ((ParamImpl)params.getParam(i)).getDefaultValue()).split(" ");
118 21 nbrodin
                                        renderBands[0] = new Integer(bands[0]).intValue();
119
                                        renderBands[1] = new Integer(bands[1]).intValue();
120
                                        renderBands[2] = new Integer(bands[2]).intValue();
121
                                        continue;
122
                                }
123 2308 nbrodin
                                if (((ParamImpl)params.getParam(i)).getId().equals("alphaBand") &&
124
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer) {
125
                                        renderBands[3] = (Integer)((ParamImpl)params.getParam(i)).getDefaultValue();
126
                                        continue;
127
                                }
128 107 nbrodin
                                if (((ParamImpl)params.getParam(i)).getId().equals("red"))
129
                                        red = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
130
                                if (((ParamImpl)params.getParam(i)).getId().equals("green"))
131
                                        green = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
132
                                if (((ParamImpl)params.getParam(i)).getId().equals("blue"))
133
                                        blue = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
134
                                if (((ParamImpl)params.getParam(i)).getId().equals("luminosity"))
135
                                        luminosity = ((Boolean) ((ParamImpl)params.getParam(i)).getDefaultValue()).booleanValue();
136 21 nbrodin
                        }
137
                        addColorBalanceFilter(red, green, blue, luminosity, renderBands);
138
                }
139
        }
140 125 nbrodin
141 155 nbrodin
        public RasterFilter createFilter(Params params) {
142
                int[] renderBands = { 0, 1, 2 };
143
                String b = ((String) params.getParamById("RenderBands").getDefaultValue());
144
                String[] bands = b.split(" ");
145
                renderBands[0] = new Integer(bands[0]).intValue();
146
                renderBands[1] = new Integer(bands[1]).intValue();
147
                renderBands[2] = new Integer(bands[2]).intValue();
148
                Double red = ((Double) params.getParamById("red").getDefaultValue());
149
                Double green = ((Double) params.getParamById("green").getDefaultValue());
150
                Double blue = ((Double) params.getParamById("blue").getDefaultValue());
151
                Double lum = ((Double) params.getParamById("luminosity").getDefaultValue());
152
153
                RasterFilter filter = new ColorBalanceRGBByteFilter();
154
                filter.addParam("red", red);
155
                filter.addParam("luminosity", lum);
156
                filter.addParam("green", green);
157
                filter.addParam("blue", blue);
158
                filter.addParam("renderBands", renderBands);
159
                return filter;
160
        }
161
162 125 nbrodin
        public void addFilter(Params params) throws FilterTypeException {
163
                addFilter(ColorBalanceRGBFilter.class, params);
164
        }
165 21 nbrodin
}