Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libCq CMS for java.old / src / org / cresques / filter / enhancement / TransparencyShortFilter.java @ 9056

History | View | Annotate | Download (4.35 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.filter.enhancement;
25

    
26
import org.cresques.filter.RasterBuf;
27

    
28

    
29
/**
30
 * Filtro de transparencia aplicada a un rango de valores de un pixel sobre un objeto image
31
 * @author Nacho Brodin (brodin_ign@gva.es)
32
 *
33
 */
34
public class TransparencyShortFilter extends TransparencyFilter {
35
    /**
36
     * Constructor
37
     *
38
     */
39
    public TransparencyShortFilter() {
40
        super();
41
    }
42

    
43
    /* (non-Javadoc)
44
     * @see org.cresques.io.raster.IRasterFilter#pre()
45
     */
46
    public void pre() {
47
        //Obtenci?n de par?metros
48
        this.raster = (RasterBuf) params.get("raster");
49
        height = raster.getHeight();
50
        width = raster.getWidth();
51
        super.pre();
52
    }
53

    
54
    /**
55
     * Asigna al pixel pasado como par?metro como transparente con 
56
     * el color de transparencia que est? seleccionado
57
     * @param px Pixel a asignarle transparencia
58
     */
59
    private void setPixelTransparent(int[] px){
60
                px[3] = this.alpha;
61
        px[0] = this.transparencyColorRed;
62
        px[1] = this.transparencyColorGreen;
63
        px[2] = this.transparencyColorBlue;        
64
    }
65
    
66
    /**     
67
     * @param range rango
68
     * @param banda banda
69
     * @param px    pixel
70
     */
71
    private void processRange(int[] px) {
72
            for (int i = 0; i < rangesList.size(); i++) {
73
                    TransparencyRange tr = ((TransparencyRange)rangesList.get(i));
74

    
75
                    if(tr.isAnd()){
76
                            if(tr.getRed() != null)
77
                                    if (px[0] < tr.getRed()[0] || px[0] > tr.getRed()[1])
78
                                            continue;
79
                            if(tr.getGreen() != null)
80
                                    if (px[1] < tr.getGreen()[0] || px[1] > tr.getGreen()[1])
81
                                            continue;
82
                            if(tr.getBlue() != null)
83
                                    if (px[2] < tr.getBlue()[0] || px[2] > tr.getBlue()[1])
84
                                            continue;
85
                            if(tr.getRed() != null || tr.getGreen() != null || tr.getBlue() != null)
86
                                    setPixelTransparent(px);
87
                            
88
                    }else{
89
                            if(tr.getRed() != null){
90
                                    if (px[0] >= tr.getRed()[0] && px[0] <= tr.getRed()[1]){
91
                                            setPixelTransparent(px);
92
                                            continue;
93
                                    }
94
                            }
95
                            if(tr.getGreen() != null){
96
                                    if (px[1] >= tr.getGreen()[0] && px[1] <= tr.getGreen()[1]){
97
                                            setPixelTransparent(px);
98
                                            continue;
99
                                    }
100
                            }
101
                            if(tr.getBlue() != null){
102
                                    if (px[2] >= tr.getBlue()[0] && px[2] <= tr.getBlue()[1]){
103
                                            setPixelTransparent(px);
104
                                            continue;
105
                                    }
106
                            }
107
                    }
108
            }
109
            
110
    }
111

    
112
    /* (non-Javadoc)
113
     * @see org.cresques.io.raster.IRasterFilter#process(int, int)
114
     */
115
    public void process(int x, int y) {
116
        raster.getElemInt(x, y, px);
117
        processRange(px);
118
        raster.setElemInt(x, y, px);
119
    }
120

    
121
    /* (non-Javadoc)
122
     * @see org.cresques.io.raster.IRasterFilter#getInRasterDataType()
123
     */
124
    public int getInRasterDataType() {
125
        return RasterBuf.TYPE_SHORT;
126
    }
127

    
128
    /* (non-Javadoc)
129
     * @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType()
130
     */
131
    public int getOutRasterDataType() {
132
        return RasterBuf.TYPE_SHORT;
133
    }
134

    
135
    /* (non-Javadoc)
136
     * @see org.cresques.io.raster.IRasterFilter#getResult(java.lang.String)
137
     */
138
    public Object getResult(String name) {
139
        if (name.equals("raster")) {
140
            return (Object) this.raster;
141
        } else {
142
            return null;
143
        }
144
    }
145

    
146
    /* (non-Javadoc)
147
     * @see org.cresques.io.raster.RasterFilter#processLine(int)
148
     */
149
    public void processLine(int y) {
150
    }
151

    
152
    /* (non-Javadoc)
153
     * @see org.cresques.io.raster.IRasterFilter#post()
154
     */
155
    public void post() {
156
    }
157
}