Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools / src / org / gvsig / rasterTools / brightnessContrast / filter / BrightnessContrastStackManager.java @ 5497

History | View | Annotate | Download (7.7 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19

    
20
package org.gvsig.rasterTools.brightnessContrast.filter;
21

    
22
import java.util.ArrayList;
23

    
24
import org.cresques.io.GeoRasterFile;
25
import org.cresques.io.raster.IStackManager;
26
import org.cresques.io.raster.RasterBuf;
27
import org.cresques.io.raster.RasterFilter;
28
import org.cresques.io.raster.RasterFilterStack;
29
import org.cresques.io.raster.RasterFilterStackManager;
30

    
31
/**
32
 * Gestor de la pila de filtros para el filtro de brillo.
33
 * @author Miguel ?ngel Querol Carratal?  <querol_mig@gva.es>
34
 *
35
 */
36

    
37
public class BrightnessContrastStackManager implements IStackManager{
38
        
39
        public final static int                                brightness = 7;
40
        public final static int                                histogram = 6;
41
        public final static int                                contrast = 8;
42
        protected RasterFilterStack                 filterStack = null;
43
        private RasterFilterStackManager        filterStackManager = null;
44
        private GeoRasterFile[]                         grfList = null;
45
        
46
        public BrightnessContrastStackManager(RasterFilterStackManager filterStackManager){
47
                this.filterStackManager = filterStackManager;
48
                this.filterStack = filterStackManager.getFilterStack();
49
                filterStackManager.addTypeFilter("histogram", BrightnessContrastStackManager.histogram, 5);
50
                filterStackManager.addTypeFilter("brightness", BrightnessContrastStackManager.brightness, 6);
51
                filterStackManager.addTypeFilter("contrast", BrightnessContrastStackManager.contrast, 7);
52
                
53
        }
54
        
55
        
56
        /**
57
         * Obtiene el valor entero que corresponde al tipo de filtro.
58
         * @param rasterFilter
59
         * @return
60
         */
61
        public int getType(RasterFilter rasterFilter){
62
                if(rasterFilter instanceof BrightnessFilter)
63
                        return BrightnessContrastStackManager.brightness;
64
                if(rasterFilter instanceof HistogramFilter)
65
                        return BrightnessContrastStackManager.histogram;
66
                if(rasterFilter instanceof ContrastFilter)
67
                        return BrightnessContrastStackManager.contrast;
68
                                        
69
                return filterStackManager.getType(rasterFilter);
70
        }
71
        
72
        /**
73
         * A?ade un filtro de brillo a la pila de filtros.
74
         * @param incrBrillo
75
         */
76
        public void addBrightnessFilter(int incrBrillo){
77
                //Si ya hay un filtro de brillo en la pila lo sobreescribimos
78
                
79
                if(filterStack.isActive(((Integer) filterStackManager.getTypeFilters().get("brightness")).intValue()))
80
                        filterStack.removeFilter(((Integer) filterStackManager.getTypeFilters().get("brightness")).intValue());
81
        
82
                RasterFilter filtro = null;
83
                
84
                switch(filterStack.getDataTypeInFilter(((Integer)this.filterStackManager.getTypeFilters().get("brightness")).intValue())){
85
                case RasterBuf.TYPE_IMAGE:
86
                        filtro = new BrightnessImageFilter();
87
                case RasterBuf.TYPE_SHORT:
88
                case RasterBuf.TYPE_USHORT:
89
                case RasterBuf.TYPE_INT:
90
                        break;
91
                }
92
                
93
                //Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
94
                
95
                if(filtro != null){
96
                        filtro.addParam("incrBrillo", new Integer(incrBrillo));
97
                        
98
                        
99
                        filterStack.addFilter(((Integer) filterStackManager.getTypeFilters().get("brightness")).intValue(), filtro);
100
                
101
                        filterStackManager.controlTypes();
102
                }
103
        }
104
        
105
        /**
106
         * A?ade un filtro de histograma a la pila de filtros
107
         *
108
         */
109
        public void addHistogramFilter(){
110
                
111
                RasterFilter filtro =  null;
112
                
113
                //Si ya hay un filtro de histrograma en la pila lo sobreescribimos
114
                
115
                if(filterStack.isActive(((Integer) filterStackManager.getTypeFilters().get("histogram")).intValue()))
116
                        filterStack.removeFilter(((Integer) filterStackManager.getTypeFilters().get("histogram")).intValue());
117
                
118
                //Crea el filtro a partir del dato de entrada que tenemos
119
                switch(filterStack.getDataTypeInFilter(((Integer) filterStackManager.getTypeFilters().get("histogram")).intValue())){
120
                case RasterBuf.TYPE_IMAGE:
121
                        filtro = new HistogramImageFilter();
122
                case RasterBuf.TYPE_SHORT:
123
                case RasterBuf.TYPE_USHORT:
124
                case RasterBuf.TYPE_INT:
125
                        break;
126
                }
127
                
128
                if(filtro != null){
129
                        filterStack.addFilter(((Integer) filterStackManager.getTypeFilters().get("histogram")).intValue(),filtro);
130
                
131
                filterStackManager.controlTypes();
132
                }
133
        }
134
        
135
        
136
        /**
137
         * A?ade un filtro de contraste a la pila de filtros.
138
         * @param incrBrillo
139
         */
140
        public void addContrastFilter(int incrContraste){
141
                //Si ya hay un filtro de contraste en la pila lo sobreescribimos
142
                
143
                if(filterStack.isActive(((Integer) filterStackManager.getTypeFilters().get("contrast")).intValue()))
144
                        filterStack.removeFilter(((Integer) filterStackManager.getTypeFilters().get("contrast")).intValue());
145
        
146
                RasterFilter filtro = null;
147
                
148
                switch(filterStack.getDataTypeInFilter(((Integer)this.filterStackManager.getTypeFilters().get("contrast")).intValue())){
149
                case RasterBuf.TYPE_IMAGE:
150
                        filtro = new ContrastImageFilter();
151
                case RasterBuf.TYPE_SHORT:
152
                case RasterBuf.TYPE_USHORT:
153
                case RasterBuf.TYPE_INT:
154
                        break;
155
                }
156
                
157
                //Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
158
                
159
                if(filtro != null){
160
                        filtro.addParam("incrContraste", new Integer(incrContraste));
161
                        
162
                        filterStack.addFilter(((Integer) filterStackManager.getTypeFilters().get("contrast")).intValue(), filtro);
163
                
164
                        filterStackManager.controlTypes();
165
                }
166
        }
167
        
168
        
169
        public void createStackFromStrings(ArrayList f, Integer pos) {
170
                // TODO Auto-generated method stub
171
                
172
        }
173

    
174
        
175
        
176
        /**
177
     * Crea una pila de filtros a partir de un Array de Strings. Cada elemento del array debe
178
     * tener la forma elemento=valor.
179
     * @param filters
180
     */
181
        public int createStackFromStrings(ArrayList filters, String fil, GeoRasterFile[] grfList, int filteri) {
182
                this.grfList = grfList;
183

    
184
                        if((fil.startsWith("filter.brightCont.active"))&&
185
                                        (RasterFilterStackManager.getValue(fil).equals("true"))){
186
                                
187
                                int incrBrillo = 0;
188
                                int incrContraste = 0;
189
                                filters.remove(0);
190
                                
191
                                for(int prop = 0; prop < filters.size() ; prop++){        
192
                                        String elem = (String) filters.get(prop);
193
                                        if(elem.startsWith("filter.brightness.incrBrillo")){
194
                                                incrBrillo = Integer.parseInt(RasterFilterStackManager.getValue(elem));
195
                                                filters.remove(prop);
196
                                                prop--;
197
                                        }
198
                                
199
                                        if(elem.startsWith("filter.contrast.incrContraste")){
200
                                                incrContraste = Integer.parseInt(RasterFilterStackManager.getValue(elem));
201
                                                filters.remove(prop);
202
                                                prop--;
203
                                        }
204
                                }
205
                                addBrightnessFilter(incrBrillo);
206
                                addContrastFilter(incrContraste);        
207
                        }
208
                return filteri;
209
        }
210

    
211
        public ArrayList getStringsFromStack() {
212
                // TODO Auto-generated method stub
213
                return null;
214
        }
215
        
216
        /**
217
         * Obtiene un Array de Strings a partir de una pila de filtros. Cada elemento del array
218
         * tendr? la forma de elemento=valor.
219
         */
220
        
221
        public ArrayList getStringsFromStack(ArrayList filterList, RasterFilter rf) {
222
                
223
                
224
                if((rf instanceof BrightnessFilter) || 
225
                        (rf instanceof ContrastFilter)){
226
                        filterList.add("filter.brightCont.active=true");
227
                }
228
                
229
                if(rf instanceof BrightnessFilter){
230
                        BrightnessFilter bright = (BrightnessFilter) rf;
231
                        filterList.add("filter.brightness.incrBrillo="+bright.incrBrillo);
232
        }else if(rf instanceof ContrastFilter){
233
                ContrastFilter contrast = (ContrastFilter) rf;
234
                filterList.add("filter.contrast.incrContraste="+contrast.incrContraste);
235
        }
236
                        
237
                return filterList;
238
        }
239

    
240
}