Statistics
| Revision:

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

History | View | Annotate | Download (5.38 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
/**
28
 * Clase base para los filtros de transparencia en sus diferentes tipos
29
 * de datos.
30
 * @author Nacho Brodin (brodin_ign@gva.es)
31
 *
32
 */
33
public abstract class TransparencyFilter extends RasterFilter {
34
    //Par?metros del filtro
35
    protected int[][] rangesR;
36
    protected int[][] rangesG;
37
    protected int[][] rangesB;
38

    
39
    /**
40
     * Valor de transparencia
41
     */
42
    public int alpha = 0x10;
43

    
44
    /**
45
     * Color en la banda del rojo para la transparencia
46
     */
47
    public int transparencyColorRed = 0xff;
48

    
49
    /**
50
     * Color en la banda del verde para la transparencia
51
     */
52
    public int transparencyColorGreen = 0xff;
53

    
54
    /**
55
     * Color en la banda del azul para la transparencia
56
     */
57
    public int transparencyColorBlue = 0xff;
58

    
59
    /**
60
     * Constructor
61
     *
62
     */
63
    public TransparencyFilter() {
64
        super();
65
    }
66

    
67
    /**
68
     * Obtiene par?metros del filtro desde la tabla Hash
69
     */
70
    public void pre() {
71
        //Obtenci?n de par?metros comunes a todos
72
        this.rangesR = (int[][]) params.get("red");
73
        this.rangesG = (int[][]) params.get("green");
74
        this.rangesB = (int[][]) params.get("blue");
75
        this.alpha = ((Integer) params.get("alpha")).intValue();
76
        this.transparencyColorRed = ((Integer) params.get("transparencyRed")).intValue();
77
        this.transparencyColorGreen = ((Integer) params.get("transparencyGreen")).intValue();
78
        this.transparencyColorBlue = ((Integer) params.get("transparencyBlue")).intValue();
79
    }
80

    
81
    /**
82
     * Para dos intervalos dados, devuelve true si el intervalo B est? dentro del A y
83
     * false si no lo est?
84
     * @param intervalA intervalo A
85
     * @param intervalB intervalo B
86
     * @return true si el intervalo B est? dentro del A y false si no lo est?
87
     */
88
    private boolean compareIntervals(int[][] intervalA, int[][] intervalB) {
89
        if ((intervalA != null) && (intervalB != null)) {
90
            boolean equalInterval = false;
91

    
92
            for (int i = 0; i < intervalB.length; i++) {
93
                for (int j = 0; j < intervalA.length; j++) {
94
                    if ((intervalB[i][0] >= intervalA[i][0]) &&
95
                            (intervalB[i][1] <= intervalA[i][1])) {
96
                        equalInterval = true;
97

    
98
                        break;
99
                    }
100
                }
101

    
102
                if (!equalInterval) {
103
                    return false;
104
                }
105
            }
106

    
107
            return true;
108
        }
109

    
110
        if ((intervalA == null) && (intervalB == null)) {
111
            return true;
112
        }
113

    
114
        return false;
115
    }
116

    
117
    /**
118
     * Devuelve true si el filtro pasado por par?metro es equivalente a este
119
     * y false si no lo es.
120
     * @param filter        Filtro a comparar
121
     * @return        true si son equivalentes y false si no lo son
122
     */
123
    public boolean isEquivalent(TransparencyFilter filter) {
124
        if ((alpha != filter.alpha) ||
125
                (transparencyColorRed != filter.transparencyColorRed) ||
126
                (transparencyColorGreen != filter.transparencyColorGreen) ||
127
                (transparencyColorBlue != filter.transparencyColorBlue)) {
128
            return false;
129
        }
130

    
131
        boolean equalRange = false;
132
        equalRange = compareIntervals((int[][]) params.get("red"),
133
                                      (int[][]) filter.params.get("red"));
134

    
135
        if (!equalRange) {
136
            return false;
137
        }
138

    
139
        equalRange = false;
140
        equalRange = compareIntervals((int[][]) params.get("green"),
141
                                      (int[][]) filter.params.get("green"));
142

    
143
        if (!equalRange) {
144
            return false;
145
        }
146

    
147
        equalRange = false;
148
        equalRange = compareIntervals((int[][]) params.get("blue"),
149
                                      (int[][]) filter.params.get("blue"));
150

    
151
        if (!equalRange) {
152
            return false;
153
        }
154

    
155
        return true;
156
    }
157

    
158
    /**
159
     * Obtiene los rangos de transparencia en la banda  del rojo
160
     * @return rangos de transparencia en la banda del rojo
161
     */
162
    public int[][] getRangeR() {
163
        return this.rangesR;
164
    }
165

    
166
    /**
167
     * Obtiene los rangos de transparencia en la banda  del verde
168
     * @return rangos de transparencia en la banda del verde
169
     */
170
    public int[][] getRangeG() {
171
        return this.rangesG;
172
    }
173

    
174
    /**
175
     * Obtiene los rangos de transparencia en la banda  del azul
176
     * @return rangos de transparencia en la banda del azul
177
     */
178
    public int[][] getRangeB() {
179
        return this.rangesB;
180
    }
181
}