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

History | View | Annotate | Download (7.03 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.enhancement;
23

    
24
import java.util.ArrayList;
25
import java.util.List;
26

    
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
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl;
33
import org.gvsig.raster.impl.store.ParamImpl;
34
/**
35
 * Gestor de los filtros de brillo y contraste. Contiene m?todos para a?adir
36
 * ambos tipos de filtro en la pila.
37
 *
38
 * @author Miguel ?ngel Querol Carratal? 
39
 */
40
public class BrightnessContrastListManager extends AbstractRasterFilterManager {
41
        private static String   ID = "BrightnessContrast";
42
        
43
        /**
44
         * Default constructor. Sets the filter list.
45
         * @param filterList
46
         */
47
        public BrightnessContrastListManager(RasterFilterList filterList) {
48
                super(filterList);
49
        }
50
        
51
        public String getManagerID() {
52
                return ID;
53
        }
54

    
55
        public static void register() {
56
                AbstractRasterFilterManager.register(ID, BrightnessContrastListManager.class);
57
        }
58

    
59
        /**
60
         * Constructor. Asigna la lista de filtros y el manager.
61
         * @param filterListManager
62
         */
63
        public BrightnessContrastListManager(RasterFilterListManagerImpl filterListManager) {
64
                super(filterListManager.getFilterList());
65
        }
66

    
67
        public boolean isDataTypeSupported(int dataType) {
68
                return true;
69
        }
70

    
71
        /**
72
         * A?ade un filtro de brillo a la pila de filtros.
73
         * @param incrBrillo valor de brillo a aplicar
74
         * @param removeAll true si se desea eliminar cualquier filtro de brillo que
75
         * hubiera en la pila antes y false si se acumula sobre lo que haya
76
         * @throws FilterTypeException
77
         */
78
        public void addBrightnessFilter(int incrBrillo) throws FilterTypeException {
79
                RasterFilter filter = createBrightnessFilter(incrBrillo);
80

    
81
                if (filter != null)
82
                        getFilterList().add(filter);
83
        }
84
        
85
        public Class<?> getFilterClassByID(String id) {
86
                if(id.compareTo("brightness") == 0)
87
                        return BrightnessFilter.class;
88
                if(id.compareTo("contrast") == 0)
89
                        return ContrastFilter.class;
90
                return null;
91
        }
92

    
93
        public static RasterFilter createBrightnessFilter(int incrBrillo) {
94
                RasterFilter filter = new BrightnessByteFilter();
95

    
96
                // Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
97
                if (filter != null) {
98
                        filter.addParam("incrBrillo", new Integer(incrBrillo));
99
                }
100
                return filter;
101
        }
102

    
103
        /**
104
         * A?ade un filtro de contraste a la pila de filtros.
105
         * @param incrBrillo
106
         * @throws FilterTypeException
107
         */
108
        public void addContrastFilter(int incrContraste) throws FilterTypeException {
109
                RasterFilter filter = createContrastFilter(incrContraste);
110

    
111
                // Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
112
                if (filter != null)
113
                        getFilterList().add(filter);
114
        }
115

    
116
        public static RasterFilter createContrastFilter(int incrContraste) {
117
                RasterFilter filter = new ContrastByteFilter();
118

    
119
                // Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
120
                if (filter != null)
121
                        filter.addParam("incrContraste", new Integer(incrContraste));
122

    
123
                return filter;
124
        }
125

    
126
        public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) {
127

    
128
                if ((rf instanceof BrightnessFilter) || (rf instanceof ContrastFilter)) {
129
                        filterList.add("filter.brightCont.active=true");
130
                }
131

    
132
                if (rf instanceof BrightnessFilter) {
133
                        BrightnessFilter bright = (BrightnessFilter) rf;
134
                        filterList.add("filter.brightness.incrBrillo=" + bright.incrBrillo);
135
                } else if (rf instanceof ContrastFilter) {
136
                        ContrastFilter contrast = (ContrastFilter) rf;
137
                        filterList.add("filter.contrast.incrContraste=" + contrast.incrContraste);
138
                }
139

    
140
                return filterList;
141
        }
142

    
143
        public int createFilterListFromStrings(List<String> filters, String fil, int filteri) throws FilterTypeException {
144
                if ((fil.startsWith("filter.brightCont.active")) && (RasterFilterListManagerImpl.getValue(fil).equals("true"))) {
145

    
146
                        int incrBrillo = 0;
147
                        int incrContraste = 0;
148
                        filters.remove(0);
149

    
150
                        for (int prop = 0; prop < filters.size(); prop++) {
151
                                String elem = (String) filters.get(prop);
152
                                if (elem.startsWith("filter.brightness.incrBrillo")) {
153
                                        incrBrillo = Integer.parseInt(RasterFilterListManagerImpl.getValue(elem));
154
                                        addBrightnessFilter(incrBrillo);
155
                                        filters.remove(prop);
156
                                        prop--;
157
                                }
158

    
159
                                if (elem.startsWith("filter.contrast.incrContraste")) {
160
                                        incrContraste = Integer.parseInt(RasterFilterListManagerImpl.getValue(elem));
161
                                        addContrastFilter(incrContraste);
162
                                        filters.remove(prop);
163
                                        prop--;
164
                                }
165
                        }
166
                        filteri = -1;
167
                }
168
                return filteri;
169
        }
170

    
171
        public List<Class<?>> getRasterFilterList() {
172
                List<Class<?>> filters = new ArrayList<Class<?>>();
173
                filters.add(BrightnessFilter.class);
174
                filters.add(ContrastFilter.class);
175
                return filters;
176
        }
177

    
178
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
179
                if (ContrastFilter.class.isAssignableFrom(classFilter)) {
180
                        int contrast = 0;
181
                        for (int i = 0; i < params.getNumParams(); i++) {
182
                                if (((ParamImpl)params.getParam(i)).getId().equals("Contrast"))
183
                                        contrast = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
184
                        }
185
                        addContrastFilter(contrast);
186
                }
187
                if (BrightnessFilter.class.isAssignableFrom(classFilter)) {
188
                        int brightness = 0;
189
                        for (int i = 0; i < params.getNumParams(); i++) {
190
                                if (((ParamImpl)params.getParam(i)).getId().equals("Brightness") && ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer)
191
                                        brightness = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
192
                        }
193
                        addBrightnessFilter(brightness);
194
                }
195
        }
196
        
197
        public void addFilter(Params params) throws FilterTypeException {
198
                addFilter(ContrastFilter.class, params);
199
        }
200
        
201
        public RasterFilter createFilter(Params params) {
202
                if(        params.getParamById("Brightness") != null) {
203
                        int brightness = ((Integer) params.getParamById("Brightness").getDefaultValue()).intValue();
204
                        return createBrightnessFilter(brightness);
205
                }
206
                if(        params.getParamById("Contrast") != null) {
207
                        int contrast = ((Integer) params.getParamById("Contrast").getDefaultValue()).intValue();
208
                        return createContrastFilter(contrast);
209
                }
210
                return null;
211
        }
212
}