Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / raster / TransparencyFilter.java @ 2312

History | View | Annotate | Download (4.53 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 * 
4
 * Copyright (C) 2004-5. 
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 * 
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io.raster;
25

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

    
162

    
163