Statistics
| Revision:

gvsig-raster / org.gvsig.raster / tags / 2.0.0 / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / band / ToLumSaFilter.java @ 1708

History | View | Annotate | Download (5.22 KB)

1 21 nbrodin
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.impl.grid.filter.band;
23
24 55 nbrodin
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
25 21 nbrodin
import org.gvsig.fmap.dal.coverage.datastruct.Params;
26 151 nbrodin
import org.gvsig.fmap.dal.coverage.grid.filter.BaseRasterFilter;
27 28 nbrodin
import org.gvsig.raster.impl.DefaultRasterManager;
28 21 nbrodin
import org.gvsig.raster.impl.buffer.RasterBuffer;
29 71 nbrodin
import org.gvsig.raster.impl.store.ParamsImpl;
30 112 nbrodin
import org.gvsig.raster.util.DefaultColorConversion;
31 21 nbrodin
/**
32
 * <P>
33
 * Clase base para el filtro de Tono, Saturaci?n y Brillo
34
 * </P>
35
 *
36
 * @version 04/12/2007
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 */
39 151 nbrodin
public class ToLumSaFilter extends BaseRasterFilter {
40 21 nbrodin
        protected Buffer          rasterAlpha      = null;
41
        public static String[]     names            = new String[] { "tolumsa" };
42 112 nbrodin
        protected DefaultColorConversion  colorConversion  = null;
43 21 nbrodin
        protected int              out              = Buffer.TYPE_BYTE;
44
        protected double           hue              = 0;
45
        protected double           luminosity       = 0;
46
        protected double           saturation       = 0;
47
        protected int[]            renderBands      = null;
48
49
        /**
50
         * Constructor
51
         */
52
        public ToLumSaFilter() {
53
                super();
54
                setName(names[0]);
55
        }
56
57
        /*
58
         * (non-Javadoc)
59
         * @see org.gvsig.raster.grid.filter.RasterFilter#pre()
60
         */
61
        public void pre() {
62
                exec = true;
63
                raster = (RasterBuffer) params.get("raster");
64
                int[] rb = (int[]) params.get("renderBands");
65
66
                switch (raster.getBandCount()) {
67
                case 1:renderBands = new int[]{0, 0, 0}; break;
68
                case 2:renderBands = rb; break;
69
                case 3:renderBands = new int[]{0, 1, 2}; break;
70
                }
71
                //Mantenemos los valores de -1 ya que esas bandas no se procesan
72
                for(int i = 0; i < renderBands.length; i++)
73
                        if(rb[i] == -1)
74
                                renderBands[i] = -1;
75
76
                if(raster.getDataType() != Buffer.TYPE_BYTE) {
77
                        exec = false;
78
                        raster = rasterResult;
79
                        return;
80
                }
81
                if(params.get("hue") != null)
82
                        hue = ((Double) params.get("hue")).doubleValue();
83
                if(params.get("luminosity") != null)
84
                        luminosity = ((Double) params.get("luminosity")).doubleValue();
85
                if(params.get("saturation") != null)
86
                        saturation = ((Double) params.get("saturation")).doubleValue();
87
88
                if(raster != null) {
89
                        height = raster.getHeight();
90
                        width = raster.getWidth();
91 30 nbrodin
                        rasterResult = DefaultRasterManager.getInstance().createBuffer(Buffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), 3, true);
92 21 nbrodin
                }
93
                if(colorConversion == null)
94 112 nbrodin
                        colorConversion = new DefaultColorConversion();
95 21 nbrodin
        }
96
97
        /*
98
         * (non-Javadoc)
99
         * @see org.gvsig.raster.grid.filter.RasterFilter#getGroup()
100
         */
101
        public String getGroup() {
102
                return "colores";
103
        }
104
105
        /*
106
         * (non-Javadoc)
107
         * @see org.gvsig.raster.grid.filter.RasterFilter#getNames()
108
         */
109
        public String[] getNames() {
110
                return names;
111
        }
112
113
        /*
114
         * (non-Javadoc)
115
         * @see org.gvsig.raster.grid.filter.RasterFilter#getResult(java.lang.String)
116
         */
117
        public Object getResult(String name) {
118
                if (name.equals("raster"))
119
                        return (Object) this.rasterResult;
120
                return null;
121
        }
122
123
        /*
124
         * (non-Javadoc)
125
         * @see org.gvsig.raster.grid.filter.RasterFilter#getUIParams(java.lang.String)
126
         */
127
        public Params getUIParams(String nameFilter) {
128
                Params params = new ParamsImpl();
129
                params.setParam("hue",
130
                                new Double(hue),
131
                                Params.SLIDER,
132
                                new String[]{ "-180", "180", "0", "10", "50"}); //min, max, valor defecto, intervalo peque?o, intervalo grande;
133
                params.setParam("luminosity",
134
                                new Double(luminosity),
135
                                Params.SLIDER,
136
                                new String[]{ "-100", "100", "0", "10", "50"}); //min, max, valor defecto, intervalo peque?o, intervalo grande;
137
                params.setParam("saturation",
138
                                new Double(saturation),
139
                                Params.SLIDER,
140
                                new String[]{ "-100", "100", "0", "10", "50"}); //min, max, valor defecto, intervalo peque?o, intervalo grande;
141
                return params;
142
        }
143
144
        public void post() {
145
146
        }
147
148
        public void process(int x, int y) {
149
        }
150
151
        /*
152
         * (non-Javadoc)
153
         * @see org.gvsig.raster.grid.filter.RasterFilter#getOutRasterDataType()
154
         */
155
        public int getOutRasterDataType() {
156
                return Buffer.TYPE_BYTE;
157
        }
158
159
        /*
160
         * (non-Javadoc)
161
         * @see org.gvsig.raster.grid.filter.RasterFilter#isVisible()
162
         */
163
        public boolean isVisible() {
164
                //IRasterDataSource datasource = (IRasterDataSource)getEnv().get("MultiRasterDataset");
165
                //return (datasource != null && datasource.getBandCount() >= 3);
166
                return true;
167
        }
168
169
        /*
170
         * (non-Javadoc)
171
         * @see org.gvsig.raster.grid.filter.RasterFilter#getInRasterDataType()
172
         */
173
        public int getInRasterDataType() {
174
                return Buffer.TYPE_BYTE;
175
        }
176
}