Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / BrightnessFilter.java @ 12333

History | View | Annotate | Download (3.81 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 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.enhancement;
20

    
21
import org.gvsig.raster.buffer.RasterBuffer;
22
import org.gvsig.raster.dataset.IBuffer;
23
import org.gvsig.raster.dataset.Params;
24
import org.gvsig.raster.grid.filter.RasterFilter;
25
/**
26
 * Clase basa para los filtros de brillo.
27
 *
28
 * @version 31/05/2007
29
 * @author Miguel ?ngel Querol Carratal?  (miguelangel.querol@iver.es)
30
 */
31
public class BrightnessFilter extends RasterFilter {
32
        protected IBuffer                                rasterResult = null;
33
        public static String[]        names = new String[] {"brightness"};
34

    
35
        /**
36
         * Variable para guardar el incremento de brillo que se va a aplicar
37
         */
38
        int incrBrillo = 0;
39

    
40
        /**
41
         * Constructor. Llama al constructor de la clase base y asigna el
42
         * nombre del filtro.
43
         */
44
        public BrightnessFilter() {
45
                setName(names[0]);
46
        }
47

    
48
        /*
49
         * (non-Javadoc)
50
         * @see org.gvsig.raster.grid.filter.RasterFilter#pre()
51
         */
52
        public void pre() {
53
                exec = true;
54
                raster = (RasterBuffer) params.get("raster");
55
                height = raster.getHeight();
56
                width = raster.getWidth();
57
                incrBrillo = ((Integer) params.get("incrBrillo")).intValue();
58
        }
59

    
60
        /*
61
         * (non-Javadoc)
62
         * @see org.gvsig.raster.grid.filter.RasterFilter#post()
63
         */
64
        public void post() {
65
                // En caso de que nadie apunte a raster, se liberar? su memoria.
66
                raster = null;
67
        }
68

    
69
        /**
70
         * Obtiene el incremento de brillo que se est? aplicando
71
         * @return entero que representa el incremento de brillo aplicado.
72
         */
73
        public int getBrightnessIncrease() {
74
                return this.incrBrillo;
75
        }
76

    
77
        /*
78
         * (non-Javadoc)
79
         * @see org.gvsig.raster.grid.filter.IRasterFilter#getGroup()
80
         */
81
        public String getGroup() {
82
                return "basics";
83
        }
84

    
85
        /*
86
         * (non-Javadoc)
87
         * @see org.gvsig.raster.grid.filter.IRasterFilter#getParams()
88
         */
89
        public Params getUIParams(String nameFilter) {
90
                Params params = new Params();
91
                params.setParam("Brightness",
92
                                incrBrillo + "",
93
                                Params.SLIDER,
94
                                new String[]{ "-255", "255", "50", "1", "25" }); //min, max, valor defecto, intervalo peque?o, intervalo grande;
95
                return params;
96
        }
97

    
98
        /*
99
         * (non-Javadoc)
100
         * @see org.gvsig.raster.grid.filter.RasterFilter#getInRasterDataType()
101
         */
102
        public int getInRasterDataType() {
103
                return 0;
104
        }
105

    
106
        /*
107
         * (non-Javadoc)
108
         * @see org.gvsig.raster.grid.filter.RasterFilter#getOutRasterDataType()
109
         */
110
        public int getOutRasterDataType() {
111
                return 0;
112
        }
113

    
114
        /*
115
         * (non-Javadoc)
116
         * @see org.gvsig.raster.grid.filter.enhancement.BrightnessFilter#getResult(java.lang.String)
117
         */
118
        public Object getResult(String name) {
119
                if (name.equals("raster"))
120
                        return (Object) this.rasterResult;
121
                return null;
122
        }
123

    
124
        /*
125
         * (non-Javadoc)
126
         * @see org.gvsig.raster.grid.filter.RasterFilter#process(int, int)
127
         */
128
        public void process(int x, int y) {
129
        }
130

    
131
        /**
132
         * Calcula el brillo para un pixel
133
         * @param px
134
         * @return
135
         */
136
        protected int calcBrightness(int px) {
137
                px += incrBrillo;
138
                if (px > 255)
139
                        px = 255;
140
                else if (px < 0)
141
                        px = 0;
142
                return px;
143
        }
144

    
145
        /*
146
         * (non-Javadoc)
147
         * @see org.gvsig.raster.grid.filter.RasterFilter#getName()
148
         */
149
        public String[] getNames() {
150
                return names;
151
        }
152
}