Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / filter / enhancement / BrightnessContrastStackManager.java @ 8026

History | View | Annotate | Download (6.82 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.cresques.filter.enhancement;
21

    
22
import java.util.ArrayList;
23

    
24
import org.cresques.filter.IStackManager;
25
import org.cresques.filter.RasterFilter;
26
import org.cresques.filter.RasterFilterStack;
27
import org.cresques.filter.RasterFilterStackManager;
28
import org.cresques.io.GeoRasterFile;
29
import org.cresques.io.data.RasterBuf;
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 -1;
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
                        break;
88
                case RasterBuf.TYPE_SHORT:
89
                        filtro = new BrightnessShortFilter();
90
                        break;
91
                case RasterBuf.TYPE_USHORT:
92
                case RasterBuf.TYPE_INT:
93
                        break;
94
                }
95
                
96
                //Cuando el filtro esta creado, tomamos los valores y lo a�adimos a la pila
97
                
98
                if(filtro != null){
99
                        filtro.addParam("incrBrillo", new Integer(incrBrillo));
100
                        filterStack.addFilter(((Integer) filterStackManager.getTypeFilters().get("brightness")).intValue(), filtro);
101
                        filterStackManager.controlTypes();
102
                }
103
        }
104
                
105
        /**
106
         * A�ade un filtro de contraste a la pila de filtros.
107
         * @param incrBrillo
108
         */
109
        public void addContrastFilter(int incrContraste){
110
                //Si ya hay un filtro de contraste en la pila lo sobreescribimos
111
                
112
                if(filterStack.isActive(((Integer) filterStackManager.getTypeFilters().get("contrast")).intValue()))
113
                        filterStack.removeFilter(((Integer) filterStackManager.getTypeFilters().get("contrast")).intValue());
114
        
115
                RasterFilter filtro = null;
116
                
117
                switch(filterStack.getDataTypeInFilter(((Integer)this.filterStackManager.getTypeFilters().get("contrast")).intValue())){
118
                case RasterBuf.TYPE_IMAGE:
119
                        filtro = new ContrastImageFilter();
120
                        break;
121
                case RasterBuf.TYPE_SHORT:
122
                        filtro = new ContrastShortFilter();
123
                        break;
124
                case RasterBuf.TYPE_USHORT:
125
                case RasterBuf.TYPE_INT:
126
                        
127
                        break;
128
                }
129
                
130
                //Cuando el filtro esta creado, tomamos los valores y lo a�adimos a la pila
131
                
132
                if(filtro != null){
133
                        filtro.addParam("incrContraste", new Integer(incrContraste));
134
                        filterStack.addFilter(((Integer) filterStackManager.getTypeFilters().get("contrast")).intValue(), filtro);
135
                        filterStackManager.controlTypes();
136
                }
137
        }
138
        
139
        
140
        public void createStackFromStrings(ArrayList f, Integer pos) {
141
                // TODO Auto-generated method stub
142
                
143
        }
144

    
145
        
146
        
147
        /**
148
     * Crea una pila de filtros a partir de un Array de Strings. Cada elemento del array debe
149
     * tener la forma elemento=valor.
150
     * @param filters
151
     */
152
        public int createStackFromStrings(ArrayList filters, String fil, GeoRasterFile[] grfList, int filteri) {
153
                this.grfList = grfList;
154

    
155
                        if((fil.startsWith("filter.brightCont.active"))&&
156
                                        (RasterFilterStackManager.getValue(fil).equals("true"))){
157
                                
158
                                int incrBrillo = 0;
159
                                int incrContraste = 0;
160
                                filters.remove(0);
161
                                
162
                                for(int prop = 0; prop < filters.size() ; prop++){        
163
                                        String elem = (String) filters.get(prop);
164
                                        if(elem.startsWith("filter.brightness.incrBrillo")){
165
                                                incrBrillo = Integer.parseInt(RasterFilterStackManager.getValue(elem));
166
                                                filters.remove(prop);
167
                                                prop--;
168
                                        }
169
                                
170
                                        if(elem.startsWith("filter.contrast.incrContraste")){
171
                                                incrContraste = Integer.parseInt(RasterFilterStackManager.getValue(elem));
172
                                                filters.remove(prop);
173
                                                prop--;
174
                                        }
175
                                }
176
                                        addBrightnessFilter(incrBrillo);
177
                                        addContrastFilter(incrContraste);        
178
                        }
179
                return filteri;
180
        }
181

    
182
        public ArrayList getStringsFromStack() {
183
                // TODO Auto-generated method stub
184
                return null;
185
        }
186
        
187
        /**
188
         * Obtiene un Array de Strings a partir de una pila de filtros. Cada elemento del array
189
         * tendr� la forma de elemento=valor.
190
         */
191
        
192
        public ArrayList getStringsFromStack(ArrayList filterList, RasterFilter rf) {
193
                
194
                
195
                if((rf instanceof BrightnessFilter) || 
196
                        (rf instanceof ContrastFilter)){
197
                        filterList.add("filter.brightCont.active=true");
198
                        
199
                }
200
                
201
                if(rf instanceof BrightnessFilter){
202
                        BrightnessFilter bright = (BrightnessFilter) rf;
203
                        filterList.add("filter.brightness.incrBrillo="+bright.incrBrillo);
204
        }else if(rf instanceof ContrastFilter){
205
                ContrastFilter contrast = (ContrastFilter) rf;
206
                filterList.add("filter.contrast.incrContraste="+contrast.incrContraste);
207
        }
208
                        
209
                return filterList;
210
        }
211

    
212
}