Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / BrightnessContrastListManager.java @ 11067

History | View | Annotate | Download (5.27 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 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.raster.grid.filter.enhancement;
21

    
22
import java.util.ArrayList;
23

    
24
import org.gvsig.raster.dataaccess.buffer.RasterBuffer;
25
import org.gvsig.raster.grid.filter.IRasterFilterListManager;
26
import org.gvsig.raster.grid.filter.RasterFilter;
27
import org.gvsig.raster.grid.filter.RasterFilterList;
28
import org.gvsig.raster.grid.filter.RasterFilterListManager;
29

    
30
public class BrightnessContrastListManager implements IRasterFilterListManager{
31
        
32
        protected RasterFilterList                         filterList = null;
33
        private RasterFilterListManager                filterListManager = null;
34
        
35
        public BrightnessContrastListManager(RasterFilterListManager filterListManager){
36
                this.filterListManager = filterListManager;
37
                this.filterList = filterListManager.getFilterList();
38
        }
39
                
40
        /**
41
         * A?ade un filtro de brillo a la pila de filtros.
42
         * @param incrBrillo valor de brillo a aplicar
43
         * @param removeAll        true si se desea eliminar cualquier filtro de brillo que 
44
         * hubiera en la pila antes y false si se acumula sobre lo que haya
45
         */
46
        public void addBrightnessFilter(int incrBrillo, boolean removeAll){
47
                //Si ya hay un filtro de brillo en la pila lo sobreescribimos
48
                String fName = BrightnessFilter.genericName;
49
                
50
                RasterFilter filtro = null;
51
                
52
                switch(filterList.getDataTypeInFilter(fName)){
53
                case RasterBuffer.TYPE_BYTE:
54
                        filtro = new BrightnessByteFilter();
55
                        break;
56
                case RasterBuffer.TYPE_SHORT:
57
                        filtro = new BrightnessShortFilter();
58
                        break;
59
                case RasterBuffer.TYPE_USHORT:
60
                case RasterBuffer.TYPE_INT:
61
                        break;
62
                }
63
                
64
                //Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
65
                
66
                if(filtro != null){
67
                        if(removeAll)
68
                                filterList.remove(BrightnessFilter.genericName);
69
                        filtro.addParam("incrBrillo", new Integer(incrBrillo));
70
                        filterList.add(filtro);
71
                        filterListManager.controlTypes();
72
                }
73
        }
74
                
75
        /**
76
         * A?ade un filtro de contraste a la pila de filtros.
77
         * @param incrBrillo
78
         */
79
        public void addContrastFilter(int incrContraste, boolean removeAll){
80
                //Si ya hay un filtro de contraste en la pila lo sobreescribimos
81
                String fName = ContrastFilter.genericName;
82
                
83
                RasterFilter filtro = null;
84
                
85
                switch(filterList.getDataTypeInFilter(fName)){
86
                case RasterBuffer.TYPE_BYTE:
87
                        filtro = new ContrastByteFilter();
88
                        break;
89
                case RasterBuffer.TYPE_SHORT:
90
                        filtro = new ContrastShortFilter();
91
                        break;
92
                case RasterBuffer.TYPE_USHORT:
93
                case RasterBuffer.TYPE_INT:
94
                        break;
95
                }
96
                
97
                //Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
98
                
99
                if(filtro != null){
100
                        if(removeAll && filterList.isActive(fName))
101
                                filterList.remove(fName);
102
                        filtro.addParam("incrContraste", new Integer(incrContraste));
103
                        filterList.add(filtro);
104
                        filterListManager.controlTypes();
105
                }
106
        }
107
        
108
        
109
        public void createStackFromStrings(ArrayList f, Integer pos) {
110
                        
111
        }
112

    
113
        public ArrayList getStringsFromStack() {
114
                return null;
115
        }
116
        
117
        /**
118
         * Obtiene un Array de Strings a partir de una pila de filtros. Cada elemento del array
119
         * tendr? la forma de elemento=valor.
120
         */
121
        
122
        public ArrayList getStringsFromStack(ArrayList filterList, RasterFilter rf) {
123
                
124
                /*if((rf instanceof BrightnessFilter) || 
125
                        (rf instanceof ContrastFilter)){
126
                        filterList.add("filter.brightCont.active=true");
127
                        
128
                }
129
                
130
                if(rf instanceof BrightnessFilter){
131
                        BrightnessFilter bright = (BrightnessFilter) rf;
132
                        filterList.add("filter.brightness.incrBrillo="+bright.incrBrillo);
133
        }else if(rf instanceof ContrastFilter){
134
                ContrastFilter contrast = (ContrastFilter) rf;
135
                filterList.add("filter.contrast.incrContraste="+contrast.incrContraste);
136
        }*/
137
                        
138
                return filterList;
139
        }
140

    
141
        public int createStackFromStrings(ArrayList filters, String fil, int filteri) {
142
                if((fil.startsWith("filter.brightCont.active"))&&
143
                                (RasterFilterListManager.getValue(fil).equals("true"))){
144
                        
145
                        int incrBrillo = 0;
146
                        int incrContraste = 0;
147
                        filters.remove(0);
148
                        
149
                        for(int prop = 0; prop < filters.size() ; prop++){        
150
                                String elem = (String) filters.get(prop);
151
                                if(elem.startsWith("filter.brightness.incrBrillo")){
152
                                        incrBrillo = Integer.parseInt(RasterFilterListManager.getValue(elem));
153
                                        filters.remove(prop);
154
                                        prop--;
155
                                }
156
                        
157
                                if(elem.startsWith("filter.contrast.incrContraste")){
158
                                        incrContraste = Integer.parseInt(RasterFilterListManager.getValue(elem));
159
                                        filters.remove(prop);
160
                                        prop--;
161
                                }
162
                        }
163
                        addBrightnessFilter(incrBrillo, true);
164
                        addContrastFilter(incrContraste, true);        
165
                }
166
        return filteri;
167
        }
168

    
169
        public void createStackFromStrings(ArrayList f) {
170
        }
171

    
172
}