Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / BrightnessFilter.java @ 29786

History | View | Annotate | Download (4.07 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.buffer.cache.RasterReadOnlyBuffer;
23
import org.gvsig.raster.dataset.IBuffer;
24
import org.gvsig.raster.dataset.Params;
25
import org.gvsig.raster.grid.filter.RasterFilter;
26
/**
27
 * Clase base para los filtros de brillo.
28
 *
29
 * @version 31/05/2007
30
 * @author Miguel ?ngel Querol Carratal?  (miguelangel.querol@iver.es)
31
 */
32
public class BrightnessFilter extends RasterFilter {
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
                incrBrillo = ((Integer) params.get("incrBrillo")).intValue();
55
                raster = rasterResult;
56
                raster = (RasterBuffer) params.get("raster");
57
                if (raster != null) {
58
                        height = raster.getHeight();
59
                        width = raster.getWidth();
60
                        rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
61
                }
62
        }
63

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

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

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

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

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

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

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

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

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

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