Statistics
| Revision:

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

History | View | Annotate | Download (5.57 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<Class<?>> getRasterFilterList() {
127
                List<Class<?>> filters = new ArrayList<Class<?>>();
128
                filters.add(BrightnessFilter.class);
129
                filters.add(ContrastFilter.class);
130
                return filters;
131
        }
132

    
133
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
134
                if (ContrastFilter.class.isAssignableFrom(classFilter)) {
135
                        int contrast = 0;
136
                        for (int i = 0; i < params.getNumParams(); i++) {
137
                                if (((ParamImpl)params.getParam(i)).getId().equals("Contrast"))
138
                                        contrast = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
139
                        }
140
                        addContrastFilter(contrast);
141
                }
142
                if (BrightnessFilter.class.isAssignableFrom(classFilter)) {
143
                        int brightness = 0;
144
                        for (int i = 0; i < params.getNumParams(); i++) {
145
                                if (((ParamImpl)params.getParam(i)).getId().equals("Brightness") && ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer)
146
                                        brightness = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
147
                        }
148
                        addBrightnessFilter(brightness);
149
                }
150
        }
151
        
152
        public void addFilter(Params params) throws FilterTypeException {
153
                addFilter(ContrastFilter.class, params);
154
        }
155
        
156
        public RasterFilter createFilter(Params params) {
157
                if(        params.getParamById("Brightness") != null) {
158
                        int brightness = ((Integer) params.getParamById("Brightness").getDefaultValue()).intValue();
159
                        return createBrightnessFilter(brightness);
160
                }
161
                if(        params.getParamById("Contrast") != null) {
162
                        int contrast = ((Integer) params.getParamById("Contrast").getDefaultValue()).intValue();
163
                        return createContrastFilter(contrast);
164
                }
165
                return null;
166
        }
167
}