Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / bands / ColorBalanceRGBFilter.java @ 17108

History | View | Annotate | Download (4.83 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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
package org.gvsig.raster.grid.filter.bands;
20

    
21
import org.gvsig.raster.buffer.RasterBuffer;
22
import org.gvsig.raster.dataset.IBuffer;
23
import org.gvsig.raster.dataset.IRasterDataSource;
24
import org.gvsig.raster.dataset.Params;
25
import org.gvsig.raster.grid.filter.RasterFilter;
26
import org.gvsig.raster.util.ColorConversion;
27
/**
28
 * <P>
29
 * Clase base para los filtros de balance de color RGB
30
 * </P>
31
 *
32
 * @version 30/11/2007
33
 * @author Nacho Brodin (nachobrodin@gmail.com)
34
 */
35
public class ColorBalanceRGBFilter extends RasterFilter {
36
        protected IBuffer          rasterResult     = null;
37
        protected IBuffer          rasterAlpha      = null;
38
        public static String[]     names            = new String[] { "colorbalancergb" };
39
        protected ColorConversion  colorConversion  = null;
40
        protected int              out              = IBuffer.TYPE_BYTE;
41
        protected int              red              = 0;
42
        protected int              green            = 0;
43
        protected int              blue             = 0;
44
        protected boolean          luminosity       = false;
45

    
46
        /**
47
         * Constructor
48
         */
49
        public ColorBalanceRGBFilter() {
50
                super();
51
                setName(names[0]);
52
        }
53

    
54
        /*
55
         * (non-Javadoc)
56
         * @see org.gvsig.raster.grid.filter.RasterFilter#pre()
57
         */
58
        public void pre() {
59
                exec = true;
60
                raster = (RasterBuffer) params.get("raster");
61
                if(raster.getDataType() != IBuffer.TYPE_BYTE) {
62
                        exec = false;
63
                        raster = rasterResult;
64
                        return;
65
                }
66
                if(params.get("red") != null)
67
                        red = ((Integer) params.get("red")).intValue();
68
                if(params.get("green") != null)
69
                        green = ((Integer) params.get("green")).intValue();
70
                if(params.get("blue") != null)
71
                        blue = ((Integer) params.get("blue")).intValue();
72
                if(params.get("luminosity") != null)
73
                        luminosity = ((Boolean) params.get("luminosity")).booleanValue();
74
                if(raster != null) {
75
                        height = raster.getHeight();
76
                        width = raster.getWidth();
77
                        rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), 3, true);        
78
                }
79
                if(colorConversion == null)
80
                        colorConversion = new ColorConversion();
81
        }
82

    
83
        /*
84
         * (non-Javadoc)
85
         * @see org.gvsig.raster.grid.filter.RasterFilter#getGroup()
86
         */
87
        public String getGroup() {
88
                return "colores";
89
        }
90

    
91
        /*
92
         * (non-Javadoc)
93
         * @see org.gvsig.raster.grid.filter.RasterFilter#getNames()
94
         */
95
        public String[] getNames() {
96
                return names;
97
        }
98

    
99
        /*
100
         * (non-Javadoc)
101
         * @see org.gvsig.raster.grid.filter.RasterFilter#getResult(java.lang.String)
102
         */
103
        public Object getResult(String name) {
104
                if (name.equals("raster"))
105
                        return (Object) this.rasterResult;
106
                return null;
107
        }
108

    
109
        /*
110
         * (non-Javadoc)
111
         * @see org.gvsig.raster.grid.filter.RasterFilter#getUIParams(java.lang.String)
112
         */
113
        public Params getUIParams(String nameFilter) {
114
                Params params = new Params();
115
                params.setParam("red",
116
                                new Integer(red),
117
                                Params.SLIDER,
118
                                new String[]{ "0", "100", "0", "5", "25"}); //min, max, valor defecto, intervalo peque?o, intervalo grande;
119
                params.setParam("green",
120
                                new Integer(green),
121
                                Params.SLIDER,
122
                                new String[]{ "0", "100", "0", "5", "25"}); //min, max, valor defecto, intervalo peque?o, intervalo grande;
123
                params.setParam("blue",
124
                                new Integer(blue),
125
                                Params.SLIDER,
126
                                new String[]{ "0", "100", "0", "5", "25"}); //min, max, valor defecto, intervalo peque?o, intervalo grande;
127
                params.setParam("luminosity",
128
                                new Boolean(luminosity),
129
                                Params.CHECK,
130
                                null);
131

    
132
                return params;
133
        }
134

    
135
        public void post() {
136
        
137
        }
138

    
139
        public void process(int x, int y) {
140
        }
141

    
142
        /*
143
         * (non-Javadoc)
144
         * @see org.gvsig.raster.grid.filter.RasterFilter#getOutRasterDataType()
145
         */
146
        public int getOutRasterDataType() {
147
                return IBuffer.TYPE_BYTE;
148
        }
149

    
150
        /*
151
         * (non-Javadoc)
152
         * @see org.gvsig.raster.grid.filter.RasterFilter#isVisible()
153
         */
154
        public boolean isVisible() {
155
                IRasterDataSource datasource = (IRasterDataSource)getEnv().get("MultiRasterDataset");
156
                return (datasource != null && datasource.getBandCount() >= 3);
157
        }
158

    
159
        /*
160
         * (non-Javadoc)
161
         * @see org.gvsig.raster.grid.filter.RasterFilter#getInRasterDataType()
162
         */
163
        public int getInRasterDataType() {
164
                return IBuffer.TYPE_BYTE;
165
        }
166
}