Statistics
| Revision:

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

History | View | Annotate | Download (4.01 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 base 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
        public static String[]        names = new String[] {"brightness"};
33

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

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

    
47
        /*
48
         * (non-Javadoc)
49
         * @see org.gvsig.raster.grid.filter.RasterFilter#pre()
50
         */
51
        public void pre() {
52
                exec = true;
53
                incrBrillo = ((Integer) params.get("incrBrillo")).intValue();
54
                raster = rasterResult;
55
                raster = (RasterBuffer) params.get("raster");
56
                if (raster != null) {
57
                        height = raster.getHeight();
58
                        width = raster.getWidth();
59
                        rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
60
                }
61
        }
62

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

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

    
80
        /*
81
         * (non-Javadoc)
82
         * @see org.gvsig.raster.grid.filter.IRasterFilter#getGroup()
83
         */
84
        public String getGroup() {
85
                return "realces";
86
        }
87

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

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

    
109
        /*
110
         * (non-Javadoc)
111
         * @see org.gvsig.raster.grid.filter.RasterFilter#getOutRasterDataType()
112
         */
113
        public int getOutRasterDataType() {
114
                return RasterBuffer.TYPE_BYTE;
115
        }
116

    
117
        /*
118
         * (non-Javadoc)
119
         * @see org.gvsig.raster.grid.filter.enhancement.BrightnessFilter#getResult(java.lang.String)
120
         */
121
        public Object getResult(String name) {
122
                if (name.equals("raster")) {
123
                        if (!exec)
124
                                return this.raster;
125
                        return this.rasterResult;
126
                }
127
                return null;
128
        }
129

    
130
        /*
131
         * (non-Javadoc)
132
         * @see org.gvsig.raster.grid.filter.RasterFilter#process(int, int)
133
         */
134
        public void process(int x, int y) {
135
        }
136

    
137
        /**
138
         * Calcula el brillo para un pixel
139
         * @param px
140
         * @return
141
         */
142
        protected int calcBrightness(int px) {
143
                px += incrBrillo;
144
                if (px > 255)
145
                        px = 255;
146
                else if (px < 0)
147
                        px = 0;
148
                return px;
149
        }
150

    
151
        /*
152
         * (non-Javadoc)
153
         * @see org.gvsig.raster.grid.filter.RasterFilter#getName()
154
         */
155
        public String[] getNames() {
156
                return names;
157
        }
158
}