Statistics
| Revision:

root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / raster / TransparencyFilter.java @ 2249

History | View | Annotate | Download (4.76 KB)

1
/*
2
 * Created on 21-jun-2005
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package org.cresques.io.raster;
48

    
49
/**
50
 * @author Nacho Brodin <brodin_ign@gva.es>
51
 * 
52
 * Clase base para los filtros de transparencia en sus diferentes tipos
53
 * de datos.
54
 */ 
55
public abstract class TransparencyFilter extends RasterFilter{
56
                
57
        //Par?metros del filtro
58
        protected int[][] rangesR;
59
        protected int[][] rangesG;
60
        protected int[][] rangesB;
61
        public int                 alpha = 0x10;
62
        public int                 transparencyColorRed = 0xff;
63
        public int                 transparencyColorGreen = 0xff;
64
        public int                 transparencyColorBlue = 0xff;
65
        
66
        
67
        public TransparencyFilter(){
68
                super();
69
        }
70
        
71
        /**
72
         * Obtiene par?metros del filtro desde la tabla Hash
73
         */
74
        public void pre(){
75
                //Obtenci?n de par?metros comunes a todos
76
                this.rangesR = (int[][])params.get("red");
77
                this.rangesG = (int[][])params.get("green");
78
                this.rangesB = (int[][])params.get("blue");
79
                this.alpha = ((Integer)params.get("alpha")).intValue();
80
                this.transparencyColorRed = ((Integer)params.get("transparencyRed")).intValue();
81
                this.transparencyColorGreen = ((Integer)params.get("transparencyGreen")).intValue();
82
                this.transparencyColorBlue = ((Integer)params.get("transparencyBlue")).intValue();
83
        }
84
        
85
        /**
86
         * Para dos intervalos dados, devuelve true si el intervalo B est? dentro del A y
87
         * false si no lo est?
88
         * @param intervalA intervalo A
89
         * @param intervalB intervalo B
90
         * @return true si el intervalo B est? dentro del A y false si no lo est?
91
         */
92
        private boolean compareIntervals(int[][] intervalA, int[][] intervalB){
93
                if(intervalA != null && intervalB != null){
94
                        boolean equalInterval = false;
95
                        for(int i=0;i<intervalB.length;i++){
96
                                for(int j=0;j<intervalA.length;j++){
97
                                        if(        intervalB[i][0] >= intervalA[i][0] && 
98
                                                intervalB[i][1] <= intervalA[i][1]){
99
                                                equalInterval = true;
100
                                                break;
101
                                        }
102
                                }
103
                                if(!equalInterval)
104
                                        return false;
105
                        }
106
                        return true;
107
                }
108
                
109
                if(intervalA == null && intervalB == null)
110
                        return true;
111
                
112
                return false;
113
        }
114
        
115
        /**
116
         * Devuelve true si el filtro pasado por par?metro es equivalente a este
117
         * y false si no lo es.
118
         * @param filter        Filtro a comparar
119
         * @return        true si son equivalentes y false si no lo son
120
         */
121
        public boolean isEquivalent(TransparencyFilter filter){
122
                
123
                if(        alpha!=filter.alpha ||
124
                        transparencyColorRed != filter.transparencyColorRed ||
125
                        transparencyColorGreen != filter.transparencyColorGreen ||
126
                        transparencyColorBlue != filter.transparencyColorBlue)
127
                        return false;
128
                
129
                boolean equalRange = false;
130
                equalRange = compareIntervals((int[][])params.get("red"), (int[][])filter.params.get("red"));
131
                if(!equalRange)
132
                        return false;
133
                equalRange = false;
134
                equalRange = compareIntervals((int[][])params.get("green"), (int[][])filter.params.get("green"));
135
                if(!equalRange)
136
                        return false;
137
                equalRange = false;
138
                equalRange = compareIntervals((int[][])params.get("blue"), (int[][])filter.params.get("blue"));
139
                if(!equalRange)
140
                        return false;
141
                
142
                return true;                
143
        }
144
        
145
        /**
146
         * Obtiene los rangos de transparencia en la banda  del rojo 
147
         * @return rangos de transparencia en la banda del rojo
148
         */
149
        public int[][] getRangeR(){
150
                return this.rangesR;
151
        }
152
        
153
        /**
154
         * Obtiene los rangos de transparencia en la banda  del verde
155
         * @return rangos de transparencia en la banda del verde
156
         */
157
        public int[][] getRangeG(){
158
                return this.rangesG;
159
        }
160
        
161
        /**
162
         * Obtiene los rangos de transparencia en la banda  del azul
163
         * @return rangos de transparencia en la banda del azul
164
         */
165
        public int[][] getRangeB(){
166
                return this.rangesB;
167
        }
168
}
169

    
170

    
171